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