Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@babel/helper-compilation-targets

Package Overview
Dependencies
Maintainers
4
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@babel/helper-compilation-targets - npm Package Compare versions

Comparing version 7.20.0 to 7.20.7

7

lib/debug.js

@@ -7,9 +7,5 @@ "use strict";

exports.getInclusionReasons = getInclusionReasons;
var _semver = require("semver");
var _pretty = require("./pretty");
var _utils = require("./utils");
function getInclusionReasons(item, targetVersions, list) {

@@ -20,3 +16,2 @@ const minVersions = list[item] || {};

const targetVersion = targetVersions[env];
if (!minVersion) {

@@ -27,3 +22,2 @@ result[env] = (0, _pretty.prettifyVersion)(targetVersion);

const targetIsUnreleased = (0, _utils.isUnreleasedVersion)(targetVersion, env);
if (!targetIsUnreleased && (minIsUnreleased || _semver.lt(targetVersion.toString(), (0, _utils.semverify)(minVersion)))) {

@@ -33,3 +27,2 @@ result[env] = (0, _pretty.prettifyVersion)(targetVersion);

}
return result;

@@ -36,0 +29,0 @@ }, {});

@@ -9,16 +9,10 @@ "use strict";

exports.targetsSupported = targetsSupported;
var _semver = require("semver");
var _plugins = require("@babel/compat-data/plugins");
var _utils = require("./utils");
function targetsSupported(target, support) {
const targetEnvironments = Object.keys(target);
if (targetEnvironments.length === 0) {
return false;
}
const unsupportedEnvironments = targetEnvironments.filter(environment => {

@@ -30,3 +24,2 @@ const lowestImplementedVersion = (0, _utils.getLowestImplementedVersion)(support, environment);

}
const lowestTargetedVersion = target[environment];

@@ -41,7 +34,5 @@

}
if (!_semver.valid(lowestTargetedVersion.toString())) {
throw new Error(`Invalid version passed for target "${environment}": "${lowestTargetedVersion}". ` + "Versions must be in semver format (major.minor.patch)");
}
return _semver.gt((0, _utils.semverify)(lowestImplementedVersion), lowestTargetedVersion.toString());

@@ -51,3 +42,2 @@ });

}
function isRequired(name, targets, {

@@ -62,3 +52,2 @@ compatData = _plugins,

}
function filterItems(list, includes, excludes, targets, defaultIncludes, defaultExcludes, pluginSyntaxMap) {

@@ -71,3 +60,2 @@ const result = new Set();

};
for (const item in list) {

@@ -78,3 +66,2 @@ if (isRequired(item, targets, options)) {

const shippedProposalsSyntax = pluginSyntaxMap.get(item);
if (shippedProposalsSyntax) {

@@ -85,11 +72,8 @@ result.add(shippedProposalsSyntax);

}
if (defaultIncludes) {
defaultIncludes.forEach(item => !excludes.has(item) && result.add(item));
}
if (defaultExcludes) {
defaultExcludes.forEach(item => !includes.has(item) && result.delete(item));
}
return result;

@@ -96,0 +80,0 @@ }

58

lib/index.js

@@ -44,27 +44,16 @@ "use strict";

});
var _browserslist = require("browserslist");
var _helperValidatorOption = require("@babel/helper-validator-option");
var _nativeModules = require("@babel/compat-data/native-modules");
var _lruCache = require("lru-cache");
var _utils = require("./utils");
var _targets = require("./targets");
var _options = require("./options");
var _pretty = require("./pretty");
var _debug = require("./debug");
var _filterItems = require("./filter-items");
const ESM_SUPPORT = _nativeModules["es6.module"];
const v = new _helperValidatorOption.OptionValidator("@babel/helper-compilation-targets");
function validateTargetNames(targets) {
const validTargets = Object.keys(_options.TargetNames);
for (const target of Object.keys(targets)) {

@@ -76,10 +65,7 @@ if (!(target in _options.TargetNames)) {

}
return targets;
}
function isBrowsersQueryValid(browsers) {
return typeof browsers === "string" || Array.isArray(browsers) && browsers.every(b => typeof b === "string");
}
function validateBrowsers(browsers) {

@@ -89,3 +75,2 @@ v.invariant(browsers === undefined || isBrowsersQueryValid(browsers), `'${String(browsers)}' is not a valid browserslist query`);

}
function getLowestVersions(browsers) {

@@ -95,11 +80,8 @@ return browsers.reduce((all, browser) => {

const target = _targets.browserNameMap[browserName];
if (!target) {
return all;
}
try {
const splitVersion = browserVersion.split("-")[0].toLowerCase();
const isSplitUnreleased = (0, _utils.isUnreleasedVersion)(splitVersion, target);
if (!all[target]) {

@@ -109,6 +91,4 @@ all[target] = isSplitUnreleased ? splitVersion : (0, _utils.semverify)(splitVersion);

}
const version = all[target];
const isUnreleased = (0, _utils.isUnreleasedVersion)(version, target);
if (isUnreleased && isSplitUnreleased) {

@@ -123,7 +103,5 @@ all[target] = (0, _utils.getLowestUnreleased)(version, splitVersion, target);

} catch (e) {}
return all;
}, {});
}
function outputDecimalWarning(decimalTargets) {

@@ -133,3 +111,2 @@ if (!decimalTargets.length) {

}
console.warn("Warning, the following targets are using a decimal version:\n");

@@ -145,3 +122,2 @@ decimalTargets.forEach(({

}
function semverifyTarget(target, value) {

@@ -159,3 +135,2 @@ try {

}
function defaultTargetParser(target, value) {

@@ -165,3 +140,2 @@ const version = (0, _utils.isUnreleasedVersion)(value, target) ? value.toLowerCase() : semverifyTarget(target, value);

}
function generateTargets(inputTargets) {

@@ -173,3 +147,2 @@ const input = Object.assign({}, inputTargets);

}
function resolveTargets(queries, env) {

@@ -180,9 +153,18 @@ const resolved = _browserslist(queries, {

});
return getLowestVersions(resolved);
}
const targetsCache = new _lruCache({
max: 64
});
function resolveTargetsCached(queries, env) {
const cacheKey = typeof queries === "string" ? queries : queries.join() + env;
let cached = targetsCache.get(cacheKey);
if (!cached) {
cached = resolveTargets(queries, env);
targetsCache.set(cacheKey, cached);
}
return Object.assign({}, cached);
}
function getTargets(inputTargets = {}, options = {}) {
var _browsers, _browsers2;
let {

@@ -201,3 +183,2 @@ browsers,

const shouldSearchForConfig = !options.ignoreBrowserslistConfig && !hasTargets;
if (!browsers && shouldSearchForConfig) {

@@ -209,3 +190,2 @@ browsers = _browserslist.loadConfig({

});
if (browsers == null) {

@@ -224,9 +204,8 @@ {

if ((_browsers2 = browsers) != null && _browsers2.length) {
const queryBrowsers = resolveTargets(browsers, options.browserslistEnv);
const queryBrowsers = resolveTargetsCached(browsers, options.browserslistEnv);
if (esmodules === "intersect") {
for (const browser of Object.keys(queryBrowsers)) {
const version = queryBrowsers[browser];
const esmSupportVersion = ESM_SUPPORT[browser];
const esmSupportVersion =
ESM_SUPPORT[browser];
if (esmSupportVersion) {

@@ -239,3 +218,2 @@ queryBrowsers[browser] = (0, _utils.getHighestUnreleased)(version, (0, _utils.semverify)(esmSupportVersion), browser);

}
targets = Object.assign(queryBrowsers, targets);

@@ -246,3 +224,2 @@ }

const decimalWarnings = [];
for (const target of Object.keys(targets).sort()) {

@@ -257,5 +234,3 @@ const value = targets[target];

}
const [parsedTarget, parsedValue] = target === "node" ? nodeTargetParser(value) : defaultTargetParser(target, value);
if (parsedValue) {

@@ -265,3 +240,2 @@ result[parsedTarget] = parsedValue;

}
outputDecimalWarning(decimalWarnings);

@@ -268,0 +242,0 @@ return result;

@@ -8,7 +8,4 @@ "use strict";

exports.prettifyVersion = prettifyVersion;
var _semver = require("semver");
var _targets = require("./targets");
function prettifyVersion(version) {

@@ -18,29 +15,24 @@ if (typeof version !== "string") {

}
const parts = [_semver.major(version)];
const minor = _semver.minor(version);
const patch = _semver.patch(version);
const {
major,
minor,
patch
} = _semver.parse(version);
const parts = [major];
if (minor || patch) {
parts.push(minor);
}
if (patch) {
parts.push(patch);
}
return parts.join(".");
}
function prettifyTargets(targets) {
return Object.keys(targets).reduce((results, target) => {
let value = targets[target];
const unreleasedLabel = _targets.unreleasedLabels[target];
const unreleasedLabel =
_targets.unreleasedLabels[target];
if (typeof value === "string" && unreleasedLabel !== value) {
value = prettifyVersion(value);
}
results[target] = value;

@@ -47,0 +39,0 @@ return results;

@@ -12,12 +12,7 @@ "use strict";

exports.semverify = semverify;
var _semver = require("semver");
var _helperValidatorOption = require("@babel/helper-validator-option");
var _targets = require("./targets");
const versionRegExp = /^(\d+|\d+.\d+)$/;
const v = new _helperValidatorOption.OptionValidator("@babel/helper-compilation-targets");
function semverMin(first, second) {

@@ -31,43 +26,35 @@ return first && _semver.lt(first, second) ? first : second;

}
v.invariant(typeof version === "number" || typeof version === "string" && versionRegExp.test(version), `'${version}' is not a valid version`);
const split = version.toString().split(".");
while (split.length < 3) {
split.push("0");
version = version.toString();
let pos = 0;
let num = 0;
while ((pos = version.indexOf(".", pos + 1)) > 0) {
num++;
}
return split.join(".");
return version + ".0".repeat(2 - num);
}
function isUnreleasedVersion(version, env) {
const unreleasedLabel = _targets.unreleasedLabels[env];
const unreleasedLabel =
_targets.unreleasedLabels[env];
return !!unreleasedLabel && unreleasedLabel === version.toString().toLowerCase();
}
function getLowestUnreleased(a, b, env) {
const unreleasedLabel = _targets.unreleasedLabels[env];
const unreleasedLabel =
_targets.unreleasedLabels[env];
if (a === unreleasedLabel) {
return b;
}
if (b === unreleasedLabel) {
return a;
}
return semverMin(a, b);
}
function getHighestUnreleased(a, b, env) {
return getLowestUnreleased(a, b, env) === a ? b : a;
}
function getLowestImplementedVersion(plugin, environment) {
const result = plugin[environment];
if (!result && environment === "android") {
return plugin.chrome;
}
return result;

@@ -74,0 +61,0 @@ }

{
"name": "@babel/helper-compilation-targets",
"version": "7.20.0",
"version": "7.20.7",
"author": "The Babel Team (https://babel.dev/team)",

@@ -25,5 +25,6 @@ "license": "MIT",

"dependencies": {
"@babel/compat-data": "^7.20.0",
"@babel/compat-data": "^7.20.5",
"@babel/helper-validator-option": "^7.18.6",
"browserslist": "^4.21.3",
"lru-cache": "^5.1.1",
"semver": "^6.3.0"

@@ -35,4 +36,5 @@ },

"devDependencies": {
"@babel/core": "^7.19.6",
"@babel/core": "^7.20.7",
"@babel/helper-plugin-test-runner": "^7.18.6",
"@types/lru-cache": "^5.1.1",
"@types/semver": "^5.5.0"

@@ -39,0 +41,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc