Skip to content

Commit

Permalink
feat: Add types and ES module build (#270)
Browse files Browse the repository at this point in the history
Co-authored-by: Jimmy Jia <[email protected]>
  • Loading branch information
itajaja and taion authored Jun 10, 2020
1 parent 5c6f66b commit b3962a5
Show file tree
Hide file tree
Showing 12 changed files with 1,267 additions and 550 deletions.
7 changes: 0 additions & 7 deletions .babelrc

This file was deleted.

12 changes: 12 additions & 0 deletions .babelrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = (api) => ({
presets: [
[
'@babel/env',
{
bugfixes: true,
loose: true,
modules: api.env() === 'esm' ? false : 'commonjs',
},
],
],
});
7 changes: 7 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
!.babelrc.js
!.eslintrc.js

**/coverage/
**/lib/
**/es/
**/node_modules/
13 changes: 0 additions & 13 deletions .eslintrc

This file was deleted.

7 changes: 7 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
extends: ['4catalyzer', '4catalyzer-jest', 'prettier'],
plugins: ['prettier'],
rules: {
'prettier/prettier': 'error',
},
};
93 changes: 88 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,118 @@
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directory
node_modules
# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Transpiled code
# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2

.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.pnp.*

# Transpiled code.
/lib
/es
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ export default makeExecutableSchema({ typeDefs, resolvers });

[build-badge]: https://img.shields.io/travis/taion/graphql-type-json/master.svg
[build]: https://travis-ci.org/taion/graphql-type-json

[npm-badge]: https://img.shields.io/npm/v/graphql-type-json.svg
[npm]: https://www.npmjs.com/package/graphql-type-json

[codecov-badge]: https://img.shields.io/codecov/c/github/taion/graphql-type-json/master.svg
[codecov]: https://codecov.io/gh/taion/graphql-type-json
33 changes: 23 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,24 @@
"version": "0.3.1",
"description": "JSON scalar types for GraphQL.js",
"files": [
"lib"
"lib",
"es"
],
"main": "lib/index.js",
"module": "es/index.js",
"types": "lib/index.d.ts",
"scripts": {
"build": "babel src -d lib --delete-dir-on-start",
"lint": "eslint src test",
"build": "npm run build:cjs && npm run build:esm && npm run build:types",
"build:cjs": "babel -d lib --delete-dir-on-start src",
"build:esm": "babel --env-name esm -d es --delete-dir-on-start src",
"build:types": "cpy types/*.d.ts lib",
"format": "eslint --fix . && npm run prettier -- --write",
"lint": "eslint . && npm run prettier -- -l",
"prepublish": "npm run build",
"prettier": "prettier --ignore-path .eslintignore '**/*.{md,ts,tsx}'",
"tdd": "jest --watch",
"test": "npm run lint && npm run testonly -- --coverage",
"test": "npm run lint && npm run test:ts && npm run testonly -- --coverage",
"test:ts": "dtslint types",
"testonly": "jest --runInBand --verbose"
},
"husky": {
Expand All @@ -20,7 +29,8 @@
}
},
"lint-staged": {
"*.js": "eslint --fix"
"*.js": "eslint --fix",
"*.{md,ts}": "prettier --write"
},
"prettier": {
"printWidth": 79,
Expand All @@ -46,26 +56,29 @@
"url": "https://github.com/taion/graphql-type-json/issues"
},
"homepage": "https://github.com/taion/graphql-type-json#readme",
"peerDependencies": {
"graphql": ">=0.8.0"
},
"devDependencies": {
"@babel/cli": "^7.10.1",
"@babel/core": "^7.10.2",
"@babel/preset-env": "^7.10.2",
"babel-jest": "^26.0.1",
"codecov": "^3.7.0",
"cpy-cli": "^3.1.1",
"dtslint": "^3.6.11",
"eslint": "^7.2.0",
"eslint-config-4catalyzer": "^1.1.2",
"eslint-config-4catalyzer-jest": "^2.0.7",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-import": "^2.21.1",
"eslint-plugin-import": "^2.21.2",
"eslint-plugin-jest": "^23.13.2",
"eslint-plugin-prettier": "^3.1.3",
"graphql": "^15.1.0",
"husky": "^4.2.5",
"jest": "^26.0.1",
"lint-staged": "^10.2.9",
"prettier": "^2.0.5"
"prettier": "^2.0.5",
"typescript": "^3.9.5"
},
"peerDependencies": {
"graphql": ">=0.8.0"
}
}
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function parseLiteral(typeName, ast, variables) {
}

// This named export is intended for users of CommonJS. Users of ES modules
// should instead use the default export.
// should instead use the default export.
export const GraphQLJSON = new GraphQLScalarType({
name: 'JSON',
description:
Expand Down
11 changes: 11 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// TypeScript Version: 3.0

import { GraphQLScalarType } from 'graphql';

// This named export is intended for users of CommonJS. Users of ES modules
// should instead use the default export.
export const GraphQLJSON: GraphQLScalarType;

export default GraphQLJSON;

export const GraphQLJSONObject: GraphQLScalarType;
10 changes: 10 additions & 0 deletions types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"forceConsistentCasingInFileNames": true,
"lib": ["es2015", "esnext.asynciterable"],
"strict": true,
"types": [],
"noEmit": true,
"baseUrl": "."
}
}
Loading

0 comments on commit b3962a5

Please sign in to comment.