Skip to content

Commit 378b096

Browse files
committed
Merge branch 'esm-with-instanceof' of https://github.com/yaacovCR/graphql-js into esm-with-instanceof
2 parents d38a037 + 896db34 commit 378b096

File tree

6 files changed

+25
-25
lines changed

6 files changed

+25
-25
lines changed

integrationTests/dev-node-implicit/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{
2-
"name": "graphql-js-test-dev-node",
3-
"description": "Node.js development mode integration test",
4-
"version": "1.0.0",
52
"private": true,
3+
"description": "graphql-js development condition should work with node",
64
"type": "module",
75
"scripts": {
86
"test": "node --conditions=development test.js"
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import assert from 'assert';
1+
import assert from 'node:assert';
2+
23
import { isObjectType } from 'graphql';
34

45
class GraphQLObjectType {
@@ -9,10 +10,12 @@ class GraphQLObjectType {
910

1011
try {
1112
isObjectType(new GraphQLObjectType());
12-
assert.fail('Expected isObjectType to throw an error in Node.js implicit development mode.');
13+
assert.fail(
14+
'Expected isObjectType to throw an error in Node.js implicit development mode.',
15+
);
1316
} catch (error) {
1417
assert.ok(
1518
error.message.includes('multiple') || error.message.includes('GraphQL'),
16-
`Expected error message to include 'multiple' or 'GraphQL', but got: "${error.message}"`
19+
`Expected error message to include 'multiple' or 'GraphQL', but got: "${error.message}"`,
1720
);
1821
}

resources/build-npm.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,17 @@ async function buildPackage(outDir: string): Promise<void> {
8888
extension: '.js',
8989
});
9090

91-
const devHelper = path.join(outDir, 'dev/index.js');
92-
9391
for (const prodFile of emittedTSFiles) {
9492
const { dir, base } = path.parse(prodFile);
9593

9694
const match = base.match(/^([^.]*)\.?(.*)$/);
9795
assert(match);
9896
const [, name, ext] = match;
9997

100-
if (prodFile === devHelper || ext === 'js.map') {
98+
if (ext === 'js.map') {
99+
continue;
100+
} else if (path.basename(dir) === 'dev') {
101+
packageJSON.exports['./dev'] = './dev/index.js';
101102
continue;
102103
}
103104

@@ -107,7 +108,8 @@ async function buildPackage(outDir: string): Promise<void> {
107108
`${dir}/${name}`,
108109
);
109110

110-
const lines = ext === 'd.ts' ? [] : [`import '${relativePathToProd}/dev';`];
111+
const lines =
112+
ext === 'd.ts' ? [] : [`import '${relativePathToProd}/dev/index.js';`];
111113
lines.push(
112114
`export * from '${relativePathToProd}/${relativePathAndName}.js';`,
113115
);
@@ -121,19 +123,19 @@ async function buildPackage(outDir: string): Promise<void> {
121123
if (base === 'index.js') {
122124
const dirname = path.dirname(relativePathAndName);
123125
packageJSON.exports[dirname === '.' ? dirname : `./${dirname}`] = {
124-
development: `./dev/${relativePathAndName}.js`,
126+
development: `./__dev__/${relativePathAndName}.js`,
125127
default: `./${relativePathAndName}.js`,
126128
};
127129
}
128130
}
129131

130132
// Temporary workaround to allow "internal" imports, no grantees provided
131133
packageJSON.exports['./*.js'] = {
132-
development: './dev/*.js',
134+
development: './__dev__/*.js',
133135
default: './*.js',
134136
};
135137
packageJSON.exports['./*'] = {
136-
development: './dev/*.js',
138+
development: './__dev__/*.js',
137139
default: './*.js',
138140
};
139141

@@ -168,7 +170,7 @@ function emitTSFiles(options: {
168170
tsHost.writeFile = (filepath, body) => writeGeneratedFile(filepath, body);
169171

170172
const tsProgram = ts.createProgram(
171-
['src/index.ts', 'src/development.ts'],
173+
['src/index.ts', 'src/dev/index.ts'],
172174
tsOptions,
173175
tsHost,
174176
);

resources/utils.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,12 @@ interface PackageJSON {
235235
scripts?: { [name: string]: string };
236236
type?: string;
237237
exports: {
238-
[path: string]: {
239-
development: string;
240-
default: string;
241-
};
238+
[path: string]:
239+
| string
240+
| {
241+
development: string;
242+
default: string;
243+
};
242244
};
243245
types?: string;
244246
typesVersions: { [ranges: string]: { [path: string]: Array<string> } };

src/dev/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { inspect } from '../jsutils/inspect.js';
22
import type { Constructor } from '../jsutils/instanceOf.js';
3-
import { symbolForGraphQLInstanceOfCheck } from '../jsutils/instanceOf.js';
43

54
/**
65
* An additional check to be included within instanceOf warning when
@@ -43,5 +42,5 @@ spurious results.`,
4342
}
4443
}
4544

46-
(globalThis as any)[symbolForGraphQLInstanceOfCheck] =
45+
(globalThis as any)[Symbol.for('graphql.instanceOfCheck')] =
4746
developmentInstanceOfCheck;

src/jsutils/instanceOf.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
export const symbolForGraphQLInstanceOfCheck = Symbol.for(
2-
'graphql.instanceOfCheck',
3-
);
4-
51
/**
62
* "src/development.ts" includes an additional check for development mode
73
* which throws on multiple versions of graphql-js.
@@ -12,7 +8,7 @@ export const symbolForGraphQLInstanceOfCheck = Symbol.for(
128
* 2. if the "development" condition is set.
139
*/
1410
const check: (_value: unknown, _constructor: Constructor) => void =
15-
(globalThis as any)[symbolForGraphQLInstanceOfCheck] ??
11+
(globalThis as any)[Symbol.for('graphql.instanceOfCheck')] ??
1612
((_value: unknown, _constructor: Constructor) => {
1713
/* no-op */
1814
});

0 commit comments

Comments
 (0)