Skip to content

Commit f0e72b7

Browse files
committed
Add esm/cjs exports to package.json, update hybrid fix scripts
1 parent 93d6520 commit f0e72b7

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

fix-hybrid-module.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ cat >dist/cjs/package.json <<!EOF
44
}
55
!EOF
66

7-
sed -i '' "s/require(\"graphql\/execution\/values\")/require(\"graphql\/execution\/values.js\")/" "dist/cjs/QueryComplexity.js"
7+
sed -i '' 's/require("graphql\/execution\/values")/require("graphql\/execution\/values.js")/' "dist/cjs/QueryComplexity.js"
88

99
cat >dist/esm/package.json <<!EOF
1010
{
1111
"type": "module"
1212
}
1313
!EOF
1414

15-
sed -i '' "s/from 'graphql\/execution\/values';/from 'graphql\/execution\/values.mjs';/" "dist/esm/QueryComplexity.js"
15+
sed -i '' 's/from '\''graphql\/execution\/values'\'';/from '\''graphql\/execution\/values.mjs'\'';/' "dist/esm/QueryComplexity.js"
16+
17+
# We need to update from 'graphql' to 'graphql/index.mjs' in all files in dist/esm to ensure the GraphQL module is loaded from the same realm
18+
find dist/esm -type f -name "*.js" -exec sed -i '' 's/from '\''graphql'\'';/from '\''graphql\/index.mjs'\'';/' {} +

fix-hybrid-module.test.cjs.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ cat >dist/test/cjs/package.json <<!EOF
22
{
33
"type": "commonjs"
44
}
5-
!EOF
5+
!EOF
6+
7+
sed -i '' 's/require("graphql\/execution\/values")/require("graphql\/execution\/values.js")/' "dist/test/cjs/QueryComplexity.js"

fix-hybrid-module.test.esm.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@ cat >dist/test/esm/package.json <<!EOF
33
"type": "module"
44
}
55
!EOF
6+
7+
sed -i '' 's/from '\''graphql\/execution\/values'\'';/from '\''graphql\/execution\/values.mjs'\'';/' "dist/test/esm/QueryComplexity.js"
8+
9+
# We need to update from 'graphql' to 'graphql/index.mjs' in all files in dist/esm to ensure the GraphQL module is loaded from the same realm
10+
find dist/test/esm -type f -name "*.js" -exec sed -i '' 's/from '\''graphql'\'';/from '\''graphql\/index.mjs'\'';/' {} +

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"build:test:esm": "tsc -p ./tsconfig.test.esm.json && ./fix-hybrid-module.test.esm.sh",
1717
"test": "npm run lint && npm run build:test:cjs && npm run testonly:cjs && npm run build:test:esm && npm run testonly:esm",
1818
"testonly:cjs": "mocha --check-leaks --exit --full-trace 'dist/test/cjs/**/__tests__/**/*-test.js'",
19-
"testonly:esm": "mocha -n experimental-json-modules --check-leaks --exit --full-trace 'dist/test/esm/**/__tests__/**/*-test.js'",
19+
"testonly:esm": "mocha -n experimental-json-modules --loader=ts-node/esm --check-leaks --exit --full-trace 'dist/test/esm/**/__tests__/**/*-test.js'",
2020
"dist": "npm run clean && npm run build",
2121
"prepare": "npm run clean && npm run dist"
2222
},
@@ -47,7 +47,9 @@
4747
".": {
4848
"import": "./dist/esm/index.js",
4949
"require": "./dist/cjs/index.js"
50-
}
50+
},
51+
"./esm": "./dist/esm/index.js",
52+
"./cjs": "./dist/cjs/index.js"
5153
},
5254
"author": "Ivo Meißner",
5355
"license": "MIT",

0 commit comments

Comments
 (0)