Remove remaining lodash dependencies (#13139)
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
export default class Container {
|
||||
last(key) {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
);
|
||||
|
||||
@@ -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()
|
||||
})
|
||||
);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user