-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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: fix loading of externals on Edge #72349
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3a12d2d
try fix edge
arlyon 6bfccc9
try fix edge: remaining call-sites
mischnic c9e7223
Remove programatic loader-runner fallback
mischnic 44d163f
turbopackIgnore instead of turbopack_external_require
mischnic 4de62d7
Link `FreeVar` to prevent `require` replacement
mischnic c6ae880
Add test for __turbopack_require_stub__
mischnic f894b9c
Cleanup
mischnic 36c6c2d
Moar replacements!
mischnic a7198c4
Review comments: remove unnecessary Box
mischnic 29aef24
Review comments: replace with unknown
mischnic 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
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
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
44 changes: 44 additions & 0 deletions
44
turbopack/crates/turbopack-ecmascript/src/references/ident.rs
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use anyhow::Result; | ||
use swc_core::{ecma::ast::Expr, quote}; | ||
use turbo_rcstr::RcStr; | ||
use turbo_tasks::Vc; | ||
use turbopack_core::chunk::ChunkingContext; | ||
|
||
use super::AstPath; | ||
use crate::{ | ||
code_gen::{CodeGenerateable, CodeGeneration}, | ||
create_visitor, | ||
}; | ||
|
||
#[turbo_tasks::value] | ||
pub struct IdentReplacement { | ||
value: RcStr, | ||
path: Vc<AstPath>, | ||
} | ||
|
||
#[turbo_tasks::value_impl] | ||
impl IdentReplacement { | ||
#[turbo_tasks::function] | ||
pub fn new(value: RcStr, path: Vc<AstPath>) -> Vc<Self> { | ||
Self::cell(IdentReplacement { value, path }) | ||
} | ||
} | ||
|
||
#[turbo_tasks::value_impl] | ||
impl CodeGenerateable for IdentReplacement { | ||
#[turbo_tasks::function] | ||
async fn code_generation( | ||
&self, | ||
_context: Vc<Box<dyn ChunkingContext>>, | ||
) -> Result<Vc<CodeGeneration>> { | ||
let value = self.value.clone(); | ||
let path = &self.path.await?; | ||
|
||
let visitor = create_visitor!(path, visit_mut_expr(expr: &mut Expr) { | ||
let id = Expr::Ident((&*value).into()); | ||
*expr = quote!("(\"TURBOPACK ident replacement\", $e)" as Expr, e: Expr = id); | ||
}); | ||
|
||
Ok(CodeGeneration::visitors(vec![visitor])) | ||
} | ||
} |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need that at all? We could just call
require
directly.Any indirect usage of
require
would cause these nested bundling problems again...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is this special handling to always have
require
available though (and we want this for both ESM and CJS-on-Edge-without-require):next.js/turbopack/crates/turbopack-ecmascript-runtime/js/src/shared/runtime-utils.ts
Lines 229 to 239 in 55834d9