Skip to content

Commit 8fc1d0a

Browse files
committed
Publish as ESM only
1 parent 7fdd84e commit 8fc1d0a

13 files changed

+29
-175
lines changed

eslint.config.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ export default tsConfig(
764764
'n/no-missing-import': [
765765
'error',
766766
{
767-
allowModules: ['graphql', 'graphql-esm'],
767+
allowModules: ['graphql'],
768768
},
769769
],
770770
'n/no-missing-require': [

integrationTests/node/index.cjs renamed to integrationTests/node/index.js

+6-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
'use strict';
2-
3-
const assert = require('node:assert');
4-
const { readFileSync } = require('node:fs');
5-
6-
const {
7-
experimentalExecuteIncrementally,
8-
graphqlSync,
9-
parse,
10-
} = require('graphql');
11-
const { buildSchema } = require('graphql/utilities');
12-
const { version } = require('graphql/version');
1+
import assert from 'node:assert';
2+
import { readFileSync } from 'node:fs';
3+
4+
import { experimentalExecuteIncrementally, graphqlSync, parse } from 'graphql';
5+
import { buildSchema } from 'graphql/utilities';
6+
import { version } from 'graphql/version';
137

148
assert.deepStrictEqual(
159
version,

integrationTests/node/index.mjs

-54
This file was deleted.

integrationTests/node/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"test": "node test.js"
77
},
88
"dependencies": {
9-
"graphql": "file:../graphql.tgz",
10-
"graphql-esm": "file:../graphql-esm.tgz"
9+
"graphql": "file:../graphql.tgz"
1110
}
1211
}

integrationTests/node/test.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@ for (const version of nodeVersions) {
1515
console.log(`Testing on node@${version} ...`);
1616

1717
childProcess.execSync(
18-
`docker run --rm --volume "$PWD":/usr/src/app -w /usr/src/app node:${version}-slim node ./index.cjs`,
19-
{ stdio: 'inherit' },
20-
);
21-
22-
childProcess.execSync(
23-
`docker run --rm --volume "$PWD":/usr/src/app -w /usr/src/app node:${version}-slim node ./index.mjs`,
18+
`docker run --rm --volume "$PWD":/usr/src/app -w /usr/src/app node:${version}-slim node ./index.js`,
2419
{ stdio: 'inherit' },
2520
);
2621
}

integrationTests/ts/esm.ts

-38
This file was deleted.

integrationTests/ts/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
},
88
"dependencies": {
99
"graphql": "file:../graphql.tgz",
10-
"graphql-esm": "file:../graphql-esm.tgz",
1110
"typescript-4.9": "npm:[email protected]",
1211
"typescript-5.0": "npm:[email protected]",
1312
"typescript-5.1": "npm:[email protected]",

integrationTests/webpack/entry-esm.mjs

-10
This file was deleted.

integrationTests/webpack/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
},
88
"dependencies": {
99
"graphql": "file:../graphql.tgz",
10-
"graphql-esm": "file:../graphql-esm.tgz",
1110
"webpack": "5.x.x",
1211
"webpack-cli": "4.x.x"
1312
}

integrationTests/webpack/test.js

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
import assert from 'node:assert';
22

33
/* eslint-disable n/no-missing-import */
4-
import cjs from './dist/main-cjs.cjs';
5-
import mjs from './dist/main-mjs.cjs';
4+
import js from './dist/main-js.js';
65
/* eslint-enable n/no-missing-import */
76

8-
assert.deepStrictEqual(cjs.result, {
9-
data: {
10-
__proto__: null,
11-
hello: 'world',
12-
},
13-
});
14-
15-
assert.deepStrictEqual(mjs.result, {
7+
assert.deepStrictEqual(js.result, {
168
data: {
179
__proto__: null,
1810
hello: 'world',

integrationTests/webpack/webpack.config.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
{
22
"mode": "production",
33
"entry": {
4-
"cjs": "./entry.js",
5-
"mjs": "./entry-esm.mjs"
4+
"js": "./entry.js"
65
},
76
"output": {
8-
"filename": "main-[name].cjs",
7+
"filename": "main-[name].js",
98
"library": {
109
"type": "commonjs2"
1110
}

resources/build-npm.ts

+16-31
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,10 @@ import {
1515
} from './utils.js';
1616

1717
console.log('\n./npmDist');
18-
await buildPackage('./npmDist', false);
18+
await buildPackage('./npmDist');
1919
showDirStats('./npmDist');
2020

21-
console.log('\n./npmEsmDist');
22-
await buildPackage('./npmEsmDist', true);
23-
showDirStats('./npmEsmDist');
24-
25-
async function buildPackage(outDir: string, isESMOnly: boolean): Promise<void> {
21+
async function buildPackage(outDir: string): Promise<void> {
2622
fs.rmSync(outDir, { recursive: true, force: true });
2723
fs.mkdirSync(outDir);
2824

@@ -82,36 +78,25 @@ async function buildPackage(outDir: string, isESMOnly: boolean): Promise<void> {
8278
);
8379
}
8480

85-
if (isESMOnly) {
86-
packageJSON.exports = {};
81+
packageJSON.exports = {};
8782

88-
const { emittedTSFiles } = emitTSFiles({
89-
outDir,
90-
module: 'es2020',
91-
extension: '.js',
92-
});
83+
const { emittedTSFiles } = emitTSFiles({
84+
outDir,
85+
module: 'es2020',
86+
extension: '.js',
87+
});
9388

94-
for (const filepath of emittedTSFiles) {
95-
if (path.basename(filepath) === 'index.js') {
96-
const relativePath = './' + path.relative('./npmEsmDist', filepath);
97-
packageJSON.exports[path.dirname(relativePath)] = relativePath;
98-
}
89+
for (const filepath of emittedTSFiles) {
90+
if (path.basename(filepath) === 'index.js') {
91+
const relativePath = './' + path.relative('./npmDist', filepath);
92+
packageJSON.exports[path.dirname(relativePath)] = relativePath;
9993
}
100-
101-
// Temporary workaround to allow "internal" imports, no grantees provided
102-
packageJSON.exports['./*.js'] = './*.js';
103-
packageJSON.exports['./*'] = './*.js';
104-
105-
packageJSON.publishConfig.tag += '-esm';
106-
packageJSON.version += '+esm';
107-
} else {
108-
delete packageJSON.type;
109-
packageJSON.main = 'index';
110-
packageJSON.module = 'index.mjs';
111-
emitTSFiles({ outDir, module: 'commonjs', extension: '.js' });
112-
emitTSFiles({ outDir, module: 'es2020', extension: '.mjs' });
11394
}
11495

96+
// Temporary workaround to allow "internal" imports, no grantees provided
97+
packageJSON.exports['./*.js'] = './*.js';
98+
packageJSON.exports['./*'] = './*.js';
99+
115100
const packageJsonPath = `./${outDir}/package.json`;
116101
const prettified = await prettify(
117102
packageJsonPath,

resources/integration-test.ts

-6
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ describe('Integration Tests', () => {
1616
const archiveName = npm({ cwd: tmpDirPath(), quiet: true }).pack(distDir);
1717
fs.renameSync(tmpDirPath(archiveName), tmpDirPath('graphql.tgz'));
1818

19-
const esmDistDir = localRepoPath('npmEsmDist');
20-
const archiveEsmName = npm({ cwd: tmpDirPath(), quiet: true }).pack(
21-
esmDistDir,
22-
);
23-
fs.renameSync(tmpDirPath(archiveEsmName), tmpDirPath('graphql-esm.tgz'));
24-
2519
npm().run('build:deno');
2620

2721
function testOnNodeProject(projectName: string) {

0 commit comments

Comments
 (0)