File tree Expand file tree Collapse file tree 3 files changed +48
-9
lines changed Expand file tree Collapse file tree 3 files changed +48
-9
lines changed Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ # Create package.json for CommonJS
1
4
cat > dist/cjs/package.json << !EOF
2
5
{
3
6
"type": "commonjs"
4
7
}
5
8
!EOF
6
9
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
8
23
24
+ # Create package.json for ES modules
9
25
cat > dist/esm/package.json << !EOF
10
26
{
11
27
"type": "module"
12
28
}
13
29
!EOF
14
30
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
Original file line number Diff line number Diff line change @@ -4,4 +4,12 @@ cat >dist/test/cjs/package.json <<!EOF
4
4
}
5
5
!EOF
6
6
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
Original file line number Diff line number Diff line change @@ -4,7 +4,16 @@ cat >dist/test/esm/package.json <<!EOF
4
4
}
5
5
!EOF
6
6
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"
8
9
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
You can’t perform that action at this time.
0 commit comments