[babel 8] Replace lodash/escapeRegExp with escape-string-regexp (#12677)

Co-authored-by: James Addison <jay@jp-hosting.net>
This commit is contained in:
Henry Zhu 2021-01-23 16:21:34 -05:00 committed by GitHub
parent 568679e301
commit 464a02ffe1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 41 additions and 4 deletions

View File

@ -54,6 +54,7 @@
"@babel/types": "workspace:^7.12.10", "@babel/types": "workspace:^7.12.10",
"convert-source-map": "^1.7.0", "convert-source-map": "^1.7.0",
"debug": "^4.1.0", "debug": "^4.1.0",
"escape-string-regexp": "condition:BABEL_8_BREAKING ? ^4.0.0 : ",
"gensync": "^1.0.0-beta.1", "gensync": "^1.0.0-beta.1",
"json5": "^2.1.2", "json5": "^2.1.2",
"lodash": "^4.17.19", "lodash": "^4.17.19",

View File

@ -1,6 +1,9 @@
// @flow // @flow
import path from "path"; import path from "path";
import escapeRegExp from "lodash/escapeRegExp";
const escapeRegExp = process.env.BABEL_8_BREAKING
? require("escape-string-regexp")
: require("lodash/escapeRegExp");
const sep = `\\${path.sep}`; const sep = `\\${path.sep}`;
const endSep = `(?:${sep}|$)`; const endSep = `(?:${sep}|$)`;
@ -39,11 +42,13 @@ export default function pathToPattern(
// *.ext matches a wildcard with an extension. // *.ext matches a wildcard with an extension.
if (part.indexOf("*.") === 0) { if (part.indexOf("*.") === 0) {
return ( return (
// $FlowIgnore
substitution + escapeRegExp(part.slice(1)) + (last ? endSep : sep) substitution + escapeRegExp(part.slice(1)) + (last ? endSep : sep)
); );
} }
// Otherwise match the pattern text. // Otherwise match the pattern text.
// $FlowIgnore
return escapeRegExp(part) + (last ? endSep : sep); return escapeRegExp(part) + (last ? endSep : sep);
}), }),
].join(""), ].join(""),

View File

@ -19,6 +19,7 @@
"@babel/core": "workspace:^7.12.10", "@babel/core": "workspace:^7.12.10",
"@babel/helper-fixtures": "workspace:^7.12.12", "@babel/helper-fixtures": "workspace:^7.12.12",
"babel-check-duplicated-nodes": "^1.0.0", "babel-check-duplicated-nodes": "^1.0.0",
"escape-string-regexp": "condition:BABEL_8_BREAKING ? ^4.0.0 : ",
"jest-diff": "^24.8.0", "jest-diff": "^24.8.0",
"lodash": "^4.17.19", "lodash": "^4.17.19",
"quick-lru": "5.1.0", "quick-lru": "5.1.0",

View File

@ -7,7 +7,6 @@ import {
} from "@babel/helper-fixtures"; } from "@babel/helper-fixtures";
import sourceMap from "source-map"; import sourceMap from "source-map";
import { codeFrameColumns } from "@babel/code-frame"; import { codeFrameColumns } from "@babel/code-frame";
import escapeRegExp from "lodash/escapeRegExp";
import * as helpers from "./helpers"; import * as helpers from "./helpers";
import merge from "lodash/merge"; import merge from "lodash/merge";
import assert from "assert"; import assert from "assert";
@ -16,9 +15,13 @@ import path from "path";
import vm from "vm"; import vm from "vm";
import checkDuplicatedNodes from "babel-check-duplicated-nodes"; import checkDuplicatedNodes from "babel-check-duplicated-nodes";
import QuickLRU from "quick-lru"; import QuickLRU from "quick-lru";
import diff from "jest-diff"; import diff from "jest-diff";
// $FlowIgnore
const escapeRegExp = process.env.BABEL_8_BREAKING
? require("escape-string-regexp")
: require("lodash/escapeRegExp");
const cachedScripts = new QuickLRU({ maxSize: 10 }); const cachedScripts = new QuickLRU({ maxSize: 10 });
const contextModuleCache = new WeakMap(); const contextModuleCache = new WeakMap();
const sharedTestContext = createContext(); const sharedTestContext = createContext();

View File

@ -17,6 +17,7 @@
"./lib/nodeWrapper.js": "./lib/browser.js" "./lib/nodeWrapper.js": "./lib/browser.js"
}, },
"dependencies": { "dependencies": {
"escape-string-regexp": "condition:BABEL_8_BREAKING ? ^4.0.0 : ",
"find-cache-dir": "condition:BABEL_8_BREAKING ? ^3.3.1 : ^2.0.0", "find-cache-dir": "condition:BABEL_8_BREAKING ? ^3.3.1 : ^2.0.0",
"lodash": "^4.17.19", "lodash": "^4.17.19",
"make-dir": "^2.1.0", "make-dir": "^2.1.0",

View File

@ -1,7 +1,6 @@
import deepClone from "lodash/cloneDeep"; import deepClone from "lodash/cloneDeep";
import sourceMapSupport from "source-map-support"; import sourceMapSupport from "source-map-support";
import * as registerCache from "./cache"; import * as registerCache from "./cache";
import escapeRegExp from "lodash/escapeRegExp";
import * as babel from "@babel/core"; import * as babel from "@babel/core";
import { OptionManager, DEFAULT_EXTENSIONS } from "@babel/core"; import { OptionManager, DEFAULT_EXTENSIONS } from "@babel/core";
import { addHook } from "pirates"; import { addHook } from "pirates";
@ -9,6 +8,11 @@ import fs from "fs";
import path from "path"; import path from "path";
import Module from "module"; import Module from "module";
// $FlowIgnore
const escapeRegExp = process.env.BABEL_8_BREAKING
? require("escape-string-regexp")
: require("lodash/escapeRegExp");
const maps = {}; const maps = {};
let transformOpts = {}; let transformOpts = {};
let piratesRevert = null; let piratesRevert = null;
@ -145,16 +149,19 @@ export default function register(opts?: Object = {}) {
if (transformOpts.ignore === undefined && transformOpts.only === undefined) { if (transformOpts.ignore === undefined && transformOpts.only === undefined) {
transformOpts.only = [ transformOpts.only = [
// Only compile things inside the current working directory. // Only compile things inside the current working directory.
// $FlowIgnore
new RegExp("^" + escapeRegExp(cwd), "i"), new RegExp("^" + escapeRegExp(cwd), "i"),
]; ];
transformOpts.ignore = [ transformOpts.ignore = [
// Ignore any node_modules inside the current working directory. // Ignore any node_modules inside the current working directory.
new RegExp( new RegExp(
"^" + "^" +
// $FlowIgnore
escapeRegExp(cwd) + escapeRegExp(cwd) +
"(?:" + "(?:" +
path.sep + path.sep +
".*)?" + ".*)?" +
// $FlowIgnore
escapeRegExp(path.sep + "node_modules" + path.sep), escapeRegExp(path.sep + "node_modules" + path.sep),
"i", "i",
), ),

View File

@ -139,6 +139,7 @@ __metadata:
"@babel/types": "workspace:^7.12.10" "@babel/types": "workspace:^7.12.10"
convert-source-map: ^1.7.0 convert-source-map: ^1.7.0
debug: ^4.1.0 debug: ^4.1.0
escape-string-regexp: "condition:BABEL_8_BREAKING ? ^4.0.0 : "
gensync: ^1.0.0-beta.1 gensync: ^1.0.0-beta.1
json5: ^2.1.2 json5: ^2.1.2
lodash: ^4.17.19 lodash: ^4.17.19
@ -759,6 +760,7 @@ __metadata:
"@babel/core": "workspace:^7.12.10" "@babel/core": "workspace:^7.12.10"
"@babel/helper-fixtures": "workspace:^7.12.12" "@babel/helper-fixtures": "workspace:^7.12.12"
babel-check-duplicated-nodes: ^1.0.0 babel-check-duplicated-nodes: ^1.0.0
escape-string-regexp: "condition:BABEL_8_BREAKING ? ^4.0.0 : "
jest-diff: ^24.8.0 jest-diff: ^24.8.0
lodash: ^4.17.19 lodash: ^4.17.19
quick-lru: 5.1.0 quick-lru: 5.1.0
@ -3146,6 +3148,7 @@ __metadata:
"@babel/core": "workspace:*" "@babel/core": "workspace:*"
"@babel/plugin-transform-modules-commonjs": "workspace:*" "@babel/plugin-transform-modules-commonjs": "workspace:*"
browserify: ^16.5.2 browserify: ^16.5.2
escape-string-regexp: "condition:BABEL_8_BREAKING ? ^4.0.0 : "
find-cache-dir: "condition:BABEL_8_BREAKING ? ^3.3.1 : ^2.0.0" find-cache-dir: "condition:BABEL_8_BREAKING ? ^3.3.1 : ^2.0.0"
lodash: ^4.17.19 lodash: ^4.17.19
make-dir: ^2.1.0 make-dir: ^2.1.0
@ -6467,6 +6470,22 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"escape-string-regexp-BABEL_8_BREAKING-true@npm:escape-string-regexp@^4.0.0":
version: 4.0.0
resolution: "escape-string-regexp@npm:4.0.0"
checksum: c747be8d5ff7873127e3e0cffe7d2206a37208077fa9c30a3c1bb4f26bebd081c8c24d5fba7a99449f9d20670bea3dc5e1b6098b0f074b099bd38766271a272f
languageName: node
linkType: hard
"escape-string-regexp@condition:BABEL_8_BREAKING ? ^4.0.0 : ":
version: 0.0.0-condition-76f759
resolution: "escape-string-regexp@condition:BABEL_8_BREAKING?^4.0.0:#76f759"
dependencies:
escape-string-regexp-BABEL_8_BREAKING-true: "npm:escape-string-regexp@^4.0.0"
checksum: 1c6b06b9d1094aa0c4bcb60d0d8d82237c35a11132cddf9ecf3fe52a356ae1cf5a65a7d2cfc19cfdb7397474dbbfeafeab74944a5f5e35a6e615db7019209a7d
languageName: node
linkType: hard
"escape-string-regexp@npm:^1.0.2, escape-string-regexp@npm:^1.0.5": "escape-string-regexp@npm:^1.0.2, escape-string-regexp@npm:^1.0.5":
version: 1.0.5 version: 1.0.5
resolution: "escape-string-regexp@npm:1.0.5" resolution: "escape-string-regexp@npm:1.0.5"