Socket
Socket
Sign inDemoInstall

@babel/helper-fixtures

Package Overview
Dependencies
Maintainers
4
Versions
97
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@babel/helper-fixtures - npm Package Compare versions

Comparing version 7.22.9 to 7.22.13

164

lib/index.js

@@ -42,13 +42,13 @@ "use strict";

const JSON_AND_EXTENSIONS = [".json", ...EXTENSIONS];
function findFile(filepath, allowJSON) {
const matches = [];
function checkFile(loc, allowJSON, matchedLoc) {
const ext = _path.extname(loc);
const extensions = allowJSON ? JSON_AND_EXTENSIONS : EXTENSIONS;
for (const ext of extensions) {
const name = filepath + ext;
if (_fs.existsSync(name)) matches.push(name);
if (!extensions.includes(ext)) {
throw new Error(`Unsupported input extension: ${loc}`);
}
if (matches.length > 1) {
throw new Error(`Found conflicting file matches: ${matches.join(", ")}`);
if (!matchedLoc) {
return loc;
} else {
throw new Error(`Found conflicting file matches: ${matchedLoc},${loc}`);
}
return matches[0];
}

@@ -58,21 +58,47 @@ function pushTask(taskName, taskDir, suite, suiteName) {

const taskDirStats = _fs.statSync(taskDir);
let actualLoc = findFile(taskDir + "/input");
let execLoc = findFile(taskDir + "/exec");
if (taskDirStats.isDirectory() && !actualLoc && !execLoc) {
if (_fs.readdirSync(taskDir).length > 0) {
let actualLoc, expectLoc, execLoc, execLocAlias, taskOptsLoc, stdoutLoc, stderrLoc, sourceMapLoc, inputSourceMap;
const taskOpts = JSON.parse(JSON.stringify(suite.options));
if (taskDirStats.isDirectory()) {
var _actualLoc, _execLoc, _expectLoc;
const files = _fs.readdirSync(taskDir);
for (const file of files) {
const loc = _path.join(taskDir, file);
const name = _path.basename(file, _path.extname(file));
switch (name) {
case "input":
actualLoc = checkFile(loc, false, actualLoc);
break;
case "exec":
execLoc = checkFile(loc, false, execLoc);
break;
case "output":
expectLoc = checkFile(loc, true, expectLoc);
break;
case "output.extended":
expectLoc = checkFile(loc, true, expectLoc);
break;
case "options":
taskOptsLoc = loc;
Object.assign(taskOpts, require(taskOptsLoc));
break;
case "source-map":
{
sourceMapLoc = loc;
break;
}
case "input-source-map":
inputSourceMap = JSON.parse(readFile(loc));
break;
}
}
if (files.length > 0 && !actualLoc && !execLoc) {
console.warn(`Skipped test folder with invalid layout: ${taskDir}`);
return;
}
return;
} else if (!actualLoc) {
actualLoc = taskDir + "/input.js";
} else if (!execLoc) {
execLoc = taskDir + "/exec.js";
}
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()) {
(_actualLoc = actualLoc) != null ? _actualLoc : actualLoc = taskDir + "/input.js";
(_execLoc = execLoc) != null ? _execLoc : execLoc = taskDir + "/exec.js";
(_expectLoc = expectLoc) != null ? _expectLoc : expectLoc = taskDir + "/output.js";
stdoutLoc = taskDir + "/stdout.txt";
stderrLoc = taskDir + "/stderr.txt";
} else if (taskDirStats.isFile()) {
const ext = _path.extname(taskDir);

@@ -82,6 +108,17 @@ if (EXTENSIONS.indexOf(ext) === -1) return;

execLocAlias = suiteName + "/" + taskName;
} else {
console.warn(`Skipped test folder with invalid layout: ${taskDir}`);
return;
}
const taskOpts = JSON.parse(JSON.stringify(suite.options));
const taskOptsLoc = tryResolve(taskDir + "/options");
if (taskOptsLoc) Object.assign(taskOpts, require(taskOptsLoc));
const shouldIgnore = taskOpts.BABEL_8_BREAKING === true;
if (shouldIgnore) return;
function buildTestFile(loc, fileName) {
return {
loc,
code: readFile(loc),
filename: !loc ? undefined : fileName === true ? suiteName + "/" + taskName + "/" + _path.basename(loc) : fileName || undefined
};
}
const sourceMapFile = buildTestFile(sourceMapLoc, true);
sourceMapFile.code && (sourceMapFile.code = JSON.parse(sourceMapFile.code));
const test = {

@@ -91,3 +128,3 @@ taskDir,

title: humanize(taskName, true),
disabled: taskName[0] === "." || taskOpts.BABEL_8_BREAKING === true,
disabled: taskName[0] === ".",
options: taskOpts,

@@ -98,29 +135,14 @@ doNotSetSourceType: taskOpts.DO_NOT_SET_SOURCE_TYPE,

ignoreOutput: taskOpts.ignoreOutput,
stdout: {
loc: stdoutLoc,
code: readFile(stdoutLoc)
},
stderr: {
loc: stderrLoc,
code: readFile(stderrLoc)
},
exec: {
loc: execLoc,
code: readFile(execLoc),
filename: execLocAlias
},
actual: {
loc: actualLoc,
code: readFile(actualLoc),
filename: actualLocAlias
},
expect: {
loc: expectLoc,
code: readFile(expectLoc),
filename: expectLocAlias
},
sourceMap: undefined,
sourceMapFile: undefined,
inputSourceMap: undefined
stdout: buildTestFile(stdoutLoc),
stderr: buildTestFile(stderrLoc),
exec: buildTestFile(execLoc, execLocAlias),
actual: buildTestFile(actualLoc, true),
expect: buildTestFile(expectLoc, true),
sourceMap: sourceMapFile.code,
sourceMapFile,
inputSourceMap
};
if (test.exec.code && test.actual.code && _path.extname(execLoc) !== _path.extname(actualLoc)) {
throw new Error(`Input file extension should match exec file extension: ${execLoc}, ${actualLoc}`);
}
delete taskOpts.BABEL_8_BREAKING;

@@ -151,19 +173,3 @@ delete taskOpts.DO_NOT_SET_SOURCE_TYPE;

}
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 = {
loc: sourceMapLoc,
code: test.sourceMap,
filename: ""
};
const inputMapLoc = taskDir + "/input-source-map.json";
if (_fs.existsSync(inputMapLoc)) {
test.inputSourceMap = JSON.parse(readFile(inputMapLoc));
}
if (taskOpts.throws) {

@@ -278,8 +284,12 @@ if (test.expect.code) {

function readFile(filename) {
if (_fs.existsSync(filename)) {
let file = _fs.readFileSync(filename, "utf8").trimRight();
file = file.replace(/\r\n/g, "\n");
return file;
} else {
return "";
try {
if (filename === undefined) {
return "";
}
return _fs.readFileSync(filename, "utf8").trimRight();
} catch (e) {
if (e.code === "ENOENT") {
return "";
}
throw e;
}

@@ -286,0 +296,0 @@ }

{
"name": "@babel/helper-fixtures",
"version": "7.22.9",
"version": "7.22.13",
"description": "Helper function to support fixtures",

@@ -21,2 +21,3 @@ "author": "The Babel Team (https://babel.dev/team)",

"devDependencies": {
"@jridgewell/gen-mapping": "^0.3.3",
"@types/semver": "^7.3.4"

@@ -23,0 +24,0 @@ },

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