Remove remaining lodash dependencies (#13139)

This commit is contained in:
Nicolò Ribaudo 2021-04-13 22:41:22 +02:00 committed by GitHub
parent b35c78f08d
commit d24bd7ce5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 55 additions and 56 deletions

View File

@ -40,7 +40,7 @@
"eslint-rule-composer": "^0.3.0"
},
"devDependencies": {
"eslint": "^7.5.0",
"lodash": "^4.17.20"
"clone-deep": "^4.0.1",
"eslint": "^7.5.0"
}
}

View File

@ -1,4 +1,4 @@
import cloneDeep from "lodash/cloneDeep";
import cloneDeep from "clone-deep";
import rule from "../../src/rules/no-invalid-this";
import RuleTester from "../../../babel-eslint-shared-fixtures/utils/RuleTester";

View File

@ -28,7 +28,6 @@
"convert-source-map": "^1.1.0",
"fs-readdir-recursive": "^1.1.0",
"glob": "^7.0.0",
"lodash": "^4.17.19",
"make-dir": "^2.1.0",
"slash": "condition:BABEL_8_BREAKING ? ^3.0.0 : ^2.0.0",
"source-map": "^0.5.0"

View File

@ -1,6 +1,5 @@
// @flow
import debounce from "lodash/debounce";
import slash from "slash";
import path from "path";
import fs from "fs";
@ -135,27 +134,23 @@ export default async function ({
let compiledFiles = 0;
let startTime = null;
const logSuccess = debounce(
function () {
if (startTime === null) {
// This should never happen, but just in case it's better
// to ignore the log message rather than making @babel/cli crash.
return;
}
const logSuccess = util.debounce(function () {
if (startTime === null) {
// This should never happen, but just in case it's better
// to ignore the log message rather than making @babel/cli crash.
return;
}
const diff = process.hrtime(startTime);
const diff = process.hrtime(startTime);
console.log(
`Successfully compiled ${compiledFiles} ${
compiledFiles !== 1 ? "files" : "file"
} with Babel (${diff[0] * 1e3 + Math.round(diff[1] / 1e6)}ms).`,
);
compiledFiles = 0;
startTime = null;
},
100,
{ trailing: true },
);
console.log(
`Successfully compiled ${compiledFiles} ${
compiledFiles !== 1 ? "files" : "file"
} with Babel (${diff[0] * 1e3 + Math.round(diff[1] / 1e6)}ms).`,
);
compiledFiles = 0;
startTime = null;
}, 100);
if (!cliOptions.skipInitialBuild) {
if (cliOptions.deleteDirOnStart) {

View File

@ -141,3 +141,16 @@ export function withExtension(filename: string, ext: string = ".js") {
const newBasename = path.basename(filename, path.extname(filename)) + ext;
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;
}

View File

@ -68,7 +68,6 @@
"@babel/helper-transform-fixture-test-runner": "workspace:*",
"@types/convert-source-map": "^1.5.1",
"@types/debug": "^4.1.0",
"@types/lodash": "^4.14.150",
"@types/resolve": "^1.3.2",
"@types/semver": "^5.4.0",
"@types/source-map": "^0.5.0"

View File

@ -27,7 +27,6 @@
"@babel/helper-fixtures": "workspace:*",
"@babel/parser": "workspace:*",
"@types/jsesc": "^2.5.0",
"@types/lodash": "^4.14.150",
"@types/source-map": "^0.5.0"
}
}

View File

@ -1,4 +1,4 @@
import last from "lodash/last"
import last from "lo-dash/last"
export default class Container {
last(key) {

View File

@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
});
exports.default = void 0;
var _last2 = babelHelpers.interopRequireDefault(require("lodash/last"));
var _last2 = babelHelpers.interopRequireDefault(require("lo-dash/last"));
let Container = /*#__PURE__*/function () {
function Container() {

View File

@ -17,8 +17,8 @@
"./lib/nodeWrapper.js": "./lib/browser.js"
},
"dependencies": {
"clone-deep": "^4.0.1",
"find-cache-dir": "condition:BABEL_8_BREAKING ? ^3.3.1 : ^2.0.0",
"lodash": "^4.17.19",
"make-dir": "^2.1.0",
"pirates": "^4.0.0",
"source-map-support": "^0.5.16"

View File

@ -1,4 +1,4 @@
import deepClone from "lodash/cloneDeep";
import cloneDeep from "clone-deep";
import sourceMapSupport from "source-map-support";
import * as registerCache from "./cache";
import * as babel from "@babel/core";
@ -42,7 +42,7 @@ function compile(code, filename) {
// sourceRoot can be overwritten
{
sourceRoot: path.dirname(filename) + path.sep,
...deepClone(transformOpts),
...cloneDeep(transformOpts),
filename,
},
);

View File

@ -22,7 +22,6 @@ register( {
console.log(
JSON.stringify({
convertSourceMap: require('convert-source-map').fromObject.toString(),
isPlainObject: require('lodash/isPlainObject').toString()
convertSourceMap: require('convert-source-map').fromObject.toString()
})
);

View File

@ -198,16 +198,14 @@ describe("@babel/register", function () {
test("transforms modules used within register", callback => {
// Need a clean environment without `convert-source-map`
// and `lodash/isPlainObject` already in the require cache,
// so we spawn a separate process
// already in the require cache, so we spawn a separate process
spawnNode([internalModulesTestFile], output => {
let err;
try {
const { convertSourceMap, isPlainObject } = JSON.parse(output);
const { convertSourceMap } = JSON.parse(output);
expect(convertSourceMap).toMatch("/* transformed */");
expect(isPlainObject).toMatch("/* transformed */");
} catch (e) {
err = e;
}

View File

@ -25,13 +25,11 @@
},
"dependencies": {
"@babel/helper-validator-identifier": "workspace:^7.12.11",
"lodash": "^4.17.19",
"to-fast-properties": "^2.0.0"
},
"devDependencies": {
"@babel/generator": "workspace:*",
"@babel/parser": "workspace:*",
"@types/lodash": "^4.14.162",
"chalk": "^4.1.0"
}
}

View File

@ -1,4 +1,3 @@
import isPlainObject from "lodash/isPlainObject";
import isValidIdentifier from "../validators/isValidIdentifier";
import {
identifier,
@ -25,15 +24,27 @@ export default valueToNode as {
(value: RegExp): t.RegExpLiteral;
(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
(value: object): t.ObjectExpression;
(value: unknown): t.Expression;
};
const objectToString: (value: object) => string = Function.call.bind(
Object.prototype.toString,
);
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 {

View File

@ -94,7 +94,6 @@ __metadata:
convert-source-map: ^1.1.0
fs-readdir-recursive: ^1.1.0
glob: ^7.0.0
lodash: ^4.17.19
make-dir: ^2.1.0
rimraf: ^3.0.0
slash: "condition:BABEL_8_BREAKING ? ^3.0.0 : ^2.0.0"
@ -213,7 +212,6 @@ __metadata:
"@babel/types": "workspace:^7.13.14"
"@types/convert-source-map": ^1.5.1
"@types/debug": ^4.1.0
"@types/lodash": ^4.14.150
"@types/resolve": ^1.3.2
"@types/semver": ^5.4.0
"@types/source-map": ^0.5.0
@ -274,9 +272,9 @@ __metadata:
version: 0.0.0-use.local
resolution: "@babel/eslint-plugin@workspace:eslint/babel-eslint-plugin"
dependencies:
clone-deep: ^4.0.1
eslint: ^7.5.0
eslint-rule-composer: ^0.3.0
lodash: ^4.17.20
peerDependencies:
"@babel/eslint-parser": ">=7.11.0"
eslint: ">=7.5.0"
@ -331,7 +329,6 @@ __metadata:
"@babel/parser": "workspace:*"
"@babel/types": "workspace:^7.13.0"
"@types/jsesc": ^2.5.0
"@types/lodash": ^4.14.150
"@types/source-map": ^0.5.0
jsesc: "condition: BABEL_8_BREAKING ? ^3.0.2 : ^2.5.1"
source-map: ^0.5.0
@ -3286,8 +3283,8 @@ __metadata:
"@babel/core": "workspace:*"
"@babel/plugin-transform-modules-commonjs": "workspace:*"
browserify: ^16.5.2
clone-deep: ^4.0.1
find-cache-dir: "condition:BABEL_8_BREAKING ? ^3.3.1 : ^2.0.0"
lodash: ^4.17.19
make-dir: ^2.1.0
pirates: ^4.0.0
source-map-support: ^0.5.16
@ -3519,9 +3516,7 @@ __metadata:
"@babel/generator": "workspace:*"
"@babel/helper-validator-identifier": "workspace:^7.12.11"
"@babel/parser": "workspace:*"
"@types/lodash": ^4.14.162
chalk: ^4.1.0
lodash: ^4.17.19
to-fast-properties: ^2.0.0
languageName: unknown
linkType: soft
@ -4142,13 +4137,6 @@ __metadata:
languageName: node
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:*":
version: 3.0.3
resolution: "@types/minimatch@npm:3.0.3"