forked from vercel/turborepo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apply the next/dynamic SWC transform (vercel#3184)
This PR adds the next/dynamic SWC transform to the repo. This is copied over from the implementation in [](https://github.com/vercel/next.js/blob/3e2e39c55939bd156cbb4dab926aaaa126b53d1c/packages/next-swc/crates/core/src/next_dynamic.rs), with an additional mode for Turbopack. For now, it applies it to all sources files (excluding node_modules, but including embedded modules). I've refactored the Next transforms logic to make it more easily extendable in the future, and avoid creating more Vcs than absolutely necessary. This PR is the last item in the list of what's needed to support next/dynamic in development.
- Loading branch information
Showing
84 changed files
with
1,693 additions
and
272 deletions.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub(crate) mod context; | ||
pub(crate) mod runtime_entry; | ||
pub(crate) mod transforms; | ||
pub(crate) mod transition; |
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,40 @@ | ||
use anyhow::Result; | ||
use turbopack::module_options::ModuleRule; | ||
use turbopack_ecmascript::NextJsPageExportFilter; | ||
|
||
use crate::{ | ||
next_client::context::ClientContextType, | ||
next_shared::transforms::{ | ||
get_next_dynamic_transform_rule, get_next_font_transform_rule, | ||
get_next_pages_transforms_rule, | ||
}, | ||
}; | ||
|
||
/// Returns a list of module rules which apply client-side, Next.js-specific | ||
/// transforms. | ||
pub async fn get_next_client_transforms_rules( | ||
context_ty: ClientContextType, | ||
) -> Result<Vec<ModuleRule>> { | ||
let mut rules = vec![]; | ||
|
||
rules.push(get_next_font_transform_rule()); | ||
|
||
let pages_dir = match context_ty { | ||
ClientContextType::Pages { pages_dir } => { | ||
rules.push( | ||
get_next_pages_transforms_rule(pages_dir, NextJsPageExportFilter::StripDataExports) | ||
.await?, | ||
); | ||
Some(pages_dir) | ||
} | ||
ClientContextType::App { .. } | ClientContextType::Fallback | ClientContextType::Other => { | ||
None | ||
} | ||
}; | ||
|
||
rules.push(get_next_dynamic_transform_rule( | ||
true, false, false, pages_dir, | ||
)); | ||
|
||
Ok(rules) | ||
} |
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.