File tree 5 files changed +86
-7
lines changed
5 files changed +86
-7
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,16 @@ describe('Integration Tests', () => {
27
27
path . join ( tmpDir , 'graphql.tgz' ) ,
28
28
) ;
29
29
30
+ const esmDistDir = path . resolve ( './npmEsmDist' ) ;
31
+ const esmArchiveName = exec ( `npm --quiet pack ${ esmDistDir } ` , {
32
+ cwd : tmpDir ,
33
+ } ) ;
34
+
35
+ fs . renameSync (
36
+ path . join ( tmpDir , esmArchiveName ) ,
37
+ path . join ( tmpDir , 'graphql-esm.tgz' ) ,
38
+ ) ;
39
+
30
40
function testOnNodeProject ( projectName ) {
31
41
const projectPath = path . join ( __dirname , projectName ) ;
32
42
@@ -45,4 +55,5 @@ describe('Integration Tests', () => {
45
55
testOnNodeProject ( 'ts' ) ;
46
56
testOnNodeProject ( 'node' ) ;
47
57
testOnNodeProject ( 'webpack' ) ;
58
+ testOnNodeProject ( 'node-esm' ) ;
48
59
} ) ;
Original file line number Diff line number Diff line change
1
+ import { deepStrictEqual , strictEqual } from 'assert' ;
2
+ import { readFileSync } from 'fs' ;
3
+
4
+ // Regular import
5
+ import { graphqlSync } from 'graphql' ;
6
+ // import with explicit extension
7
+ import { version } from 'graphql/version.js' ;
8
+ // _/index.js import
9
+ import { buildSchema } from 'graphql/utilities' ;
10
+ // import without explicit extension
11
+ import { isPromise } from 'graphql/jsutils/isPromise' ;
12
+
13
+ deepStrictEqual (
14
+ version ,
15
+ JSON . parse ( readFileSync ( './node_modules/graphql/package.json' ) ) . version ,
16
+ ) ;
17
+
18
+ const schema = buildSchema ( 'type Query { hello: String }' ) ;
19
+
20
+ const result = graphqlSync ( {
21
+ schema,
22
+ source : '{ hello }' ,
23
+ rootValue : { hello : 'world' } ,
24
+ } ) ;
25
+
26
+ deepStrictEqual ( result , {
27
+ data : {
28
+ __proto__ : null ,
29
+ hello : 'world' ,
30
+ } ,
31
+ } ) ;
32
+
33
+ strictEqual ( isPromise ( Promise . resolve ( ) ) , true ) ;
Original file line number Diff line number Diff line change
1
+ {
2
+ "type" : " module" ,
3
+ "description" : " graphql-js should work on all supported node versions with ESM" ,
4
+ "scripts" : {
5
+ "test" : " node test.js"
6
+ },
7
+ "dependencies" : {
8
+ "graphql" : " file:../graphql-esm.tgz" ,
9
+ "node-12" : " npm:node@12.x.x" ,
10
+ "node-14" : " npm:node@14.x.x" ,
11
+ "node-16" : " npm:node@16.x.x"
12
+ }
13
+ }
Original file line number Diff line number Diff line change
1
+ import { execSync } from 'child_process' ;
2
+ import { createRequire } from 'module' ;
3
+ import { dirname , join } from 'path' ;
4
+ import { fileURLToPath } from 'url' ;
5
+
6
+ const { dependencies } = createRequire ( import . meta. url ) ( './package.json' ) ;
7
+
8
+ const nodeVersions = Object . keys ( dependencies )
9
+ . filter ( ( pkg ) => pkg . startsWith ( 'node-' ) )
10
+ . sort ( ( a , b ) => b . localeCompare ( a ) ) ;
11
+
12
+ for ( const version of nodeVersions ) {
13
+ console . log ( `Testing on ${ version } ...` ) ;
14
+
15
+ const nodePath = join (
16
+ dirname ( fileURLToPath ( import . meta. url ) ) ,
17
+ 'node_modules' ,
18
+ version ,
19
+ 'bin/node' ,
20
+ ) ;
21
+ execSync ( nodePath + ' index.js' , { stdio : 'inherit' } ) ;
22
+ }
Original file line number Diff line number Diff line change @@ -32,14 +32,14 @@ if (require.main === module) {
32
32
const destPath = path . join ( distDirectory , filepath ) ;
33
33
34
34
fs . mkdirSync ( path . dirname ( destPath ) , { recursive : true } ) ;
35
- if ( isFullESM && filepath === 'version.ts' ) {
36
- const js = babelTransform ( getVersionFileBody ( packageJSON . version ) , {
37
- envName : 'esm' ,
38
- } ) ;
39
- writeGeneratedFile ( destPath . replace ( / \. t s $ / , '.js' ) , js ) ;
40
- } else if ( filepath . endsWith ( '.ts' ) ) {
35
+ if ( filepath . endsWith ( '.ts' ) ) {
41
36
if ( isFullESM ) {
42
- const js = babelBuild ( srcPath , { envName : 'esm' } ) ;
37
+ const js =
38
+ filepath === 'version.ts'
39
+ ? babelTransform ( getVersionFileBody ( packageJSON . version ) , {
40
+ envName : 'esm' ,
41
+ } )
42
+ : babelBuild ( srcPath , { envName : 'esm' } ) ;
43
43
writeGeneratedFile ( destPath . replace ( / \. t s $ / , '.js' ) , js ) ;
44
44
} else {
45
45
const cjs = babelBuild ( srcPath , { envName : 'cjs' } ) ;
You can’t perform that action at this time.
0 commit comments