Skip to content

Commit

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

This reverts commit b5a9336.
  • Loading branch information
jaysoo authored Sep 5, 2024
1 parent 4068ecb commit 825e68f
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 825e68f

Please sign in to comment.