Don't use require() in ESM files (#12728)
* Update `yarn-plugin-conditions` * Don't use `require()` in ESM files
This commit is contained in:
5
packages/babel-core/src/config/helpers/escape-regexp.cjs
Normal file
5
packages/babel-core/src/config/helpers/escape-regexp.cjs
Normal file
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = process.env.BABEL_8_BREAKING
|
||||
? require("escape-string-regexp")
|
||||
: require("lodash/escapeRegExp");
|
||||
@@ -1,9 +1,8 @@
|
||||
// @flow
|
||||
import path from "path";
|
||||
|
||||
const escapeRegExp = process.env.BABEL_8_BREAKING
|
||||
? require("escape-string-regexp")
|
||||
: require("lodash/escapeRegExp");
|
||||
// $FlowIgnore
|
||||
import escapeRegExp from "./helpers/escape-regexp";
|
||||
|
||||
const sep = `\\${path.sep}`;
|
||||
const endSep = `(?:${sep}|$)`;
|
||||
@@ -42,13 +41,11 @@ export default function pathToPattern(
|
||||
// *.ext matches a wildcard with an extension.
|
||||
if (part.indexOf("*.") === 0) {
|
||||
return (
|
||||
// $FlowIgnore
|
||||
substitution + escapeRegExp(part.slice(1)) + (last ? endSep : sep)
|
||||
);
|
||||
}
|
||||
|
||||
// Otherwise match the pattern text.
|
||||
// $FlowIgnore
|
||||
return escapeRegExp(part) + (last ? endSep : sep);
|
||||
}),
|
||||
].join(""),
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = process.env.BABEL_8_BREAKING
|
||||
? require("escape-string-regexp")
|
||||
: require("lodash/escapeRegExp");
|
||||
@@ -16,11 +16,7 @@ import vm from "vm";
|
||||
import checkDuplicatedNodes from "babel-check-duplicated-nodes";
|
||||
import QuickLRU from "quick-lru";
|
||||
import diff from "jest-diff";
|
||||
|
||||
// $FlowIgnore
|
||||
const escapeRegExp = process.env.BABEL_8_BREAKING
|
||||
? require("escape-string-regexp")
|
||||
: require("lodash/escapeRegExp");
|
||||
import escapeRegExp from "./escape-regexp";
|
||||
|
||||
const cachedScripts = new QuickLRU({ maxSize: 10 });
|
||||
const contextModuleCache = new WeakMap();
|
||||
|
||||
5
packages/babel-register/src/escape-regexp.cjs
Normal file
5
packages/babel-register/src/escape-regexp.cjs
Normal file
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = process.env.BABEL_8_BREAKING
|
||||
? require("escape-string-regexp")
|
||||
: require("lodash/escapeRegExp");
|
||||
@@ -7,11 +7,7 @@ import { addHook } from "pirates";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import Module from "module";
|
||||
|
||||
// $FlowIgnore
|
||||
const escapeRegExp = process.env.BABEL_8_BREAKING
|
||||
? require("escape-string-regexp")
|
||||
: require("lodash/escapeRegExp");
|
||||
import escapeRegExp from "./escape-regexp";
|
||||
|
||||
const maps = {};
|
||||
let transformOpts = {};
|
||||
|
||||
Reference in New Issue
Block a user