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:
Nicolò Ribaudo
2021-03-05 19:55:36 +01:00
committed by GitHub
parent ea620e822e
commit d04842a700
147 changed files with 651 additions and 346 deletions

View File

@@ -1,5 +1,9 @@
const babel = require("@babel/core");
const vm = require("vm");
import * as babel from "@babel/core";
import vm from "vm";
import { fileURLToPath } from "url";
import path from "path";
import transformCommonJS from "..";
test("Re-export doesn't overwrite __esModule flag", function () {
let code = 'export * from "./dep";';
@@ -13,14 +17,14 @@ test("Re-export doesn't overwrite __esModule flag", function () {
},
require: function (id) {
if (id === "./dep") return depStub;
return require(id);
throw new Error("Unexpected dependency: " + id);
},
};
context.exports = context.module.exports;
code = babel.transform(code, {
cwd: __dirname,
plugins: [[require("../"), { loose: true }]],
cwd: path.dirname(fileURLToPath(import.meta.url)),
plugins: [[transformCommonJS, { loose: true }]],
ast: false,
}).code;