Avoid using CJS globals in internal source files (#12963)
* Lint against CJS globals in modules * Use `import.meta.url` instead of `__filename` in `src` files * Prepare fixtures runner for `import.meta.url` * Use `import.meta.url` instead of `__filename` in `test/index` files * Remove `__dirname` from remaining test files dirname * Avoid using `module` in `src` files * Avoid using `require` in `src` files * Avoid using `require` in `test` files * Update `@types/node` * Compile dynamic import in `@babel/node` * Fix windows * Use `@babel/plugin-proposal-dynamic-import` from npm
This commit is contained in:
@@ -1,7 +1,24 @@
|
||||
import testRunner from "@babel/helper-transform-fixture-test-runner";
|
||||
import path from "path";
|
||||
import { URL } from "url";
|
||||
|
||||
export default function (loc) {
|
||||
const name = path.basename(path.dirname(loc));
|
||||
testRunner(loc + "/fixtures", name);
|
||||
if (!process.env.BABEL_8_BREAKING) {
|
||||
if (!loc.startsWith("file://")) {
|
||||
const name = path.basename(path.dirname(loc));
|
||||
testRunner(loc + "/fixtures", name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
let fixtures = new URL("./fixtures", loc).pathname;
|
||||
if (process.platform === "win32") {
|
||||
// Remove the leading / before the drive letter
|
||||
// TODO: After dropping Node.js 10 support, use fileURLToPath
|
||||
fixtures = fixtures.slice(1);
|
||||
}
|
||||
|
||||
const name = path.basename(new URL("..", loc).pathname);
|
||||
|
||||
testRunner(fixtures, name);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user