Skip to content

Commit a52327f

Browse files
committed
npm esm tag
1 parent cce8a85 commit a52327f

20 files changed

+269
-21
lines changed

.babelrc-npm.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222
"plugins": [
2323
["./resources/add-extension-to-import-paths", { "extension": "mjs" }]
2424
]
25+
},
26+
"esm": {
27+
"presets": [
28+
["@babel/preset-env", { "modules": false, "targets": { "node": "12" } }]
29+
],
30+
"plugins": [
31+
["./resources/add-extension-to-import-paths", { "extension": "js" }]
32+
]
2533
}
2634
}
2735
}

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/node_modules
44
/coverage
55
/npmDist
6+
/npmEsmDist
67
/denoDist
78
/npm
89
/deno

.eslintrc.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,10 @@ rules:
442442
yield-star-spacing: off
443443

444444
overrides:
445+
- files:
446+
- 'integrationTests/node-esm/**/*.js'
447+
parserOptions:
448+
sourceType: module
445449
- files: '**/*.ts'
446450
parser: '@typescript-eslint/parser'
447451
parserOptions:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
/node_modules
1212
/coverage
1313
/npmDist
14+
/npmEsmDist
1415
/denoDist
1516
/npm
1617
/deno

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
/node_modules
55
/coverage
66
/npmDist
7+
/npmEsmDist
78
/denoDist
89
/npm
910
/deno

integrationTests/integration-test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ describe('Integration Tests', () => {
2727
path.join(tmpDir, 'graphql.tgz'),
2828
);
2929

30+
const esmDistDir = path.resolve('./npmEsmDist');
31+
const esmArchiveName = exec(`npm --quiet pack ${esmDistDir}`, {
32+
cwd: tmpDir,
33+
});
34+
35+
fs.renameSync(
36+
path.join(tmpDir, esmArchiveName),
37+
path.join(tmpDir, 'graphql-esm.tgz'),
38+
);
39+
3040
function testOnNodeProject(projectName) {
3141
const projectPath = path.join(__dirname, projectName);
3242

@@ -44,5 +54,6 @@ describe('Integration Tests', () => {
4454

4555
testOnNodeProject('ts');
4656
testOnNodeProject('node');
57+
testOnNodeProject('node-esm');
4758
testOnNodeProject('webpack');
4859
});

integrationTests/node-esm/index.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* eslint-disable node/no-missing-import, import/no-unresolved, node/no-unsupported-features/es-syntax */
2+
3+
import { deepStrictEqual, strictEqual } from 'assert';
4+
5+
import { version } from 'version';
6+
import { schema } from 'schema';
7+
8+
import { graphqlSync } from 'graphql';
9+
10+
// Import without explicit extension
11+
import { isPromise } from 'graphql/jsutils/isPromise';
12+
13+
// Import package.json
14+
import pkg from 'graphql/package.json';
15+
16+
deepStrictEqual(`${version}-esm`, pkg.version);
17+
18+
const result = graphqlSync({
19+
schema,
20+
source: '{ hello }',
21+
rootValue: { hello: 'world' },
22+
});
23+
24+
deepStrictEqual(result, {
25+
data: {
26+
__proto__: null,
27+
hello: 'world',
28+
},
29+
});
30+
31+
strictEqual(isPromise(Promise.resolve()), true);
32+
33+
// The possible promise rejection is handled by "--unhandled-rejections=strict"
34+
import('graphql/jsutils/isPromise').then((isPromisePkg) => {
35+
strictEqual(isPromisePkg.isPromise(Promise.resolve()), true);
36+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"type": "module",
3+
"description": "graphql-js ESM should work on all supported node versions",
4+
"scripts": {
5+
"test": "node test.js"
6+
},
7+
"dependencies": {
8+
"graphql": "file:../graphql-esm.tgz",
9+
"node-12": "npm:[email protected]",
10+
"node-14": "npm:[email protected]",
11+
"node-16": "npm:[email protected]",
12+
"schema": "file:./schema",
13+
"version": "file:./version"
14+
}
15+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "schema",
3+
"exports": {
4+
".": {
5+
"import": "./schema.mjs"
6+
}
7+
},
8+
"peerDependencies": {
9+
"graphql": "*"
10+
}
11+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { buildSchema } from 'graphql/utilities';
2+
3+
export const schema = buildSchema('type Query { hello: String }');

0 commit comments

Comments
 (0)