Skip to content

Publish as ESM only #4385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ export default tsConfig(
'n/no-missing-import': [
'error',
{
allowModules: ['graphql', 'graphql-esm'],
allowModules: ['graphql'],
},
],
'n/no-missing-require': [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
'use strict';

const assert = require('node:assert');
const { readFileSync } = require('node:fs');

const {
experimentalExecuteIncrementally,
graphqlSync,
parse,
} = require('graphql');
const { buildSchema } = require('graphql/utilities');
const { version } = require('graphql/version');
import assert from 'node:assert';
import { readFileSync } from 'node:fs';

import { experimentalExecuteIncrementally, graphqlSync, parse } from 'graphql';
import { buildSchema } from 'graphql/utilities';
import { version } from 'graphql/version';

assert.deepStrictEqual(
version,
Expand Down
54 changes: 0 additions & 54 deletions integrationTests/node/index.mjs

This file was deleted.

3 changes: 1 addition & 2 deletions integrationTests/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"test": "node test.js"
},
"dependencies": {
"graphql": "file:../graphql.tgz",
"graphql-esm": "file:../graphql-esm.tgz"
"graphql": "file:../graphql.tgz"
}
}
7 changes: 1 addition & 6 deletions integrationTests/node/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ for (const version of nodeVersions) {
console.log(`Testing on node@${version} ...`);

childProcess.execSync(
`docker run --rm --volume "$PWD":/usr/src/app -w /usr/src/app node:${version}-slim node ./index.cjs`,
{ stdio: 'inherit' },
);

childProcess.execSync(
`docker run --rm --volume "$PWD":/usr/src/app -w /usr/src/app node:${version}-slim node ./index.mjs`,
`docker run --rm --volume "$PWD":/usr/src/app -w /usr/src/app node:${version}-slim node ./index.js`,
{ stdio: 'inherit' },
);
}
38 changes: 0 additions & 38 deletions integrationTests/ts/esm.ts

This file was deleted.

1 change: 0 additions & 1 deletion integrationTests/ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
},
"dependencies": {
"graphql": "file:../graphql.tgz",
"graphql-esm": "file:../graphql-esm.tgz",
"typescript-4.9": "npm:[email protected]",
"typescript-5.0": "npm:[email protected]",
"typescript-5.1": "npm:[email protected]",
Expand Down
10 changes: 0 additions & 10 deletions integrationTests/webpack/entry-esm.mjs

This file was deleted.

1 change: 0 additions & 1 deletion integrationTests/webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
},
"dependencies": {
"graphql": "file:../graphql.tgz",
"graphql-esm": "file:../graphql-esm.tgz",
"webpack": "5.x.x",
"webpack-cli": "4.x.x"
}
Expand Down
12 changes: 2 additions & 10 deletions integrationTests/webpack/test.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
import assert from 'node:assert';

/* eslint-disable n/no-missing-import */
import cjs from './dist/main-cjs.cjs';
import mjs from './dist/main-mjs.cjs';
import { result } from './dist/main-js.js';
/* eslint-enable n/no-missing-import */

assert.deepStrictEqual(cjs.result, {
data: {
__proto__: null,
hello: 'world',
},
});

assert.deepStrictEqual(mjs.result, {
assert.deepStrictEqual(result, {
data: {
__proto__: null,
hello: 'world',
Expand Down
10 changes: 6 additions & 4 deletions integrationTests/webpack/webpack.config.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{
"experiments": {
"outputModule": true
},
"mode": "production",
"entry": {
"cjs": "./entry.js",
"mjs": "./entry-esm.mjs"
"js": "./entry.js"
},
"output": {
"filename": "main-[name].cjs",
"filename": "main-[name].js",
"library": {
"type": "commonjs2"
"type": "module"
}
}
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"graphql-js"
],
"engines": {
"node": "^16.19.0 || ^18.14.0 || >=19.7.0"
"node": ">=19.7.0 || >=20.0.0 || >=22.0.0"
},
"scripts": {
"preversion": "bash -c '. ./resources/checkgit.sh && npm ci --ignore-scripts'",
Expand Down
47 changes: 16 additions & 31 deletions resources/build-npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@ import {
} from './utils.js';

console.log('\n./npmDist');
await buildPackage('./npmDist', false);
await buildPackage('./npmDist');
showDirStats('./npmDist');

console.log('\n./npmEsmDist');
await buildPackage('./npmEsmDist', true);
showDirStats('./npmEsmDist');

async function buildPackage(outDir: string, isESMOnly: boolean): Promise<void> {
async function buildPackage(outDir: string): Promise<void> {
fs.rmSync(outDir, { recursive: true, force: true });
fs.mkdirSync(outDir);

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

if (isESMOnly) {
packageJSON.exports = {};
packageJSON.exports = {};

const { emittedTSFiles } = emitTSFiles({
outDir,
module: 'es2020',
extension: '.js',
});
const { emittedTSFiles } = emitTSFiles({
outDir,
module: 'es2020',
extension: '.js',
});

for (const filepath of emittedTSFiles) {
if (path.basename(filepath) === 'index.js') {
const relativePath = './' + path.relative('./npmEsmDist', filepath);
packageJSON.exports[path.dirname(relativePath)] = relativePath;
}
for (const filepath of emittedTSFiles) {
if (path.basename(filepath) === 'index.js') {
const relativePath = './' + path.relative('./npmDist', filepath);
packageJSON.exports[path.dirname(relativePath)] = relativePath;
}

// Temporary workaround to allow "internal" imports, no grantees provided
packageJSON.exports['./*.js'] = './*.js';
packageJSON.exports['./*'] = './*.js';

packageJSON.publishConfig.tag += '-esm';
packageJSON.version += '+esm';
} else {
delete packageJSON.type;
packageJSON.main = 'index';
packageJSON.module = 'index.mjs';
emitTSFiles({ outDir, module: 'commonjs', extension: '.js' });
emitTSFiles({ outDir, module: 'es2020', extension: '.mjs' });
}

// Temporary workaround to allow "internal" imports, no grantees provided
packageJSON.exports['./*.js'] = './*.js';
packageJSON.exports['./*'] = './*.js';

const packageJsonPath = `./${outDir}/package.json`;
const prettified = await prettify(
packageJsonPath,
Expand Down
6 changes: 0 additions & 6 deletions resources/integration-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ describe('Integration Tests', () => {
const archiveName = npm({ cwd: tmpDirPath(), quiet: true }).pack(distDir);
fs.renameSync(tmpDirPath(archiveName), tmpDirPath('graphql.tgz'));

const esmDistDir = localRepoPath('npmEsmDist');
const archiveEsmName = npm({ cwd: tmpDirPath(), quiet: true }).pack(
esmDistDir,
);
fs.renameSync(tmpDirPath(archiveEsmName), tmpDirPath('graphql-esm.tgz'));

npm().run('build:deno');

function testOnNodeProject(projectName: string) {
Expand Down
Loading