Don't use require() in ESM files (#12728)

* Update `yarn-plugin-conditions`

* Don't use `require()` in ESM files
This commit is contained in:
Nicolò Ribaudo
2021-02-01 17:09:02 +01:00
committed by GitHub
parent 108564fdad
commit 4f2d47500f
11 changed files with 78 additions and 66 deletions

View File

@@ -0,0 +1,5 @@
"use strict";
module.exports = process.env.BABEL_8_BREAKING
? require("escape-string-regexp")
: require("lodash/escapeRegExp");

View File

@@ -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(""),

View File

@@ -0,0 +1,5 @@
"use strict";
module.exports = process.env.BABEL_8_BREAKING
? require("escape-string-regexp")
: require("lodash/escapeRegExp");

View File

@@ -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();

View File

@@ -0,0 +1,5 @@
"use strict";
module.exports = process.env.BABEL_8_BREAKING
? require("escape-string-regexp")
: require("lodash/escapeRegExp");

View File

@@ -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 = {};