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

@babel/helper-fixtures

Package Overview
Dependencies
Maintainers
4
Versions
101
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 8.0.0-alpha.2 to 8.0.0-alpha.3

166

lib/index.js

@@ -34,35 +34,61 @@ import semver from "semver";

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];
}
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, sourceMapVisualLoc, inputSourceMap;
const taskOpts = JSON.parse(JSON.stringify(suite.options));
if (taskDirStats.isDirectory()) {
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 "source-map-visual":
sourceMapVisualLoc = 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 ??= taskDir + "/input.js";
execLoc ??= taskDir + "/exec.js";
expectLoc ??= taskDir + "/output.js";
stdoutLoc = taskDir + "/stdout.txt";
stderrLoc = taskDir + "/stderr.txt";
} else if (taskDirStats.isFile()) {
const ext = path.extname(taskDir);

@@ -72,6 +98,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 === false;
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 &&= JSON.parse(sourceMapFile.code);
const test = {

@@ -81,3 +118,3 @@ taskDir,

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

@@ -88,29 +125,16 @@ 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,
sourceMapVisual: buildTestFile(sourceMapVisualLoc),
validateSourceMapVisual: taskOpts.sourceMaps === true || taskOpts.sourceMaps === "both",
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;

@@ -141,19 +165,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) {

@@ -268,8 +276,12 @@ if (test.expect.code) {

export 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;
}

@@ -276,0 +288,0 @@ }

{
"name": "@babel/helper-fixtures",
"version": "8.0.0-alpha.2",
"version": "8.0.0-alpha.3",
"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