Use native or lodash util module where full "lodash" is required
This commit is contained in:
committed by
Logan Smyth
parent
5d31316fb1
commit
85b3aec747
@@ -7,7 +7,6 @@ import repl from "repl";
|
||||
import { util } from "babel-core";
|
||||
import * as babel from "babel-core";
|
||||
import vm from "vm";
|
||||
import _ from "lodash";
|
||||
import "babel-polyfill";
|
||||
import register from "babel-register";
|
||||
|
||||
@@ -94,7 +93,7 @@ if (program.eval || program.print) {
|
||||
|
||||
const result = _eval(code, global.__filename);
|
||||
if (program.print) {
|
||||
const output = _.isString(result) ? result : inspect(result);
|
||||
const output = typeof result === "string" ? result : inspect(result);
|
||||
process.stdout.write(output + "\n");
|
||||
}
|
||||
} else {
|
||||
@@ -104,7 +103,7 @@ if (program.eval || program.print) {
|
||||
|
||||
let i = 0;
|
||||
let ignoreNext = false;
|
||||
_.each(args, function (arg, i2) {
|
||||
args.forEach(function (arg, i2) {
|
||||
if (ignoreNext) {
|
||||
ignoreNext = false;
|
||||
return;
|
||||
|
||||
@@ -3,7 +3,6 @@ const slash = require("slash");
|
||||
const path = require("path");
|
||||
const util = require("./util");
|
||||
const fs = require("fs");
|
||||
const _ = require("lodash");
|
||||
|
||||
module.exports = function (commander, filenames) {
|
||||
function write(src, relative) {
|
||||
@@ -51,7 +50,7 @@ module.exports = function (commander, filenames) {
|
||||
if (stat.isDirectory(filename)) {
|
||||
const dirname = filename;
|
||||
|
||||
_.each(util.readdir(dirname), function (filename) {
|
||||
util.readdir(dirname).forEach(function (filename) {
|
||||
const src = path.join(dirname, filename);
|
||||
handleFile(src, filename);
|
||||
});
|
||||
@@ -61,19 +60,19 @@ module.exports = function (commander, filenames) {
|
||||
}
|
||||
|
||||
if (!commander.skipInitialBuild) {
|
||||
_.each(filenames, handle);
|
||||
filenames.forEach(handle);
|
||||
}
|
||||
|
||||
if (commander.watch) {
|
||||
const chokidar = util.requireChokidar();
|
||||
|
||||
_.each(filenames, function (dirname) {
|
||||
filenames.forEach(function (dirname) {
|
||||
const watcher = chokidar.watch(dirname, {
|
||||
persistent: true,
|
||||
ignoreInitial: true
|
||||
});
|
||||
|
||||
_.each(["add", "change"], function (type) {
|
||||
["add", "change"].forEach(function (type) {
|
||||
watcher.on(type, function (filename) {
|
||||
const relative = path.relative(dirname, filename) || filename;
|
||||
try {
|
||||
|
||||
@@ -4,7 +4,6 @@ const slash = require("slash");
|
||||
const path = require("path");
|
||||
const util = require("./util");
|
||||
const fs = require("fs");
|
||||
const _ = require("lodash");
|
||||
|
||||
module.exports = function (commander, filenames, opts) {
|
||||
if (commander.sourceMaps === "inline") {
|
||||
@@ -22,7 +21,7 @@ module.exports = function (commander, filenames, opts) {
|
||||
let code = "";
|
||||
let offset = 0;
|
||||
|
||||
_.each(results, function (result) {
|
||||
results.forEach(function (result) {
|
||||
code += result.code + "\n";
|
||||
|
||||
if (result.map) {
|
||||
@@ -107,14 +106,14 @@ module.exports = function (commander, filenames, opts) {
|
||||
const _filenames = [];
|
||||
results = [];
|
||||
|
||||
_.each(filenames, function (filename) {
|
||||
filenames.forEach(function (filename) {
|
||||
if (!fs.existsSync(filename)) return;
|
||||
|
||||
const stat = fs.statSync(filename);
|
||||
if (stat.isDirectory()) {
|
||||
const dirname = filename;
|
||||
|
||||
_.each(util.readdirFilter(filename), function (filename) {
|
||||
util.readdirFilter(filename).forEach(function (filename) {
|
||||
_filenames.push(path.join(dirname, filename));
|
||||
});
|
||||
} else {
|
||||
@@ -122,7 +121,7 @@ module.exports = function (commander, filenames, opts) {
|
||||
}
|
||||
});
|
||||
|
||||
_.each(_filenames, function (filename) {
|
||||
_filenames.forEach(function (filename) {
|
||||
if (util.shouldIgnore(filename)) return;
|
||||
|
||||
let sourceFilename = filename;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
const commander = require("commander");
|
||||
const defaults = require("lodash/defaults");
|
||||
const readdir = require("fs-readdir-recursive");
|
||||
const index = require("./index");
|
||||
const babel = require("babel-core");
|
||||
const util = require("babel-core").util;
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const _ = require("lodash");
|
||||
|
||||
export function chmod(src, dest) {
|
||||
fs.chmodSync(dest, fs.statSync(src).mode);
|
||||
@@ -34,7 +34,7 @@ export function log(msg) {
|
||||
}
|
||||
|
||||
export function transform(filename, code, opts) {
|
||||
opts = _.defaults(opts || {}, index.opts);
|
||||
opts = defaults(opts || {}, index.opts);
|
||||
opts.filename = filename;
|
||||
|
||||
const result = babel.transform(code, opts);
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
const includes = require("lodash/includes");
|
||||
const readdir = require("fs-readdir-recursive");
|
||||
const helper = require("babel-helper-fixtures");
|
||||
const assert = require("assert");
|
||||
const rimraf = require("rimraf");
|
||||
const outputFileSync = require("output-file-sync");
|
||||
const child = require("child_process");
|
||||
const merge = require("lodash/merge");
|
||||
const path = require("path");
|
||||
const chai = require("chai");
|
||||
const fs = require("fs");
|
||||
const _ = require("lodash");
|
||||
|
||||
const fixtureLoc = path.join(__dirname, "fixtures");
|
||||
const tmpLoc = path.join(__dirname, "tmp");
|
||||
@@ -25,7 +26,7 @@ const pluginLocs = [
|
||||
const readDir = function (loc) {
|
||||
const files = {};
|
||||
if (fs.existsSync(loc)) {
|
||||
_.each(readdir(loc), function (filename) {
|
||||
readdir(loc).forEach(function (filename) {
|
||||
files[filename] = helper.readFile(path.join(loc, filename));
|
||||
});
|
||||
}
|
||||
@@ -33,7 +34,8 @@ const readDir = function (loc) {
|
||||
};
|
||||
|
||||
const saveInFiles = function (files) {
|
||||
_.each(files, function (content, filename) {
|
||||
Object.keys(files).forEach(function (filename) {
|
||||
const content = files[filename];
|
||||
outputFileSync(filename, content);
|
||||
});
|
||||
};
|
||||
@@ -44,7 +46,7 @@ const assertTest = function (stdout, stderr, opts) {
|
||||
|
||||
if (opts.stderr) {
|
||||
if (opts.stderrContains) {
|
||||
assert.ok(_.includes(stderr, expectStderr), "stderr " + JSON.stringify(stderr) + " didn't contain " + JSON.stringify(expectStderr));
|
||||
assert.ok(includes(stderr, expectStderr), "stderr " + JSON.stringify(stderr) + " didn't contain " + JSON.stringify(expectStderr));
|
||||
} else {
|
||||
chai.expect(stderr).to.equal(expectStderr, "stderr didn't match");
|
||||
}
|
||||
@@ -58,7 +60,7 @@ const assertTest = function (stdout, stderr, opts) {
|
||||
|
||||
if (opts.stdout) {
|
||||
if (opts.stdoutContains) {
|
||||
assert.ok(_.includes(stdout, expectStdout), "stdout " + JSON.stringify(stdout) + " didn't contain " + JSON.stringify(expectStdout));
|
||||
assert.ok(includes(stdout, expectStdout), "stdout " + JSON.stringify(stdout) + " didn't contain " + JSON.stringify(expectStdout));
|
||||
} else {
|
||||
chai.expect(stdout).to.equal(expectStdout, "stdout didn't match");
|
||||
}
|
||||
@@ -66,7 +68,8 @@ const assertTest = function (stdout, stderr, opts) {
|
||||
throw new Error("stdout:\n" + stdout);
|
||||
}
|
||||
|
||||
_.each(opts.outFiles, function (expect, filename) {
|
||||
Object.keys(opts.outFiles, function (filename) {
|
||||
const expect = opts.outFiles[filename];
|
||||
const actual = helper.readFile(filename);
|
||||
chai.expect(actual).to.equal(expect, "out-file " + filename);
|
||||
});
|
||||
@@ -134,12 +137,12 @@ const clear = function () {
|
||||
process.chdir(tmpLoc);
|
||||
};
|
||||
|
||||
_.each(fs.readdirSync(fixtureLoc), function (binName) {
|
||||
fs.readdirSync(fixtureLoc).forEach(function (binName) {
|
||||
if (binName[0] === ".") return;
|
||||
|
||||
const suiteLoc = path.join(fixtureLoc, binName);
|
||||
describe("bin/" + binName, function () {
|
||||
_.each(fs.readdirSync(suiteLoc), function (testName) {
|
||||
fs.readdirSync(suiteLoc).forEach(function (testName) {
|
||||
if (testName[0] === ".") return;
|
||||
|
||||
const testLoc = path.join(suiteLoc, testName);
|
||||
@@ -149,9 +152,9 @@ _.each(fs.readdirSync(fixtureLoc), function (binName) {
|
||||
};
|
||||
|
||||
const optionsLoc = path.join(testLoc, "options.json");
|
||||
if (fs.existsSync(optionsLoc)) _.merge(opts, require(optionsLoc));
|
||||
if (fs.existsSync(optionsLoc)) merge(opts, require(optionsLoc));
|
||||
|
||||
_.each(["stdout", "stdin", "stderr"], function (key) {
|
||||
["stdout", "stdin", "stderr"].forEach(function (key) {
|
||||
const loc = path.join(testLoc, key + ".txt");
|
||||
if (fs.existsSync(loc)) {
|
||||
opts[key] = helper.readFile(loc);
|
||||
|
||||
Reference in New Issue
Block a user