diff --git a/packages/babel-helper-fixtures/src/index.js b/packages/babel-helper-fixtures/src/index.js index b768442302..5e863ba2f0 100644 --- a/packages/babel-helper-fixtures/src/index.js +++ b/packages/babel-helper-fixtures/src/index.js @@ -1,3 +1,4 @@ +import assert from "assert"; import cloneDeep from "lodash/cloneDeep"; import trimEnd from "lodash/trimEnd"; import resolve from "try-resolve"; @@ -83,17 +84,44 @@ export default function get(entryLoc): Array { } function push(taskName, taskDir) { - const actualLocAlias = suiteName + "/" + taskName + "/actual.js"; - const expectLocAlias = suiteName + "/" + taskName + "/expected.js"; - const execLocAlias = suiteName + "/" + taskName + "/exec.js"; + let actualLocAlias = suiteName + "/" + taskName + "/actual.js"; + let expectLocAlias = suiteName + "/" + taskName + "/expected.js"; + let execLocAlias = suiteName + "/" + taskName + "/exec.js"; - const actualLoc = taskDir + "/actual.js"; - const expectLoc = taskDir + "/expected.js"; + let actualLoc = taskDir + "/actual.js"; + let expectLoc = taskDir + "/expected.js"; let execLoc = taskDir + "/exec.js"; + const hasExecJS = fs.existsSync(execLoc); + const hasExecMJS = fs.existsSync(asMJS(execLoc)); + if (hasExecMJS) { + assert(!hasExecJS, `${asMJS(execLoc)}: Found conflicting .js`); + + execLoc = asMJS(execLoc); + execLocAlias = asMJS(execLocAlias); + } + + const hasExpectJS = fs.existsSync(expectLoc); + const hasExpectMJS = fs.existsSync(asMJS(expectLoc)); + if (hasExpectMJS) { + assert(!hasExpectJS, `${asMJS(expectLoc)}: Found conflicting .js`); + + expectLoc = asMJS(expectLoc); + expectLocAlias = asMJS(expectLocAlias); + } + + const hasActualJS = fs.existsSync(actualLoc); + const hasActualMJS = fs.existsSync(asMJS(actualLoc)); + if (hasActualMJS) { + assert(!hasActualJS, `${asMJS(actualLoc)}: Found conflicting .js`); + + actualLoc = asMJS(actualLoc); + actualLocAlias = asMJS(actualLocAlias); + } + if (fs.statSync(taskDir).isFile()) { const ext = path.extname(taskDir); - if (ext !== ".js" && ext !== ".module.js") return; + if (ext !== ".js" && ext !== ".mjs") return; execLoc = taskDir; } @@ -181,6 +209,10 @@ export function multiple(entryLoc, ignore?: Array) { return categories; } +function asMJS(filepath) { + return filepath.replace(/\.js$/, ".mjs"); +} + export function readFile(filename) { if (fs.existsSync(filename)) { let file = trimEnd(fs.readFileSync(filename, "utf8"));