Skip to content

Commit 0449966

Browse files
committed
Fully switch to ESM (scripts, tests, etc.)
1 parent 97c9512 commit 0449966

File tree

243 files changed

+1649
-1606
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

243 files changed

+1649
-1606
lines changed

.eslintrc.yml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ rules:
3535
node/no-exports-assign: error
3636
node/no-extraneous-import: error
3737
node/no-extraneous-require: error
38-
node/no-missing-import: [error, { allowModules: ['graphql'] }]
38+
node/no-missing-import: off # Blocked by https://github.com/mysticatea/eslint-plugin-node/issues/248
3939
node/no-missing-require: error
4040
node/no-new-require: error
4141
node/no-path-concat: error
@@ -81,7 +81,7 @@ rules:
8181

8282
# Static analysis
8383
# https://github.com/benmosher/eslint-plugin-import#static-analysis
84-
import/no-unresolved: [error, { ignore: ['graphql'] }]
84+
import/no-unresolved: off # blocked by https://github.com/import-js/eslint-plugin-import/issues/2170
8585
import/named: error
8686
import/default: error
8787
import/namespace: error
@@ -127,7 +127,6 @@ rules:
127127
import/extensions:
128128
- error
129129
- ignorePackages
130-
- ts: never # TODO: remove once TS supports extensions
131130
import/order: [error, { newlines-between: always-and-inside-groups }]
132131
import/newline-after-import: error
133132
import/prefer-default-export: off
@@ -691,13 +690,9 @@ overrides:
691690
env:
692691
node: true
693692
rules:
694-
internal-rules/only-ascii: [error, { allowEmoji: true }]
695693
node/no-sync: off
696694
import/no-namespace: off
697-
import/no-unresolved: off
698695
import/no-nodejs-modules: off
699-
no-console: off
700-
no-await-in-loop: off
701696
- files: 'resources/**'
702697
env:
703698
node: true
@@ -709,6 +704,7 @@ overrides:
709704
import/no-extraneous-dependencies: [error, { devDependencies: true }]
710705
import/no-nodejs-modules: off
711706
no-console: off
707+
no-await-in-loop: off
712708
- files: 'resources/eslint-internal-rules/**'
713709
env:
714710
node: true
@@ -735,7 +731,6 @@ overrides:
735731
version: detect
736732
rules:
737733
node/no-unpublished-require: off
738-
node/no-missing-import: off
739734
import/no-default-export: off
740735
import/no-commonjs: off
741736
import/no-nodejs-modules: off

.mocharc.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
fail-zero: true
22
throw-deprecation: true
33
check-leaks: true
4-
require:
5-
- 'ts-node/register/transpile-only'
64
extension:
7-
- 'ts'
5+
- ts
6+
node-option:
7+
- 'loader=ts-node/esm/transpile-only'

integrationTests/integration-test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import * as childProcess from 'node:child_process';
2-
import * as fs from 'node:fs';
3-
import * as os from 'node:os';
4-
import * as path from 'node:path';
1+
import childProcess from 'node:child_process';
2+
import fs from 'node:fs';
3+
import os from 'node:os';
4+
import path from 'node:path';
55

66
import { describe, it } from 'mocha';
77

@@ -26,7 +26,7 @@ describe('Integration Tests', () => {
2626
);
2727

2828
function testOnNodeProject(projectName: string) {
29-
const projectPath = path.join(__dirname, projectName);
29+
const projectPath = new URL(projectName, import.meta.url).pathname;
3030

3131
const packageJSONPath = path.join(projectPath, 'package.json');
3232
const packageJSON = JSON.parse(fs.readFileSync(packageJSONPath, 'utf-8'));

integrationTests/webpack/test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import assert from 'assert';
22

3-
// eslint-disable-next-line import/no-unresolved, node/no-missing-import
43
import mainCJS from './dist/main.cjs';
54

65
assert.deepStrictEqual(mainCJS.result, {

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "A Query Language and Runtime which can target any service.",
55
"license": "MIT",
66
"private": true,
7+
"type": "module",
78
"typesVersions": {
89
">=4.4.0": {
910
"*": [
@@ -32,7 +33,7 @@
3233
"version": "ts-node resources/gen-version.ts && npm test && git add src/version.ts",
3334
"fuzzonly": "mocha --full-trace src/**/__tests__/**/*-fuzz.ts",
3435
"changelog": "ts-node resources/gen-changelog.ts",
35-
"benchmark": "ts-node benchmark/benchmark.ts",
36+
"benchmark": "ts-node resources/benchmark.ts",
3637
"test": "npm run lint && npm run check && npm run testonly:cover && npm run prettier:check && npm run check:spelling && npm run check:integrations",
3738
"lint": "eslint --cache --max-warnings 0 .",
3839
"check": "tsc --pretty",

resources/add-extension-to-import-paths.ts

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

benchmark/benchmark.ts renamed to resources/benchmark.ts

Lines changed: 42 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import * as assert from 'node:assert';
2-
import * as cp from 'node:child_process';
3-
import * as fs from 'node:fs';
4-
import * as os from 'node:os';
5-
import * as path from 'node:path';
1+
import assert from 'node:assert';
2+
import cp from 'node:child_process';
3+
import fs from 'node:fs';
4+
import os from 'node:os';
5+
import path from 'node:path';
6+
7+
import { exec, execOutput, localRepoPath } from './utils.js';
68

79
const NS_PER_SEC = 1e9;
810
const LOCAL = 'local';
@@ -12,28 +14,14 @@ const maxTime = 5;
1214
// The minimum sample size required to perform statistical analysis.
1315
const minSamples = 5;
1416

15-
// Get the revisions and make things happen!
16-
if (require.main === module) {
17+
async function runBenchmarks() {
18+
// Get the revisions and make things happen!
1719
const { benchmarks, revisions } = getArguments(process.argv.slice(2));
1820
const benchmarkProjects = prepareBenchmarkProjects(revisions);
1921

20-
runBenchmarks(benchmarks, benchmarkProjects).catch((error) => {
21-
console.error(error);
22-
process.exit(1);
23-
});
24-
}
25-
26-
function localDir(...paths: ReadonlyArray<string>) {
27-
return path.join(__dirname, '..', ...paths);
28-
}
29-
30-
function exec(command: string, options = {}) {
31-
const result = cp.execSync(command, {
32-
encoding: 'utf-8',
33-
stdio: ['inherit', 'pipe', 'inherit'],
34-
...options,
35-
});
36-
return result?.trimEnd();
22+
for (const benchmark of benchmarks) {
23+
await runBenchmark(benchmark, benchmarkProjects);
24+
}
3725
}
3826

3927
interface BenchmarkProject {
@@ -59,7 +47,7 @@ function prepareBenchmarkProjects(
5947
fs.rmSync(projectPath, { recursive: true, force: true });
6048
fs.mkdirSync(projectPath);
6149

62-
fs.cpSync(localDir('benchmark'), path.join(projectPath, 'benchmark'), {
50+
fs.cpSync(localRepoPath('benchmark'), path.join(projectPath, 'benchmark'), {
6351
recursive: true,
6452
});
6553

@@ -81,14 +69,14 @@ function prepareBenchmarkProjects(
8169

8270
function prepareNPMPackage(revision: string) {
8371
if (revision === LOCAL) {
84-
const repoDir = localDir();
72+
const repoDir = localRepoPath();
8573
const archivePath = path.join(tmpDir, 'graphql-local.tgz');
8674
fs.renameSync(buildNPMArchive(repoDir), archivePath);
8775
return archivePath;
8876
}
8977

9078
// Returns the complete git hash for a given git revision reference.
91-
const hash = exec(`git rev-parse "${revision}"`);
79+
const hash = execOutput(`git rev-parse "${revision}"`);
9280

9381
const archivePath = path.join(tmpDir, `graphql-${hash}.tgz`);
9482
if (fs.existsSync(archivePath)) {
@@ -109,7 +97,9 @@ function prepareBenchmarkProjects(
10997
exec('npm --quiet run build:npm', { cwd: repoDir });
11098

11199
const distDir = path.join(repoDir, 'npmDist');
112-
const archiveName = exec(`npm --quiet pack ${distDir}`, { cwd: repoDir });
100+
const archiveName = execOutput(`npm --quiet pack ${distDir}`, {
101+
cwd: repoDir,
102+
});
113103
return path.join(repoDir, archiveName);
114104
}
115105
}
@@ -266,35 +256,33 @@ function maxBy<T>(array: ReadonlyArray<T>, fn: (obj: T) => number) {
266256
}
267257

268258
// Prepare all revisions and run benchmarks matching a pattern against them.
269-
async function runBenchmarks(
270-
benchmarks: ReadonlyArray<string>,
259+
async function runBenchmark(
260+
benchmark: string,
271261
benchmarkProjects: ReadonlyArray<BenchmarkProject>,
272262
) {
273-
for (const benchmark of benchmarks) {
274-
const results = [];
275-
for (let i = 0; i < benchmarkProjects.length; ++i) {
276-
const { revision, projectPath } = benchmarkProjects[i];
277-
const modulePath = path.join(projectPath, benchmark);
278-
279-
if (i === 0) {
280-
const { name } = await sampleModule(modulePath);
281-
console.log('⏱ ' + name);
282-
}
263+
const results = [];
264+
for (let i = 0; i < benchmarkProjects.length; ++i) {
265+
const { revision, projectPath } = benchmarkProjects[i];
266+
const modulePath = path.join(projectPath, benchmark);
267+
268+
if (i === 0) {
269+
const { name } = await sampleModule(modulePath);
270+
console.log('⏱ ' + name);
271+
}
283272

284-
try {
285-
const samples = await collectSamples(modulePath);
273+
try {
274+
const samples = await collectSamples(modulePath);
286275

287-
results.push(computeStats(revision, samples));
288-
process.stdout.write(' ' + cyan(i + 1) + ' tests completed.\u000D');
289-
} catch (error) {
290-
console.log(' ' + revision + ': ' + red(String(error)));
291-
}
276+
results.push(computeStats(revision, samples));
277+
process.stdout.write(' ' + cyan(i + 1) + ' tests completed.\u000D');
278+
} catch (error) {
279+
console.log(' ' + revision + ': ' + red(String(error)));
292280
}
293-
console.log('\n');
294-
295-
beautifyBenchmark(results);
296-
console.log('');
297281
}
282+
console.log('\n');
283+
284+
beautifyBenchmark(results);
285+
console.log('');
298286
}
299287

300288
function getArguments(argv: ReadonlyArray<string>) {
@@ -324,7 +312,7 @@ function getArguments(argv: ReadonlyArray<string>) {
324312

325313
function findAllBenchmarks() {
326314
return fs
327-
.readdirSync(localDir('benchmark'), { withFileTypes: true })
315+
.readdirSync(localRepoPath('benchmark'), { withFileTypes: true })
328316
.filter((dirent) => dirent.isFile())
329317
.map((dirent) => dirent.name)
330318
.filter((name) => name.endsWith('-benchmark.js'))
@@ -421,3 +409,5 @@ function sampleModule(modulePath: string): Promise<BenchmarkSample> {
421409
});
422410
});
423411
}
412+
413+
await runBenchmarks();

0 commit comments

Comments
 (0)