diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index 0b0fd7c24acad1..aff746f9716032 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -115,12 +115,9 @@ if (isMainThread) { } const { - onWarning, emitWarning } = NativeModule.require('internal/process/warning'); -if (!process.noProcessWarnings && process.env.NODE_NO_WARNINGS !== '1') { - process.on('warning', onWarning); -} + process.emitWarning = emitWarning; const { @@ -222,20 +219,6 @@ Object.defineProperty(process, 'argv0', { }); process.argv[0] = process.execPath; -// Handle `--debug*` deprecation and invalidation. -if (process._invalidDebug) { - process.emitWarning( - '`node --debug` and `node --debug-brk` are invalid. ' + - 'Please use `node --inspect` or `node --inspect-brk` instead.', - 'DeprecationWarning', 'DEP0062', undefined, true); - process.exit(9); -} else if (process._deprecatedDebugBrk) { - process.emitWarning( - '`node --inspect --debug-brk` is deprecated. ' + - 'Please use `node --inspect-brk` instead.', - 'DeprecationWarning', 'DEP0062', undefined, true); -} - // TODO(jasnell): The following have been globals since around 2012. // That's just silly. The underlying perfctr support has been removed // so these are now deprecated non-ops that can be removed after one @@ -320,29 +303,6 @@ Object.defineProperty(process, 'features', { hasUncaughtExceptionCaptureCallback; } -// User-facing NODE_V8_COVERAGE environment variable that writes -// ScriptCoverage to a specified file. -if (process.env.NODE_V8_COVERAGE) { - const originalReallyExit = process.reallyExit; - const cwd = NativeModule.require('internal/process/execution').tryGetCwd(); - const { resolve } = NativeModule.require('path'); - // Resolve the coverage directory to an absolute path, and - // overwrite process.env so that the original path gets passed - // to child processes even when they switch cwd. - const coverageDirectory = resolve(cwd, process.env.NODE_V8_COVERAGE); - process.env.NODE_V8_COVERAGE = coverageDirectory; - const { - writeCoverage, - setCoverageDirectory - } = NativeModule.require('internal/coverage-gen/with_profiler'); - setCoverageDirectory(coverageDirectory); - process.on('exit', writeCoverage); - process.reallyExit = (code) => { - writeCoverage(); - originalReallyExit(code); - }; -} - function setupProcessObject() { const EventEmitter = NativeModule.require('events'); const origProcProto = Object.getPrototypeOf(process); diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js index 02acf6b46f6338..35c1a510f0b2f2 100644 --- a/lib/internal/bootstrap/pre_execution.js +++ b/lib/internal/bootstrap/pre_execution.js @@ -8,6 +8,16 @@ let traceEventsAsyncHook; function prepareMainThreadExecution() { setupTraceCategoryState(); + setupWarningHandler(); + + // Resolve the coverage directory to an absolute path, and + // overwrite process.env so that the original path gets passed + // to child processes even when they switch cwd. + if (process.env.NODE_V8_COVERAGE) { + process.env.NODE_V8_COVERAGE = + setupCoverageHooks(process.env.NODE_V8_COVERAGE); + } + // Only main thread receives signals. setupSignalHandlers(); @@ -36,6 +46,35 @@ function prepareMainThreadExecution() { loadPreloadModules(); } +function setupWarningHandler() { + const { + onWarning + } = require('internal/process/warning'); + if (!process.noProcessWarnings && process.env.NODE_NO_WARNINGS !== '1') { + process.on('warning', onWarning); + } +} + +// Setup User-facing NODE_V8_COVERAGE environment variable that writes +// ScriptCoverage to a specified file. +function setupCoverageHooks(dir) { + const originalReallyExit = process.reallyExit; + const cwd = require('internal/process/execution').tryGetCwd(); + const { resolve } = require('path'); + const coverageDirectory = resolve(cwd, dir); + const { + writeCoverage, + setCoverageDirectory + } = require('internal/coverage-gen/with_profiler'); + setCoverageDirectory(coverageDirectory); + process.on('exit', writeCoverage); + process.reallyExit = (code) => { + writeCoverage(); + originalReallyExit(code); + }; + return coverageDirectory; +} + function initializeReport() { if (!getOptionValue('--experimental-report')) { return; @@ -106,6 +145,23 @@ function initializeDeprecations() { const { deprecate } = require('internal/util'); const pendingDeprecation = getOptionValue('--pending-deprecation'); + // Handle `--debug*` deprecation and invalidation. + if (getOptionValue('--debug')) { + if (!getOptionValue('--inspect')) { + process.emitWarning( + '`node --debug` and `node --debug-brk` are invalid. ' + + 'Please use `node --inspect` or `node --inspect-brk` instead.', + 'DeprecationWarning', 'DEP0062', undefined, true); + process.exit(9); + } else if (getOptionValue('--inspect-brk')) { + process._deprecatedDebugBrk = true; + process.emitWarning( + '`node --inspect --debug-brk` is deprecated. ' + + 'Please use `node --inspect-brk` instead.', + 'DeprecationWarning', 'DEP0062', undefined, true); + } + } + // DEP0103: access to `process.binding('util').isX` type checkers // TODO(addaleax): Turn into a full runtime deprecation. const utilBinding = internalBinding('util'); @@ -251,6 +307,8 @@ function loadPreloadModules() { } module.exports = { + setupCoverageHooks, + setupWarningHandler, prepareMainThreadExecution, initializeDeprecations, initializeESMLoader, diff --git a/lib/internal/main/inspect.js b/lib/internal/main/inspect.js index 7376f8984b13e1..f6777fe852bcfc 100644 --- a/lib/internal/main/inspect.js +++ b/lib/internal/main/inspect.js @@ -2,6 +2,12 @@ // `node inspect ...` or `node debug ...` +const { + prepareMainThreadExecution +} = require('internal/bootstrap/pre_execution'); + +prepareMainThreadExecution(); + if (process.argv[1] === 'debug') { process.emitWarning( '`node debug` is deprecated. Please use `node inspect` instead.', diff --git a/lib/internal/main/worker_thread.js b/lib/internal/main/worker_thread.js index 0dc1b61ef94f45..0289f97fb1c110 100644 --- a/lib/internal/main/worker_thread.js +++ b/lib/internal/main/worker_thread.js @@ -4,6 +4,8 @@ // message port. const { + setupCoverageHooks, + setupWarningHandler, initializeDeprecations, initializeESMLoader, initializeFrozenIntrinsics, @@ -39,6 +41,14 @@ const { const publicWorker = require('worker_threads'); const debug = require('util').debuglog('worker'); +setupWarningHandler(); + +// Since worker threads cannot switch cwd, we do not need to +// overwrite the process.env.NODE_V8_COVERAGE variable. +if (process.env.NODE_V8_COVERAGE) { + setupCoverageHooks(process.env.NODE_V8_COVERAGE); +} + debug(`[${threadId}] is setting up worker child environment`); // Set up the message port and start listening diff --git a/src/node_process_object.cc b/src/node_process_object.cc index e4d9d97c681bdd..e3b8eb8d54b7ba 100644 --- a/src/node_process_object.cc +++ b/src/node_process_object.cc @@ -256,18 +256,6 @@ MaybeLocal CreateProcessObject( "_breakNodeFirstLine", True(env->isolate())); } - // --inspect --debug-brk - if (env->options()->debug_options().deprecated_invocation()) { - READONLY_DONT_ENUM_PROPERTY(process, - "_deprecatedDebugBrk", True(env->isolate())); - } - - // --debug or, --debug-brk without --inspect - if (env->options()->debug_options().invalid_invocation()) { - READONLY_DONT_ENUM_PROPERTY(process, - "_invalidDebug", True(env->isolate())); - } - // --security-revert flags #define V(code, _, __) \ do { \