Skip to content

Commit a28ef99

Browse files
try esm only
Co-Authored-By: Yaacov Rydzinski <[email protected]>
1 parent 3283f8a commit a28ef99

File tree

13 files changed

+31
-108
lines changed

13 files changed

+31
-108
lines changed

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
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.mjs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
11
import assert from 'node:assert';
2-
import { readFileSync } from 'node:fs';
3-
4-
import {
5-
experimentalExecuteIncrementally,
6-
graphqlSync,
7-
parse,
8-
} from 'graphql-esm';
9-
import { buildSchema } from 'graphql-esm/utilities';
10-
import { version } from 'graphql-esm/version';
11-
12-
assert.deepStrictEqual(
13-
version + '+esm',
14-
JSON.parse(readFileSync('./node_modules/graphql-esm/package.json')).version,
15-
);
2+
3+
import { experimentalExecuteIncrementally, graphqlSync, parse } from 'graphql';
4+
import { buildSchema } from 'graphql/utilities';
165

176
const schema = buildSchema('type Query { hello: String }');
187

integrationTests/node/package.json

Lines changed: 1 addition & 2 deletions
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/ts/esm.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
import type { ExecutionResult } from 'graphql-esm/execution';
1+
import type { ExecutionResult } from 'graphql/execution';
22

3-
import { graphqlSync } from 'graphql-esm';
4-
import {
5-
GraphQLString,
6-
GraphQLSchema,
7-
GraphQLObjectType,
8-
} from 'graphql-esm/type';
3+
import { graphqlSync } from 'graphql';
4+
import { GraphQLString, GraphQLSchema, GraphQLObjectType } from 'graphql/type';
95

106
const queryType: GraphQLObjectType = new GraphQLObjectType({
117
name: 'Query',

integrationTests/ts/package.json

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 10 deletions
This file was deleted.

integrationTests/webpack/package.json

Lines changed: 0 additions & 1 deletion
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

Lines changed: 2 additions & 10 deletions
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 main from './dist/main.cjs';
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(main.result, {
168
data: {
179
__proto__: null,
1810
hello: 'world',

integrationTests/webpack/webpack.config.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
{
22
"mode": "production",
3-
"entry": {
4-
"cjs": "./entry.js",
5-
"mjs": "./entry-esm.mjs"
6-
},
3+
"entry": "./entry.js",
74
"output": {
8-
"filename": "main-[name].cjs",
5+
"filename": "main.cjs",
96
"library": {
107
"type": "commonjs2"
118
}

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"graphql-js"
2727
],
2828
"engines": {
29-
"node": "^16.19.0 || ^18.14.0 || >=19.7.0"
29+
"node": "^20.19.0 || ^22.12.0 || >=23.0.0"
3030
},
3131
"scripts": {
3232
"preversion": "bash -c '. ./resources/checkgit.sh && npm ci --ignore-scripts'",

resources/build-npm.ts

Lines changed: 17 additions & 49 deletions
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

@@ -81,37 +77,25 @@ async function buildPackage(outDir: string, isESMOnly: boolean): Promise<void> {
8177
'Publish tag and version tag should match!',
8278
);
8379
}
80+
packageJSON.exports = {};
8481

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

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-
}
88+
for (const filepath of emittedTSFiles) {
89+
if (path.basename(filepath) === 'index.js') {
90+
const relativePath = './' + path.relative('./npmDist', filepath);
91+
packageJSON.exports[path.dirname(relativePath)] = relativePath;
9992
}
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' });
11393
}
11494

95+
// Temporary workaround to allow "internal" imports, no grantees provided
96+
packageJSON.exports['./*.js'] = './*.js';
97+
packageJSON.exports['./*'] = './*.js';
98+
11599
const packageJsonPath = `./${outDir}/package.json`;
116100
const prettified = await prettify(
117101
packageJsonPath,
@@ -140,23 +124,7 @@ function emitTSFiles(options: {
140124
});
141125

142126
const tsHost = ts.createCompilerHost(tsOptions);
143-
tsHost.writeFile = (filepath, body) => {
144-
if (filepath.match(/.js$/) && extension === '.mjs') {
145-
let bodyToWrite = body;
146-
bodyToWrite = bodyToWrite.replace(
147-
'//# sourceMappingURL=graphql.js.map',
148-
'//# sourceMappingURL=graphql.mjs.map',
149-
);
150-
writeGeneratedFile(filepath.replace(/.js$/, extension), bodyToWrite);
151-
} else if (filepath.match(/.js.map$/) && extension === '.mjs') {
152-
writeGeneratedFile(
153-
filepath.replace(/.js.map$/, extension + '.map'),
154-
body,
155-
);
156-
} else {
157-
writeGeneratedFile(filepath, body);
158-
}
159-
};
127+
tsHost.writeFile = (filepath, body) => writeGeneratedFile(filepath, body);
160128

161129
const tsProgram = ts.createProgram(['src/index.ts'], tsOptions, tsHost);
162130
const tsResult = tsProgram.emit(undefined, undefined, undefined, undefined, {

resources/integration-test.ts

Lines changed: 0 additions & 6 deletions
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)