diff --git a/packages/graphiql/.browserslistrc b/.browserslistrc similarity index 100% rename from packages/graphiql/.browserslistrc rename to .browserslistrc diff --git a/.gitignore b/.gitignore index 3abf2603e67..62c0f1f5019 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ node_modules/ npm-debug.log lerna-debug.log **/tsconfig.tsbuildinfo +**/*.tsbuildinfo diff --git a/babel.config.js b/babel.config.js index 5646fbbd7ff..67202d07106 100644 --- a/babel.config.js +++ b/babel.config.js @@ -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'), ], diff --git a/jest.config.js b/jest.config.js index 6e34f3c9a6c..0086cf70186 100644 --- a/jest.config.js +++ b/jest.config.js @@ -5,8 +5,8 @@ const { jsWithBabel: jsWithBabelPreset } = require('ts-jest/presets'); module.exports = { globals: { 'ts-jest': { - tsConfig: './tsconfig.base.json' - } + tsConfig: './resources/tsconfig.base.esm.json', + }, }, verbose: true, clearMocks: true, @@ -19,12 +19,13 @@ module.exports = { transform: { '^.+\\.jsx?$': require.resolve('./resources/jestBabelTransform'), ...tsjPreset.transform, - ...jsWithBabelPreset.transform + ...jsWithBabelPreset.transform, }, testEnvironment: require.resolve('jest-environment-jsdom-global'), testPathIgnorePatterns: ['node_modules', 'dist', 'codemirror-graphql'], collectCoverageFrom: [ '**/src/**/*.{js,jsx,ts,tsx}', + '!**/{dist,esm}/**', '!**/node_modules/**', '!**/__tests__/**', '!**/resources/**', diff --git a/package.json b/package.json index 6d2afcc2dd1..df07f39c4cb 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/packages/codemirror-graphql/.npmignore b/packages/codemirror-graphql/.npmignore new file mode 100644 index 00000000000..76d2c8e5aab --- /dev/null +++ b/packages/codemirror-graphql/.npmignore @@ -0,0 +1,4 @@ +babel.config.js +.gitignore +resources +src diff --git a/packages/codemirror-graphql/babel.config.js b/packages/codemirror-graphql/babel.config.js index 5646fbbd7ff..bc2cb5401c6 100644 --- a/packages/codemirror-graphql/babel.config.js +++ b/packages/codemirror-graphql/babel.config.js @@ -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') diff --git a/packages/codemirror-graphql/package.json b/packages/codemirror-graphql/package.json index df611794d7a..312abf0add8 100644 --- a/packages/codemirror-graphql/package.json +++ b/packages/codemirror-graphql/package.json @@ -14,20 +14,13 @@ }, "license": "MIT", "files": [ - "dist", - "hint.js", - "info.js", - "jump.js", - "lint.js", - "mode.js", + "esm", + "*.js", "*.flow", "utils", "variables", - "results", - "README.md", - "LICENSE" + "results" ], - "main": "dist", "options": { "mocha": "--full-trace --require resources/mochaBootload src/*/__tests__/*-test.js", "mocha_tdd": "--full-trace --watch --require resources/mochaBootload src/**/*/__tests__/*-test.js" @@ -35,8 +28,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", diff --git a/packages/examples/graphiql-cdn/index.html b/packages/examples/graphiql-cdn/index.html index 31795dd79de..5b2d5def130 100644 --- a/packages/examples/graphiql-cdn/index.html +++ b/packages/examples/graphiql-cdn/index.html @@ -36,13 +36,10 @@ favored resource bundler. --> - - -