Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow to execute util scripts #12670

Merged
merged 1 commit into from
Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 37 additions & 17 deletions packages/babel-generator/scripts/generate-typescript-tests.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
/*
Copies tests from the @babel/parser's TypeScript test suite to @babel/generator.
*/
const {
copySync,
emptyDirSync,
existsSync,
readdirSync,
readFileSync,
} = require("fs-extra");
const fs = require("fs");
const { join } = require("path");

const testsFrom = join(
Expand All @@ -16,15 +10,16 @@ const testsFrom = join(
);
const testsTo = join(__dirname, "../test/fixtures/typescript");

emptyDirSync(testsTo);
fs.rmdirSync(testsTo, { recursive: true });
fs.mkdirSync(testsTo);

copySync(join(testsFrom, "options.json"), join(testsTo, "options.json"));
fs.copyFileSync(join(testsFrom, "options.json"), join(testsTo, "options.json"));

for (const groupName of readdirSync(testsFrom)) {
for (const groupName of fs.readdirSync(testsFrom)) {
if (groupName === "options.json") continue;

const groupFromDir = join(testsFrom, groupName);
const testNames = readdirSync(groupFromDir);
const testNames = fs.readdirSync(groupFromDir);
const groupHasOptions = testNames.includes("options.json");

for (const testName of testNames) {
Expand All @@ -37,10 +32,14 @@ for (const groupName of readdirSync(testsFrom)) {

let optionsJsonFrom;
const ownOptions = join(testFromDir, "options.json");
if (existsSync(ownOptions)) {
const options = JSON.parse(readFileSync(ownOptions));
if (fs.existsSync(ownOptions)) {
const options = JSON.parse(fs.readFileSync(ownOptions));
// Don't include a test that doesn't parse or does not provide babel AST
if (options.throws || options.plugins.indexOf("estree") >= 0) {
if (
options.throws ||
!options.plugins ||
options.plugins.indexOf("estree") >= 0
) {
continue;
}
optionsJsonFrom = ownOptions;
Expand All @@ -49,10 +48,31 @@ for (const groupName of readdirSync(testsFrom)) {
optionsJsonFrom = join(groupFromDir, "options.json");
}

emptyDirSync(testToDir);
fs.rmdirSync(testToDir, { recursive: true });
fs.mkdirSync(testToDir);
if (optionsJsonFrom) {
copySync(optionsJsonFrom, join(testToDir, "options.json"));
fs.copyFileSync(optionsJsonFrom, join(testToDir, "options.json"));
}
if (fs.existsSync(join(testFromDir, "input.js"))) {
fs.copyFileSync(
join(testFromDir, "input.js"),
join(testToDir, "input.js")
);
} else if (fs.existsSync(join(testFromDir, "input.tsx"))) {
fs.copyFileSync(
join(testFromDir, "input.tsx"),
join(testToDir, "input.tsx")
);
} else if (fs.existsSync(join(testFromDir, "input.jsx"))) {
fs.copyFileSync(
join(testFromDir, "input.jsx"),
join(testToDir, "input.jsx")
);
} else if (fs.existsSync(join(testFromDir, "input.ts"))) {
fs.copyFileSync(
join(testFromDir, "input.ts"),
join(testToDir, "input.ts")
);
}
copySync(join(testFromDir, "actual.js"), join(testToDir, "actual.js"));
}
}
4 changes: 2 additions & 2 deletions packages/babel-preset-env/scripts/smoke-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const fs = require("fs-extra");
const fs = require("fs");
const execSync = require("child_process").execSync;
const path = require("path");
const pkg = require("../package.json");
Expand All @@ -14,7 +14,7 @@ try {

console.log("Setting up smoke test dependencies");

fs.ensureDirSync(tempFolderPath);
fs.mkdirSync(tempFolderPath);
process.chdir(tempFolderPath);

const babelCliVersion = pkg.devDependencies["babel-cli"];
Expand Down