Remove babel-doctor from babel-cli (#4725)
* Remove babel-doctor from babel-cli fixes #4678 * Throw when babel-doctor is used
This commit is contained in:
@@ -1,96 +0,0 @@
|
||||
import chalk from "chalk";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
import * as rules from "./rules";
|
||||
import symbols from "log-symbols";
|
||||
|
||||
let didError = false;
|
||||
let lastWasSep = false;
|
||||
|
||||
function sep() {
|
||||
if (lastWasSep) return;
|
||||
lastWasSep = true;
|
||||
|
||||
console.log();
|
||||
}
|
||||
|
||||
function log(msg) {
|
||||
lastWasSep = false;
|
||||
console.log(msg);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
log("\n" + chalk.underline.yellow("Babel Doctor"));
|
||||
log("Running sanity checks on your system. This may take a few minutes...\n");
|
||||
|
||||
//
|
||||
|
||||
let packages = [];
|
||||
|
||||
let nodeModulesDirectories = [
|
||||
path.join(process.cwd(), "node_modules")
|
||||
];
|
||||
|
||||
while (nodeModulesDirectories.length) {
|
||||
let loc = nodeModulesDirectories.shift();
|
||||
if (!fs.existsSync(loc)) continue;
|
||||
|
||||
let packagesNames: Array<string> = fs.readdirSync(loc);
|
||||
|
||||
for (let packageName of packagesNames) {
|
||||
if (packageName[0] === ".") continue;
|
||||
|
||||
let packageLoc = path.join(loc, packageName);
|
||||
let packageJsonLoc = path.join(packageLoc, "package.json");
|
||||
if (!fs.existsSync(packageJsonLoc)) continue;
|
||||
|
||||
packages.push({
|
||||
name: packageName,
|
||||
loc: packageLoc,
|
||||
version: require(packageJsonLoc).version
|
||||
});
|
||||
|
||||
nodeModulesDirectories.push(path.join(packageLoc, "node_modules"));
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
async function run() {
|
||||
let promises = [];
|
||||
|
||||
for (let key in rules) {
|
||||
if (key[0] === "_") continue;
|
||||
|
||||
let fn = rules[key];
|
||||
promises.push(fn(packages));
|
||||
}
|
||||
|
||||
let results = await Promise.all(promises);
|
||||
|
||||
for (let [success, message] of results) {
|
||||
if (!success) didError = true;
|
||||
let multiline = message.indexOf("\n") >= 0;
|
||||
if (multiline) sep();
|
||||
log(`${success ? symbols.success : symbols.error} ${message}`);
|
||||
if (multiline) sep();
|
||||
}
|
||||
|
||||
sep();
|
||||
|
||||
if (didError) {
|
||||
log(chalk.red("Found potential issues on your machine :("));
|
||||
} else {
|
||||
log(chalk.green("Everything looks all right!"));
|
||||
}
|
||||
|
||||
sep();
|
||||
}
|
||||
|
||||
run().then(function () {
|
||||
process.exit(0);
|
||||
}, function (err) {
|
||||
console.error(err.stack);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -1,31 +0,0 @@
|
||||
export default async function (packages) {
|
||||
let foundDeps = {};
|
||||
let foundDuplicated = false;
|
||||
let duplicatedPackages = {};
|
||||
|
||||
function checkDep(name) {
|
||||
if (name.indexOf("babel-") === 0 && foundDeps[name]) {
|
||||
foundDuplicated = true;
|
||||
duplicatedPackages[name] = (duplicatedPackages[name] || 0) + 1;
|
||||
}
|
||||
|
||||
foundDeps[name] = true;
|
||||
}
|
||||
|
||||
for (let pkg of packages) {
|
||||
checkDep(pkg.name);
|
||||
}
|
||||
|
||||
if (foundDuplicated) {
|
||||
let msg = "Found these duplicate packages:\n\n";
|
||||
|
||||
for (let name in duplicatedPackages) {
|
||||
msg += `- ${name} x ${duplicatedPackages[name]}\n`;
|
||||
}
|
||||
|
||||
msg += "\nRecommend running `npm dedupe`";
|
||||
return [false, msg];
|
||||
} else {
|
||||
return [true, "No duplicate babel packages found"];
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
|
||||
export default async function () {
|
||||
let cwd = process.cwd();
|
||||
let parts = cwd.split(path.sep);
|
||||
|
||||
do {
|
||||
let loc = parts.join(path.sep);
|
||||
if (!loc) break;
|
||||
|
||||
let babelrc = path.join(loc, ".babelrc");
|
||||
if (fs.existsSync(babelrc)) {
|
||||
return [true, `Found config at ${babelrc}`];
|
||||
}
|
||||
|
||||
let packagejson = path.join(loc, "package.json");
|
||||
if (fs.existsSync(packagejson)) {
|
||||
let pkg = require(packagejson);
|
||||
if (pkg.babel) {
|
||||
return [true, `Found config at ${packagejson}`];
|
||||
}
|
||||
}
|
||||
|
||||
parts.pop();
|
||||
} while (parts.length);
|
||||
|
||||
return [false, "Found no .babelrc config"];
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
export { default as hasConfig } from "./has-config";
|
||||
export { default as deduped } from "./deduped";
|
||||
export { default as latestPackages } from "./latest-packages";
|
||||
export { default as npm } from "./npm-3";
|
||||
@@ -1,55 +0,0 @@
|
||||
import request from "request";
|
||||
|
||||
let cache = {};
|
||||
|
||||
function getInfo(packageName) {
|
||||
if (cache[packageName]) {
|
||||
return cache[packageName];
|
||||
} else {
|
||||
return cache[packageName] = new Promise(function (resolve, reject) {
|
||||
request.get({
|
||||
url: `https://registry.npmjs.org/${packageName}/latest`,
|
||||
json: true
|
||||
}, function (err, res, body) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(cache[packageName] = body);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default async function (packages) {
|
||||
let filteredPackages = [];
|
||||
let promises = [];
|
||||
|
||||
for (let pkg of packages) {
|
||||
if (pkg.name.indexOf("babel-") !== 0) continue;
|
||||
|
||||
promises.push(getInfo(pkg.name));
|
||||
filteredPackages.push(pkg);
|
||||
}
|
||||
|
||||
let infos = await Promise.all(promises);
|
||||
let messages = [];
|
||||
|
||||
for (let i = 0; i < infos.length; i++) {
|
||||
let info = infos[i];
|
||||
let pkg = filteredPackages[i];
|
||||
|
||||
// https://github.com/babel/babel/issues/2915
|
||||
if (pkg.name === "babel-runtime") continue;
|
||||
|
||||
if (info.version !== pkg.version) {
|
||||
messages.push(`${pkg.name} - Latest is ${info.version}. Local version is ${pkg.version}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (messages.length) {
|
||||
return [false, `We found some outdated packages:\n\n- ${messages.join("\n- ")}`];
|
||||
} else {
|
||||
return [true, "All babel packages appear to be up to date"];
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
/* eslint max-len: 0 */
|
||||
|
||||
import binVersionCheck from "bin-version-check";
|
||||
import chalk from "chalk";
|
||||
|
||||
export default function () {
|
||||
return new Promise(function (resolve) {
|
||||
binVersionCheck("npm", ">=3.3.0", function (err) {
|
||||
if (err) {
|
||||
let message = `Your npm version is outdated. Upgrade to the latest version by running:\n$ ${chalk.magenta("npm install -g npm")}.`;
|
||||
if (process.platform === "win32") {
|
||||
message += ` See this guide if you are having trouble upgrading: ${chalk.underline.blue("https://github.com/npm/npm/wiki/Troubleshooting#upgrading-on-windows")}`;
|
||||
}
|
||||
resolve([false, message]);
|
||||
} else {
|
||||
resolve([true, "You're on npm >=3.3.0"]);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user