Skip to content

Commit

Permalink
chore: esm for all packages
Browse files Browse the repository at this point in the history
  • Loading branch information
acao committed Nov 17, 2019
1 parent 7ba107d commit e225d56
Show file tree
Hide file tree
Showing 31 changed files with 478 additions and 75 deletions.
File renamed without changes.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ node_modules/
npm-debug.log
lerna-debug.log
**/tsconfig.tsbuildinfo
**/*.tsbuildinfo
10 changes: 8 additions & 2 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@

// for ESM don't transpile modules
module.exports = {
presets: [
require.resolve('@babel/preset-env'),
[
require.resolve('@babel/preset-env'),
{
modules: process.env.ESM ? false : 'commonjs',
targets: process.env.ESM ? { node: true } : '> 0.25%, not dead'
},
],
require.resolve('@babel/preset-flow'),
require.resolve('@babel/preset-react'),
],
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"build-js": "lerna run build --scope codemirror-graphql --scope graphql-language-service-server --scope graphiql graphql-language-service",
"build-ts": "tsc --build",
"build-clean": "tsc --build --clean && rm -rf 'packages/**/src/{dist,esm,bundle}' && lerna run build-clean --parallel",
"build-demo": "lerna run build-demo",
"test": "yarn run lint && yarn run check && yarn run build && yarn run testonly && yarn run e2e",
"testonly": "jest && lerna run test --scope codemirror-graphql",
"e2e": "cd packages/graphiql && yarn e2e",
Expand Down Expand Up @@ -61,6 +62,7 @@
"chai": "4.2.0",
"codecov": "^3.5.0",
"conventional-changelog-conventionalcommits": "^4.1.0",
"copy": "^0.3.2",
"cypress": "^3.4.1",
"eslint": "^6.4.0",
"eslint-config-prettier": "6.3.0",
Expand Down
12 changes: 1 addition & 11 deletions packages/codemirror-graphql/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,2 @@

module.exports = {
presets: [
require.resolve('@babel/preset-env'),
require.resolve('@babel/preset-flow'),
require.resolve('@babel/preset-react'),
],
plugins: [
require.resolve('@babel/plugin-proposal-class-properties'),
require.resolve('@babel/plugin-syntax-dynamic-import'),
],
};
module.exports = require('../../babel.config')
5 changes: 3 additions & 2 deletions packages/codemirror-graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@
"scripts": {
"lint": "eslint src",
"check": "flow check",
"build": "yarn build-clean && yarn build-js && yarn build-flow .",
"build-js": "babel src --root-mode upward --ignore src/__tests__ --out-dir .",
"build": "yarn build-clean && yarn build-js && yarn build-esm && yarn build-flow .",
"build-js": "babel src --root-mode upward --ignore src/__tests__ --out-dir . && babel src --root-mode upward --ignore src/__tests__ --out-dir esm && node ../../resources/renameFileExtensions.js './esm/**/*.js' . .esm.js",
"build-esm": "ESM=true babel src --root-mode upward --ignore src/__tests__ --out-dir esm",
"build-clean": "rimraf {mode,hint,info,jump,lint}.{js,js.flow} && rimraf esm results utils variables coverage __tests__",
"build-flow": "node ../../resources/buildFlow.js",
"watch": "babel --optional runtime resources/watch.js | node",
Expand Down
7 changes: 2 additions & 5 deletions packages/examples/graphiql-cdn/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,10 @@
favored resource bundler.
-->
<link rel="stylesheet" href="/graphiql.css" />
<script src="/graphiql.js" type="application/javascript"></script>
<script src="/renderExample.js" type="application/javascript"></script>

</head>
<body>
<div id="graphiql">Loading...</div>
<script>
</script>
<script src="/graphiql.js" type="application/javascript"></script>
<script src="/renderExample.js" type="application/javascript"></script>
</body>
</html>
1 change: 1 addition & 0 deletions packages/graphiql/.babelrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./babel.config')
14 changes: 1 addition & 13 deletions packages/graphiql/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1 @@
module.exports = {
presets: [
[
require.resolve('@babel/preset-env'),
{
targets: '> 0.25%, not dead',
},
],
require.resolve('@babel/preset-flow'),
require.resolve('@babel/preset-react'),
],
plugins: [require.resolve('@babel/plugin-proposal-class-properties')],
};
module.exports = require('../../babel.config')
14 changes: 1 addition & 13 deletions packages/graphiql/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// https://on.cypress.io/custom-commands
// ***********************************************
//
//

Cypress.Commands.add('getCy', cyName => {
return cy.get(`[data-cy=${cyName}]`);
});
Expand Down Expand Up @@ -39,15 +39,3 @@ Cypress.Commands.add('assertQueryResult', (op, mockSuccess) => {
);
});
});
//
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This is will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
1 change: 1 addition & 0 deletions packages/graphiql/resources/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ if [ ! -d "node_modules/.bin" ]; then
fi

babel src --ignore __tests__ --out-dir dist/
ESM=true babel src --ignore __tests__ --out-dir esm/
echo "Bundling graphiql.js..."
browserify -g browserify-shim -s GraphiQL dist/index.js > graphiql.js
echo "Bundling graphiql.min.js..."
Expand Down
2 changes: 2 additions & 0 deletions packages/graphql-language-service-interface/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"graphql"
],
"main": "dist/index.js",
"module": "esm/index.js",
"typings": "esm/index.d.ts",
"scripts": {
"test": "node ../../resources/runTests.js",
"build": "yarn run build-ts && yarn run build-flow",
Expand Down
19 changes: 19 additions & 0 deletions packages/graphql-language-service-interface/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "../../resources/tsconfig.base.esm.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./esm",
"composite": true
},
"references": [
{
"path": "../graphql-language-service-parser"
},
{
"path": "../graphql-language-service-types"
},
{
"path": "../graphql-language-service-utils"
}
]
}
16 changes: 14 additions & 2 deletions packages/graphql-language-service-interface/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
{
"extends": "../../tsconfig.base",
"extends": "../../resources/tsconfig.base.cjs.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist",
}
"composite": true
},
"references": [
{
"path": "../graphql-language-service-parser"
},
{
"path": "../graphql-language-service-types"
},
{
"path": "../graphql-language-service-utils"
}
]
}
5 changes: 3 additions & 2 deletions packages/graphql-language-service-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
"keywords": [
"graphql"
],
"main": "./dist/index.js",
"typings": "./dist/index.d.ts",
"main": "dist/index.js",
"module": "esm/index.js",
"typings": "esm/index.d.ts",
"scripts": {
"build": "yarn run build-ts && yarn run build-flow",
"build-ts": "tsc",
Expand Down
13 changes: 13 additions & 0 deletions packages/graphql-language-service-parser/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../resources/tsconfig.base.esm.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./esm",
"composite": true
},
"references": [
{
"path": "../graphql-language-service-types"
}
]
}
12 changes: 9 additions & 3 deletions packages/graphql-language-service-parser/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
{
"extends": "../../tsconfig.base",
"extends": "../../resources/tsconfig.base.cjs.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist"
}
"outDir": "./dist",
"composite": true
},
"references": [
{
"path": "../graphql-language-service-types"
}
]
}
5 changes: 4 additions & 1 deletion packages/graphql-language-service-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
"graphql"
],
"main": "dist/index.js",
"module": "esm/index.js",
"typings": "esm/index.d.ts",
"scripts": {
"test": "node ../../resources/runTests.js",
"build": "yarn run build-js && yarn run build-flow",
"build": "yarn build-js && yarn build-esm && yarn build-flow",
"build-js": "node ../../resources/buildJs.js",
"build-esm": "ESM=true babel src --root-mode upward --ignore __tests__ --out-dir esm",
"build-flow": "node ../../resources/buildFlow.js",
"prepublish": "node ../../resources/prepublish.js"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/graphql-language-service-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"graphql"
],
"main": "dist/index.js",
"typings": "src/index",
"module": "esm/index.js",
"typings": "src/index.ts",
"scripts": {
"build": "yarn run build-ts && yarn run build-flow",
"build-ts": "tsc",
Expand Down
7 changes: 7 additions & 0 deletions packages/graphql-language-service-types/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../resources/tsconfig.base.esm.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./esm",
}
}
2 changes: 1 addition & 1 deletion packages/graphql-language-service-types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../tsconfig.base",
"extends": "../../resources/tsconfig.base.cjs.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist",
Expand Down
3 changes: 2 additions & 1 deletion packages/graphql-language-service-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"graphql"
],
"main": "dist/index.js",
"types": "src/index.ts",
"module": "esm/index.js",
"typings": "esm/index.d.ts",
"engines": {
"node": ">= 9.7.3"
},
Expand Down
7 changes: 7 additions & 0 deletions packages/graphql-language-service-utils/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../resources/tsconfig.base.esm.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./esm",
}
}
2 changes: 1 addition & 1 deletion packages/graphql-language-service-utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../tsconfig.base",
"extends": "../../resources/tsconfig.base.cjs.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist",
Expand Down
30 changes: 30 additions & 0 deletions resources/renameFileExtensions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const copy = require('copy');
const path = require('path');
const fs = require('fs');
const os = require('os');

const tmpDir = os.tmpdir();
const [, , src, dest, destExtension] = process.argv;
if (!src || !dest || !destExtension) {
console.error(
`\nMissing arguments.\n\nUsage:\nnode renameFileExtensions.js './dist/**/*.js' './dest-dir' .new.extension.js`,
);
process.exit(1);
}

const tempDirectory = fs.mkdtempSync(`${tmpDir}${path.sep}`);

copy(src, tempDirectory, (error, files) => {
if (error) {
throw error;
}
files.forEach(file => {
if (file.dest) {
const srcExt = path.parse(file.dest).ext;
const destinationPath = file.dest
.replace(srcExt, destExtension)
.replace(tempDirectory, dest);
fs.renameSync(file.dest, path.resolve(destinationPath));
}
});
});
2 changes: 1 addition & 1 deletion tsconfig.base.json → resources/tsconfig.base.cjs.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"composite": false,
"composite": true,
"target": "esnext",
"module": "commonjs",
"moduleResolution": "node",
Expand Down
6 changes: 6 additions & 0 deletions resources/tsconfig.base.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./tsconfig.base.cjs.json",
"compilerOptions": {
"module": "esnext"
}
}
21 changes: 21 additions & 0 deletions resources/tsconfig.build.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"composite": true
},
"files": [],
"include": [],
"references": [
{
"path": "../packages/graphql-language-service-utils"
},
{
"path": "../packages/graphql-language-service-types"
},
{
"path": "../packages/graphql-language-service-parser"
},
{
"path": "../packages/graphql-language-service-interface"
}
]
}
21 changes: 21 additions & 0 deletions resources/tsconfig.build.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"composite": true
},
"files": [],
"include": [],
"references": [
{
"path": "../packages/graphql-language-service-utils/tsconfig.esm.json"
},
{
"path": "../packages/graphql-language-service-types/tsconfig.esm.json"
},
{
"path": "../packages/graphql-language-service-parser/tsconfig.esm.json"
},
{
"path": "../packages/graphql-language-service-interface/tsconfig.esm.json"
}
]
}
10 changes: 2 additions & 8 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@
"include": [],
"references": [
{
"path": "packages/graphql-language-service-utils"
"path": "resources/tsconfig.build.esm.json"
},
{
"path": "packages/graphql-language-service-types"
},
{
"path": "packages/graphql-language-service-parser"
},
{
"path": "packages/graphql-language-service-interface"
"path": "resources/tsconfig.build.cjs.json"
}
]
}

0 comments on commit e225d56

Please sign in to comment.