1
- import path from 'path' ;
1
+ import path from 'node:path' ;
2
+ import assert from 'node:assert' ;
2
3
3
4
import dotenv from 'dotenv' ;
4
5
import readPackageUp from 'read-pkg-up' ;
@@ -56,6 +57,12 @@ async function getServiceDetails(argv: BootstrapArguments = {}) {
56
57
} ;
57
58
}
58
59
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
+
59
66
// Automagically start your app by using common patterns
60
67
// to find your implementation and settings. This is most useful
61
68
// for jobs or other scripts that need service infra but are
@@ -67,18 +74,19 @@ export async function bootstrap<
67
74
const { main, rootDirectory, name } = await getServiceDetails ( argv ) ;
68
75
69
76
let entrypoint : string ;
70
- let codepath : 'build' | 'src' = 'build' ;
77
+ let codepath : 'build' | 'dist' | ' src' = 'build' ;
71
78
if ( isDev ( ) && argv ?. built !== true ) {
72
79
// eslint-disable-next-line import/no-extraneous-dependencies
73
80
const { register } = await import ( 'ts-node' ) ;
74
81
register ( ) ;
75
82
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' ) ;
77
84
} else {
78
85
entrypoint = './src/index.ts' ;
79
86
}
80
87
codepath = 'src' ;
81
88
} else if ( main ) {
89
+ codepath = getBuildDir ( main ) ;
82
90
entrypoint = main ;
83
91
} else {
84
92
entrypoint = './build/index.js' ;
0 commit comments