Skip to content

Commit

Permalink
Revert "feat(core): add shutdown lifecycle hook to node executor" (#2…
Browse files Browse the repository at this point in the history
…7794)

Reverts #27354

This patch is causing issues that are more serious than what it fixes.
  • Loading branch information
jaysoo authored Sep 6, 2024
1 parent 7351a1a commit e71e2f3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 58 deletions.
26 changes: 20 additions & 6 deletions packages/js/src/executors/node/node-with-require-overrides.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
const Module = require('module');
const url = require('node:url');
const { patchSigint } = require('./patch-sigint');
const { patchRequire } = require('./patch-require');

patchSigint();
patchRequire();
const originalLoader = Module._load;

const dynamicImport = new Function('specifier', 'return import(specifier)');
dynamicImport(url.pathToFileURL(process.env.NX_FILE_TO_RUN));

const mappings = JSON.parse(process.env.NX_MAPPINGS);
const keys = Object.keys(mappings);
const fileToRun = url.pathToFileURL(process.env.NX_FILE_TO_RUN);

Module._load = function (request, parent) {
if (!parent) return originalLoader.apply(this, arguments);
const match = keys.find((k) => request === k);
if (match) {
const newArguments = [...arguments];
newArguments[0] = mappings[match];
return originalLoader.apply(this, newArguments);
} else {
return originalLoader.apply(this, arguments);
}
};

dynamicImport(fileToRun);
11 changes: 3 additions & 8 deletions packages/js/src/executors/node/node.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,18 +172,13 @@ export async function* nodeExecutor(
task.childProcess.stderr.on('data', handleStdErr);
task.childProcess.once('exit', (code) => {
task.childProcess.off('data', handleStdErr);
if (
options.watch &&
!task.killed &&
// SIGINT should exist the process rather than watch for changes.
code !== 130
) {
if (options.watch && !task.killed) {
logger.info(
`NX Process exited with code ${code}, waiting for changes to restart...`
);
}
if (!options.watch || code === 130) {
if (code !== 0 && code !== 130) {
if (!options.watch) {
if (code !== 0) {
error(new Error(`Process exited with code ${code}`));
} else {
done();
Expand Down
23 changes: 0 additions & 23 deletions packages/js/src/executors/node/patch-require.ts

This file was deleted.

21 changes: 0 additions & 21 deletions packages/js/src/executors/node/patch-sigint.ts

This file was deleted.

0 comments on commit e71e2f3

Please sign in to comment.