Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove remaining lodash dependencies #13139

Merged
merged 6 commits into from Apr 13, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions eslint/babel-eslint-plugin/package.json
Expand Up @@ -40,7 +40,7 @@
"eslint-rule-composer": "^0.3.0"
},
"devDependencies": {
"eslint": "^7.5.0",
"lodash": "^4.17.20"
"clone-deep": "^4.0.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clone-deep is quite bloated package. Maybe try klona?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My strategy for choosing the clone-deep package was "Ctrl+F for clone in our yarn.lock file", so thanks for suggesting an alternative 😂

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh it looks like klona requires Node.js >= 8, so until the Babel 8 release we cannot use it.

"eslint": "^7.5.0"
}
}
2 changes: 1 addition & 1 deletion eslint/babel-eslint-plugin/test/rules/no-invalid-this.js
@@ -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";

Expand Down
1 change: 0 additions & 1 deletion packages/babel-cli/package.json
Expand Up @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions packages/babel-cli/src/babel/dir.js
@@ -1,6 +1,5 @@
// @flow

import debounce from "lodash/debounce";
import slash from "slash";
import path from "path";
import fs from "fs";
Expand Down Expand Up @@ -135,7 +134,7 @@ export default async function ({
let compiledFiles = 0;
let startTime = null;

const logSuccess = debounce(
const logSuccess = util.debounce(
function () {
if (startTime === null) {
// This should never happen, but just in case it's better
Expand Down
14 changes: 14 additions & 0 deletions packages/babel-cli/src/babel/util.js
Expand Up @@ -141,3 +141,17 @@ 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, time) {
let timer;
const clear = () => clearTimeout(timer);
function debounced() {
clear();
timer = setTimeout(fn, time);
}
debounced.flush = () => {
clear();
fn();
};
return debounced;
}
1 change: 0 additions & 1 deletion packages/babel-core/package.json
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion packages/babel-generator/package.json
Expand Up @@ -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"
}
}
@@ -1,4 +1,4 @@
import last from "lodash/last"
import last from "lo-dash/last"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just an input/output fixture, but it was annoying when grepping for lodash 😂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol we want to ctrl+f and find no results


export default class Container {
last(key) {
Expand Down
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-register/package.json
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-register/src/node.js
@@ -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";
Expand Down Expand Up @@ -42,7 +42,7 @@ function compile(code, filename) {
// sourceRoot can be overwritten
{
sourceRoot: path.dirname(filename) + path.sep,
...deepClone(transformOpts),
...cloneDeep(transformOpts),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the reason we probably want to keep this is because transformOpts might have like things like functions vs. just objects given how people configure @babel/register with js?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, also people can pass any JS value as plugin options.

filename,
},
);
Expand Down
Expand Up @@ -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()
})
);
3 changes: 1 addition & 2 deletions packages/babel-register/test/index.js
Expand Up @@ -198,8 +198,7 @@ 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;
Expand Down
2 changes: 0 additions & 2 deletions packages/babel-types/package.json
Expand Up @@ -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"
}
}
17 changes: 14 additions & 3 deletions packages/babel-types/src/converters/valueToNode.ts
@@ -1,4 +1,3 @@
import isPlainObject from "lodash/isPlainObject";
import isValidIdentifier from "../validators/isValidIdentifier";
import {
identifier,
Expand All @@ -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 {
Expand Down
16 changes: 2 additions & 14 deletions yarn.lock
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down