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

lib: make internal/options lazy #38993

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 28 additions & 4 deletions lib/internal/options.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
'use strict';

const { getOptions, shouldNotRegisterESMLoader } = internalBinding('options');
const { options, aliases } = getOptions();

let warnOnAllowUnauthorized = true;

let optionsMap;
let aliasesMap;

// getOptions() would serialize the option values from C++ land.
// It would error if the values are queried before bootstrap is
// complete so that we don't accidentally include runtime-dependent
// states into a runtime-independent snapshot.
function getOptionsFromBinding() {
if (!optionsMap) {
({ options: optionsMap } = getOptions());
joyeecheung marked this conversation as resolved.
Show resolved Hide resolved
}
return optionsMap;
}

function getAliasesFromBinding() {
if (!aliasesMap) {
({ aliases: aliasesMap } = getOptions());
joyeecheung marked this conversation as resolved.
Show resolved Hide resolved
}
return aliasesMap;
}

function getOptionValue(option) {
return options.get(option)?.value;
return getOptionsFromBinding().get(option)?.value;
}

function getAllowUnauthorized() {
Expand All @@ -24,8 +44,12 @@ function getAllowUnauthorized() {
}

module.exports = {
options,
aliases,
get options() {
return getOptionsFromBinding();
},
get aliases() {
return getAliasesFromBinding();
},
getOptionValue,
getAllowUnauthorized,
shouldNotRegisterESMLoader
Expand Down