Skip to content

Comments

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

Merged
tido64 merged 1 commit intomainfrom
tido/override-modulesuffixes
Jul 20, 2023
Merged

fix(metro-plugin-typescript): respect root moduleSuffixes#2544
tido64 merged 1 commit intomainfrom
tido/override-modulesuffixes

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

@tido64 tido64 requested review from JasonVMo and kelset as code owners July 19, 2023 17:41
@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
@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.

2 participants