-
Notifications
You must be signed in to change notification settings - Fork 117
Drive Metro config using Kit config #376
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
46e6b04
fix TPN tests
afoxman 0cabb2d
Add Metro config options to kit config, removing the need to manually…
afoxman 36c3bd8
Change files
afoxman a679bf8
update the Metro config based on the kit config. enable/disable cycli…
afoxman fee589a
fixes based on PR feedback
afoxman 7b0ef36
Merge remote-tracking branch 'origin/main' into afoxman/bundle-config
afoxman 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
7 changes: 7 additions & 0 deletions
7
change/@rnx-kit-config-f87e92f1-da12-415e-8e14-3424c2b86c27.json
This file contains hidden or 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,7 @@ | ||
| { | ||
| "type": "minor", | ||
| "comment": "Add Metro config options to kit config, removing the need to manually control Metro config. Update test app.", | ||
| "packageName": "@rnx-kit/config", | ||
| "email": "afoxman@microsoft.com", | ||
| "dependentChangeType": "patch" | ||
| } |
7 changes: 7 additions & 0 deletions
7
...x-kit-metro-plugin-cyclic-dependencies-detector-046f01b8-4af7-4c55-b84e-6de97f3cc406.json
This file contains hidden or 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,7 @@ | ||
| { | ||
| "type": "patch", | ||
| "comment": "Publish plugin options type", | ||
| "packageName": "@rnx-kit/metro-plugin-cyclic-dependencies-detector", | ||
| "email": "afoxman@microsoft.com", | ||
| "dependentChangeType": "patch" | ||
| } |
7 changes: 7 additions & 0 deletions
7
change/@rnx-kit-metro-plugin-duplicates-checker-0cf1029f-2078-4cd0-81e5-125fb063c6a8.json
This file contains hidden or 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,7 @@ | ||
| { | ||
| "type": "patch", | ||
| "comment": "Publish plugin options type", | ||
| "packageName": "@rnx-kit/metro-plugin-duplicates-checker", | ||
| "email": "afoxman@microsoft.com", | ||
| "dependentChangeType": "patch" | ||
| } |
7 changes: 7 additions & 0 deletions
7
change/@rnx-kit-third-party-notices-0acf1f84-6acc-4f27-857d-1c83446a1c44.json
This file contains hidden or 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,7 @@ | ||
| { | ||
| "type": "none", | ||
| "comment": "fix TPN tests", | ||
| "packageName": "@rnx-kit/third-party-notices", | ||
| "email": "afoxman@microsoft.com", | ||
| "dependentChangeType": "none" | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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,72 @@ | ||
| import type { ConfigT, InputConfigT, SerializerConfigT } from "metro-config"; | ||
| import { | ||
| CyclicDependencies, | ||
| PluginOptions as CyclicDetectorOptions, | ||
| } from "@rnx-kit/metro-plugin-cyclic-dependencies-detector"; | ||
| import { | ||
| DuplicateDependencies, | ||
| Options as DuplicateDetectorOptions, | ||
| } from "@rnx-kit/metro-plugin-duplicates-checker"; | ||
| import { MetroSerializer, MetroPlugin } from "@rnx-kit/metro-serializer"; | ||
|
|
||
| function reportError(prop: string) { | ||
| console.error( | ||
| "error: Metro configuration property '%o' should not be set. This command may overwrite it, based on command-line arguments or kit configuration.", | ||
| prop | ||
| ); | ||
| } | ||
|
|
||
| // Validate the Metro configuration. Make sure that any reserved | ||
| // fields haven't been set by the app. We reserve certain fields | ||
| // so that we can control them through configuration. | ||
| export function validateMetroConfig(metroConfig: ConfigT): boolean { | ||
| if (metroConfig.serializer.customSerializer) { | ||
| reportError("customSerializer"); | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| // Customize the Metro configuration | ||
| export function customizeMetroConfig( | ||
| metroConfigReadonly: InputConfigT, | ||
| detectCyclicDependencies: boolean | CyclicDetectorOptions, | ||
| detectDuplicateDependencies: boolean | DuplicateDetectorOptions | ||
| ): void { | ||
| // We will be making changes to the Metro configuration. Coerce from a | ||
| // type with readonly props to a type where the props are writeable. | ||
| const metroConfig = metroConfigReadonly as InputConfigT; | ||
afoxman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const plugins: MetroPlugin[] = []; | ||
| if (typeof detectDuplicateDependencies === "boolean") { | ||
| plugins.push(DuplicateDependencies()); | ||
| } else if (typeof detectDuplicateDependencies === "object") { | ||
| plugins.push(DuplicateDependencies(detectDuplicateDependencies)); | ||
| } | ||
| if (typeof detectCyclicDependencies === "boolean") { | ||
| plugins.push(CyclicDependencies()); | ||
| } else if (typeof detectCyclicDependencies === "object") { | ||
| plugins.push(CyclicDependencies(detectCyclicDependencies)); | ||
| } | ||
|
|
||
| if (plugins.length > 0) { | ||
| // MetroSerializer acts as a CustomSerializer, and it works with both | ||
| // older and newer versions of Metro. Older versions expect a return | ||
| // value, while newer versions expect a promise. | ||
| // | ||
| // Its return type is the union of both the value and the promise. | ||
| // This makes TypeScript upset because for any given version of Metro, | ||
| // it's one or the other. Not both. | ||
| // | ||
| // Since it can handle either scenario, just coerce it to whatever | ||
| // the current version of Metro expects. | ||
| const serializer = MetroSerializer( | ||
| plugins | ||
| ) as SerializerConfigT["customSerializer"]; | ||
|
|
||
| metroConfig.serializer.customSerializer = serializer; | ||
| } else { | ||
| delete metroConfig.serializer.customSerializer; | ||
afoxman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,22 +1,9 @@ | ||
| const { makeMetroConfig } = require("@rnx-kit/metro-config"); | ||
| const { | ||
| CyclicDependencies, | ||
| } = require("@rnx-kit/metro-plugin-cyclic-dependencies-detector"); | ||
| const { | ||
| DuplicateDependencies, | ||
| } = require("@rnx-kit/metro-plugin-duplicates-checker"); | ||
| const { | ||
| MetroSerializer, | ||
| esbuildTransformerConfig, | ||
| } = require("@rnx-kit/metro-serializer-esbuild"); | ||
|
|
||
| module.exports = makeMetroConfig({ | ||
| projectRoot: __dirname, | ||
| serializer: { | ||
| customSerializer: MetroSerializer([ | ||
| CyclicDependencies(), | ||
| DuplicateDependencies({ ignoredModules: ["react-is"] }), | ||
| ]), | ||
| }, | ||
| transformer: esbuildTransformerConfig, | ||
| }); |
This file contains hidden or 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,18 +1,5 @@ | ||
| const { makeMetroConfig } = require("@rnx-kit/metro-config"); | ||
| const { | ||
| CyclicDependencies, | ||
| } = require("@rnx-kit/metro-plugin-cyclic-dependencies-detector"); | ||
| const { | ||
| DuplicateDependencies, | ||
| } = require("@rnx-kit/metro-plugin-duplicates-checker"); | ||
| const { MetroSerializer } = require("@rnx-kit/metro-serializer"); | ||
|
|
||
| module.exports = makeMetroConfig({ | ||
| projectRoot: __dirname, | ||
| serializer: { | ||
| customSerializer: MetroSerializer([ | ||
| CyclicDependencies(), | ||
| DuplicateDependencies({ ignoredModules: ["react-is"] }), | ||
| ]), | ||
| }, | ||
| }); |
This file contains hidden or 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 hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.