Remove lodash deps (#13057)
* inline escapeRegExp instead of using any dep * inline camelCase * replace merge with object spread * copy if array instead of using clone * inline isRegExp * review fixes! * remove escape-string-regexp from package.json and in test * add error for field defaults that are not primitives or empty arrays * replace merge with object spread * yarn
This commit is contained in:
parent
6ac07a1647
commit
6b39bafab6
@ -8,7 +8,6 @@ import through from "through2";
|
|||||||
import chalk from "chalk";
|
import chalk from "chalk";
|
||||||
import newer from "gulp-newer";
|
import newer from "gulp-newer";
|
||||||
import babel from "gulp-babel";
|
import babel from "gulp-babel";
|
||||||
import camelCase from "lodash/camelCase.js";
|
|
||||||
import fancyLog from "fancy-log";
|
import fancyLog from "fancy-log";
|
||||||
import filter from "gulp-filter";
|
import filter from "gulp-filter";
|
||||||
import revertPath from "gulp-revert-path";
|
import revertPath from "gulp-revert-path";
|
||||||
@ -162,7 +161,9 @@ function generateStandalone() {
|
|||||||
let allList = "";
|
let allList = "";
|
||||||
|
|
||||||
for (const plugin of pluginConfig) {
|
for (const plugin of pluginConfig) {
|
||||||
const camelPlugin = camelCase(plugin);
|
const camelPlugin = plugin.replace(/-[a-z]/g, c =>
|
||||||
|
c[1].toUpperCase()
|
||||||
|
);
|
||||||
imports += `import ${camelPlugin} from "@babel/plugin-${plugin}";`;
|
imports += `import ${camelPlugin} from "@babel/plugin-${plugin}";`;
|
||||||
list += `${camelPlugin},`;
|
list += `${camelPlugin},`;
|
||||||
allList += `"${plugin}": ${camelPlugin},`;
|
allList += `"${plugin}": ${camelPlugin},`;
|
||||||
|
|||||||
@ -22,18 +22,6 @@ declare module "json5" {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module "lodash/clone" {
|
|
||||||
declare export default <T>(obj: T) => T;
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module "lodash/merge" {
|
|
||||||
declare export default <T: Object>(T, Object) => T;
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module "lodash/escapeRegExp" {
|
|
||||||
declare export default (toEscape?: string) => string;
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module "semver" {
|
declare module "semver" {
|
||||||
declare class SemVer {
|
declare class SemVer {
|
||||||
build: Array<string>;
|
build: Array<string>;
|
||||||
|
|||||||
@ -3,8 +3,6 @@ import * as helper from "@babel/helper-fixtures";
|
|||||||
import rimraf from "rimraf";
|
import rimraf from "rimraf";
|
||||||
import { sync as makeDirSync } from "make-dir";
|
import { sync as makeDirSync } from "make-dir";
|
||||||
import child from "child_process";
|
import child from "child_process";
|
||||||
import escapeRegExp from "lodash/escapeRegExp";
|
|
||||||
import merge from "lodash/merge";
|
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import { fileURLToPath } from "url";
|
import { fileURLToPath } from "url";
|
||||||
@ -58,6 +56,10 @@ const saveInFiles = function (files) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function escapeRegExp(string) {
|
||||||
|
return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&");
|
||||||
|
}
|
||||||
|
|
||||||
const normalizeOutput = function (str, cwd) {
|
const normalizeOutput = function (str, cwd) {
|
||||||
let result = str
|
let result = str
|
||||||
.replace(/\(\d+ms\)/g, "(123ms)")
|
.replace(/\(\d+ms\)/g, "(123ms)")
|
||||||
@ -218,7 +220,7 @@ fs.readdirSync(fixtureLoc).forEach(function (binName) {
|
|||||||
|
|
||||||
const testLoc = path.join(suiteLoc, testName);
|
const testLoc = path.join(suiteLoc, testName);
|
||||||
|
|
||||||
const opts = {
|
let opts = {
|
||||||
args: [],
|
args: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -244,7 +246,7 @@ fs.readdirSync(fixtureLoc).forEach(function (binName) {
|
|||||||
|
|
||||||
delete taskOpts.os;
|
delete taskOpts.os;
|
||||||
}
|
}
|
||||||
merge(opts, taskOpts);
|
opts = { args: [], ...taskOpts };
|
||||||
}
|
}
|
||||||
|
|
||||||
["stdout", "stdin", "stderr"].forEach(function (key) {
|
["stdout", "stdin", "stderr"].forEach(function (key) {
|
||||||
|
|||||||
@ -58,10 +58,8 @@
|
|||||||
"@babel/types": "workspace:^7.13.13",
|
"@babel/types": "workspace:^7.13.13",
|
||||||
"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.2",
|
"gensync": "^1.0.0-beta.2",
|
||||||
"json5": "^2.1.2",
|
"json5": "^2.1.2",
|
||||||
"lodash": "^4.17.19",
|
|
||||||
"semver": "condition:BABEL_8_BREAKING ? ^7.3.4 : ^6.3.0",
|
"semver": "condition:BABEL_8_BREAKING ? ^7.3.4 : ^6.3.0",
|
||||||
"source-map": "^0.5.0"
|
"source-map": "^0.5.0"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,5 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
|
|
||||||
module.exports = process.env.BABEL_8_BREAKING
|
|
||||||
? require("escape-string-regexp")
|
|
||||||
: require("lodash/escapeRegExp");
|
|
||||||
@ -1,9 +1,6 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
// $FlowIgnore
|
|
||||||
import escapeRegExp from "./helpers/escape-regexp.cjs";
|
|
||||||
|
|
||||||
const sep = `\\${path.sep}`;
|
const sep = `\\${path.sep}`;
|
||||||
const endSep = `(?:${sep}|$)`;
|
const endSep = `(?:${sep}|$)`;
|
||||||
|
|
||||||
@ -15,6 +12,10 @@ const starPatLast = `(?:${substitution}${endSep})`;
|
|||||||
const starStarPat = `${starPat}*?`;
|
const starStarPat = `${starPat}*?`;
|
||||||
const starStarPatLast = `${starPat}*?${starPatLast}?`;
|
const starStarPatLast = `${starPat}*?${starPatLast}?`;
|
||||||
|
|
||||||
|
function escapeRegExp(string) {
|
||||||
|
return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implement basic pattern matching that will allow users to do the simple
|
* Implement basic pattern matching that will allow users to do the simple
|
||||||
* tests with * and **. If users want full complex pattern matching, then can
|
* tests with * and **. If users want full complex pattern matching, then can
|
||||||
|
|||||||
@ -2,7 +2,6 @@ import fs from "fs";
|
|||||||
import os from "os";
|
import os from "os";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { fileURLToPath } from "url";
|
import { fileURLToPath } from "url";
|
||||||
import escapeRegExp from "lodash/escapeRegExp";
|
|
||||||
import * as babel from "../lib";
|
import * as babel from "../lib";
|
||||||
import getTargets from "@babel/helper-compilation-targets";
|
import getTargets from "@babel/helper-compilation-targets";
|
||||||
|
|
||||||
@ -63,6 +62,10 @@ function pairs(items) {
|
|||||||
return pairs;
|
return pairs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function escapeRegExp(string) {
|
||||||
|
return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&");
|
||||||
|
}
|
||||||
|
|
||||||
async function getTemp(name) {
|
async function getTemp(name) {
|
||||||
const cwd = await pfs.mkdtemp(os.tmpdir() + path.sep + name);
|
const cwd = await pfs.mkdtemp(os.tmpdir() + path.sep + name);
|
||||||
const tmp = name => path.join(cwd, name);
|
const tmp = name => path.join(cwd, name);
|
||||||
|
|||||||
@ -19,8 +19,6 @@
|
|||||||
"@babel/core": "workspace:^7.13.10",
|
"@babel/core": "workspace:^7.13.10",
|
||||||
"@babel/helper-fixtures": "workspace:^7.13.10",
|
"@babel/helper-fixtures": "workspace:^7.13.10",
|
||||||
"babel-check-duplicated-nodes": "^1.0.0",
|
"babel-check-duplicated-nodes": "^1.0.0",
|
||||||
"escape-string-regexp": "condition:BABEL_8_BREAKING ? ^4.0.0 : ",
|
|
||||||
"lodash": "^4.17.19",
|
|
||||||
"quick-lru": "5.1.0",
|
"quick-lru": "5.1.0",
|
||||||
"regenerator-runtime": "^0.13.7",
|
"regenerator-runtime": "^0.13.7",
|
||||||
"source-map": "^0.5.0"
|
"source-map": "^0.5.0"
|
||||||
|
|||||||
@ -1,5 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
|
|
||||||
module.exports = process.env.BABEL_8_BREAKING
|
|
||||||
? require("escape-string-regexp")
|
|
||||||
: require("lodash/escapeRegExp");
|
|
||||||
@ -8,14 +8,11 @@ import {
|
|||||||
import sourceMap from "source-map";
|
import sourceMap from "source-map";
|
||||||
import { codeFrameColumns } from "@babel/code-frame";
|
import { codeFrameColumns } from "@babel/code-frame";
|
||||||
import * as helpers from "./helpers";
|
import * as helpers from "./helpers";
|
||||||
import merge from "lodash/merge";
|
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import vm from "vm";
|
import vm from "vm";
|
||||||
import QuickLRU from "quick-lru";
|
import QuickLRU from "quick-lru";
|
||||||
// @ts-ignore
|
|
||||||
import escapeRegExp from "./escape-regexp.cjs";
|
|
||||||
import { fileURLToPath } from "url";
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
import { createRequire } from "module";
|
import { createRequire } from "module";
|
||||||
@ -202,19 +199,17 @@ function run(task) {
|
|||||||
|
|
||||||
// todo(flow->ts) add proper return type (added any, because empty object is inferred)
|
// todo(flow->ts) add proper return type (added any, because empty object is inferred)
|
||||||
function getOpts(self): any {
|
function getOpts(self): any {
|
||||||
const newOpts = merge(
|
const newOpts = {
|
||||||
{
|
ast: true,
|
||||||
ast: true,
|
cwd: path.dirname(self.loc),
|
||||||
cwd: path.dirname(self.loc),
|
filename: self.loc,
|
||||||
filename: self.loc,
|
filenameRelative: self.filename,
|
||||||
filenameRelative: self.filename,
|
sourceFileName: self.filename,
|
||||||
sourceFileName: self.filename,
|
sourceType: "script",
|
||||||
sourceType: "script",
|
babelrc: false,
|
||||||
babelrc: false,
|
inputSourceMap: task.inputSourceMap || undefined,
|
||||||
inputSourceMap: task.inputSourceMap || undefined,
|
...opts,
|
||||||
},
|
};
|
||||||
opts,
|
|
||||||
);
|
|
||||||
|
|
||||||
return resolveOptionPluginOrPreset(newOpts, optionsDir);
|
return resolveOptionPluginOrPreset(newOpts, optionsDir);
|
||||||
}
|
}
|
||||||
@ -345,6 +340,10 @@ function validateFile(actualCode, expectedLoc, expectedCode) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function escapeRegExp(string) {
|
||||||
|
return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&");
|
||||||
|
}
|
||||||
|
|
||||||
function normalizeOutput(code, normalizePathSeparator?) {
|
function normalizeOutput(code, normalizePathSeparator?) {
|
||||||
const projectRoot = path.resolve(
|
const projectRoot = path.resolve(
|
||||||
path.dirname(fileURLToPath(import.meta.url)),
|
path.dirname(fileURLToPath(import.meta.url)),
|
||||||
|
|||||||
@ -17,7 +17,6 @@
|
|||||||
"./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",
|
||||||
|
|||||||
@ -1,5 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
|
|
||||||
module.exports = process.env.BABEL_8_BREAKING
|
|
||||||
? require("escape-string-regexp")
|
|
||||||
: require("lodash/escapeRegExp");
|
|
||||||
@ -7,7 +7,6 @@ import { addHook } from "pirates";
|
|||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import Module from "module";
|
import Module from "module";
|
||||||
import escapeRegExp from "./escape-regexp.cjs";
|
|
||||||
|
|
||||||
const maps = {};
|
const maps = {};
|
||||||
let transformOpts = {};
|
let transformOpts = {};
|
||||||
@ -109,6 +108,10 @@ export function revert() {
|
|||||||
if (piratesRevert) piratesRevert();
|
if (piratesRevert) piratesRevert();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function escapeRegExp(string) {
|
||||||
|
return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&");
|
||||||
|
}
|
||||||
|
|
||||||
export default function register(opts?: Object = {}) {
|
export default function register(opts?: Object = {}) {
|
||||||
// Clone to avoid mutating the arguments object with the 'delete's below.
|
// Clone to avoid mutating the arguments object with the 'delete's below.
|
||||||
opts = {
|
opts = {
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
import loClone from "lodash/clone";
|
|
||||||
import { NODE_FIELDS, BUILDER_KEYS } from "../definitions";
|
import { NODE_FIELDS, BUILDER_KEYS } from "../definitions";
|
||||||
import validate from "../validators/validate";
|
import validate from "../validators/validate";
|
||||||
import type * as t from "..";
|
import type * as t from "..";
|
||||||
@ -23,7 +22,9 @@ export default function builder<T extends t.Node>(
|
|||||||
|
|
||||||
let arg;
|
let arg;
|
||||||
if (i < countArgs) arg = args[i];
|
if (i < countArgs) arg = args[i];
|
||||||
if (arg === undefined) arg = loClone(field.default);
|
if (arg === undefined) {
|
||||||
|
arg = Array.isArray(field.default) ? [] : field.default;
|
||||||
|
}
|
||||||
|
|
||||||
node[key] = arg;
|
node[key] = arg;
|
||||||
i++;
|
i++;
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
import isPlainObject from "lodash/isPlainObject";
|
import isPlainObject from "lodash/isPlainObject";
|
||||||
import isRegExp from "lodash/isRegExp";
|
|
||||||
import isValidIdentifier from "../validators/isValidIdentifier";
|
import isValidIdentifier from "../validators/isValidIdentifier";
|
||||||
import {
|
import {
|
||||||
identifier,
|
identifier,
|
||||||
@ -33,6 +32,10 @@ export default valueToNode as {
|
|||||||
(value: unknown): t.Expression;
|
(value: unknown): t.Expression;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function isRegExp(value): value is RegExp {
|
||||||
|
return Object.prototype.toString.call(value) === "[object RegExp]";
|
||||||
|
}
|
||||||
|
|
||||||
function valueToNode(value: unknown): t.Expression {
|
function valueToNode(value: unknown): t.Expression {
|
||||||
// undefined
|
// undefined
|
||||||
if (value === undefined) {
|
if (value === undefined) {
|
||||||
|
|||||||
@ -279,8 +279,16 @@ export default function defineType(
|
|||||||
const keys = Object.getOwnPropertyNames(inherits.fields);
|
const keys = Object.getOwnPropertyNames(inherits.fields);
|
||||||
for (const key of keys) {
|
for (const key of keys) {
|
||||||
const field = inherits.fields[key];
|
const field = inherits.fields[key];
|
||||||
|
const def = field.default;
|
||||||
|
if (
|
||||||
|
Array.isArray(def) ? def.length > 0 : def && typeof def === "object"
|
||||||
|
) {
|
||||||
|
throw new Error(
|
||||||
|
"field defaults can only be primitives or empty arrays currently",
|
||||||
|
);
|
||||||
|
}
|
||||||
fields[key] = {
|
fields[key] = {
|
||||||
default: field.default,
|
default: Array.isArray(def) ? [] : def,
|
||||||
optional: field.optional,
|
optional: field.optional,
|
||||||
validate: field.validate,
|
validate: field.validate,
|
||||||
};
|
};
|
||||||
|
|||||||
21
yarn.lock
21
yarn.lock
@ -213,10 +213,8 @@ __metadata:
|
|||||||
"@babel/types": "workspace:^7.13.13"
|
"@babel/types": "workspace:^7.13.13"
|
||||||
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.2
|
gensync: ^1.0.0-beta.2
|
||||||
json5: ^2.1.2
|
json5: ^2.1.2
|
||||||
lodash: ^4.17.19
|
|
||||||
semver: "condition:BABEL_8_BREAKING ? ^7.3.4 : ^6.3.0"
|
semver: "condition:BABEL_8_BREAKING ? ^7.3.4 : ^6.3.0"
|
||||||
source-map: ^0.5.0
|
source-map: ^0.5.0
|
||||||
languageName: unknown
|
languageName: unknown
|
||||||
@ -820,8 +818,6 @@ __metadata:
|
|||||||
"@babel/helper-fixtures": "workspace:^7.13.10"
|
"@babel/helper-fixtures": "workspace:^7.13.10"
|
||||||
"@types/jest": ^25.2.2
|
"@types/jest": ^25.2.2
|
||||||
babel-check-duplicated-nodes: ^1.0.0
|
babel-check-duplicated-nodes: ^1.0.0
|
||||||
escape-string-regexp: "condition:BABEL_8_BREAKING ? ^4.0.0 : "
|
|
||||||
lodash: ^4.17.19
|
|
||||||
quick-lru: 5.1.0
|
quick-lru: 5.1.0
|
||||||
regenerator-runtime: ^0.13.7
|
regenerator-runtime: ^0.13.7
|
||||||
source-map: ^0.5.0
|
source-map: ^0.5.0
|
||||||
@ -3257,7 +3253,6 @@ __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
|
||||||
@ -7429,22 +7424,6 @@ __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-d458a5
|
|
||||||
resolution: "escape-string-regexp@condition:BABEL_8_BREAKING?^4.0.0:#d458a5"
|
|
||||||
dependencies:
|
|
||||||
escape-string-regexp-BABEL_8_BREAKING-true: "npm:escape-string-regexp@^4.0.0"
|
|
||||||
checksum: a67cb3a0fc219d92f2c6f0964e302cc079b0ce38bf2bd19257d26865c600bec42befed4dc88aec2bfbe9e62f757ce4bec80a408937bf48c5c779e13d9b238c01
|
|
||||||
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"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user