Skip to content

Commit 6783308

Browse files
authored
fix: allow to execute util scripts (#12670)
[skip ci]
1 parent 10978bb commit 6783308

2 files changed

Lines changed: 39 additions & 19 deletions

File tree

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
/*
22
Copies tests from the @babel/parser's TypeScript test suite to @babel/generator.
33
*/
4-
const {
5-
copySync,
6-
emptyDirSync,
7-
existsSync,
8-
readdirSync,
9-
readFileSync,
10-
} = require("fs-extra");
4+
const fs = require("fs");
115
const { join } = require("path");
126

137
const testsFrom = join(
@@ -16,15 +10,16 @@ const testsFrom = join(
1610
);
1711
const testsTo = join(__dirname, "../test/fixtures/typescript");
1812

19-
emptyDirSync(testsTo);
13+
fs.rmdirSync(testsTo, { recursive: true });
14+
fs.mkdirSync(testsTo);
2015

21-
copySync(join(testsFrom, "options.json"), join(testsTo, "options.json"));
16+
fs.copyFileSync(join(testsFrom, "options.json"), join(testsTo, "options.json"));
2217

23-
for (const groupName of readdirSync(testsFrom)) {
18+
for (const groupName of fs.readdirSync(testsFrom)) {
2419
if (groupName === "options.json") continue;
2520

2621
const groupFromDir = join(testsFrom, groupName);
27-
const testNames = readdirSync(groupFromDir);
22+
const testNames = fs.readdirSync(groupFromDir);
2823
const groupHasOptions = testNames.includes("options.json");
2924

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

3833
let optionsJsonFrom;
3934
const ownOptions = join(testFromDir, "options.json");
40-
if (existsSync(ownOptions)) {
41-
const options = JSON.parse(readFileSync(ownOptions));
35+
if (fs.existsSync(ownOptions)) {
36+
const options = JSON.parse(fs.readFileSync(ownOptions));
4237
// Don't include a test that doesn't parse or does not provide babel AST
43-
if (options.throws || options.plugins.indexOf("estree") >= 0) {
38+
if (
39+
options.throws ||
40+
!options.plugins ||
41+
options.plugins.indexOf("estree") >= 0
42+
) {
4443
continue;
4544
}
4645
optionsJsonFrom = ownOptions;
@@ -49,10 +48,31 @@ for (const groupName of readdirSync(testsFrom)) {
4948
optionsJsonFrom = join(groupFromDir, "options.json");
5049
}
5150

52-
emptyDirSync(testToDir);
51+
fs.rmdirSync(testToDir, { recursive: true });
52+
fs.mkdirSync(testToDir);
5353
if (optionsJsonFrom) {
54-
copySync(optionsJsonFrom, join(testToDir, "options.json"));
54+
fs.copyFileSync(optionsJsonFrom, join(testToDir, "options.json"));
55+
}
56+
if (fs.existsSync(join(testFromDir, "input.js"))) {
57+
fs.copyFileSync(
58+
join(testFromDir, "input.js"),
59+
join(testToDir, "input.js")
60+
);
61+
} else if (fs.existsSync(join(testFromDir, "input.tsx"))) {
62+
fs.copyFileSync(
63+
join(testFromDir, "input.tsx"),
64+
join(testToDir, "input.tsx")
65+
);
66+
} else if (fs.existsSync(join(testFromDir, "input.jsx"))) {
67+
fs.copyFileSync(
68+
join(testFromDir, "input.jsx"),
69+
join(testToDir, "input.jsx")
70+
);
71+
} else if (fs.existsSync(join(testFromDir, "input.ts"))) {
72+
fs.copyFileSync(
73+
join(testFromDir, "input.ts"),
74+
join(testToDir, "input.ts")
75+
);
5576
}
56-
copySync(join(testFromDir, "actual.js"), join(testToDir, "actual.js"));
5777
}
5878
}

packages/babel-preset-env/scripts/smoke-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const fs = require("fs-extra");
1+
const fs = require("fs");
22
const execSync = require("child_process").execSync;
33
const path = require("path");
44
const pkg = require("../package.json");
@@ -14,7 +14,7 @@ try {
1414

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

17-
fs.ensureDirSync(tempFolderPath);
17+
fs.mkdirSync(tempFolderPath);
1818
process.chdir(tempFolderPath);
1919

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

0 commit comments

Comments
 (0)