Skip to content

Commit

Permalink
feat(next-core): relay transform plugin (#48899)
Browse files Browse the repository at this point in the history
<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### Why?

### How?

Closes NEXT-
Fixes #

-->

#### What
Part 1 for WEB-848. 

This PR implements initial path to enable relay compiler option in
Turbopack. PR is based on approach WEB-955, that passing custom plugin
transform itself instead of trying to pass down configuration into
turbopack. In result, this PR requires counterpart turbopack PR at
vercel/turbo#4721.

PR also refactors next-shared's transform bit, as we have grown number
of custom transforms.

Unfortunately there are some runtime errors with this transforms, so it
is not possible to use relay actually yet. WEB-956 tracks this.
(swc-project/plugins#179)

---------

Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
Co-authored-by: JJ Kasper <jj@jjsweb.site>
  • Loading branch information
3 people committed May 9, 2023
1 parent 0dce75f commit 71d8064
Show file tree
Hide file tree
Showing 19 changed files with 519 additions and 342 deletions.
71 changes: 37 additions & 34 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions Cargo.toml
Expand Up @@ -38,15 +38,14 @@ next-transform-strip-page-exports = { path = "packages/next-swc/crates/next-tran
# SWC crates
# Keep consistent with preset_env_base through swc_core
swc_core = { version = "0.75.41" }
swc_relay = { version = "0.2.7" }
testing = { version = "0.33.6" }
testing = { version = "0.33.4" }

# Turbo crates
turbo-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230504.3" }
turbo-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230508.2" }
# [TODO]: need to refactor embed_directory! macro usages, as well as resolving turbo_tasks::function, macros..
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230504.3" }
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230508.2" }
# [TODO]: need to refactor embed_directory! macro usage in next-core
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230504.3" }
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230508.2" }

# General Deps

Expand Down
1 change: 0 additions & 1 deletion packages/next-swc/crates/core/Cargo.toml
Expand Up @@ -31,7 +31,6 @@ turbo-binding = { workspace = true, features = [
"__swc_transform_modularize_imports",
"__swc_transform_relay",
] }
swc_relay = { workspace = true }

[dev-dependencies]
turbo-binding = { workspace = true, features = [
Expand Down
4 changes: 2 additions & 2 deletions packages/next-swc/crates/core/src/lib.rs
Expand Up @@ -101,7 +101,7 @@ pub struct TransformOptions {

#[serde(default)]
#[cfg(not(target_arch = "wasm32"))]
pub relay: Option<swc_relay::Config>,
pub relay: Option<turbo_binding::swc::custom_transform::relay::Config>,

#[allow(unused)]
#[serde(default)]
Expand Down Expand Up @@ -142,7 +142,7 @@ where
#[cfg(not(target_arch = "wasm32"))]
let relay_plugin = {
if let Some(config) = &opts.relay {
Either::Left(swc_relay::relay(
Either::Left(turbo_binding::swc::custom_transform::relay::relay(
config,
file.name.clone(),
current_dir().unwrap(),
Expand Down
4 changes: 2 additions & 2 deletions packages/next-swc/crates/core/tests/fixture.rs
Expand Up @@ -12,7 +12,6 @@ use next_swc::{
shake_exports::{shake_exports, Config as ShakeExportsConfig},
};
use next_transform_font::{next_font_loaders, Config as FontLoaderConfig};
use swc_relay::{relay, RelayLanguageConfig};
use turbo_binding::swc::{
core::{
common::{chain, comments::SingleThreadedComments, FileName, Mark},
Expand All @@ -25,6 +24,7 @@ use turbo_binding::swc::{
},
},
},
custom_transform::relay::{relay, RelayLanguageConfig},
testing::fixture,
};

Expand Down Expand Up @@ -151,7 +151,7 @@ fn page_config_fixture(input: PathBuf) {
#[fixture("tests/fixture/relay/**/input.ts*")]
fn relay_no_artifact_dir_fixture(input: PathBuf) {
let output = input.parent().unwrap().join("output.js");
let config = swc_relay::Config {
let config = turbo_binding::swc::custom_transform::relay::Config {
language: RelayLanguageConfig::TypeScript,
artifact_directory: Some(PathBuf::from("__generated__")),
..Default::default()
Expand Down

0 comments on commit 71d8064

Please sign in to comment.