First Commit of new way of building the Platform

This commit is contained in:
Luis Fernando Molina committed 2020-01-28 17:27:23 +01:00
1 parent e48cf0dae5
commit 40e60b42cc
4616 files changed
+713402

No files matched your search

+62
View File
@@ -0,0 +1,62 @@
'use strict';
const semver = require('semver');
const flags = require('./flags.json');
const getDescriptors = require('object.getownpropertydescriptors');
const replaceUnderscoresRegex = /_/g;
const leadingDashesRegex = /^--?/;
const trailingValuesRegex = /=.*$/;
const replace = Function.call.bind(String.prototype.replace);
const has = Function.call.bind(Set.prototype.has);
const test = Function.call.bind(RegExp.prototype.test);
const [allowedNodeEnvironmentFlags, detectedSemverRange] = Object.keys(
flags
).reduce(
(acc, range) =>
acc ||
(semver.satisfies(process.version, range) ? [flags[range], range] : acc),
null
);
const trimLeadingDashes = flag => replace(flag, leadingDashesRegex, '');
class NodeEnvironmentFlagsSet extends Set {
constructor(...args) {
super(...args);
this.add = () => this;
}
delete() {
return false;
}
clear() {}
has(key) {
if (typeof key === 'string') {
key = replace(key, replaceUnderscoresRegex, '-');
if (test(leadingDashesRegex, key)) {
key = replace(key, trailingValuesRegex, '');
return has(this, key);
}
return has(nodeFlags, key);
}
return false;
}
}
const nodeFlags = Object.defineProperties(
new Set(allowedNodeEnvironmentFlags.map(trimLeadingDashes)),
getDescriptors(Set.prototype)
);
Object.freeze(NodeEnvironmentFlagsSet.prototype.constructor);
Object.freeze(NodeEnvironmentFlagsSet.prototype);
exports.allowedNodeEnvironmentFlags = Object.freeze(
new NodeEnvironmentFlagsSet(allowedNodeEnvironmentFlags)
);
exports.detectedSemverRange = detectedSemverRange;