Commit graph

417 commits

Author SHA1 Message Date
Tobias Koppers
a093e313db separate app and pages structure extraction from source generation (vercel/turbo#3912)
We need to invalidate router node.js process when routes change for correctness

In future we can pass the routes list to next.js instead of only invalidating @jridgewell 

We also need the separated structure for next build @alexkirsz
2023-02-22 16:05:44 +00:00
Tobias Koppers
1d767db511 update next.js to 13.1.7-canary.25 (vercel/turbo#3895) 2023-02-22 14:51:00 +01:00
Alex Kirszenberg
36aca516db Include chunk path in WithClientChunks (vercel/turbo#3910)
`WithClientChunksChunkItem` currently only includes paths to chunks' references, but not chunks themselves.

Fixes WEB-621.
2023-02-22 12:39:54 +00:00
github-actions[bot]
f87dc8e6e9 Update Google font-data.json (2023-02-22) (vercel/turbo#3905)
Automated changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action

Co-authored-by: Will Binns-Smith <755844+wbinnssmith@users.noreply.github.com>
2023-02-22 09:21:16 +00:00
Justin Ridgewell
d05101622e Implement Rewrite Headers support during routing (vercel/turbo#3897) 2023-02-21 19:40:50 -05:00
JJ Kasper
d6e560e486 Ensure next global is initialized correctly (vercel/turbo#3894)
This ensures our tests can run properly as they rely on the next global being present.
2023-02-21 21:36:49 +00:00
Will Binns-Smith
166b3d62cc loaders: use pre-compiled loader-runner distributed with Next.js (vercel/turbo#3823)
The benefit of this depends on
https://github.com/vercel/next.js/pull/45962, but it remains compatible
with apps including `loader-runner`.

This first attempts to require `loader-runner` from the app's installed
version of Next.js, falling back to requiring the package directly. We
should probably eventually remove this fallback once all compatible
versions of Next.js include the precompiled version, as that has a more
predictable version of the package.

Test Plan: Linked a local copy of Next.js including
https://github.com/vercel/next.js/pull/45962 to an app without
`loader-runner` that uses loaders and verified loaders ran.
2023-02-21 12:34:01 -08:00
Tobias Koppers
90675f2a7c add possible unknown mutation to objects and arrays (vercel/turbo#3882)
Before the static evaluation didn't consider the fact that objects and arrays can be mutated. So we can't just assume for sure that they have certain properties/items. Instead we add an unknown mutation alternative to handle that.

This avoids `if(obj.prop)` to be replaced with `if(true)` when prop is initialized with true. It might be modified in future.
2023-02-21 15:26:15 +00:00
Tobias Koppers
0345d9e120 alias @swc/helpers to the version within next.js (vercel/turbo#3865) 2023-02-17 21:23:43 +00:00
Justin Ridgewell
3d90dcf03e Use IndexSet in IntrospectableChildrenVc (vercel/turbo#3853)
Another small cleanup stemming from the the `basePath` PR. Makes the
introspection ordering consistent, which is a nice usability win.

Co-authored-by: Alex Kirszenberg <1621758+alexkirsz@users.noreply.github.com>
2023-02-17 12:07:19 -05:00
Leah
866dfec256 make error overlay message scrollable (vercel/turbo#3861)
Before long messages would just be hidden:

![](https://uploads.linear.app/099ed59a-06c6-472f-9977-4798721bda90/6ea99100-27be-4192-adea-46ff2ed78cc8/860978fd-9ea5-456e-8c5a-48cecacf3e95)
2023-02-17 16:23:45 +00:00
github-actions[bot]
7400b3ba2b Update Google font-data.json (2023-02-17) (vercel/turbo#3850)
Automated changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action

Co-authored-by: Will Binns-Smith <755844+wbinnssmith@users.noreply.github.com>
2023-02-17 16:12:24 +00:00
Justin Ridgewell
ab49dc265a Use name-value tuples for headers (vercel/turbo#3848)
This is a small cleanup extracted out of the WIP `basePath` PR.
2023-02-17 00:34:48 +00:00
Leah
2f466eb40c strip UNC prefix on windows paths (vercel/turbo#3847) 2023-02-17 00:01:52 +00:00
Justin Ridgewell
81542ff759 Fix routing cases (vercel/turbo#3832)
This fixes 2 bugs that I've found:
1. If the `middleware.ts` file doesn't exist, then we get an unhelpful `unable to resolve relative "."` error during `next-edge` transition processing
   - This is fixed by not processing the `VirtualAssetVc` with the edge transition
2. If you're using an older Next version, then the router doesn't have a `type` field
   - Because the `type` field is empty, we hit neither the `rewrite` nor `none` cases and fall through to the middleware case, returning an empty response with no body.
   - This is fixed by treating `{ url: string, headers: … }` as `{ type: 'rewrite', url: string, headers: … }`
2023-02-16 08:55:14 +00:00
Leah
22939fe98d set correct CWD for node processes (vercel/turbo#3746) 2023-02-16 08:01:00 +00:00
Justin Ridgewell
2872010c27 Next Router Middleware Support (vercel/turbo#3690)
This updates our Next.js router, passing the `edgeInfo` manifest generated from the `middleware.js` file (or any other configured page extension).

Fixes WEB-277
Fixes WEB-370
2023-02-16 03:44:55 +00:00
Tobias Koppers
8de5b4e0d0 add CompileTimeInfo struct for passing compile time info (vercel/turbo#3685)
extracted from https://github.com/vercel/turbo/pull/3670

Refactoring to allow to pass more compile time info next to the environment to modules.
e. g. we want to pass `process.env.NODE_ENV = "development"` in future
2023-02-15 19:03:41 +00:00
Alex Kirszenberg
09af739aa0 Add support for CSS module composes: and fix CSS precedence issues (vercel/turbo#3771)
Adds support for the CSS module `composes:` rule.

This also fixes a large issue with our chunk ordering and CSS precedence, where the BFS order of our chunks did not match the expected topological ordering.
2023-02-15 10:36:09 +00:00
Will Binns-Smith
268c9e08fc Restore Issue Reporters (vercel/turbo#3803)
This restores issue reporters, addressing a bug that prevented turbo-trace from completing. This moves `ConsoleUiVc::new` into an async block to prevent it from stalling.

Test Plan: Verify `cargo run --bin node-file-trace -- print path/to/my/app` no longer stalls.
2023-02-14 19:10:12 +00:00
Tobias Koppers
e12e4760ce fix export * warning for client pages (vercel/turbo#3795)
This gets rid of this warning when using a client component as page:

```
warning - [analyze] [project-with-next]/src/app/client/page.jsx  unexpected export *
  export * used with module [project-with-next]/src/app/client/page.jsx which has no exports
  Typescript only: Did you want to export only types with `export type { ... } from "..."`?
```

* fix export * warning for client pages
* Detect `__turbopack_export_value__` as CJS style exports
* fix `__turbopack_cjs__` name
* flag turbopackHelper in client proxy
2023-02-14 14:38:55 +00:00
LongYinan
c881b16e49 Revert "Issue Reporters (vercel/turbo#3707)" (vercel/turbo#3796)
This reverts commit a8612abf5edbde3013d6fcf8845976f422cb2ffc.

This commit makes the `turbotrace` hanging, x-ref:
https://vercel.slack.com/archives/C02UJN0A1UL/p1676369060652879
2023-02-14 20:53:56 +08:00
Alex Kirszenberg
4460521e70 Fix the router when Next.js returns no result (vercel/turbo#3741)
I changed the return type of the Next.js router in https://github.com/vercel/next.js/pull/45668 to account for cases where the router does and does not find a matching rewrite.
2023-02-14 12:33:07 +00:00
LongYinan
ca14667a0e Split swc_core/allocator_node out of __swc_core_binding_napi (vercel/turbo#3772)
We only can use `turbo_malloc`  in `next.js` without `swc_node_base` included
2023-02-14 03:23:54 +00:00
chicoworry
61712322cf Fix typo (vercel/turbo#3763)
Just a small type I belive :)
2023-02-13 13:22:55 -05:00
Alex Kirszenberg
4682034c78 Make stringify_str and stringify_module_id use Serialize (vercel/turbo#3770)
Both `stringify_str` and `stringify_module_id` are now simply `stringify_js`. We could skip this and go directly to `serde_json`, but this hides the dependency behind turbopack-ecmascript.
2023-02-13 16:51:53 +00:00
Tobias Koppers
0e3bb903e3 fix integration tests on windows (vercel/turbo#3737)
For windows it's important that the browser is dropped so that the test can
complete. To do that we need to cancel the spawned task below (which will
drop the browser). For this we are using a JoinSet which cancels all tasks
when dropped.
2023-02-13 16:16:15 +00:00
Will Binns-Smith
5926753a2f Issue Reporters (vercel/turbo#3707)
Big thanks to @jridgewell for helping me out with a number of Rust-isms
with this change.

This expands `handle_issues` and the `NextDevServerBuilder` to accept an
arbitrary `IssueReporter` -- a trait implementing `report_issues` which
receives captured issues to send somewhere.

This replaces using a fixed `ConsoleUi` to send issues to stdout/stderr,
though `ConsoleUi` now implements `IssueReporter` and is the default
implementation of an issue reporter if no other is provided. It also
moves the responsibility of detecting fatal errors out of `ConsoleUi`
and into `handle_issues` itself.

This lays the foundation for alternative reporters, such as a test
reporter to snapshot or assert against issues emitted, or a
newline-delimited JSON reporter for other tools to consume.

Co-authored-by: Justin Ridgewell <justin@ridgewell.name>

---------

Co-authored-by: Justin Ridgewell <justin@ridgewell.name>
2023-02-13 08:07:19 -08:00
Alex Kirszenberg
6fb1402d87 Add support for ctx.params in getStaticProps/getServerSideProps (vercel/turbo#3696)
Dynamic segments should be passed a single string, while catch-all segments should be passed a list of strings.

Furthermore, ctx.params was previously undefined because we weren't passing it forward through the render options.
2023-02-13 12:07:34 +00:00
Tobias Koppers
a43d02d15a improve node_modules as externals handling (vercel/turbo#3736)
Run after_resolve with original request

try to resolve original request with node.js options to determine if it can be external

typescript extends need to resolve with bare node.js resolving to avoid custom resolve options

add special pnpm logic to improve externals when pnpm is used
2023-02-10 22:34:01 +00:00
Nicholas Yang
37ccaf0ca0 fix: Made native-tls our default feature for ease of dev workflows (vercel/turbo#3748) 2023-02-10 15:52:48 -05:00
Alex Kirszenberg
114ef6b8c0 Add req.cookies to API requests (vercel/turbo#3695)
This PR does a little bit more than what it says on the box. Before, we were parsing URL queries and request headers, only to serialize them some other way afterwards. The reason why we were parsing headers and queries is because we sometimes need to filter them. However, we don't need that for router/page SSR/page API. This PR makes it so we avoid parsing on Turbopack's side through `rawHeaders` and `rawQuery`.
2023-02-10 17:35:49 +00:00
Tobias Koppers
2bf64a5a9c update to 13.1.7-canary.8 (vercel/turbo#3712) 2023-02-10 15:31:45 +00:00
Tobias Koppers
792ca8755d fix incorrect segment path (vercel/turbo#3739)
fixes app dir with `/(basic)/about` routes
2023-02-10 14:40:37 +00:00
Alex Kirszenberg
fab373da1b Enable HMR updates even when critical issues occur (vercel/turbo#3714)
This enables HMR updates, even when the update message also contains
critical issues.

There were some inconsistencies with the logic previously, so I'm not
sure whether this fix is fully correct. More on that in PR comments.
2023-02-10 13:30:57 +01:00
Tobias Koppers
c039615006 share asset and chunking context between server, server data and client navigation (vercel/turbo#3738)
This improves the performance for client-side navigation as it can reuse the modules from the initial navigation. Same for server data requests.
2023-02-10 12:10:52 +00:00
Leah
3679862c21 match next.js client side routing (buildManifest rewrites & devPagesManifest HMR) (vercel/turbo#3701) 2023-02-09 22:37:27 +01:00
Tobias Koppers
40a49f44bf set nextExport flag for page rendering (vercel/turbo#3717)
Otherwise `router.isReady` will never be true for pages without gSSP, gSP or gIP
2023-02-09 20:30:01 +00:00
Will Binns-Smith
337ac59101 Accept next/font/google as well as @next/font/google (vercel/turbo#3723)
Aligning with https://github.com/vercel/next.js/pull/45707, this allows users to import fonts from `next/font/google` as well as `@next/font/google`.

Test Plan: Adjusted tests to use `next/font/google` and added another test to verify `@next/font/google` continues to work.
2023-02-09 18:15:46 +00:00
Will Binns-Smith
1197edc8ab Combine next.config.js Turbopack options into a nested object (vercel/turbo#3689)
This combines Turbopack-specific options into a nested object
`experimental.turbopack`, exposing `loaders` and `resolveAlias`
properties.

x-ref:
631b637f42 (r1098123643)

Test Plan: Integration tests for loaders and resolveAlias.
2023-02-08 16:25:43 -08:00
Tobias Koppers
44f23bd5da improve error reporting of JSON parsing (vercel/turbo#3676)
also make source context generation more reusable

This adds a source context snippet of the JSON that failed parsing and
the json path to the error.

```
An error occurred while generating the chunk item [project]/crates/turbopack-tests/tests/snapshot/imports/json/input/invalid.json (json)
  at Execution of module_factory failed
  at Execution of JsonChunkItem::content failed
  at Unable to make a module from invalid JSON: expected `,` or `}` at line 3 column 26
  at nested.?
     1 | {
     2 |   "nested": {
       |                          v
     3 |     "this-is": "invalid" // lint-staged will remove trailing commas, so here's a comment
       |                          ^
     4 |   }
     5 | }
```
2023-02-08 10:17:42 +01:00
Tobias Koppers
f83691f700 refactor ResolveResult to allow mixing special and assets in alternatives (vercel/turbo#3675)
Co-authored-by: Justin Ridgewell <justin@ridgewell.name>
2023-02-07 23:56:06 +01:00
Leah
f65d709b56 detect missing trait methods at compile time (vercel/turbo#3657)
Leaves the default implementations of a trait "in place" and implements
the "cross-trait" resolving differently

we get back the normal rust error messages when you don't have every
method implemented 🎉
2023-02-07 17:06:19 +01:00
Alex Kirszenberg
17fba45a54 Export __N_SSG and __N_SSP from the error component (vercel/turbo#3574)
`export *` would be preferable once supported.
2023-02-07 09:39:49 +00:00
Will Binns-Smith
f43c3588be Rename experimental.resolveAlias to experimental.turbopackResolveAlias (vercel/turbo#3651)
Following discussion at https://github.com/vercel/next.js/pull/45560,
this renames `experimental.resolveAlias` to
`experimental.turbopackResolveAlias` to make it clear that this option
is only available in Turbopack.

Test Plan: `cargo test -p next-dev-tests`
2023-02-06 16:22:36 -08:00
Justin Ridgewell
9694fc4f7c Import Next's CJS AsyncLocalStorage modules (vercel/turbo#3634)
The node evaluation always renders with `type: "commonjs"` and `require()` calls, so we'll always import the CJS files. But here we're importing the ESM files. That means we have 2 distinct instances of `requestAsyncStorage` in our node instance, and they cannot properly communicate with the other.

Fixes WEB-543
2023-02-06 22:47:29 +00:00
github-actions[bot]
38c78b65d5 Update Google font-data.json (2023-02-06) (vercel/turbo#3614)
Automated changes by
[create-pull-request](https://github.com/peter-evans/create-pull-request)
GitHub action

Co-authored-by: wbinnssmith <wbinnssmith@users.noreply.github.com>
2023-02-06 10:28:35 -08:00
Alex Kirszenberg
035d36fd77 Support for getStaticPaths.fallback = false (vercel/turbo#3600)
Adds support for `getStaticPaths` returning `{ fallback: false }` by
building out all static paths and checking whether the resolved path is
included in that list.

`buildStaticPaths` requires the `next.config.js` path, as well as other
config options such as locale. I created WEB-546 to track being able to
pass them to the handlers.
2023-02-06 09:56:55 +01:00
Tobias Koppers
5d532b6b75 add helper for walking a tree concurrently and deterministic (vercel/turbo#3619)
Similar to our `try_join` helper this adds a
`try_flat_map_recursive_join` helper, which allows to async expand a
tree structure into all nodes. It will call the async mapper function
concurrently to allow parallelism. It will handle circular and duplicate
references and return all nodes in a determinstic way (breath-first).
2023-02-03 20:31:45 +01:00
Tobias Koppers
aa3422a56f always allow to close the error overlay (vercel/turbo#3624)
It's difficult to test an app, if a single error blocks using the whole
page.

Therefore, error overlay should always be closeable.
2023-02-03 19:10:47 +01:00