Skip to content

Commit

Permalink
add showConfig support (#11588)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
JLHwung and existentialism committed Jul 30, 2020
1 parent 374a253 commit 164a939
Show file tree
Hide file tree
Showing 57 changed files with 827 additions and 39 deletions.
@@ -0,0 +1,14 @@
{
"sourceType": "script",
"overrides": [
{
"test": "src/index.js",
"sourceType": "module"
}
],
"env": {
"test": {
"ignore": ["./src/index.js"]
}
}
}
@@ -0,0 +1,7 @@
{
"args": ["./src/index.js"],
"env": {
"BABEL_SHOW_CONFIG_FOR": "./src/index.js"
},
"os": ["darwin", "linux"]
}
@@ -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";
@@ -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"]
}
}
}
@@ -0,0 +1,7 @@
{
"args": ["./src/index.js"],
"env": {
"BABEL_SHOW_CONFIG_FOR": "./src/index.js"
},
"os": ["darwin", "linux"]
}
@@ -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>"
@@ -0,0 +1,13 @@
{
"sourceType": "script",
"overrides": [
{
"test": "src/foo.js",
"sourceType": "module"
},
{
"test": "src/bar.js",
"sourceType": "script"
}
]
}
Empty file.
Empty file.
@@ -0,0 +1,7 @@
{
"args": ["./src", "-d", "lib"],
"env": {
"BABEL_SHOW_CONFIG_FOR": "./src/foo.js"
},
"os": ["win32"]
}
@@ -0,0 +1 @@
"use strict";
@@ -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).
@@ -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"],
},
},
};
@@ -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"],
},
},
};

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty 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"]
}

0 comments on commit 164a939

Please sign in to comment.