File tree 4 files changed +23
-58
lines changed
packages/js/src/executors/node
4 files changed +23
-58
lines changed Original file line number Diff line number Diff line change
1
+ const Module = require ( 'module' ) ;
1
2
const url = require ( 'node:url' ) ;
2
- const { patchSigint } = require ( './patch-sigint' ) ;
3
- const { patchRequire } = require ( './patch-require' ) ;
4
-
5
- patchSigint ( ) ;
6
- patchRequire ( ) ;
3
+ const originalLoader = Module . _load ;
7
4
8
5
const dynamicImport = new Function ( 'specifier' , 'return import(specifier)' ) ;
9
- dynamicImport ( url . pathToFileURL ( process . env . NX_FILE_TO_RUN ) ) ;
6
+
7
+ const mappings = JSON . parse ( process . env . NX_MAPPINGS ) ;
8
+ const keys = Object . keys ( mappings ) ;
9
+ const fileToRun = url . pathToFileURL ( process . env . NX_FILE_TO_RUN ) ;
10
+
11
+ Module . _load = function ( request , parent ) {
12
+ if ( ! parent ) return originalLoader . apply ( this , arguments ) ;
13
+ const match = keys . find ( ( k ) => request === k ) ;
14
+ if ( match ) {
15
+ const newArguments = [ ...arguments ] ;
16
+ newArguments [ 0 ] = mappings [ match ] ;
17
+ return originalLoader . apply ( this , newArguments ) ;
18
+ } else {
19
+ return originalLoader . apply ( this , arguments ) ;
20
+ }
21
+ } ;
22
+
23
+ dynamicImport ( fileToRun ) ;
Original file line number Diff line number Diff line change @@ -172,18 +172,13 @@ export async function* nodeExecutor(
172
172
task . childProcess . stderr . on ( 'data' , handleStdErr ) ;
173
173
task . childProcess . once ( 'exit' , ( code ) => {
174
174
task . childProcess . off ( 'data' , handleStdErr ) ;
175
- if (
176
- options . watch &&
177
- ! task . killed &&
178
- // SIGINT should exist the process rather than watch for changes.
179
- code !== 130
180
- ) {
175
+ if ( options . watch && ! task . killed ) {
181
176
logger . info (
182
177
`NX Process exited with code ${ code } , waiting for changes to restart...`
183
178
) ;
184
179
}
185
- if ( ! options . watch || code === 130 ) {
186
- if ( code !== 0 && code !== 130 ) {
180
+ if ( ! options . watch ) {
181
+ if ( code !== 0 ) {
187
182
error ( new Error ( `Process exited with code ${ code } ` ) ) ;
188
183
} else {
189
184
done ( ) ;
Load Diff This file was deleted.
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments