From abb1680bc0d8bb2ca68f3c95670ce2f461eb8bfa Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Tue, 12 Mar 2019 17:01:16 -0400 Subject: [PATCH] Use esm instead of creating multiple bundles --- packages/core/cjs/index.js | 1 + packages/core/package.json | 9 ++++-- packages/core/tsconfig.es2015.json | 29 ------------------ packages/core/tsconfig.json | 2 +- packages/di/cjs/index.js | 1 + packages/di/package.json | 8 +++-- packages/di/tsconfig.es2015.json | 30 ------------------- packages/di/tsconfig.json | 2 +- packages/graphql-modules/cjs/index.js | 1 + packages/graphql-modules/package.json | 8 +++-- packages/graphql-modules/src/index.ts | 1 + packages/graphql-modules/tsconfig.es2015.json | 29 ------------------ packages/graphql-modules/tsconfig.json | 2 +- yarn.lock | 5 ++++ 14 files changed, 28 insertions(+), 100 deletions(-) create mode 100644 packages/core/cjs/index.js delete mode 100644 packages/core/tsconfig.es2015.json create mode 100644 packages/di/cjs/index.js delete mode 100644 packages/di/tsconfig.es2015.json create mode 100644 packages/graphql-modules/cjs/index.js delete mode 100644 packages/graphql-modules/tsconfig.es2015.json diff --git a/packages/core/cjs/index.js b/packages/core/cjs/index.js new file mode 100644 index 0000000000..b45eb86fa2 --- /dev/null +++ b/packages/core/cjs/index.js @@ -0,0 +1 @@ +module.exports = require('esm')(module)('../dist/index.js'); diff --git a/packages/core/package.json b/packages/core/package.json index eabc1b736c..72eaef5438 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -5,8 +5,10 @@ "homepage": "https://graphql-modules.com/", "license": "MIT", "scripts": { + "clean": "rm -rf dist", + "prebuild": "yarn clean", + "build": "tsc", "test": "jest", - "build": "tsc && tsc -p tsconfig.es2015.json", "lint": "tslint -c ../../tslint.json 'src/**/*.ts' --format stylish" }, "jest": { @@ -29,6 +31,7 @@ ] }, "dependencies": { + "esm":"3.2.16", "@graphql-modules/di": "0.4.2", "graphql-toolkit": "0.0.5", "graphql-tools": "4.0.4", @@ -43,8 +46,8 @@ "tslint": "5.12.1", "typescript": "3.3.3" }, - "main": "dist/index.js", - "module": "dist/es2015/index.js", + "main": "cjs/index.js", + "module": "dist/index.js", "typings": "./dist/index.d.ts", "typescript": { "definition": "./dist/index.d.ts" diff --git a/packages/core/tsconfig.es2015.json b/packages/core/tsconfig.es2015.json deleted file mode 100644 index 1caba4102a..0000000000 --- a/packages/core/tsconfig.es2015.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "compilerOptions": { - "experimentalDecorators": true, - "module": "es2015", - "target": "es2018", - "lib": [ - "es2018", - "esnext.asynciterable" - ], - "suppressImplicitAnyIndexErrors": true, - "moduleResolution": "node", - "emitDecoratorMetadata": true, - "sourceMap": true, - "inlineSources": true, - "declaration": true, - "outDir": "./dist/es2015", - "rootDir": "./src", - "importHelpers": true, - "noImplicitAny": true, - "noImplicitThis": true, - "alwaysStrict": true, - "noImplicitReturns": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "downlevelIteration": true - }, - "files": ["src/index.ts"], - "exclude": ["node_modules"] -} diff --git a/packages/core/tsconfig.json b/packages/core/tsconfig.json index bd7745d12d..f057a75c62 100644 --- a/packages/core/tsconfig.json +++ b/packages/core/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "experimentalDecorators": true, - "module": "commonjs", + "module": "esnext", "target": "es2018", "lib": [ "es2018", diff --git a/packages/di/cjs/index.js b/packages/di/cjs/index.js new file mode 100644 index 0000000000..b45eb86fa2 --- /dev/null +++ b/packages/di/cjs/index.js @@ -0,0 +1 @@ +module.exports = require('esm')(module)('../dist/index.js'); diff --git a/packages/di/package.json b/packages/di/package.json index 66b7f6550a..7a590b361a 100644 --- a/packages/di/package.json +++ b/packages/di/package.json @@ -5,8 +5,10 @@ "homepage": "https://graphql-modules.com/", "license": "MIT", "scripts": { + "clean": "rm -rf dist", + "prebuild": "yarn clean", + "build": "tsc", "test": "jest", - "build": "tsc && tsc -p tsconfig.es2015.json", "lint": "tslint -c ../../tslint.json 'src/**/*.ts' --format stylish" }, "jest": { @@ -44,8 +46,8 @@ "dependencies": { "tslib": "1.9.3" }, - "main": "dist/index.js", - "module": "dist/es2015/index.js", + "main": "cjs/index.js", + "module": "dist/index.js", "typings": "./dist/index.d.ts", "typescript": { "definition": "./dist/index.d.ts" diff --git a/packages/di/tsconfig.es2015.json b/packages/di/tsconfig.es2015.json deleted file mode 100644 index f79c6055f9..0000000000 --- a/packages/di/tsconfig.es2015.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "compilerOptions": { - "experimentalDecorators": true, - "module": "es2015", - "target": "es2018", - "lib": [ - "es2018", - "esnext.asynciterable" - ], - "suppressImplicitAnyIndexErrors": true, - "moduleResolution": "node", - "emitDecoratorMetadata": true, - "sourceMap": true, - "inlineSources": true, - "declaration": true, - "outDir": "./dist/es2015", - "rootDir": "./src", - "importHelpers": true, - "noImplicitAny": true, - "noImplicitThis": true, - "alwaysStrict": true, - "noImplicitReturns": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "downlevelIteration": true, - "strictFunctionTypes": true - }, - "files": ["src/index.ts"], - "exclude": ["node_modules"] -} diff --git a/packages/di/tsconfig.json b/packages/di/tsconfig.json index 26ac589498..4ccab93203 100644 --- a/packages/di/tsconfig.json +++ b/packages/di/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "experimentalDecorators": true, - "module": "commonjs", + "module": "esnext", "target": "es2018", "lib": [ "es2018", diff --git a/packages/graphql-modules/cjs/index.js b/packages/graphql-modules/cjs/index.js new file mode 100644 index 0000000000..b45eb86fa2 --- /dev/null +++ b/packages/graphql-modules/cjs/index.js @@ -0,0 +1 @@ +module.exports = require('esm')(module)('../dist/index.js'); diff --git a/packages/graphql-modules/package.json b/packages/graphql-modules/package.json index 822ab6a3e3..a08460dd69 100644 --- a/packages/graphql-modules/package.json +++ b/packages/graphql-modules/package.json @@ -5,8 +5,10 @@ "homepage": "https://graphql-modules.com/", "license": "MIT", "scripts": { + "clean": "rm -rf dist", + "prebuild": "yarn clean", + "build": "tsc", "test": "jest", - "build": "tsc && tsc -p tsconfig.es2015.json", "lint": "tslint -c ../../tslint.json 'src/**/*.ts' --format stylish" }, "jest": { @@ -41,8 +43,8 @@ "@graphql-modules/core": "0.4.2", "tslib": "1.9.3" }, - "main": "dist/index.js", - "module": "dist/es2015/index.js", + "main": "cjs/index.js", + "module": "dist/index.js", "typings": "./dist/index.d.ts", "typescript": { "definition": "./dist/index.d.ts" diff --git a/packages/graphql-modules/src/index.ts b/packages/graphql-modules/src/index.ts index c36b19f29f..9f39afaab2 100644 --- a/packages/graphql-modules/src/index.ts +++ b/packages/graphql-modules/src/index.ts @@ -1 +1,2 @@ export * from '@graphql-modules/core'; +export * from '@graphql-modules/di'; diff --git a/packages/graphql-modules/tsconfig.es2015.json b/packages/graphql-modules/tsconfig.es2015.json deleted file mode 100644 index 349083c2c0..0000000000 --- a/packages/graphql-modules/tsconfig.es2015.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "compilerOptions": { - "experimentalDecorators": true, - "module": "commonjs", - "target": "es2018", - "lib": [ - "es2018", - "esnext.asynciterable" - ], - "suppressImplicitAnyIndexErrors": true, - "moduleResolution": "node", - "emitDecoratorMetadata": true, - "sourceMap": true, - "inlineSources": true, - "declaration": true, - "outDir": "./dist/es2015", - "rootDir": "./src", - "importHelpers": true, - "noImplicitAny": true, - "noImplicitThis": true, - "alwaysStrict": true, - "noImplicitReturns": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "downlevelIteration": true - }, - "files": ["src/index.ts"], - "exclude": ["node_modules"] -} diff --git a/packages/graphql-modules/tsconfig.json b/packages/graphql-modules/tsconfig.json index bd7745d12d..f057a75c62 100644 --- a/packages/graphql-modules/tsconfig.json +++ b/packages/graphql-modules/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "experimentalDecorators": true, - "module": "commonjs", + "module": "esnext", "target": "es2018", "lib": [ "es2018", diff --git a/yarn.lock b/yarn.lock index e90eddcec8..c002cba8aa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1440,6 +1440,11 @@ escodegen@^1.6.1, escodegen@^1.9.1: optionalDependencies: source-map "~0.6.1" +esm@3.2.16: + version "3.2.16" + resolved "https://registry.yarnpkg.com/esm/-/esm-3.2.16.tgz#e48f887c29a4a981a4da0baa2ae2bf20e30b5614" + integrity sha512-iACZMQvYFc66Y7QC+vD3oGA/fFsPA/IQwewRJ3K0gbMV52E59pdko02kF2TfVdtp5aHO62PHxL6fxtHJmhm3NQ== + esprima@^3.1.3: version "3.1.3" resolved "https://registry.yarnpkg.com/esprima/-/esprima-3.1.3.tgz#fdca51cee6133895e3c88d535ce49dbff62a4633"