Commit graph

451 commits

Author SHA1 Message Date
Tobias Koppers
951568c4c7 improve and enable issue path handling (vercel/turbo#4017)
### Description

adds the issue trace again, adds some basic descriptions e. g. to pages

### Testing Instructions

snapshot issues

[X] Auto label
2023-03-07 17:10:05 +00:00
Tobias Koppers
e01578032f place all pages in the same intermediate output directory (vercel/turbo#4081)
### Description

The isolation is unnecessary and we can reuse files when we share
directories

### Testing Instructions

Open multiple pages without client-side navigation in multiple tabs
concurrently.
2023-03-07 16:26:41 +00:00
Tobias Koppers
59c86bfdd6 fix module options in middleware (vercel/turbo#4083)
### Description

allows to use jsx in middleware
2023-03-06 19:19:35 +00:00
OJ Kwon
2d4d758a9a ci(workflow): fix build errors (vercel/turbo#4082)
### Description

Minor fix for the daily next.js test runs.
2023-03-06 10:03:27 -08:00
Tim Neutkens
6babc5ec43 Make in next.config.js optional (vercel/turbo#4080)
### Description

Ensures `target` is optional to match vercel/turbo#46801 which removes the option.

<!--
  ✍️ Write a short summary of your work.
  If necessary, include relevant screenshots.
-->

### Testing Instructions

<!--
  Give a quick description of steps to test your changes.
-->
2023-03-06 08:59:03 +00:00
Justin Ridgewell
5619c03f4c Remove graceful failure handling in routing (vercel/turbo#3959)
The graceful failures mean it's easy to accidentally break the router
without noticing.
2023-03-06 08:48:29 +00:00
Tobias Koppers
f0ee0426ae inject swc helpers (vercel/turbo#4060)
### Description

This fixed the `_extends` is not defined issue.
2023-03-04 06:51:31 +00:00
Will Binns-Smith
5f76b5d9e4 next/font: Align with Next.js integration test suite (vercel/turbo#4039)
This:
* Adds a compile-time feature, `__internal_nextjs_integration_test`,
which is set when building Turbopack for the Next.js integration test
suite.
* When built with `__internal_nextjs_integration_test`, expects the
environment variable `NEXT_FONT_GOOGLE_MOCKED_RESPONSES` to be set with
an absolute path to a JavaScript file exporting a mapping of urls to
stylesheet text. This is used in place of making real requests to Google
Fonts.
* Addresses some small bugs in next/font/google to bring the
implementation in line with the urls generated by Next.js without
Turbopack.
* Changes classnames generated by next/font to use 6 character hashes,
bringing it in alignment with Next.js without Turbopack.

Test Plan:
* Adjusted existing unit tests
* In Next.js, `node run-tests.js -c 1 test/e2e/next-font/index.test.ts`

### Description

<!--
  ✍️ Write a short summary of your work.
  If necessary, include relevant screenshots.
-->

### Testing Instructions

<!--
  Give a quick description of steps to test your changes.
-->

<!--
  When the below is checked (default) our PR bot will automatically
  assign labels to your PR based on the content to help the team
  organize and review it faster.
-->

- [x] Auto label
2023-03-03 16:12:36 -08:00
Leah
ad12551513 move common dependencies to workspace root (vercel/turbo#3890) 2023-03-03 16:34:05 +00:00
Will Binns-Smith
857e02d700 webpack loaders: implement emitError and emitWarning (vercel/turbo#3983)
This implements webpack loader context api for `emitError` and
`emitWarning`, each of which emit Turbopack issues at the appropriate
error level. As with webpack’s implementation, `emitError` does _not_
cause builds to fail [0].

This uses next-dev issue snapshots (vercel/turbo#3774) to test that issues are
emitted.

[0] https://webpack.js.org/api/loaders/#thisemiterror

---------

Co-authored-by: Justin Ridgewell <justin@ridgewell.name>
2023-03-02 13:59:43 -08:00
Leah
cdbc0eae56 handle data paths for pages with getStaticPaths (vercel/turbo#4013) 2023-03-02 18:00:47 +00:00
Leah
5ba463e89b add env to spawned processes (vercel/turbo#4005)
Fixes WEB-517
Fixes vercel/turbo#3876
2023-03-02 17:36:09 +00:00
Leah
6d4fcae5be Separate tabs for Errors and Warnings in error overlay (vercel/turbo#4001) 2023-03-02 16:58:24 +00:00
Tobias Koppers
22fb29e4ce Only handle issues in dev server (vercel/turbo#3891)
All issues from `source` are already handled here:
48d9918806/crates/turbopack-dev-server/src/lib.rs (L168)

So no need to handle them multiple times
2023-03-02 11:14:47 +00:00
Tobias Koppers
7f7b2c1041 avoid bundling and execution of modules just of watching (vercel/turbo#4053)
### Description

* use completions to signal additional invalidations for evaluation
* avoid adding these modules as runtime entries, since that will
unnecessarily code generate, bundle and execute these modules
* gets rid of the watch_files_hack

### Testing Instructions

* change postcss.config, next.config.js, etc. -> changes will be
reflected by the app and process restarts
2023-03-02 12:02:06 +01:00
Tobias Koppers
60f5289b0d follow up changes from review (vercel/turbo#4051)
### Description

Follow-up changes for https://github.com/vercel/turbo/pull/4018

<!--
  When the below is checked (default) our PR bot will automatically
  assign labels to your PR based on the content to help the team
  organize and review it faster.
-->

- [x] Auto label
2023-03-02 10:51:37 +00:00
Tobias Koppers
5c9bdd7a34 Capture console statements as one unit including stack trace (vercel/turbo#4028)
### Description

fixes the deduplication issue with multiple output
2023-03-02 11:48:46 +01:00
Tobias Koppers
7dc8f02ebd refactor internal modules (vercel/turbo#4018)
### Description

* get rid of attached filesystem for our embedded modules
* get rid of import "." in favor of inner assets

depends on vercel/turbo#3999

### Testing Instructions

existing tests

<!--
  When the below is checked (default) our PR bot will automatically
  assign labels to your PR based on the content to help the team
  organize and review it faster.
-->

[X] Auto label
2023-03-02 08:23:41 +01:00
OJ Kwon
b920d343a3 fix(route_matcher): do not include empty segment (vercel/turbo#4037)
### Description

Closes WEB-674

if a matcher tries to split path have a slash like `/x/y`, split gives a
redundant empty segment `["", 'x', 'y']`.
2023-03-02 06:03:53 +00:00
Tobias Koppers
752794f638 refactor asset identification (vercel/turbo#3999)
* add Asset::ident() as unique identifier of an Asset
* add ChunkItem::ident() instead of ChunkItem::to_string()
(ValueToString)
* base `chunk_path` on AssetIdent instead of path only

Motivation:

We want to get rid of the `import "."` in favor of inner assets. When
doing this we no longer need to place virtual assets below the actual
file path and they can stay in their original path. But placing virtual
assets below the actual asset also made the `Asset::path` unique, which
would no longer be the case after using inner assets. Some parts of the
code base relied on `Asset::path` being unique (e. g. module ids and
chunk paths). But actually we never guaranteed that to be unique.
After this PR `Asset::ident` is intended to be unique and allow to carry
more information than only the path:
* Query string (`module?query`)
* Fragment (`module#fragment`)
* Asset (additional wrapped assets by key value pairs)
* Modifiers (additional transformations applied on the module, e. g.
`chunks`, `client chunks`)
* In future: Part (select a subpart of the module, e. g. only export
abc, or the module evaluation, or some internal part)
2023-03-01 11:11:27 +01:00
OJ Kwon
fc10d02366 feat(overlay): apply data-* header for the error desc (vercel/turbo#4015)
Partially resolves WEB-671.

There are some test cases use `data-nextjs-dialog-header` to lookup its
inner text to verify error output. Due to differences of error overlay
layout between turbopack / next-dev, those 2 have different inner texts.

PR applies a workaround, by introducing new data tag
`data-nextjs-turbo-dialog-body`. Next.js upstream will need following
update to utilize this tag in its test suites.
2023-02-28 17:27:30 -08:00
Justin Ridgewell
7e2d931ffa Update Middleware Routing (vercel/turbo#3930)
This accomplishes 2 things:
- Moves the creation of the edge info onto the Next.js side
- Extracts the middleware's `export const config = {}`, so that we can know what matchers are needed before invoking the edge function definition.

After this, an update to the Next.js side will enable middleware.

Fixes WEB-623
2023-02-28 02:09:54 +00:00
Will Binns-Smith
77283326e1 Snapshot issues in next-dev-tests (vercel/turbo#3774)
This:
* Adds issue snapshot support to next-dev-tests. This will allow us to
assert that certain issues are raised in tests that require next-dev.
* Extracts common snapshot code into a new crates,
`turbopack-test-utils`, which is shared between snapshot tests and
next-dev-tests.
* Implements an issue reporter that emits issues in a channel to the the
integration test code, where they are snapshotted.
* Fixes an issue where next-dev tests that were not Next.js apps would
emit non-fatal issues for a missing `pages/` directory.

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

---------

Co-authored-by: Justin Ridgewell <justin@ridgewell.name>
2023-02-27 10:04:06 -08:00
Will Binns-Smith
819d46a606 Automatic babel-loader followup (vercel/turbo#3944)
This:
* Addresses feedback from https://github.com/vercel/turbo/pull/3862
* Exempts VirtualAssets from webpack loaders. This addresses a bug where
next-hydrate.tsx could not be read.
	* Adds `ModuleRuleCondition::ResourceIsVirtualAsset` to filter these

---------

Co-authored-by: Justin Ridgewell <justin@ridgewell.name>
2023-02-27 08:14:24 -08:00
github-actions[bot]
c568a97ad6 Update Google font-data.json (2023-02-24) (vercel/turbo#3942)
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-24 09:14:21 +01:00
Tobias Koppers
00d842a652 disable bloom filter for now (vercel/turbo#3933)
it currently breaks because it imports `crypto` in edge environment
which isn't allowed.

We need to fix this properly eventually...
2023-02-23 13:23:55 +01:00
Tobias Koppers
71e6425c3e update to 13.1.7-canary.28 (vercel/turbo#3931)
* add `@opentelemetry/api` alias
* fix some renamed imports
2023-02-23 11:36:59 +01:00
Tobias Koppers
9b39e23ca4 implement route.js support (vercel/turbo#3923)
https://beta.nextjs.org/docs/routing/route-handlers
2023-02-23 11:36:17 +01:00
Tobias Koppers
112411678e improve startup performance (vercel/turbo#3927)
lazy parse page config from pages
this avoids to need to transform and parse all pages
2023-02-22 23:46:30 +01:00
Will Binns-Smith
1b8bacece6 Automatically apply babel-loader for apps with babel configs (vercel/turbo#3862)
This will automatically apply `babel-loader` to Next.js apps that
include a babel configuration file alongside `next.config.js`. It
requires the app to provide `babel-loader` itself.

Test Plan: Added an integration test.
2023-02-22 10:07:34 -08:00
Justin Ridgewell
3a30fc8850 Support NeedData responses in SourceMap/SourceMapTrace ContentSources (vercel/turbo#3907)
This implements a new `ContentSourceProcessor` trait and
`WrappedContentSource` struct that allows our `ContentSource`s to
register some processor to transform the eventual `ContentSourceContent`
that an inner `ContentSource` returns. Yah, it's a bit of a mouthful
with lots of very similar sounding names.

Essentially, the old `SourceMapContentSource` and
`NextSourceMapTraceContentSource` wrapped some inner `ContentSource`,
and would request content from them, and process that content into a
source map JSON or trace JSON. But, they didn't implement the `NeedData`
response, so it only supported very primitive inner content sources.

This PR extracts that knowledge into a single `WrappedContentSource`,
which will recursively wrap every `ContentSourceResult` until we land on
a fully resolved `ContentSourceResult::Result`. At that point, it hands
off the work to a `WrappedGetContentSource`, which performs the
processing on whatever content is returned by the inner
`GetContentSourceContent`. If you can't tell yet, I'm making the
description intentionally verbose to highlight just how similar our
struct/trait names are.

Fixes WEB-614
2023-02-22 11:48:46 -05:00
Alex Kirszenberg
b2a414f376 Make chunk_content_internal parallel (vercel/turbo#3836)
This switches the `chunk_content_internal` function from a sequential
BFS to a parallel BFS (+ reverse topological sort at the end).

I expected this to make some difference in performance, as traversing
references in parallel can lead to better CPU usage (see vercel/turbo#3771), but in
practice our benchmarks show no significant difference.

Real apps might be a different story, but I didn't notice any particular
performance improvement on vercel.com either.

This implementation is not perfect (we're making more calls to
`get_children` than strictly necessary), but I think it's enough to
measure a potential performance improvement.

Marking this as a draft for now as it's more complicated than the
current implementation and there's no clear win to adopting this.
2023-02-22 17:37:00 +01:00
Leah
22e3bacbf0 fix: allow HMR to recover from hydration errors (vercel/turbo#3805)
We now store react errors in the error overlay (hydration errors) and if
the error overlay receives the "build ok" message after that it will
hard reload the page to recover
2023-02-22 16:30:35 +00:00
Tobias Koppers
3d6c32933b add process.env.NODE_ENV support (vercel/turbo#3670)
define process.env.NODE_ENV to development for next-dev

define and set `process.turbopack`

---------

Co-authored-by: Will Binns-Smith <wbinnssmith@gmail.com>
2023-02-22 17:19:43 +01:00
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