Skip to content

Commit 09e7788

Browse files
committed
build: add fallback case for when bundling fails
1 parent d0363d3 commit 09e7788

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

lib/node_modules/@stdlib/_tools/scripts/publish_packages.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,19 +1046,25 @@ function publish( pkg, clbk ) {
10461046
deps.push( '@stdlib/error-tools-fmtprodmsg' );
10471047
}
10481048

1049-
// Transform error messages and save files to `dist` subdirectory:
1050-
command = 'mkdir dist';
1051-
shell( command, opts );
1052-
command = [
1053-
'npx esbuild lib/index.js --bundle --format=cjs --target=es5',
1054-
'--sourcemap --minify --platform=node --outfile=dist/index.js',
1055-
'--external:'+deps.join( ' --external:' )
1056-
].join( ' ' );
1057-
debug( 'Executing command: %s', command );
1058-
shell( command, opts );
1059-
command = 'rm -rf tmp';
1060-
shell( command, opts );
1049+
// Minify, bundle, and save files to `dist` subdirectory:
1050+
try {
1051+
command = 'mkdir dist';
1052+
shell( command, opts );
1053+
command = [
1054+
'npx esbuild lib/index.js --bundle --format=cjs --target=es5',
1055+
'--sourcemap --minify --platform=node --outfile=dist/index.js',
1056+
'--external:'+deps.join( ' --external:' )
1057+
].join( ' ' );
1058+
debug( 'Executing command: %s', command );
1059+
shell( command, opts );
1060+
} catch ( error ) {
1061+
debug( 'Encountered an error when attempting to bundle the package: %s', error.message );
10611062

1063+
// Copy all source files to the `dist` subdirectory to proceed without bundling:
1064+
command = 'cp -r lib/* dist';
1065+
shell( command, opts );
1066+
}
1067+
// Apply code transformations:
10621068
jscodeshift = join( rootDir(), 'node_modules', '.bin', 'jscodeshift' );
10631069
command = 'STDLIB_INPUT_SOURCE_MAP=\'./dist/index.js.map\' STDLIB_PKG=\'@stdlib/'+distPkg+'\' '+jscodeshift+' ./dist/index.js -t '+join( __dirname, 'transform.js' );
10641070
debug( 'Executing command: %s', command );

0 commit comments

Comments
 (0)