-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
feat(turbopack-ecmascript): accept transform plugin in moduleoptioncontext #4721
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2cd7db0
feat(turbopack-ecmascript): accept transform plugin in moduleoptionco…
kwonoj 5572c5e
build(cargo): update lockfile
kwonoj 0f1a774
feat(ecma-plugins): support relay custom transformer
kwonoj 868595c
refactor(module_options): rename properties
kwonoj 4a6b403
refactor(ecmaplugins): returns result
kwonoj 829eb8c
build(cargo): update lockfile
kwonoj 2d430e9
refactor(relay): simplify artifactory_directory
kwonoj 8694ac8
refactor(module_options): minor style
kwonoj 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod emotion; | ||
pub mod relay; |
57 changes: 57 additions & 0 deletions
57
crates/turbopack-ecmascript-plugins/src/transform/relay.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,57 @@ | ||
use std::path::PathBuf; | ||
|
||
use anyhow::Result; | ||
use async_trait::async_trait; | ||
use swc_core::{ | ||
common::{util::take::Take, FileName}, | ||
ecma::{ | ||
ast::{Module, Program}, | ||
visit::FoldWith, | ||
}, | ||
}; | ||
use turbopack_ecmascript::{CustomTransformer, TransformContext}; | ||
|
||
#[derive(Debug)] | ||
pub struct RelayTransformer { | ||
config: swc_relay::Config, | ||
} | ||
|
||
impl RelayTransformer { | ||
pub fn new(config: swc_relay::Config) -> Self { | ||
Self { config } | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl CustomTransformer for RelayTransformer { | ||
async fn transform( | ||
&self, | ||
program: &mut Program, | ||
ctx: &TransformContext<'_>, | ||
) -> Result<Option<Program>> { | ||
// If user supplied artifact_directory, it should be resolvable already. | ||
// Otherwise, supply default relative path (./__generated__) | ||
let (root, config) = if self.config.artifact_directory.is_some() { | ||
(PathBuf::new(), None) | ||
} else { | ||
let config = swc_relay::Config { | ||
artifact_directory: Some(PathBuf::from("__generated__")), | ||
..self.config | ||
}; | ||
(PathBuf::from("."), Some(config)) | ||
}; | ||
|
||
let p = std::mem::replace(program, Program::Module(Module::dummy())); | ||
*program = p.fold_with(&mut swc_relay::relay( | ||
config.as_ref().unwrap_or_else(|| &self.config), | ||
FileName::Real(PathBuf::from(ctx.file_name_str)), | ||
root, | ||
// [TODO]: pages_dir comes through next-swc-loader | ||
// https://github.com/vercel/next.js/blob/ea472e8058faea8ebdab2ef6d3aab257a1f0d11c/packages/next/src/build/webpack-config.ts#L792 | ||
None, | ||
Some(ctx.unresolved_mark), | ||
)); | ||
|
||
Ok(None) | ||
} | ||
} |
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
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.
Decide to move this transform into turbopack side, as it is possible turbopack standalone might need this transform as well.