-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolve .babelrc files in a monorepo. #4132
Merged
DeMoorJasper
merged 8 commits into
parcel-bundler:v2
from
astegmaier:fix-monorepo-babelrc
Feb 25, 2020
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5ff91ea
Resolve .babelrc files in a monorepo.
astegmaier 90f260c
Resolve .babelrc files in a monorepo.
astegmaier 94dd91c
Merge branch 'fix-monorepo-babelrc' of https://github.com/astegmaier/…
astegmaier c39522b
Merge from v2, and fix conflicts.
astegmaier d58d5e8
Merge branch 'v2' into fix-monorepo-babelrc
DeMoorJasper 8dac930
Merge remote-tracking branch 'upstream/v2' into fix-monorepo-babelrc
astegmaier 46cfe07
Add a unit test.
astegmaier d937a72
Merge branch 'v2' into fix-monorepo-babelrc
DeMoorJasper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...ges/core/integration-tests/test/integration/babel-config-monorepo/babel-plugin-dummy-1.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = () => { | ||
return { | ||
visitor: { | ||
StringLiteral(path, state) { | ||
const opts = state.opts; | ||
|
||
if (path.node.value === 'REPLACE_ME') { | ||
path.node.value = 'string from a plugin in babel.config.json'; | ||
} | ||
} | ||
} | ||
}; | ||
}; |
4 changes: 4 additions & 0 deletions
4
packages/core/integration-tests/test/integration/babel-config-monorepo/babel.config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"plugins": ["./babel-plugin-dummy-1"] | ||
} | ||
|
5 changes: 5 additions & 0 deletions
5
packages/core/integration-tests/test/integration/babel-config-monorepo/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "monorepo-babel-config", | ||
"private": true, | ||
"workspaces": ["pkg-a", "pkg-b"] | ||
} |
4 changes: 4 additions & 0 deletions
4
...ges/core/integration-tests/test/integration/babel-config-monorepo/packages/pkg-a/.babelrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"plugins": ["./babel-plugin-dummy-2"] | ||
} | ||
|
13 changes: 13 additions & 0 deletions
13
...ation-tests/test/integration/babel-config-monorepo/packages/pkg-a/babel-plugin-dummy-2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = () => { | ||
return { | ||
visitor: { | ||
StringLiteral(path, state) { | ||
const opts = state.opts; | ||
|
||
if (path.node.value === 'ANOTHER_THING_TO_REPLACE') { | ||
path.node.value = 'string from a plugin in .babelrc'; | ||
} | ||
} | ||
} | ||
}; | ||
}; |
3 changes: 3 additions & 0 deletions
3
...core/integration-tests/test/integration/babel-config-monorepo/packages/pkg-a/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "pkg-a" | ||
} |
6 changes: 6 additions & 0 deletions
6
...core/integration-tests/test/integration/babel-config-monorepo/packages/pkg-a/src/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = function() { | ||
const thing1 = "REPLACE_ME"; | ||
const thing2 = "ANOTHER_THING_TO_REPLACE" | ||
const thing3 = "SOMETHING ELSE" | ||
return thing1 + thing2 + thing3; | ||
} |
4 changes: 4 additions & 0 deletions
4
...ges/core/integration-tests/test/integration/babel-config-monorepo/packages/pkg-b/.babelrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"plugins": ["./babel-plugin-dummy-3"] | ||
} | ||
|
13 changes: 13 additions & 0 deletions
13
...ation-tests/test/integration/babel-config-monorepo/packages/pkg-b/babel-plugin-dummy-3.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = () => { | ||
return { | ||
visitor: { | ||
StringLiteral(path, state) { | ||
const opts = state.opts; | ||
|
||
if (path.node.value === 'ANOTHER_THING_TO_REPLACE') { | ||
path.node.value = 'string from a plugin from a different sub-package'; | ||
} | ||
} | ||
} | ||
}; | ||
}; |
3 changes: 3 additions & 0 deletions
3
...core/integration-tests/test/integration/babel-config-monorepo/packages/pkg-b/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "pkg-b" | ||
} |
6 changes: 6 additions & 0 deletions
6
...core/integration-tests/test/integration/babel-config-monorepo/packages/pkg-b/src/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = function() { | ||
const thing1 = "REPLACE_ME"; | ||
const thing2 = "ANOTHER_THING_TO_REPLACE" | ||
const thing3 = "SOMETHING ELSE" | ||
return thing1 + thing2 + thing3; | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably also need to track the package.json paths we searched as part of the config so it will be invalidated in the cache properly. Maybe a glob? cc. @padmaia
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah, I guess that never got set. Easy to add though, it's just a call to
config.setWatchGlob()
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I fully understand how the cache invalidation works - could you elaborate on what you expect to happen (but isn't already), and how I might be able to test it?
In case it's relevant, one thing to note is that the sub-project babel config might be specified in a
.babelrc
/babelrc.json
file in the sub-package directory, or as part of thebabel
property of thepackage.json
file. Presumably, we'd want to make sure that the bundle will get regenerated if any of these change (and do whatever is necessary to keep the cache clean). Given this, are there any other tweaks you think might be necessary?