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:
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"sourceType": "script",
|
||||
"overrides": [
|
||||
{
|
||||
"test": "src/index.js",
|
||||
"sourceType": "module"
|
||||
}
|
||||
],
|
||||
"env": {
|
||||
"test": {
|
||||
"ignore": ["./src/index.js"]
|
||||
}
|
||||
}
|
||||
}
|
||||
7
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR with ignored file/options.json
vendored
Normal file
7
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR with ignored file/options.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"args": ["./src/index.js"],
|
||||
"env": {
|
||||
"BABEL_SHOW_CONFIG_FOR": "./src/index.js"
|
||||
},
|
||||
"os": ["darwin", "linux"]
|
||||
}
|
||||
1
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR with ignored file/stdout.txt
vendored
Normal file
1
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR with ignored file/stdout.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
No config is applied to "<CWD>/src/index.js" because it matches one of `ignore: ["./src/index.js"]` from "<CWD>"
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"sourceType": "script",
|
||||
"overrides": [
|
||||
{
|
||||
"test": "src/foo.js",
|
||||
"sourceType": "module"
|
||||
},
|
||||
{
|
||||
"test": "src/bar.js",
|
||||
"sourceType": "script"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"args": ["./src", "--out-file", "./test.js"],
|
||||
"os": ["win32"],
|
||||
"env": {
|
||||
"BABEL_SHOW_CONFIG_FOR": "./src/foo.js"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
"use strict";
|
||||
@@ -0,0 +1,31 @@
|
||||
Babel configs on "<CWD>/src/foo.js" (ascending priority):
|
||||
config <CWD>/babel.config.json
|
||||
{
|
||||
"sourceType": "script"
|
||||
}
|
||||
|
||||
config <CWD>/babel.config.json .overrides[0]
|
||||
{
|
||||
"test": "src/foo.js",
|
||||
"sourceType": "module"
|
||||
}
|
||||
|
||||
config <CWD>/.babelrc
|
||||
{}
|
||||
|
||||
programmatic options from @babel/cli
|
||||
{
|
||||
"sourceFileName": "src/foo.js",
|
||||
"presets": [
|
||||
"<ROOTDIR>//packages//babel-preset-react"
|
||||
],
|
||||
"plugins": [
|
||||
"<ROOTDIR>//packages//babel-plugin-transform-arrow-functions",
|
||||
"<ROOTDIR>//packages//babel-plugin-transform-strict-mode",
|
||||
"<ROOTDIR>//packages//babel-plugin-transform-modules-commonjs"
|
||||
],
|
||||
"caller": {
|
||||
"name": "@babel/cli"
|
||||
},
|
||||
"filename": "src//foo.js"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"sourceType": "script",
|
||||
"overrides": [
|
||||
{
|
||||
"test": "src/foo.js",
|
||||
"sourceType": "module"
|
||||
},
|
||||
{
|
||||
"test": "src/bar.js",
|
||||
"sourceType": "script"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"args": ["./src", "--out-file", "./test.js"],
|
||||
"os": ["darwin", "linux"],
|
||||
"env": {
|
||||
"BABEL_SHOW_CONFIG_FOR": "./src/foo.js"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
"use strict";
|
||||
31
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR with multiple files/stdout.txt
vendored
Normal file
31
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR with multiple files/stdout.txt
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
Babel configs on "<CWD>/src/foo.js" (ascending priority):
|
||||
config <CWD>/babel.config.json
|
||||
{
|
||||
"sourceType": "script"
|
||||
}
|
||||
|
||||
config <CWD>/babel.config.json .overrides[0]
|
||||
{
|
||||
"test": "src/foo.js",
|
||||
"sourceType": "module"
|
||||
}
|
||||
|
||||
config <CWD>/.babelrc
|
||||
{}
|
||||
|
||||
programmatic options from @babel/cli
|
||||
{
|
||||
"sourceFileName": "src/foo.js",
|
||||
"presets": [
|
||||
"<ROOTDIR>/packages/babel-preset-react"
|
||||
],
|
||||
"plugins": [
|
||||
"<ROOTDIR>/packages/babel-plugin-transform-arrow-functions",
|
||||
"<ROOTDIR>/packages/babel-plugin-transform-strict-mode",
|
||||
"<ROOTDIR>/packages/babel-plugin-transform-modules-commonjs"
|
||||
],
|
||||
"caller": {
|
||||
"name": "@babel/cli"
|
||||
},
|
||||
"filename": "src/foo.js"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"sourceType": "script",
|
||||
"overrides": [
|
||||
{
|
||||
"test": "src/index.js",
|
||||
"sourceType": "module"
|
||||
}
|
||||
],
|
||||
"env": {
|
||||
"test": {
|
||||
"only": ["./src/unicorn.js"]
|
||||
}
|
||||
}
|
||||
}
|
||||
7
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR with only file/options.json
vendored
Normal file
7
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR with only file/options.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"args": ["./src/index.js"],
|
||||
"env": {
|
||||
"BABEL_SHOW_CONFIG_FOR": "./src/index.js"
|
||||
},
|
||||
"os": ["darwin", "linux"]
|
||||
}
|
||||
1
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR with only file/stdout.txt
vendored
Normal file
1
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR with only file/stdout.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
No config is applied to "<CWD>/src/index.js" because it fails to match one of `only: ["./src/unicorn.js"]` from "<CWD>"
|
||||
13
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR-windows/in-files/babel.config.json
vendored
Normal file
13
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR-windows/in-files/babel.config.json
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"sourceType": "script",
|
||||
"overrides": [
|
||||
{
|
||||
"test": "src/foo.js",
|
||||
"sourceType": "module"
|
||||
},
|
||||
{
|
||||
"test": "src/bar.js",
|
||||
"sourceType": "script"
|
||||
}
|
||||
]
|
||||
}
|
||||
0
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR-windows/in-files/src/bar.js
vendored
Normal file
0
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR-windows/in-files/src/bar.js
vendored
Normal file
0
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR-windows/in-files/src/foo.js
vendored
Normal file
0
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR-windows/in-files/src/foo.js
vendored
Normal file
7
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR-windows/options.json
vendored
Normal file
7
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR-windows/options.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"args": ["./src", "-d", "lib"],
|
||||
"env": {
|
||||
"BABEL_SHOW_CONFIG_FOR": "./src/foo.js"
|
||||
},
|
||||
"os": ["win32"]
|
||||
}
|
||||
1
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR-windows/out-files/lib/bar.js
vendored
Normal file
1
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR-windows/out-files/lib/bar.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
"use strict";
|
||||
32
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR-windows/stdout.txt
vendored
Normal file
32
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR-windows/stdout.txt
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
Babel configs on "<CWD>/src/foo.js" (ascending priority):
|
||||
config <CWD>/babel.config.json
|
||||
{
|
||||
"sourceType": "script"
|
||||
}
|
||||
|
||||
config <CWD>/babel.config.json .overrides[0]
|
||||
{
|
||||
"test": "src/foo.js",
|
||||
"sourceType": "module"
|
||||
}
|
||||
|
||||
config <CWD>/.babelrc
|
||||
{}
|
||||
|
||||
programmatic options from @babel/cli
|
||||
{
|
||||
"sourceFileName": "../src/foo.js",
|
||||
"presets": [
|
||||
"<ROOTDIR>//packages//babel-preset-react"
|
||||
],
|
||||
"plugins": [
|
||||
"<ROOTDIR>//packages//babel-plugin-transform-arrow-functions",
|
||||
"<ROOTDIR>//packages//babel-plugin-transform-strict-mode",
|
||||
"<ROOTDIR>//packages//babel-plugin-transform-modules-commonjs"
|
||||
],
|
||||
"caller": {
|
||||
"name": "@babel/cli"
|
||||
},
|
||||
"filename": "src//foo.js"
|
||||
}
|
||||
Successfully compiled 1 file with Babel (123ms).
|
||||
40
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR/in-files/my-config.js
vendored
Normal file
40
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR/in-files/my-config.js
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
module.exports = {
|
||||
sourceType: "script",
|
||||
plugins: [require("@foo/babel-plugin-1")],
|
||||
extends: "./my-extended.js",
|
||||
overrides: [
|
||||
{
|
||||
test: "src/index.js",
|
||||
plugins: [["@foo/babel-plugin-2", { noDocumentAll: true }]],
|
||||
env: {
|
||||
test: {
|
||||
plugins: [
|
||||
"@foo/babel-plugin-1",
|
||||
[
|
||||
{ name: "@foo/inline-babel-plugin-1", visitor: { Program() {} } },
|
||||
{ noDocumentAll: true },
|
||||
],
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
exclude: "src/index.js",
|
||||
plugins: ["@foo/babel-plugin-4"],
|
||||
},
|
||||
],
|
||||
env: {
|
||||
test: {
|
||||
plugins: [
|
||||
[
|
||||
"@foo/babel-plugin-3",
|
||||
{ noDocumentAll: true },
|
||||
"@foo/babel-plugin-three",
|
||||
],
|
||||
],
|
||||
},
|
||||
development: {
|
||||
plugins: ["@foo/babel-plugin-4"],
|
||||
},
|
||||
},
|
||||
};
|
||||
47
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR/in-files/my-extended.js
vendored
Normal file
47
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR/in-files/my-extended.js
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
module.exports = {
|
||||
sourceMaps: false,
|
||||
presets: ["@foo/babel-preset-1"],
|
||||
overrides: [
|
||||
{
|
||||
test: "src/index.js",
|
||||
presets: [["@foo/babel-preset-2", { noDocumentAll: true }]],
|
||||
env: {
|
||||
test: {
|
||||
presets: [
|
||||
"@foo/babel-preset-1",
|
||||
[
|
||||
{
|
||||
name: "@foo/inline-babel-preset-1",
|
||||
plugins: [
|
||||
{
|
||||
name: "@foo/inline-babel-plugin-1",
|
||||
visitor: { Program() {} },
|
||||
},
|
||||
],
|
||||
},
|
||||
{ noDocumentAll: true },
|
||||
],
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
exclude: "src/index.js",
|
||||
presets: ["@foo/babel-preset-4"],
|
||||
},
|
||||
],
|
||||
env: {
|
||||
test: {
|
||||
presets: [
|
||||
[
|
||||
"@foo/babel-preset-3",
|
||||
{ noDocumentAll: true },
|
||||
"@foo/babel-preset-three",
|
||||
],
|
||||
],
|
||||
},
|
||||
development: {
|
||||
presets: ["@foo/babel-preset-4"],
|
||||
},
|
||||
},
|
||||
};
|
||||
6
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR/in-files/node_modules/@foo/babel-plugin-1/index.js
generated
vendored
Normal file
6
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR/in-files/node_modules/@foo/babel-plugin-1/index.js
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
module.exports = (api) => ({
|
||||
name: "@foo/" + __dirname,
|
||||
visitor: {
|
||||
Program() {}
|
||||
}
|
||||
})
|
||||
6
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR/in-files/node_modules/@foo/babel-plugin-2/index.js
generated
vendored
Normal file
6
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR/in-files/node_modules/@foo/babel-plugin-2/index.js
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
module.exports = (api) => ({
|
||||
name: "@foo/" + __dirname,
|
||||
visitor: {
|
||||
Program() {}
|
||||
}
|
||||
})
|
||||
6
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR/in-files/node_modules/@foo/babel-plugin-3/index.js
generated
vendored
Normal file
6
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR/in-files/node_modules/@foo/babel-plugin-3/index.js
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
module.exports = (api) => ({
|
||||
name: "@foo/" + __dirname,
|
||||
visitor: {
|
||||
Program() {}
|
||||
}
|
||||
})
|
||||
6
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR/in-files/node_modules/@foo/babel-plugin-4/index.js
generated
vendored
Normal file
6
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR/in-files/node_modules/@foo/babel-plugin-4/index.js
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
module.exports = (api) => ({
|
||||
name: "@foo/" + __dirname,
|
||||
visitor: {
|
||||
Program() {}
|
||||
}
|
||||
})
|
||||
4
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR/in-files/node_modules/@foo/babel-preset-1/index.js
generated
vendored
Normal file
4
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR/in-files/node_modules/@foo/babel-preset-1/index.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
module.exports = (api) => ({
|
||||
name: "@foo/" + __dirname,
|
||||
plugins: ["@foo/" + __dirname.replace("preset", "plugin")]
|
||||
})
|
||||
4
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR/in-files/node_modules/@foo/babel-preset-2/index.js
generated
vendored
Normal file
4
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR/in-files/node_modules/@foo/babel-preset-2/index.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
module.exports = (api) => ({
|
||||
name: "@foo/" + __dirname,
|
||||
plugins: ["@foo/" + __dirname.replace("preset", "plugin")]
|
||||
})
|
||||
4
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR/in-files/node_modules/@foo/babel-preset-3/index.js
generated
vendored
Normal file
4
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR/in-files/node_modules/@foo/babel-preset-3/index.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
module.exports = (api) => ({
|
||||
name: "@foo/" + __dirname,
|
||||
plugins: ["@foo/" + __dirname.replace("preset", "plugin")]
|
||||
})
|
||||
4
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR/in-files/node_modules/@foo/babel-preset-4/index.js
generated
vendored
Normal file
4
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR/in-files/node_modules/@foo/babel-preset-4/index.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
module.exports = (api) => ({
|
||||
name: "@foo/" + __dirname,
|
||||
plugins: ["@foo/" + __dirname.replace("preset", "plugin")]
|
||||
})
|
||||
0
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR/in-files/src/index.js
vendored
Normal file
0
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR/in-files/src/index.js
vendored
Normal file
8
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR/options.json
vendored
Normal file
8
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR/options.json
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"args": ["--config-file", "./my-config.js", "./src/index.js"],
|
||||
"env": {
|
||||
"BABEL_ENV": "test",
|
||||
"BABEL_SHOW_CONFIG_FOR": "./src/index.js"
|
||||
},
|
||||
"os": ["darwin", "linux"]
|
||||
}
|
||||
127
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR/stdout.txt
vendored
Normal file
127
packages/babel-cli/test/fixtures/babel/env - SHOW_CONFIG_FOR/stdout.txt
vendored
Normal file
@@ -0,0 +1,127 @@
|
||||
Babel configs on "<CWD>/src/index.js" (ascending priority):
|
||||
config <CWD>/my-extended.js
|
||||
{
|
||||
"sourceMaps": false,
|
||||
"presets": [
|
||||
"@foo/babel-preset-1"
|
||||
]
|
||||
}
|
||||
|
||||
config <CWD>/my-extended.js .env["test"]
|
||||
{
|
||||
"presets": [
|
||||
[
|
||||
"@foo/babel-preset-3",
|
||||
{
|
||||
"noDocumentAll": true
|
||||
},
|
||||
"@foo/babel-preset-three"
|
||||
]
|
||||
]
|
||||
}
|
||||
|
||||
config <CWD>/my-extended.js .overrides[0]
|
||||
{
|
||||
"test": "src/index.js",
|
||||
"presets": [
|
||||
[
|
||||
"@foo/babel-preset-2",
|
||||
{
|
||||
"noDocumentAll": true
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
|
||||
config <CWD>/my-extended.js .overrides[0].env["test"]
|
||||
{
|
||||
"presets": [
|
||||
"@foo/babel-preset-1",
|
||||
[
|
||||
{
|
||||
"name": "@foo/inline-babel-preset-1",
|
||||
"plugins": [
|
||||
{
|
||||
"name": "@foo/inline-babel-plugin-1",
|
||||
"visitor": {}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"noDocumentAll": true
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
|
||||
config <CWD>/my-config.js
|
||||
{
|
||||
"sourceType": "script",
|
||||
"plugins": [
|
||||
"[Function: (api) => ({/n name: /"@foo//" + __dirname,/n visitor ... ]"
|
||||
],
|
||||
"extends": "./my-extended.js"
|
||||
}
|
||||
|
||||
config <CWD>/my-config.js .env["test"]
|
||||
{
|
||||
"plugins": [
|
||||
[
|
||||
"@foo/babel-plugin-3",
|
||||
{
|
||||
"noDocumentAll": true
|
||||
},
|
||||
"@foo/babel-plugin-three"
|
||||
]
|
||||
]
|
||||
}
|
||||
|
||||
config <CWD>/my-config.js .overrides[0]
|
||||
{
|
||||
"test": "src/index.js",
|
||||
"plugins": [
|
||||
[
|
||||
"@foo/babel-plugin-2",
|
||||
{
|
||||
"noDocumentAll": true
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
|
||||
config <CWD>/my-config.js .overrides[0].env["test"]
|
||||
{
|
||||
"plugins": [
|
||||
"@foo/babel-plugin-1",
|
||||
[
|
||||
{
|
||||
"name": "@foo/inline-babel-plugin-1",
|
||||
"visitor": {}
|
||||
},
|
||||
{
|
||||
"noDocumentAll": true
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
|
||||
config <CWD>/.babelrc
|
||||
{}
|
||||
|
||||
programmatic options from @babel/cli
|
||||
{
|
||||
"sourceFileName": "./src/index.js",
|
||||
"presets": [
|
||||
"<ROOTDIR>/packages/babel-preset-react"
|
||||
],
|
||||
"plugins": [
|
||||
"<ROOTDIR>/packages/babel-plugin-transform-arrow-functions",
|
||||
"<ROOTDIR>/packages/babel-plugin-transform-strict-mode",
|
||||
"<ROOTDIR>/packages/babel-plugin-transform-modules-commonjs"
|
||||
],
|
||||
"configFile": "./my-config.js",
|
||||
"caller": {
|
||||
"name": "@babel/cli"
|
||||
},
|
||||
"filename": "./src/index.js"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"sourceType": "script",
|
||||
"overrides": [
|
||||
{
|
||||
"test": "src/foo.js",
|
||||
"sourceType": "module"
|
||||
},
|
||||
{
|
||||
"test": "src/bar.js",
|
||||
"sourceType": "script"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"args": ["./src", "-d", "lib"],
|
||||
"env": {
|
||||
"BABEL_SHOW_CONFIG_FOR": "./src"
|
||||
},
|
||||
"os": ["win32"],
|
||||
"stderrContains": true
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
Error: <CWD>\src: BABEL_SHOW_CONFIG_FOR must refer to a regular file, directories are not supported.
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"sourceType": "script",
|
||||
"overrides": [
|
||||
{
|
||||
"test": "src/foo.js",
|
||||
"sourceType": "module"
|
||||
},
|
||||
{
|
||||
"test": "src/bar.js",
|
||||
"sourceType": "script"
|
||||
}
|
||||
]
|
||||
}
|
||||
8
packages/babel-cli/test/fixtures/babel/error - SHOW_CONFIG_FOR is a folder/options.json
vendored
Normal file
8
packages/babel-cli/test/fixtures/babel/error - SHOW_CONFIG_FOR is a folder/options.json
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"args": ["./src", "-d", "lib"],
|
||||
"env": {
|
||||
"BABEL_SHOW_CONFIG_FOR": "./src"
|
||||
},
|
||||
"os": ["darwin", "linux"],
|
||||
"stderrContains": true
|
||||
}
|
||||
1
packages/babel-cli/test/fixtures/babel/error - SHOW_CONFIG_FOR is a folder/stderr.txt
vendored
Normal file
1
packages/babel-cli/test/fixtures/babel/error - SHOW_CONFIG_FOR is a folder/stderr.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
Error: <CWD>/src: BABEL_SHOW_CONFIG_FOR must refer to a regular file, directories are not supported.
|
||||
@@ -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