forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
10 changed files
with
278 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const { getOptionValue } = require('internal/options'); | ||
const assert = require('internal/assert'); | ||
|
||
const { | ||
ERR_INVALID_ARG_VALUE, | ||
} = require('internal/errors').codes; | ||
|
||
const { | ||
ArrayIsArray, | ||
SafeSet, | ||
ObjectFreeze, | ||
} = primordials; | ||
|
||
let defaultConditions; | ||
function getDefaultConditions() { | ||
assert(defaultConditions !== undefined); | ||
return defaultConditions; | ||
} | ||
|
||
let defaultConditionsSet; | ||
function getDefaultConditionsSet() { | ||
assert(defaultConditionsSet !== undefined); | ||
return defaultConditionsSet; | ||
} | ||
|
||
// This function is called during pre-execution, before any user code is run. | ||
function initializeDefaultConditions() { | ||
const userConditions = getOptionValue('--conditions'); | ||
const noAddons = getOptionValue('--no-addons'); | ||
const addonConditions = noAddons ? [] : ['node-addons']; | ||
|
||
defaultConditions = ObjectFreeze([ | ||
'node', | ||
'import', | ||
...addonConditions, | ||
...userConditions, | ||
]); | ||
defaultConditionsSet = new SafeSet(defaultConditions); | ||
} | ||
|
||
/** | ||
* @param {string[]} [conditions] | ||
* @returns {Set<string>} | ||
*/ | ||
function getConditionsSet(conditions) { | ||
if (conditions !== undefined && conditions !== getDefaultConditions()) { | ||
if (!ArrayIsArray(conditions)) { | ||
throw new ERR_INVALID_ARG_VALUE('conditions', conditions, | ||
'expected an array'); | ||
} | ||
return new SafeSet(conditions); | ||
} | ||
return getDefaultConditionsSet(); | ||
} | ||
|
||
module.exports = { | ||
initializeDefaultConditions, | ||
getDefaultConditions, | ||
getConditionsSet, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.