-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2070: Fix `importComponent` r=ZauberNerd a=ZauberNerd Ref: #1632, #1976 Todo: - [x] What happens if we import the same file from different files? I suspect our babel plugin will generate different chunk names which should in fact not be different. So maybe our hash should not include the filepath of the importing component but only the filepath of the imported component. - seems to create separate entries in the `namedChunkGroups` which point to the same asset. <details> <summary>Bors merge bot cheat sheet</summary> We are using [bors-ng](https://github.com/bors-ng/bors-ng) to automate merging of our pull requests. The following table provides a summary of commands that are available to reviewers (members of this repository with push access) and delegates (in case of `bors delegate+` or `bors delegate=[list]`). | Syntax | Description | | --- | --- | | bors merge | Run the test suite and push to master if it passes. Short for "reviewed: looks good." | | bors merge- | Cancel an r+, r=, merge, or merge= | | bors try | Run the test suite without pushing to master. | | bors try- | Cancel a try | | bors delegate+ | Allow the pull request author to merge their changes. | | bors delegate=[list] | Allow the listed users to r+ this pull request's changes. | | bors retry | Run the previous command a second time. | This is a short collection of opinionated commands. For a full list of the commands read the [bors reference](https://bors.tech/documentation/). </details> Co-authored-by: Björn Brauer <bjoern.brauer@new-work.se> Co-authored-by: Robert Kowalski <robert.kowalski@new-work.se>
- Loading branch information
Showing
36 changed files
with
298 additions
and
125 deletions.
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
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
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
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
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 |
---|---|---|
@@ -1,17 +1,27 @@ | ||
// eslint-disable-next-line node/no-extraneous-require | ||
const { createTransformer } = require('esbuild-jest'); | ||
const { transformSync } = require('@babel/core'); | ||
|
||
const transformer = createTransformer({ | ||
sourcemap: true, | ||
}); | ||
|
||
const regex = /importComponent/g; | ||
|
||
module.exports = { | ||
process(content, filename, config, opts) { | ||
content = content.replace( | ||
/importComponent\s*\(\s*\(\)\s+=>\s+import\(\s*'([^']+)'\s*\)\s*\)/g, | ||
"importComponent({ component: require('$1') })" | ||
); | ||
if (!regex.test(content)) { | ||
return transformer.process(content, filename, config, opts); | ||
} | ||
|
||
const result = transformSync(content, { | ||
plugins: [ | ||
require.resolve('../helpers/babel-plugin-import-component'), | ||
require.resolve('@babel/plugin-syntax-jsx'), | ||
], | ||
filename, | ||
}); | ||
|
||
return transformer.process(content, filename, config, opts); | ||
return transformer.process(result.code, filename, config, opts); | ||
}, | ||
}; |
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
31 changes: 26 additions & 5 deletions
31
packages/react/import-component/import-component-loader.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
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
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
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
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
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
Oops, something went wrong.