Remove remaining lodash dependencies (#13139)
This commit is contained in:
parent
b35c78f08d
commit
d24bd7ce5c
@ -40,7 +40,7 @@
|
|||||||
"eslint-rule-composer": "^0.3.0"
|
"eslint-rule-composer": "^0.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^7.5.0",
|
"clone-deep": "^4.0.1",
|
||||||
"lodash": "^4.17.20"
|
"eslint": "^7.5.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import cloneDeep from "lodash/cloneDeep";
|
import cloneDeep from "clone-deep";
|
||||||
import rule from "../../src/rules/no-invalid-this";
|
import rule from "../../src/rules/no-invalid-this";
|
||||||
import RuleTester from "../../../babel-eslint-shared-fixtures/utils/RuleTester";
|
import RuleTester from "../../../babel-eslint-shared-fixtures/utils/RuleTester";
|
||||||
|
|
||||||
|
|||||||
@ -28,7 +28,6 @@
|
|||||||
"convert-source-map": "^1.1.0",
|
"convert-source-map": "^1.1.0",
|
||||||
"fs-readdir-recursive": "^1.1.0",
|
"fs-readdir-recursive": "^1.1.0",
|
||||||
"glob": "^7.0.0",
|
"glob": "^7.0.0",
|
||||||
"lodash": "^4.17.19",
|
|
||||||
"make-dir": "^2.1.0",
|
"make-dir": "^2.1.0",
|
||||||
"slash": "condition:BABEL_8_BREAKING ? ^3.0.0 : ^2.0.0",
|
"slash": "condition:BABEL_8_BREAKING ? ^3.0.0 : ^2.0.0",
|
||||||
"source-map": "^0.5.0"
|
"source-map": "^0.5.0"
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
import debounce from "lodash/debounce";
|
|
||||||
import slash from "slash";
|
import slash from "slash";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
@ -135,27 +134,23 @@ export default async function ({
|
|||||||
let compiledFiles = 0;
|
let compiledFiles = 0;
|
||||||
let startTime = null;
|
let startTime = null;
|
||||||
|
|
||||||
const logSuccess = debounce(
|
const logSuccess = util.debounce(function () {
|
||||||
function () {
|
if (startTime === null) {
|
||||||
if (startTime === null) {
|
// This should never happen, but just in case it's better
|
||||||
// This should never happen, but just in case it's better
|
// to ignore the log message rather than making @babel/cli crash.
|
||||||
// to ignore the log message rather than making @babel/cli crash.
|
return;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const diff = process.hrtime(startTime);
|
const diff = process.hrtime(startTime);
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
`Successfully compiled ${compiledFiles} ${
|
`Successfully compiled ${compiledFiles} ${
|
||||||
compiledFiles !== 1 ? "files" : "file"
|
compiledFiles !== 1 ? "files" : "file"
|
||||||
} with Babel (${diff[0] * 1e3 + Math.round(diff[1] / 1e6)}ms).`,
|
} with Babel (${diff[0] * 1e3 + Math.round(diff[1] / 1e6)}ms).`,
|
||||||
);
|
);
|
||||||
compiledFiles = 0;
|
compiledFiles = 0;
|
||||||
startTime = null;
|
startTime = null;
|
||||||
},
|
}, 100);
|
||||||
100,
|
|
||||||
{ trailing: true },
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!cliOptions.skipInitialBuild) {
|
if (!cliOptions.skipInitialBuild) {
|
||||||
if (cliOptions.deleteDirOnStart) {
|
if (cliOptions.deleteDirOnStart) {
|
||||||
|
|||||||
@ -141,3 +141,16 @@ export function withExtension(filename: string, ext: string = ".js") {
|
|||||||
const newBasename = path.basename(filename, path.extname(filename)) + ext;
|
const newBasename = path.basename(filename, path.extname(filename)) + ext;
|
||||||
return path.join(path.dirname(filename), newBasename);
|
return path.join(path.dirname(filename), newBasename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function debounce(fn: () => void, time: number) {
|
||||||
|
let timer;
|
||||||
|
function debounced() {
|
||||||
|
clearTimeout(timer);
|
||||||
|
timer = setTimeout(fn, time);
|
||||||
|
}
|
||||||
|
debounced.flush = () => {
|
||||||
|
clearTimeout(timer);
|
||||||
|
fn();
|
||||||
|
};
|
||||||
|
return debounced;
|
||||||
|
}
|
||||||
|
|||||||
@ -68,7 +68,6 @@
|
|||||||
"@babel/helper-transform-fixture-test-runner": "workspace:*",
|
"@babel/helper-transform-fixture-test-runner": "workspace:*",
|
||||||
"@types/convert-source-map": "^1.5.1",
|
"@types/convert-source-map": "^1.5.1",
|
||||||
"@types/debug": "^4.1.0",
|
"@types/debug": "^4.1.0",
|
||||||
"@types/lodash": "^4.14.150",
|
|
||||||
"@types/resolve": "^1.3.2",
|
"@types/resolve": "^1.3.2",
|
||||||
"@types/semver": "^5.4.0",
|
"@types/semver": "^5.4.0",
|
||||||
"@types/source-map": "^0.5.0"
|
"@types/source-map": "^0.5.0"
|
||||||
|
|||||||
@ -27,7 +27,6 @@
|
|||||||
"@babel/helper-fixtures": "workspace:*",
|
"@babel/helper-fixtures": "workspace:*",
|
||||||
"@babel/parser": "workspace:*",
|
"@babel/parser": "workspace:*",
|
||||||
"@types/jsesc": "^2.5.0",
|
"@types/jsesc": "^2.5.0",
|
||||||
"@types/lodash": "^4.14.150",
|
|
||||||
"@types/source-map": "^0.5.0"
|
"@types/source-map": "^0.5.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import last from "lodash/last"
|
import last from "lo-dash/last"
|
||||||
|
|
||||||
export default class Container {
|
export default class Container {
|
||||||
last(key) {
|
last(key) {
|
||||||
|
|||||||
@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|||||||
});
|
});
|
||||||
exports.default = void 0;
|
exports.default = void 0;
|
||||||
|
|
||||||
var _last2 = babelHelpers.interopRequireDefault(require("lodash/last"));
|
var _last2 = babelHelpers.interopRequireDefault(require("lo-dash/last"));
|
||||||
|
|
||||||
let Container = /*#__PURE__*/function () {
|
let Container = /*#__PURE__*/function () {
|
||||||
function Container() {
|
function Container() {
|
||||||
|
|||||||
@ -17,8 +17,8 @@
|
|||||||
"./lib/nodeWrapper.js": "./lib/browser.js"
|
"./lib/nodeWrapper.js": "./lib/browser.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"clone-deep": "^4.0.1",
|
||||||
"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",
|
|
||||||
"make-dir": "^2.1.0",
|
"make-dir": "^2.1.0",
|
||||||
"pirates": "^4.0.0",
|
"pirates": "^4.0.0",
|
||||||
"source-map-support": "^0.5.16"
|
"source-map-support": "^0.5.16"
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import deepClone from "lodash/cloneDeep";
|
import cloneDeep from "clone-deep";
|
||||||
import sourceMapSupport from "source-map-support";
|
import sourceMapSupport from "source-map-support";
|
||||||
import * as registerCache from "./cache";
|
import * as registerCache from "./cache";
|
||||||
import * as babel from "@babel/core";
|
import * as babel from "@babel/core";
|
||||||
@ -42,7 +42,7 @@ function compile(code, filename) {
|
|||||||
// sourceRoot can be overwritten
|
// sourceRoot can be overwritten
|
||||||
{
|
{
|
||||||
sourceRoot: path.dirname(filename) + path.sep,
|
sourceRoot: path.dirname(filename) + path.sep,
|
||||||
...deepClone(transformOpts),
|
...cloneDeep(transformOpts),
|
||||||
filename,
|
filename,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@ -22,7 +22,6 @@ register( {
|
|||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
convertSourceMap: require('convert-source-map').fromObject.toString(),
|
convertSourceMap: require('convert-source-map').fromObject.toString()
|
||||||
isPlainObject: require('lodash/isPlainObject').toString()
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|||||||
@ -198,16 +198,14 @@ describe("@babel/register", function () {
|
|||||||
|
|
||||||
test("transforms modules used within register", callback => {
|
test("transforms modules used within register", callback => {
|
||||||
// Need a clean environment without `convert-source-map`
|
// Need a clean environment without `convert-source-map`
|
||||||
// and `lodash/isPlainObject` already in the require cache,
|
// already in the require cache, so we spawn a separate process
|
||||||
// so we spawn a separate process
|
|
||||||
|
|
||||||
spawnNode([internalModulesTestFile], output => {
|
spawnNode([internalModulesTestFile], output => {
|
||||||
let err;
|
let err;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { convertSourceMap, isPlainObject } = JSON.parse(output);
|
const { convertSourceMap } = JSON.parse(output);
|
||||||
expect(convertSourceMap).toMatch("/* transformed */");
|
expect(convertSourceMap).toMatch("/* transformed */");
|
||||||
expect(isPlainObject).toMatch("/* transformed */");
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,13 +25,11 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/helper-validator-identifier": "workspace:^7.12.11",
|
"@babel/helper-validator-identifier": "workspace:^7.12.11",
|
||||||
"lodash": "^4.17.19",
|
|
||||||
"to-fast-properties": "^2.0.0"
|
"to-fast-properties": "^2.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/generator": "workspace:*",
|
"@babel/generator": "workspace:*",
|
||||||
"@babel/parser": "workspace:*",
|
"@babel/parser": "workspace:*",
|
||||||
"@types/lodash": "^4.14.162",
|
|
||||||
"chalk": "^4.1.0"
|
"chalk": "^4.1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
import isPlainObject from "lodash/isPlainObject";
|
|
||||||
import isValidIdentifier from "../validators/isValidIdentifier";
|
import isValidIdentifier from "../validators/isValidIdentifier";
|
||||||
import {
|
import {
|
||||||
identifier,
|
identifier,
|
||||||
@ -25,15 +24,27 @@ export default valueToNode as {
|
|||||||
(value: RegExp): t.RegExpLiteral;
|
(value: RegExp): t.RegExpLiteral;
|
||||||
(value: ReadonlyArray<unknown>): t.ArrayExpression;
|
(value: ReadonlyArray<unknown>): t.ArrayExpression;
|
||||||
|
|
||||||
// this throws with objects that are not PlainObject according to lodash,
|
// this throws with objects that are not plain objects,
|
||||||
// or if there are non-valueToNode-able values
|
// or if there are non-valueToNode-able values
|
||||||
(value: object): t.ObjectExpression;
|
(value: object): t.ObjectExpression;
|
||||||
|
|
||||||
(value: unknown): t.Expression;
|
(value: unknown): t.Expression;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const objectToString: (value: object) => string = Function.call.bind(
|
||||||
|
Object.prototype.toString,
|
||||||
|
);
|
||||||
|
|
||||||
function isRegExp(value): value is RegExp {
|
function isRegExp(value): value is RegExp {
|
||||||
return Object.prototype.toString.call(value) === "[object RegExp]";
|
return objectToString(value) === "[object RegExp]";
|
||||||
|
}
|
||||||
|
|
||||||
|
function isPlainObject(value): value is object {
|
||||||
|
if (typeof value !== "object" || value === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const proto = Object.getPrototypeOf(value);
|
||||||
|
return proto === null || proto === Object.prototype;
|
||||||
}
|
}
|
||||||
|
|
||||||
function valueToNode(value: unknown): t.Expression {
|
function valueToNode(value: unknown): t.Expression {
|
||||||
|
|||||||
16
yarn.lock
16
yarn.lock
@ -94,7 +94,6 @@ __metadata:
|
|||||||
convert-source-map: ^1.1.0
|
convert-source-map: ^1.1.0
|
||||||
fs-readdir-recursive: ^1.1.0
|
fs-readdir-recursive: ^1.1.0
|
||||||
glob: ^7.0.0
|
glob: ^7.0.0
|
||||||
lodash: ^4.17.19
|
|
||||||
make-dir: ^2.1.0
|
make-dir: ^2.1.0
|
||||||
rimraf: ^3.0.0
|
rimraf: ^3.0.0
|
||||||
slash: "condition:BABEL_8_BREAKING ? ^3.0.0 : ^2.0.0"
|
slash: "condition:BABEL_8_BREAKING ? ^3.0.0 : ^2.0.0"
|
||||||
@ -213,7 +212,6 @@ __metadata:
|
|||||||
"@babel/types": "workspace:^7.13.14"
|
"@babel/types": "workspace:^7.13.14"
|
||||||
"@types/convert-source-map": ^1.5.1
|
"@types/convert-source-map": ^1.5.1
|
||||||
"@types/debug": ^4.1.0
|
"@types/debug": ^4.1.0
|
||||||
"@types/lodash": ^4.14.150
|
|
||||||
"@types/resolve": ^1.3.2
|
"@types/resolve": ^1.3.2
|
||||||
"@types/semver": ^5.4.0
|
"@types/semver": ^5.4.0
|
||||||
"@types/source-map": ^0.5.0
|
"@types/source-map": ^0.5.0
|
||||||
@ -274,9 +272,9 @@ __metadata:
|
|||||||
version: 0.0.0-use.local
|
version: 0.0.0-use.local
|
||||||
resolution: "@babel/eslint-plugin@workspace:eslint/babel-eslint-plugin"
|
resolution: "@babel/eslint-plugin@workspace:eslint/babel-eslint-plugin"
|
||||||
dependencies:
|
dependencies:
|
||||||
|
clone-deep: ^4.0.1
|
||||||
eslint: ^7.5.0
|
eslint: ^7.5.0
|
||||||
eslint-rule-composer: ^0.3.0
|
eslint-rule-composer: ^0.3.0
|
||||||
lodash: ^4.17.20
|
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
"@babel/eslint-parser": ">=7.11.0"
|
"@babel/eslint-parser": ">=7.11.0"
|
||||||
eslint: ">=7.5.0"
|
eslint: ">=7.5.0"
|
||||||
@ -331,7 +329,6 @@ __metadata:
|
|||||||
"@babel/parser": "workspace:*"
|
"@babel/parser": "workspace:*"
|
||||||
"@babel/types": "workspace:^7.13.0"
|
"@babel/types": "workspace:^7.13.0"
|
||||||
"@types/jsesc": ^2.5.0
|
"@types/jsesc": ^2.5.0
|
||||||
"@types/lodash": ^4.14.150
|
|
||||||
"@types/source-map": ^0.5.0
|
"@types/source-map": ^0.5.0
|
||||||
jsesc: "condition: BABEL_8_BREAKING ? ^3.0.2 : ^2.5.1"
|
jsesc: "condition: BABEL_8_BREAKING ? ^3.0.2 : ^2.5.1"
|
||||||
source-map: ^0.5.0
|
source-map: ^0.5.0
|
||||||
@ -3286,8 +3283,8 @@ __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
|
||||||
|
clone-deep: ^4.0.1
|
||||||
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
|
|
||||||
make-dir: ^2.1.0
|
make-dir: ^2.1.0
|
||||||
pirates: ^4.0.0
|
pirates: ^4.0.0
|
||||||
source-map-support: ^0.5.16
|
source-map-support: ^0.5.16
|
||||||
@ -3519,9 +3516,7 @@ __metadata:
|
|||||||
"@babel/generator": "workspace:*"
|
"@babel/generator": "workspace:*"
|
||||||
"@babel/helper-validator-identifier": "workspace:^7.12.11"
|
"@babel/helper-validator-identifier": "workspace:^7.12.11"
|
||||||
"@babel/parser": "workspace:*"
|
"@babel/parser": "workspace:*"
|
||||||
"@types/lodash": ^4.14.162
|
|
||||||
chalk: ^4.1.0
|
chalk: ^4.1.0
|
||||||
lodash: ^4.17.19
|
|
||||||
to-fast-properties: ^2.0.0
|
to-fast-properties: ^2.0.0
|
||||||
languageName: unknown
|
languageName: unknown
|
||||||
linkType: soft
|
linkType: soft
|
||||||
@ -4142,13 +4137,6 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"@types/lodash@npm:^4.14.150, @types/lodash@npm:^4.14.162":
|
|
||||||
version: 4.14.168
|
|
||||||
resolution: "@types/lodash@npm:4.14.168"
|
|
||||||
checksum: 9a4e25f89fc035b9f0388f1f7be85e5eff49f9e6db0d93432c9a89fce0916f8a89db4e8290415f7ea02de6b00d3573826378dcb655b7b2d20530a6e8d6dd6fd0
|
|
||||||
languageName: node
|
|
||||||
linkType: hard
|
|
||||||
|
|
||||||
"@types/minimatch@npm:*":
|
"@types/minimatch@npm:*":
|
||||||
version: 3.0.3
|
version: 3.0.3
|
||||||
resolution: "@types/minimatch@npm:3.0.3"
|
resolution: "@types/minimatch@npm:3.0.3"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user