Skip to content

Commit 13367e0

Browse files
committed
Add multi OS support for hybrid module fix
1 parent 6ee7ac3 commit 13367e0

File tree

3 files changed

+48
-9
lines changed

3 files changed

+48
-9
lines changed

fix-hybrid-module.sh

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,40 @@
1+
#!/bin/bash
2+
3+
# Create package.json for CommonJS
14
cat >dist/cjs/package.json <<!EOF
25
{
36
"type": "commonjs"
47
}
58
!EOF
69

7-
sed -i '' 's/require("graphql\/execution\/values")/require("graphql\/execution\/values.js")/' "dist/cjs/QueryComplexity.js"
10+
# Define the file paths
11+
cjs_file_path="dist/cjs/QueryComplexity.js"
12+
esm_file_path="dist/esm/QueryComplexity.js"
13+
find_path="dist/esm"
14+
15+
# Detect the operating system and use the appropriate sed command
16+
if [[ "$OSTYPE" == "darwin"* ]]; then
17+
# macOS (BSD sed)
18+
sed -i '' 's/require("graphql\/execution\/values")/require("graphql\/execution\/values.js")/' "$cjs_file_path"
19+
else
20+
# Linux (GNU sed)
21+
sed -i 's/require("graphql\/execution\/values")/require("graphql\/execution\/values.js")/' "$cjs_file_path"
22+
fi
823

24+
# Create package.json for ES modules
925
cat >dist/esm/package.json <<!EOF
1026
{
1127
"type": "module"
1228
}
1329
!EOF
1430

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'\'';/' {} +
31+
# Detect the operating system and use the appropriate sed command
32+
if [[ "$OSTYPE" == "darwin"* ]]; then
33+
# macOS (BSD sed)
34+
sed -i '' 's/from '\''graphql\/execution\/values'\'';/from '\''graphql\/execution\/values.mjs'\'';/' "$esm_file_path"
35+
find "$find_path" -type f -name "*.js" -exec sed -i '' 's/from '\''graphql'\'';/from '\''graphql\/index.mjs'\'';/' {} +
36+
else
37+
# Linux (GNU sed)
38+
sed -i 's/from '\''graphql\/execution\/values'\'';/from '\''graphql\/execution\/values.mjs'\'';/' "$esm_file_path"
39+
find "$find_path" -type f -name "*.js" -exec sed -i 's/from '\''graphql'\'';/from '\''graphql\/index.mjs'\'';/' {} +
40+
fi

fix-hybrid-module.test.cjs.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,12 @@ cat >dist/test/cjs/package.json <<!EOF
44
}
55
!EOF
66

7-
sed -i '' 's/require("graphql\/execution\/values")/require("graphql\/execution\/values.js")/' "dist/test/cjs/QueryComplexity.js"
7+
file_path="dist/test/cjs/QueryComplexity.js"
8+
9+
if [[ "$OSTYPE" == "darwin"* ]]; then
10+
# macOS (BSD sed)
11+
sed -i '' 's/require("graphql\/execution\/values")/require("graphql\/execution\/values.js")/' "$file_path"
12+
else
13+
# Linux (GNU sed)
14+
sed -i 's/require("graphql\/execution\/values")/require("graphql\/execution\/values.js")/' "$file_path"
15+
fi

fix-hybrid-module.test.esm.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,16 @@ cat >dist/test/esm/package.json <<!EOF
44
}
55
!EOF
66

7-
sed -i '' 's/from '\''graphql\/execution\/values'\'';/from '\''graphql\/execution\/values.mjs'\'';/' "dist/test/esm/QueryComplexity.js"
7+
file_path="dist/test/esm/QueryComplexity.js"
8+
find_path="dist/test/esm"
89

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'\'';/' {} +
10+
# Detect the operating system and use the appropriate sed command
11+
if [[ "$OSTYPE" == "darwin"* ]]; then
12+
# macOS (BSD sed)
13+
sed -i '' 's/from '\''graphql\/execution\/values'\'';/from '\''graphql\/execution\/values.mjs'\'';/' "$file_path"
14+
find "$find_path" -type f -name "*.js" -exec sed -i '' 's/from '\''graphql'\'';/from '\''graphql\/index.mjs'\'';/' {} +
15+
else
16+
# Linux (GNU sed)
17+
sed -i 's/from '\''graphql\/execution\/values'\'';/from '\''graphql\/execution\/values.mjs'\'';/' "$file_path"
18+
find "$find_path" -type f -name "*.js" -exec sed -i 's/from '\''graphql'\'';/from '\''graphql\/index.mjs'\'';/' {} +
19+
fi

0 commit comments

Comments
 (0)