@babel/helper-fixtures
Advanced tools
Comparing version 7.19.4 to 7.21.0
@@ -10,15 +10,8 @@ "use strict"; | ||
exports.resolveOptionPluginOrPreset = resolveOptionPluginOrPreset; | ||
var _semver = require("semver"); | ||
var _path = require("path"); | ||
var _fs = require("fs"); | ||
var _url = require("url"); | ||
var _module = require("module"); | ||
const nodeVersion = _semver.clean(process.version.slice(1)); | ||
function humanize(val, noext) { | ||
@@ -28,3 +21,2 @@ if (noext) val = _path.basename(val, _path.extname(val)); | ||
} | ||
function tryResolve(module) { | ||
@@ -37,3 +29,2 @@ try { | ||
} | ||
function assertDirectory(loc) { | ||
@@ -44,3 +35,2 @@ if (!_fs.statSync(loc).isDirectory()) { | ||
} | ||
function shouldIgnore(name, ignore) { | ||
@@ -50,15 +40,9 @@ if (ignore && ignore.indexOf(name) >= 0) { | ||
} | ||
const ext = _path.extname(name); | ||
const base = _path.basename(name, ext); | ||
return name[0] === "." || ext === ".md" || base === "LICENSE" || base === "options" || name === "package.json"; | ||
} | ||
const EXTENSIONS = [".js", ".mjs", ".ts", ".tsx", ".cts", ".mts"]; | ||
function findFile(filepath, allowJSON) { | ||
const matches = []; | ||
for (const ext of EXTENSIONS.concat(allowJSON ? ".json" : [])) { | ||
@@ -68,18 +52,12 @@ const name = filepath + ext; | ||
} | ||
if (matches.length > 1) { | ||
throw new Error(`Found conflicting file matches: ${matches.join(", ")}`); | ||
} | ||
return matches[0]; | ||
} | ||
function pushTask(taskName, taskDir, suite, suiteName) { | ||
var _taskOpts$externalHel; | ||
const taskDirStats = _fs.statSync(taskDir); | ||
let actualLoc = findFile(taskDir + "/input"); | ||
let execLoc = findFile(taskDir + "/exec"); | ||
if (taskDirStats.isDirectory() && !actualLoc && !execLoc) { | ||
@@ -89,3 +67,2 @@ if (_fs.readdirSync(taskDir).length > 0) { | ||
} | ||
return; | ||
@@ -97,16 +74,10 @@ } else if (!actualLoc) { | ||
} | ||
const expectLoc = findFile(taskDir + "/output", true) || findFile(`${taskDir}/output.extended`, true) || taskDir + "/output.js"; | ||
const stdoutLoc = taskDir + "/stdout.txt"; | ||
const stderrLoc = taskDir + "/stderr.txt"; | ||
const actualLocAlias = suiteName + "/" + taskName + "/" + _path.basename(actualLoc); | ||
const expectLocAlias = suiteName + "/" + taskName + "/" + _path.basename(actualLoc); | ||
let execLocAlias = suiteName + "/" + taskName + "/" + _path.basename(actualLoc); | ||
if (taskDirStats.isFile()) { | ||
const ext = _path.extname(taskDir); | ||
if (EXTENSIONS.indexOf(ext) === -1) return; | ||
@@ -116,3 +87,2 @@ execLoc = taskDir; | ||
} | ||
const taskOpts = JSON.parse(JSON.stringify(suite.options)); | ||
@@ -160,46 +130,33 @@ const taskOptsLoc = tryResolve(taskDir + "/options"); | ||
delete taskOpts.DO_NOT_SET_SOURCE_TYPE; | ||
if (taskOpts.minNodeVersion) { | ||
const minimumVersion = _semver.clean(taskOpts.minNodeVersion); | ||
if (minimumVersion == null) { | ||
throw new Error(`'minNodeVersion' has invalid semver format: ${taskOpts.minNodeVersion}`); | ||
} | ||
if (_semver.lt(nodeVersion, minimumVersion)) { | ||
return; | ||
} | ||
delete taskOpts.minNodeVersion; | ||
} | ||
if (taskOpts.os) { | ||
let os = taskOpts.os; | ||
if (!Array.isArray(os) && typeof os !== "string") { | ||
throw new Error(`'os' should be either string or string array: ${taskOpts.os}`); | ||
} | ||
if (typeof os === "string") { | ||
os = [os]; | ||
} | ||
if (!os.includes(process.platform)) { | ||
return; | ||
} | ||
delete taskOpts.os; | ||
} | ||
if (test.exec.code.indexOf("// Async.") >= 0) { | ||
return; | ||
} | ||
suite.tests.push(test); | ||
const sourceMapLoc = taskDir + "/source-map.json"; | ||
if (_fs.existsSync(sourceMapLoc)) { | ||
test.sourceMap = JSON.parse(readFile(sourceMapLoc)); | ||
} | ||
test.sourceMapFile = { | ||
@@ -211,7 +168,5 @@ loc: sourceMapLoc, | ||
const inputMapLoc = taskDir + "/input-source-map.json"; | ||
if (_fs.existsSync(inputMapLoc)) { | ||
test.inputSourceMap = JSON.parse(readFile(inputMapLoc)); | ||
} | ||
if (taskOpts.throws) { | ||
@@ -221,3 +176,2 @@ if (test.expect.code) { | ||
} | ||
if (test.sourceMap) { | ||
@@ -227,7 +181,5 @@ throw new Error("Test cannot throw and also return sourcemaps: " + sourceMapLoc); | ||
} | ||
if (!test.validateLogs && (test.stdout.code || test.stderr.code)) { | ||
throw new Error("stdout.txt and stderr.txt are only allowed when the 'validateLogs' option is enabled: " + (test.stdout.code ? stdoutLoc : stderrLoc)); | ||
} | ||
if (test.ignoreOutput) { | ||
@@ -237,3 +189,2 @@ if (test.expect.code) { | ||
} | ||
if (!test.validateLogs) { | ||
@@ -243,3 +194,2 @@ throw new Error("ignoreOutput can only be used when validateLogs is true: " + taskOptsLoc); | ||
} | ||
delete test.options.validateLogs; | ||
@@ -249,7 +199,5 @@ delete test.options.ignoreOutput; | ||
} | ||
function wrapPackagesArray(type, names, optionsDir) { | ||
return names.map(function (val) { | ||
if (typeof val === "string") val = [val]; | ||
if (val[0][0] === ".") { | ||
@@ -259,3 +207,2 @@ if (!optionsDir) { | ||
} | ||
val[0] = _path.resolve(optionsDir, val[0]); | ||
@@ -265,9 +212,6 @@ } else { | ||
const match = name.match(/^(@babel\/(?:plugin-|preset-)?)(.*)$/); | ||
if (match) { | ||
name = match[2]; | ||
} | ||
const monorepoPath = _path.join(_path.dirname(__filename), "../../..", name.startsWith("codemod") ? "codemods" : "packages", `babel-${type}-${name}/lib/index.js`); | ||
if (_fs.existsSync(monorepoPath)) { | ||
@@ -277,11 +221,8 @@ if (match) { | ||
} | ||
val[0] = monorepoPath; | ||
} | ||
} | ||
return val; | ||
}); | ||
} | ||
function resolveOptionPluginOrPreset(options, optionsDir) { | ||
@@ -291,3 +232,2 @@ if (options.plugins) { | ||
} | ||
if (options.presets) { | ||
@@ -298,10 +238,7 @@ options.presets = wrapPackagesArray("preset", options.presets, optionsDir).map(function (val) { | ||
} | ||
return val; | ||
}); | ||
} | ||
return options; | ||
} | ||
function get(entryLoc) { | ||
@@ -312,3 +249,2 @@ const suites = []; | ||
if (rootOptsLoc) rootOpts = require(rootOptsLoc); | ||
for (const suiteName of _fs.readdirSync(entryLoc)) { | ||
@@ -325,7 +261,5 @@ if (shouldIgnore(suiteName)) continue; | ||
const suiteOptsLoc = tryResolve(suite.filename + "/options"); | ||
if (suiteOptsLoc) { | ||
suite.options = resolveOptionPluginOrPreset(require(suiteOptsLoc), suite.filename); | ||
} | ||
for (const taskName of _fs.readdirSync(suite.filename)) { | ||
@@ -335,25 +269,17 @@ pushTask(taskName, suite.filename + "/" + taskName, suite, suiteName); | ||
} | ||
return suites; | ||
} | ||
function multiple(entryLoc, ignore) { | ||
const categories = {}; | ||
for (const name of _fs.readdirSync(entryLoc)) { | ||
if (shouldIgnore(name, ignore)) continue; | ||
const loc = _path.join(entryLoc, name); | ||
assertDirectory(loc); | ||
categories[name] = get(loc); | ||
} | ||
return categories; | ||
} | ||
function readFile(filename) { | ||
if (_fs.existsSync(filename)) { | ||
let file = _fs.readFileSync(filename, "utf8").trimRight(); | ||
file = file.replace(/\r\n/g, "\n"); | ||
@@ -360,0 +286,0 @@ return file; |
{ | ||
"name": "@babel/helper-fixtures", | ||
"version": "7.19.4", | ||
"version": "7.21.0", | ||
"description": "Helper function to support fixtures", | ||
@@ -5,0 +5,0 @@ "author": "The Babel Team (https://babel.dev/team)", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35727