add showConfig support (#11588)
* draft: showConfig support * feat: pass through showConfig command options * update test file * refactor: add createLogger to makeChainWalker * serializing dynamic plugin instance * fix flow errors * chore: add tests on extended config * fix: do not print empty presets * add more test cases * add windows testcases * address review comments * throw error when showConfigPath does not exist * print reason when showConfig is targetting an ignored file * remove showConfig: boolean * refactor: simplify environment flag name * rename test fixtures * fix: throw when SHOW_CONFIG_FOR is not a regular file * cleanup test fixtures * add test on only * Update packages/babel-core/src/config/files/configuration.js Co-authored-by: Brian Ng <bng412@gmail.com> * address review comments * update test fixtures * feat: sort config items in ascending priority Co-authored-by: Brian Ng <bng412@gmail.com>
This commit is contained in:
@@ -3,12 +3,14 @@ const helper = require("@babel/helper-fixtures");
|
||||
const rimraf = require("rimraf");
|
||||
const { sync: makeDirSync } = require("make-dir");
|
||||
const child = require("child_process");
|
||||
const escapeRegExp = require("lodash/escapeRegExp");
|
||||
const merge = require("lodash/merge");
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
|
||||
const fixtureLoc = path.join(__dirname, "fixtures");
|
||||
const tmpLoc = path.join(__dirname, "tmp");
|
||||
const rootDir = path.resolve(__dirname, "../../..");
|
||||
|
||||
const fileFilter = function (x) {
|
||||
return x !== ".DS_Store";
|
||||
@@ -19,12 +21,12 @@ const outputFileSync = function (filePath, data) {
|
||||
fs.writeFileSync(filePath, data);
|
||||
};
|
||||
|
||||
const presetLocs = [path.join(__dirname, "../../babel-preset-react")];
|
||||
const presetLocs = [path.join(rootDir, "./packages/babel-preset-react")];
|
||||
|
||||
const pluginLocs = [
|
||||
path.join(__dirname, "/../../babel-plugin-transform-arrow-functions"),
|
||||
path.join(__dirname, "/../../babel-plugin-transform-strict-mode"),
|
||||
path.join(__dirname, "/../../babel-plugin-transform-modules-commonjs"),
|
||||
path.join(rootDir, "./packages/babel-plugin-transform-arrow-functions"),
|
||||
path.join(rootDir, "./packages/babel-plugin-transform-strict-mode"),
|
||||
path.join(rootDir, "./packages/babel-plugin-transform-modules-commonjs"),
|
||||
].join(",");
|
||||
|
||||
const readDir = function (loc, filter) {
|
||||
@@ -50,13 +52,21 @@ const saveInFiles = function (files) {
|
||||
};
|
||||
|
||||
const normalizeOutput = function (str, cwd) {
|
||||
let prev;
|
||||
do {
|
||||
prev = str;
|
||||
str = str.replace(cwd, "<CWD>");
|
||||
} while (str !== prev);
|
||||
|
||||
return str.replace(/\(\d+ms\)/g, "(123ms)");
|
||||
let result = str
|
||||
.replace(/\(\d+ms\)/g, "(123ms)")
|
||||
.replace(new RegExp(escapeRegExp(cwd), "g"), "<CWD>")
|
||||
// (non-win32) /foo/babel/packages -> <CWD>/packages
|
||||
// (win32) C:\foo\babel\packages -> <CWD>\packages
|
||||
.replace(new RegExp(escapeRegExp(rootDir), "g"), "<ROOTDIR>");
|
||||
if (process.platform === "win32") {
|
||||
result = result
|
||||
// C:\\foo\\babel\\packages -> <CWD>\\packages (in js string literal)
|
||||
.replace(
|
||||
new RegExp(escapeRegExp(rootDir.replace(/\\/g, "\\\\")), "g"),
|
||||
"<ROOTDIR>",
|
||||
);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
const assertTest = function (stdout, stderr, opts, cwd) {
|
||||
@@ -132,8 +142,9 @@ const buildTest = function (binName, testName, opts) {
|
||||
}
|
||||
|
||||
args = args.concat(opts.args);
|
||||
const env = { ...process.env, ...opts.env };
|
||||
|
||||
const spawn = child.spawn(process.execPath, args);
|
||||
const spawn = child.spawn(process.execPath, args, { env });
|
||||
|
||||
let stderr = "";
|
||||
let stdout = "";
|
||||
|
||||
Reference in New Issue
Block a user