@@ -28,7 +28,7 @@ set -o pipefail
2828
2929# VARIABLES #
3030
31- # Get the path to the installation directory as the first argument to the build script:
31+ # Get the path to the local installation directory as the first argument to the build script:
3232install_dir=" $1 "
3333
3434# Get the name of the desired package manager as the second argument to the build script:
@@ -107,20 +107,37 @@ print_success() {
107107 echo ' Success!' >&2
108108}
109109
110- # Performs initialization tasks.
111- init () {
110+ # Performs installation initialization tasks.
111+ install_init () {
112112 echo ' Creating installation directory...' >&2
113113 mkdir -p " ${install_dir} " || return 1
114114
115115 echo ' Navigating to installation directory...' >&2
116116 cd " ${install_dir} " || return 1
117117
118118 echo ' Creating package.json...' >&2
119- echo ' {"name":"test-install","version":"0.0.0","private":true}' > " ${install_dir} " /package.json
119+ echo ' {"name":"test-install","version":"0.0.0","private":true}' > " ${install_dir} /package.json"
120120
121121 return 0
122122}
123123
124+ # Tests that an installation works as expected.
125+ install_test () {
126+ echo ' Testing installation...' >&2
127+
128+ echo ' Creating test script...' >&2
129+ echo ' var stdlib = require( "@stdlib/stdlib" ); console.log( stdlib.math.base.special.sin( 3.14 ) );' > " ${install_dir} /script.js"
130+
131+ echo ' Running test script...' >&2
132+ node " ${install_dir} /script.js"
133+ if [[ " $? " -ne 0 ]]; then
134+ echo " Encountered an error when running test script." >&2
135+ return 1
136+ fi
137+ echo ' Successfully ran test script.' >&2
138+ return 0
139+ }
140+
124141# Performs installation cleanup tasks.
125142install_clean () {
126143 echo ' Removing installation directory...' >&2
@@ -130,7 +147,7 @@ install_clean() {
130147
131148# Installs a package via `npm`.
132149npm_install () {
133- init
150+ install_init
134151 if [[ " $? " -ne 0 ]]; then
135152 echo " Encountered an error when performing pre-install initialization tasks." >&2
136153 return 1
@@ -140,6 +157,11 @@ npm_install() {
140157 echo " Installation of package ${pkg_name} @${pkg_version} via npm failed." >&2
141158 return 1
142159 fi
160+ install_test
161+ if [[ " $? " -ne 0 ]]; then
162+ echo " Encountered an error when testing installation." >&2
163+ return 1
164+ fi
143165 install_clean
144166 if [[ " $? " -ne 0 ]]; then
145167 echo " Encountered an error when performing post-install cleanup tasks." >&2
@@ -160,6 +182,11 @@ npm_install_from_github() {
160182 echo " Installation of package ${pkg_github_url} #${pkg_github_tag} via npm failed." >&2
161183 return 1
162184 fi
185+ install_test
186+ if [[ " $? " -ne 0 ]]; then
187+ echo " Encountered an error when testing installation." >&2
188+ return 1
189+ fi
163190 install_clean
164191 if [[ " $? " -ne 0 ]]; then
165192 echo " Encountered an error when performing post-install cleanup tasks." >&2
0 commit comments