Skip to content
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

fix(metro-plugin-typescript): respect root moduleSuffixes #2544

Merged
merged 1 commit into from
Jul 20, 2023

Conversation

tido64
Copy link
Member

@tido64 tido64 commented Jul 19, 2023

Description

We should only set moduleSuffixes once at the project root.

See also discussions evanw/esbuild#2395 and evanw/esbuild#3019.

Test plan

Existing tests should pass.

To verify that file extensions change with the target platform, apply the following patch:

diff --git a/packages/metro-plugin-typescript/src/resolver.ts b/packages/metro-plugin-typescript/src/resolver.ts
index 9b150754..e173049e 100644
--- a/packages/metro-plugin-typescript/src/resolver.ts
+++ b/packages/metro-plugin-typescript/src/resolver.ts
@@ -160,6 +160,8 @@ export function resolveTypeReferenceDirectives(
   containingFileMode: ts.SourceFile["impliedNodeFormat"] | undefined,
   { resolveTypeReferenceDirective } = ts
 ): (ts.ResolvedTypeReferenceDirective | undefined)[] {
+  console.log(context.platform, context.platformFileExtensions);
+
   const { host } = context;

   const resolutions: (ts.ResolvedTypeReferenceDirective | undefined)[] = [];

Rebuild, then start the dev server. Example output:

% yarn start

                        ▒▒▓▓▓▓▒▒
                     ▒▓▓▓▒▒░░▒▒▓▓▓▒
                  ▒▓▓▓▓░░░▒▒▒▒░░░▓▓▓▓▒
                 ▓▓▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▓▓
                 ▓▓░░░░░▒▓▓▓▓▓▓▒░░░░░▓▓
                 ▓▓░░▓▓▒░░░▒▒░░░▒▓▒░░▓▓
                 ▓▓░░▓▓▓▓▓▒▒▒▒▓▓▓▓▒░░▓▓
                 ▓▓░░▓▓▓▓▓▓▓▓▓▓▓▓▓▒░░▓▓
                 ▓▓▒░░▒▒▓▓▓▓▓▓▓▓▒░░░▒▓▓
                  ▒▓▓▓▒░░░▒▓▓▒░░░▒▓▓▓▒
                     ▒▓▓▓▒░░░░▒▓▓▓▒
                        ▒▒▓▓▓▓▒▒


                Welcome to Metro v0.73.10
              Fast - Scalable - Integrated


 › Press r to reload the app.
 › Press d to open developer menu.
 › Press a to show bundler address QR code.
 › Press h to show this help message.
 › Press ctrl-c to quit.

 BUNDLE  src/index.ts ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░ 96.2% (507/518)ios [ '.ios', '.native', '' ]
ios [ '.ios', '.native', '' ]
ios [ '.ios', '.native', '' ]
ios [ '.ios', '.native', '' ]
ios [ '.ios', '.native', '' ]
ios [ '.ios', '.native', '' ]
ios [ '.ios', '.native', '' ]
ios [ '.ios', '.native', '' ]
ios [ '.ios', '.native', '' ]
ios [ '.ios', '.native', '' ]
 BUNDLE  src/index.ts

 BUNDLE  src/index.ts ▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░ 93.1% (497/516)android [ '.android', '.native', '' ]
android [ '.android', '.native', '' ]
android [ '.android', '.native', '' ]
android [ '.android', '.native', '' ]
android [ '.android', '.native', '' ]
android [ '.android', '.native', '' ]
android [ '.android', '.native', '' ]
android [ '.android', '.native', '' ]
android [ '.android', '.native', '' ]
android [ '.android', '.native', '' ]
 BUNDLE  src/index.ts

 BUNDLE  src/index.ts ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░ 96.2% (512/523)windows [ '.windows', '.win', '.native', '' ]
windows [ '.windows', '.win', '.native', '' ]
windows [ '.windows', '.win', '.native', '' ]
windows [ '.windows', '.win', '.native', '' ]
windows [ '.windows', '.win', '.native', '' ]
windows [ '.windows', '.win', '.native', '' ]
windows [ '.windows', '.win', '.native', '' ]
windows [ '.windows', '.win', '.native', '' ]
windows [ '.windows', '.win', '.native', '' ]
windows [ '.windows', '.win', '.native', '' ]
 BUNDLE  src/index.ts

@github-actions github-actions bot added the feature: metro This is related to Metro label Jul 19, 2023
@tido64 tido64 merged commit a4c1820 into main Jul 20, 2023
12 checks passed
@tido64 tido64 deleted the tido/override-modulesuffixes branch July 20, 2023 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: metro This is related to Metro
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants