Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process: move deprecation warning initialization into pre_execution.js #25825

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 2 additions & 23 deletions lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,29 +229,6 @@ Object.defineProperty(process, 'argv0', {
});
process.argv[0] = process.execPath;

const { deprecate } = NativeModule.require('internal/util');
{
// Install legacy getters on the `util` binding for typechecking.
// TODO(addaleax): Turn into a full runtime deprecation.
const pendingDeprecation = getOptionValue('--pending-deprecation');
const utilBinding = internalBinding('util');
const types = NativeModule.require('internal/util/types');
for (const name of [
'isArrayBuffer', 'isArrayBufferView', 'isAsyncFunction',
'isDataView', 'isDate', 'isExternal', 'isMap', 'isMapIterator',
'isNativeError', 'isPromise', 'isRegExp', 'isSet', 'isSetIterator',
'isTypedArray', 'isUint8Array', 'isAnyArrayBuffer'
]) {
utilBinding[name] = pendingDeprecation ?
deprecate(types[name],
'Accessing native typechecking bindings of Node ' +
'directly is deprecated. ' +
`Please use \`util.types.${name}\` instead.`,
'DEP0103') :
types[name];
}
}

// process.allowedNodeEnvironmentFlags
Object.defineProperty(process, 'allowedNodeEnvironmentFlags', {
get() {
Expand All @@ -272,6 +249,8 @@ Object.defineProperty(process, 'allowedNodeEnvironmentFlags', {
enumerable: true,
configurable: true
});

const { deprecate } = NativeModule.require('internal/util');
// process.assert
process.assert = deprecate(
perThreadSetup.assert,
Expand Down
40 changes: 40 additions & 0 deletions lib/internal/bootstrap/pre_execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,45 @@

const { getOptionValue } = require('internal/options');

// In general deprecations are intialized wherever the APIs are implemented,
// this is used to deprecate APIs implemented in C++ where the deprecation
// utitlities are not easily accessible.
function initializeDeprecations() {
const { deprecate } = require('internal/util');
const pendingDeprecation = getOptionValue('--pending-deprecation');

// DEP0103: access to `process.binding('util').isX` type checkers
// TODO(addaleax): Turn into a full runtime deprecation.
const utilBinding = internalBinding('util');
const types = require('internal/util/types');
for (const name of [
'isArrayBuffer',
'isArrayBufferView',
'isAsyncFunction',
'isDataView',
'isDate',
'isExternal',
'isMap',
'isMapIterator',
'isNativeError',
'isPromise',
'isRegExp',
'isSet',
'isSetIterator',
'isTypedArray',
'isUint8Array',
'isAnyArrayBuffer'
]) {
utilBinding[name] = pendingDeprecation ?
deprecate(types[name],
'Accessing native typechecking bindings of Node ' +
'directly is deprecated. ' +
`Please use \`util.types.${name}\` instead.`,
'DEP0103') :
types[name];
}
}

function initializeClusterIPC() {
// If this is a worker in cluster mode, start up the communication
// channel. This needs to be done before any user code gets executed
Expand Down Expand Up @@ -75,6 +114,7 @@ function loadPreloadModules() {
}

module.exports = {
initializeDeprecations,
initializeClusterIPC,
initializePolicy,
initializeESMLoader,
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/main/check_syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// instead of actually running the file.

const {
initializeDeprecations,
initializeClusterIPC,
initializePolicy,
initializeESMLoader,
Expand All @@ -21,6 +22,7 @@ const {
} = require('internal/modules/cjs/helpers');

// TODO(joyeecheung): not every one of these are necessary
initializeDeprecations();
initializeClusterIPC();
initializePolicy();
initializeESMLoader();
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/main/eval_stdin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Stdin is not a TTY, we will read it and execute it.

const {
initializeDeprecations,
initializeClusterIPC,
initializePolicy,
initializeESMLoader,
Expand All @@ -14,6 +15,7 @@ const {
readStdin
} = require('internal/process/execution');

initializeDeprecations();
initializeClusterIPC();
initializePolicy();
initializeESMLoader();
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/main/eval_string.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// `--interactive`.

const {
initializeDeprecations,
initializeClusterIPC,
initializePolicy,
initializeESMLoader,
Expand All @@ -13,6 +14,7 @@ const { evalScript } = require('internal/process/execution');
const { addBuiltinLibsToObject } = require('internal/modules/cjs/helpers');

const source = require('internal/options').getOptionValue('--eval');
initializeDeprecations();
initializeClusterIPC();
initializePolicy();
initializeESMLoader();
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/main/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// the main module is not specified and stdin is a TTY.

const {
initializeDeprecations,
initializeClusterIPC,
initializePolicy,
initializeESMLoader,
Expand All @@ -14,6 +15,7 @@ const {
evalScript
} = require('internal/process/execution');

initializeDeprecations();
initializeClusterIPC();
initializePolicy();
initializeESMLoader();
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/main/run_main_module.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
'use strict';

const {
initializeDeprecations,
initializeClusterIPC,
initializePolicy,
initializeESMLoader,
loadPreloadModules
} = require('internal/bootstrap/pre_execution');

initializeDeprecations();
initializeClusterIPC();
initializePolicy();
initializeESMLoader();
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/main/worker_thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// message port.

const {
initializeDeprecations,
initializeClusterIPC,
initializeESMLoader,
loadPreloadModules
Expand Down Expand Up @@ -55,6 +56,7 @@ port.on('message', (message) => {
if (manifestSrc) {
require('internal/process/policy').setup(manifestSrc, manifestURL);
}
initializeDeprecations();
initializeClusterIPC();
initializeESMLoader();
loadPreloadModules();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any point in trying to group these 4 or 5 calls into a single one, possibly with an options object that indicates which parts of the setup to run?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried that before but a single call seems to hide too much details - I think it should be fine to directly drop some of the calls, for example, initializeClusterIPC in repl.js. Also the order in which these executes matters to some extent and an option object would blur that.

Maybe we could group them by different modes, but I cannot think of good names for those modes off the top of my head.

Expand Down