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

feat(turbopack-ecmascript): accept transform plugin in moduleoptioncontext #4721

Merged
merged 8 commits into from
May 9, 2023

Conversation

kwonoj
Copy link
Contributor

@kwonoj kwonoj commented Apr 26, 2023

Description

This PR is a part of implementing WEB-848, supporting relay graphql transform in next.js. Historically we've been expanding ModuleOptionContext to have each own config (enable_mdx, enable_emotion...) but with new CustomTransformPlugin we can pass actual transforms instead, what WEB-955 aims.

PR introduces new config option custom_ecma_transform_plugins to the ModuleOptionContext to support it. custom_ecma_transform_plugins is a struct have two fields, before / after which allows to specify order of custom transforms if it should be invoked before any core transform kicks in, or otherwise.

This effectively deprecates existing options, notably custom_ecmascript_transforms and custom_ecmascript_app_transforms. It is currently not actively being used (next-swc have 2 places utilizing custom_ecmascript_transforms), we can consolidate to the new option instead.

One another notable change is customtransformer's transform is now async fn. It is due to TransformContext have couple of Vc properties, that cannot be accessed in a sync transform fn. Refer counterpart next.js PR (https://github.com/vercel/next.js/pull/48899/files#diff-c0df3b5a390436575f35365774b078cb5303ef395b064b8992dfdd7dba8f3691) as ref.

@kwonoj kwonoj requested a review from a team as a code owner April 26, 2023 23:45
@vercel
Copy link

vercel bot commented Apr 26, 2023

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

Name Status Preview Comments Updated (UTC)
examples-cra-web 🔄 Building (Inspect) May 9, 2023 4:21am
examples-native-web 🔄 Building (Inspect) May 9, 2023 4:21am
examples-svelte-web 🔄 Building (Inspect) May 9, 2023 4:21am
examples-tailwind-web 🔄 Building (Inspect) May 9, 2023 4:21am
7 Ignored Deployments
Name Status Preview Comments Updated (UTC)
examples-basic-web ⬜️ Ignored (Inspect) May 9, 2023 4:21am
examples-designsystem-docs ⬜️ Ignored (Inspect) May 9, 2023 4:21am
examples-gatsby-web ⬜️ Ignored (Inspect) May 9, 2023 4:21am
examples-kitchensink-blog ⬜️ Ignored (Inspect) May 9, 2023 4:21am
examples-nonmonorepo ⬜️ Ignored (Inspect) May 9, 2023 4:21am
examples-vite-web ⬜️ Ignored (Inspect) May 9, 2023 4:21am
turbo-site ⬜️ Ignored (Inspect) Visit Preview May 9, 2023 4:21am

@github-actions
Copy link
Contributor

github-actions bot commented Apr 26, 2023

✅ This change can build next-swc

@github-actions
Copy link
Contributor

github-actions bot commented Apr 27, 2023

🟢 CI successful 🟢

Thanks

use turbopack_ecmascript::{CustomTransformer, TransformContext};

#[derive(Debug)]
pub struct RelayTransformer {
Copy link
Contributor Author

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.

@kwonoj kwonoj force-pushed the module-option-custom-transform branch from 16fbdb8 to 1311b2d Compare May 2, 2023 18:13
@kwonoj kwonoj added pr: automerge Kodiak will merge these automatically after checks pass and removed pr: automerge Kodiak will merge these automatically after checks pass labels May 9, 2023
@kwonoj kwonoj added the pr: automerge Kodiak will merge these automatically after checks pass label May 9, 2023
@kwonoj kwonoj enabled auto-merge (squash) May 9, 2023 05:57
@kwonoj kwonoj disabled auto-merge May 9, 2023 05:58
@kwonoj kwonoj merged commit b9e5e6d into main May 9, 2023
43 checks passed
@kwonoj kwonoj deleted the module-option-custom-transform branch May 9, 2023 05:58
alexkirsz added a commit that referenced this pull request May 9, 2023
NicholasLYang pushed a commit to NicholasLYang/turbo that referenced this pull request May 9, 2023
…ntext (vercel#4721)

### Description

- Relates with WEB-955, WEB-848.

This PR is a part of implementing WEB-848, supporting relay graphql
transform in next.js. Historically we've been expanding
`ModuleOptionContext` to have each own config (`enable_mdx`,
`enable_emotion`...) but with new CustomTransformPlugin we can pass
actual transforms instead, what WEB-955 aims.

PR introduces new config option `custom_ecma_transform_plugins` to the
ModuleOptionContext to support it. `custom_ecma_transform_plugins` is a
struct have two fields, `before` / `after` which allows to specify order
of custom transforms if it should be invoked _before_ any core transform
kicks in, or otherwise.

This effectively deprecates existing options, notably
`custom_ecmascript_transforms` and `custom_ecmascript_app_transforms`.
It is currently not actively being used (next-swc have 2 places
utilizing `custom_ecmascript_transforms`), we can consolidate to the new
option instead.

One another notable change is customtransformer's transform is now async
fn. It is due to `TransformContext` have couple of `Vc` properties, that
cannot be accessed in a sync transform fn. Refer counterpart next.js PR
(https://github.com/vercel/next.js/pull/48899/files#diff-c0df3b5a390436575f35365774b078cb5303ef395b064b8992dfdd7dba8f3691)
as ref.
ijjk added a commit to vercel/next.js that referenced this pull request May 9, 2023
<!-- 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: automerge Kodiak will merge these automatically after checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants