@@ -28,11 +28,11 @@ set -o pipefail
2828
2929# VARIABLES #
3030
31- # Get the path to the local installation directory as the first argument to the build script:
32- install_dir =" $1 "
31+ # Get the name of the desired package manager as the first argument to the build script:
32+ pm =" $1 "
3333
34- # Get the name of the desired package manager as the second argument to the build script:
35- pm =" $2 "
34+ # Get the path to the local installation directory as the second argument to the build script:
35+ install_dir =" $2 "
3636
3737# Get the path to a log file as the third argument to the build script:
3838log_file=" $3 "
@@ -58,6 +58,9 @@ heartbeat_pid=""
5858# Get the current working directory:
5959working_dir=$( pwd)
6060
61+ # Get the Node.js major version:
62+ node_major_version=$( node -e ' console.log( require( "process" ).version.substring( 1 ).split( "." )[ 0 ] );' )
63+
6164
6265# FUNCTIONS #
6366
@@ -139,17 +142,6 @@ install_test() {
139142 fi
140143 echo ' Successfully ran test script.' >&2
141144
142- echo ' Creating test script (import global namespace)...' >&2
143- echo ' import stdlib from "@stdlib/stdlib"; console.log( stdlib.math.base.special.sin( 3.14 ) );' > " ${install_dir} /script.js"
144-
145- echo ' Running test script...' >&2
146- node " ${install_dir} /script.js"
147- if [[ " $? " -ne 0 ]]; then
148- echo " Encountered an error when running test script." >&2
149- return 1
150- fi
151- echo ' Successfully ran test script.' >&2
152-
153145 echo ' Creating test script (require individual package)...' >&2
154146 echo ' var sin = require( "@stdlib/math/base/special/sin" ); console.log( sin( 3.14 ) );' > " ${install_dir} /script.js"
155147
@@ -161,16 +153,30 @@ install_test() {
161153 fi
162154 echo ' Successfully ran test script.' >&2
163155
164- echo ' Creating test script (import individual package)...' >&2
165- echo ' import sin from "@stdlib/math/base/special/sin"; console.log( sin( 3.14 ) );' > " ${install_dir} /script.js"
156+ # Test `import` syntax on more recent Node.js versions which support ES modules without having to set flags to enable experimental support...
157+ if [[ " ${node_major_version} " -gt 13 ]]; then
158+ echo ' Creating test script (import global namespace)...' >&2
159+ echo ' import stdlib from "@stdlib/stdlib"; console.log( stdlib.math.base.special.sin( 3.14 ) );' > " ${install_dir} /script.mjs"
166160
167- echo ' Running test script...' >&2
168- node " ${install_dir} /script.js"
169- if [[ " $? " -ne 0 ]]; then
170- echo " Encountered an error when running test script." >&2
171- return 1
161+ echo ' Running test script...' >&2
162+ node " ${install_dir} /script.mjs"
163+ if [[ " $? " -ne 0 ]]; then
164+ echo " Encountered an error when running test script." >&2
165+ return 1
166+ fi
167+ echo ' Successfully ran test script.' >&2
168+
169+ echo ' Creating test script (import individual package)...' >&2
170+ echo ' import sin from "@stdlib/math/base/special/sin"; console.log( sin( 3.14 ) );' > " ${install_dir} /script.mjs"
171+
172+ echo ' Running test script...' >&2
173+ node " ${install_dir} /script.mjs"
174+ if [[ " $? " -ne 0 ]]; then
175+ echo " Encountered an error when running test script." >&2
176+ return 1
177+ fi
178+ echo ' Successfully ran test script.' >&2
172179 fi
173- echo ' Successfully ran test script.' >&2
174180 return 0
175181}
176182
0 commit comments