1- import path from 'path' ;
1+ import path from 'node:path' ;
2+ import assert from 'node:assert' ;
23
34import dotenv from 'dotenv' ;
45import readPackageUp from 'read-pkg-up' ;
@@ -56,6 +57,12 @@ async function getServiceDetails(argv: BootstrapArguments = {}) {
5657 } ;
5758}
5859
60+ function getBuildDir ( main : string ) : 'build' | 'dist' {
61+ const dir = / ^ (?: \. ? \/ ? ) ( b u i l d | d i s t ) \/ / . exec ( main ) ;
62+ assert ( dir , 'Could not determine build directory - should be dist or build' ) ;
63+ return dir [ 1 ] as 'build' | 'dist' ;
64+ }
65+
5966// Automagically start your app by using common patterns
6067// to find your implementation and settings. This is most useful
6168// for jobs or other scripts that need service infra but are
@@ -67,18 +74,19 @@ export async function bootstrap<
6774 const { main, rootDirectory, name } = await getServiceDetails ( argv ) ;
6875
6976 let entrypoint : string ;
70- let codepath : 'build' | 'src' = 'build' ;
77+ let codepath : 'build' | 'dist' | ' src' = 'build' ;
7178 if ( isDev ( ) && argv ?. built !== true ) {
7279 // eslint-disable-next-line import/no-extraneous-dependencies
7380 const { register } = await import ( 'ts-node' ) ;
7481 register ( ) ;
7582 if ( main ) {
76- entrypoint = main . replace ( / ^ ( \. ? \/ ? ) b u i l d \/ / , '$1src/' ) . replace ( / \. j s $ / , '.ts' ) ;
83+ entrypoint = main . replace ( / ^ ( \. ? \/ ? ) ( b u i l d | d i s t ) \/ / , '$1src/' ) . replace ( / \. j s $ / , '.ts' ) ;
7784 } else {
7885 entrypoint = './src/index.ts' ;
7986 }
8087 codepath = 'src' ;
8188 } else if ( main ) {
89+ codepath = getBuildDir ( main ) ;
8290 entrypoint = main ;
8391 } else {
8492 entrypoint = './build/index.js' ;
0 commit comments