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

Turbopack: Add BeforeResolve plugin type #8165

Merged
merged 6 commits into from
May 20, 2024
Merged

Conversation

wbinnssmith
Copy link
Member

This adds a new plugin type for replacing resolution before it occurs. This allows plugin authors to intercept requests for modules in place of the typical resolution strategy.

This is used to replace ImportMapping replacers for @next/font/local in an upcoming Next.js PR

This adds a new plugin type for replacing resolution _before_ it occurs. This allows plugin authors to intercept requests for modules in place of the typical resolution strategy.

This is used to replace `ImportMapping` replacers for `@next/font/local` in an upcoming Next.js PR
Copy link

vercel bot commented May 16, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
examples-basic-web 🔄 Building (Inspect) Visit Preview 💬 Add feedback May 17, 2024 11:15pm
examples-gatsby-web 🔄 Building (Inspect) Visit Preview 💬 Add feedback May 17, 2024 11:15pm
examples-nonmonorepo ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 17, 2024 11:15pm
examples-svelte-web 🔄 Building (Inspect) Visit Preview 💬 Add feedback May 17, 2024 11:15pm
examples-tailwind-web 🔄 Building (Inspect) Visit Preview 💬 Add feedback May 17, 2024 11:15pm
rust-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 17, 2024 11:15pm
4 Ignored Deployments
Name Status Preview Comments Updated (UTC)
examples-designsystem-docs ⬜️ Ignored (Inspect) Visit Preview May 17, 2024 11:15pm
examples-kitchensink-blog ⬜️ Ignored (Inspect) Visit Preview May 17, 2024 11:15pm
examples-native-web ⬜️ Ignored (Inspect) Visit Preview May 17, 2024 11:15pm
examples-vite-web ⬜️ Ignored (Inspect) Visit Preview May 17, 2024 11:15pm

Copy link
Contributor

github-actions bot commented May 17, 2024

🟢 Turbopack Benchmark CI successful 🟢

Thanks

Copy link
Contributor

✅ This change can build next-swc

@@ -72,6 +72,7 @@ pub struct ResolveOptionsContext {
/// A list of plugins which get applied before (in the future) and after
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably need to adjust comment bit, also we may want to rename plugins in this case?

wbinnssmith added a commit to vercel/next.js that referenced this pull request May 17, 2024
… show custom error message

Depends on vercel/turbo#8165

This:
- Creates and uses a `BeforeResolvePlugin` to handle requests to `next/font/local/target.css` instead of `ImportMapping` replacers
- Returns a `ResolveResultItem::Error` which includes a custom `StyledString` describing the missing font file

Test Plan: `TURBOPACK=1 pnpm test-dev test/e2e/app-dir/next-font/next-font.test.ts`
Copy link
Contributor

github-actions bot commented May 17, 2024

⚠️ CI failed ⚠️

The following steps have failed in CI:

  • Turbopack Rust tests (mac/win, non-blocking)

See workflow summary for details

) -> Result<Option<Vc<ResolveResult>>> {
for plugin in &options.await?.before_resolve_plugins {
if let Some(result) = *plugin
.before_resolve(lookup_path, reference_type.clone(), request)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might have a negative performance effect, since it calls the plugin for every resolving in the application. So something like with the resolve plugins would be beneficial: before_resolve_condition

@@ -66,6 +67,7 @@ pub enum ModuleResolveResultItem {
OutputAsset(Vc<Box<dyn OutputAsset>>),
External(String, ExternalType),
Ignore,
Error(Vc<StyledString>),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Error(Vc<StyledString>),
RuntimeError(Vc<String>),

I was thinking for this to lead to a runtime error during code generation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be a build error -- we wouldn't want to produce something that is runnable if this is the case. I think that's what happens with Webpack.

@@ -2553,7 +2619,18 @@ pub async fn handle_resolve_error(
.cell()
.emit();
}
result

if let Some(error_string) = result.await?.get_first_error() {
Copy link
Member

@sokra sokra May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should not do that. It should just return the result even if that's a resolve result with runtime error.

The issue should be emitted earlier. E.g. in the before resolve plugin itself

@wbinnssmith wbinnssmith merged commit 41075ab into main May 20, 2024
48 of 50 checks passed
@wbinnssmith wbinnssmith deleted the wbinnssmith/font-plugin branch May 20, 2024 21:51
wbinnssmith added a commit to vercel/next.js that referenced this pull request May 20, 2024
… show custom error message (#65870)

Depends on vercel/turbo#8165

This:
- Creates and uses a `BeforeResolvePlugin` to handle requests to
`next/font/local/target.css` instead of `ImportMapping` replacers
- Returns a `ResolveResultItem::Error` which includes a custom
`StyledString` describing the missing font file

Test Plan: `TURBOPACK=1 pnpm test-dev
test/e2e/app-dir/next-font/next-font.test.ts`
tknickman pushed a commit that referenced this pull request May 21, 2024
This adds a new plugin type for replacing resolution _before_ it occurs.
This allows plugin authors to intercept requests for modules in place of
the typical resolution strategy.

This is used to replace `ImportMapping` replacers for `@next/font/local`
in an upcoming Next.js PR
wbinnssmith added a commit to vercel/next.js that referenced this pull request Jun 7, 2024
vercel/turbo#8165 introduced plugins that operate before resolving occurs, meaning that plugins like `InvalidImportResolvePlugin` which never use the initial resolve result and report issues can avoid that work.

Test Plan: `TURBOPACK_DEV=1 TURBOPACK=1 pnpm test-dev test/development/acceptance-app/invalid-imports.test.ts`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants