Skip to content

Commit e71e2f3

Browse files
authored
Revert "feat(core): add shutdown lifecycle hook to node executor" (#27794)
Reverts #27354 This patch is causing issues that are more serious than what it fixes.
1 parent 7351a1a commit e71e2f3

File tree

4 files changed

+23
-58
lines changed

4 files changed

+23
-58
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
1+
const Module = require('module');
12
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;
74

85
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);

packages/js/src/executors/node/node.impl.ts

+3-8
Original file line numberDiff line numberDiff line change
@@ -172,18 +172,13 @@ export async function* nodeExecutor(
172172
task.childProcess.stderr.on('data', handleStdErr);
173173
task.childProcess.once('exit', (code) => {
174174
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) {
181176
logger.info(
182177
`NX Process exited with code ${code}, waiting for changes to restart...`
183178
);
184179
}
185-
if (!options.watch || code === 130) {
186-
if (code !== 0 && code !== 130) {
180+
if (!options.watch) {
181+
if (code !== 0) {
187182
error(new Error(`Process exited with code ${code}`));
188183
} else {
189184
done();

packages/js/src/executors/node/patch-require.ts

-23
This file was deleted.

packages/js/src/executors/node/patch-sigint.ts

-21
This file was deleted.

0 commit comments

Comments
 (0)