@@ -1084,9 +1084,11 @@ function publish( pkg, clbk ) {
10841084 function publishToNPM ( ) {
10851085 var fmtProdMsgVersion ;
10861086 var jscodeshift ;
1087+ var contents ;
10871088 var command ;
10881089 var escaped ;
10891090 var cliPkg ;
1091+ var alias ;
10901092 var found ;
10911093 var opts ;
10921094 var dep ;
@@ -1162,21 +1164,43 @@ function publish( pkg, clbk ) {
11621164 }
11631165 }
11641166 }
1167+ // Add `@stdlib/error-tools-fmtprodmsg` in package.json if the package depends on `@stdlib/string-format`:
1168+ if ( pkgJSON . dependencies [ '@stdlib/string-format' ] ) {
1169+ fmtProdMsgVersion = npmVersion ( '@stdlib/error-tools-fmtprodmsg' ) ;
1170+ pkgJSON . dependencies [ '@stdlib/error-tools-fmtprodmsg' ] = fmtProdMsgVersion ;
1171+ deps . push ( '@stdlib/error-tools-fmtprodmsg' ) ;
1172+ }
1173+
11651174 // Transform error messages and save files to `dist` subdirectory:
1166- command = 'cp -r lib dist' ;
1175+ command = 'cp -r lib tmp && mkdir dist' ;
11671176 shell ( command , opts ) ;
11681177 jscodeshift = join ( rootDir ( ) , 'node_modules' , '.bin' , 'jscodeshift' ) ;
1169- command = 'STDLIB_PKG=\'@stdlib/' + distPkg + '\' ' + jscodeshift + ' ./dist /**/*.js ./dist /*.js -t ' + join ( __dirname , 'transform.js' ) ;
1178+ command = 'STDLIB_PKG=\'@stdlib/' + distPkg + '\' ' + jscodeshift + ' ./tmp /**/*.js ./tmp /*.js -t ' + join ( __dirname , 'transform.js' ) ;
11701179 debug ( 'Executing command: %s' , command ) ;
11711180 shell ( command , opts ) ;
1172- command = 'find ./dist -name "*.js" -exec sed -E -i "1i\\/\\*\\* \\@license ' + pkgJSON . license + ' \\*\\/\n" {} \\;' ;
1181+ command = 'find ./tmp -name "*.js" -exec sed -E -i "1i\\/\\*\\* \\@license ' + pkgJSON . license + ' \\*\\/\n" {} \\;' ;
1182+ shell ( command , opts ) ;
1183+ command = [
1184+ 'npx esbuild tmp/index.js --bundle --format=cjs' ,
1185+ '--sourcemap --minify --platform=node --outfile=dist/index.js' ,
1186+ '--external:' + deps . join ( ' --external:' )
1187+ ] . join ( ' ' ) ;
1188+ debug ( 'Executing command: %s' , command ) ;
1189+ shell ( command , opts ) ;
1190+ command = 'rm -rf tmp' ;
11731191 shell ( command , opts ) ;
11741192
1175- // Add `@stdlib/error-tools-fmtprodmsg` in package.json if the package depends on `@stdlib/string-format`:
1176- if ( pkgJSON . dependencies [ '@stdlib/string-format' ] ) {
1177- fmtProdMsgVersion = npmVersion ( '@stdlib/error-tools-fmtprodmsg' ) ;
1178- pkgJSON . dependencies [ '@stdlib/error-tools-fmtprodmsg' ] = fmtProdMsgVersion ;
1179- }
1193+ // Extract the alias from the Typescript definition file (after `export =` but before the semicolon):
1194+ command = 'grep -oP \'(?<=export = ).*?(?=;)\' docs/types/index.d.ts' ;
1195+ alias = trim ( shell ( command , opts ) . toString ( ) ) ;
1196+
1197+ // Create the contents of a `index.d.ts` file in `dist` subdirectory that reexports `docs/types/index.d.ts` (we don't want to duplicate type definitions, so we just reexport them):
1198+ contents = [
1199+ '/// <reference path="../docs/types/index.d.ts" />' ,
1200+ 'import ' + alias + ' from \'../docs/types/index\';' ,
1201+ 'export = ' + alias + ';'
1202+ ] . join ( '\n' ) ;
1203+ writeFileSync ( join ( dist , 'dist' , 'index.d.ts' ) , contents ) ;
11801204
11811205 // Replace GitHub MathJax equations with SVGs:
11821206 command = 'find . -type f -name \'*.md\' -print0 | xargs -0 perl -0777 -i -pe \'s/```math\\n([\\s\\S]+?)\\n```\\n\\n//g\'' ;
0 commit comments