Commit graph

233 commits

Author SHA1 Message Date
Tobias Koppers
dca015b121 move feature detection to next.js (vercel/turbo#263) 2022-10-24 16:19:14 -07:00
Tobias Koppers
233b69d203 App CSS and fixes (vercel/turbo#246)
fix app layout transition
add global css support
2022-10-25 00:27:17 +02:00
Tobias Koppers
36f7545c33 add HMR for RSC component changes (vercel/turbo#202) 2022-10-24 22:23:40 +02:00
Alex Kirszenberg
09273bdab1 Apply Next SSG transform (vercel/turbo#130)
This adds the Next SSG transform. This transform does a few things, but
the one we're most interested in right now is the removal of
`getStaticProps`/`getServerSideProps`/etc. from page modules. HMR will
be disabled if these exports are preserved.

Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
2022-10-24 22:23:00 +02:00
Justin Ridgewell
e4f6bbf6ab Implement source map tracing for errors (vercel/turbo#227)
Fixes https://github.com/vercel/web-tooling-internal/issues/67
2022-10-24 22:21:12 +02:00
Alex Kirszenberg
b0d8d36429 Add back Next's React compiled dists (vercel/turbo#209)
Required to get the layout-playground demo working.
2022-10-23 18:34:13 -07:00
Tobias Koppers
8fa162d5c5 fix app layouts (vercel/turbo#190)
Seems like app layout was left behind while shipping features to normal
SSR rendering

* fixes fallback error pages (update to error fallback changes)
* fixes process communication (update to api route changes)
* avoid busy looping
* update to next.js updates
* fix resolving cycle
* fix HMR of client components
* add some hard coded external packages
2022-10-22 19:47:59 +02:00
OJ Kwon
722930a006 feat(devserver): try to bind instead of explicit (vercel/turbo#187)
This PR attempts to try to bind server and bubbles up error, instead of
explicit `bind` which panics internally if it wasn't possible to bind.
2022-10-21 19:54:24 -07:00
Will Binns-Smith
4569ef779d Transform ecmascript with emotion (vercel/turbo#170)
Enabled in next-dev and snapshot tests.

There are quite a few output snapshot files. Maybe we make stubs for the
third-party packages to reduce the noise...

Test Plan: Added new snapshot tests. Verified transformed code contains
a digest, inline source map string.
2022-10-21 12:31:01 -07:00
Alex Kirszenberg
243bc9fbc0 Add support for API routes (vercel/turbo#163)
This reworks our Node.js rendering logic to allow for:
* passing binary request bodies in and out of Node.js: API routes can
accept request bodies in POST, and can reply with any content type.
* content source results that are recomputed every time: we don't want
API routes to be cached (at least not by turbopack for now).

It also reworks the `END_OF_OPERATION` logic to avoid hard coding a
single end of operation marker (they're now unique per pool), and allow
multiple kinds of operation events (`Step`, `Success`, `Error`).

This is not a particularly good implementation for this. A better
implementation would proxy the request from the client to the Node.js
server in a more direct manner. We also need a way to tell turbo tasks
"don't bother ever caching this", as right now every single API request
and result will still be cached, even if we know they will never be used
again. Finally, we should communicate with Node.js processes via a
better mechanism than stdout. I made some progress on a prototype for
using https://github.com/servo/ipc-channel with NAPI a while back, which
I'd like to pick up some time after conf.

However, it seems to work well enough for now, so yay.

Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
2022-10-21 21:03:52 +02:00
Tobias Koppers
06cc52ecbc remove fouc optimization (vercel/turbo#169) 2022-10-21 20:44:29 +02:00
Will Binns-Smith
dd7278c0e3 Next-dev and snapshot tests: transform ecmascript with styled_components (vercel/turbo#44)
To do:
* [x] The transform doesn't seem to be running properly yet. Fix this.
2022-10-21 09:32:39 -07:00
Will Binns-Smith
7b4f51f8fb Create a package.json with type: "commonjs" in .next/server (vercel/turbo#145)
Closes vercel/turbo#109

Note a difference between this and stable Next.js: at turbopack this
file is placed in .next/server/package.json, while Next.js currently
creates this file at .next/package.json.

Test Plan: Verified that the `hello-world-esm` no longer fails to SSR
(it's now blocked by vercel/turbo#111).

Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
2022-10-21 08:38:56 -07:00
Tobias Koppers
7d8d351d5e fix hydration bench again (vercel/turbo#162) 2022-10-21 16:29:52 +02:00
Tobias Koppers
451dccdeb8 fix startup benchmarks for CSR bundlers (vercel/turbo#152) 2022-10-21 16:11:25 +02:00
Tobias Koppers
790ff6c05c add some strongly consistent reads into nodejs source (vercel/turbo#154)
to improve performance

It doesn't fix the performance completely but makes it less bad
2022-10-21 14:23:49 +02:00
Tobias Koppers
d1db10cd37 Bugfixes for merged PRs (vercel/turbo#155) 2022-10-21 12:44:40 +02:00
Florentin / 珞辰
b1caa9ec34 terminal improvements (vercel/turbo#133)
* Adds next-like event type styling
* No tasks in logs

Closes:
- https://github.com/vercel/web-tooling-internal/issues/58

Screenshot: 
![CleanShot 2022-10-20 at 17 59
45@2x](https://user-images.githubusercontent.com/8146736/196999636-dcf3757d-6c5f-4c52-9257-86caabf6a5d6.png)

Co-authored-by: Maia Teegarden <dev@padmaia.rocks>
Co-authored-by: Justin Ridgewell <justin@ridgewell.name>
Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
2022-10-21 11:50:37 +02:00
Justin Ridgewell
a442eab26e Update default server IP to 0.0.0.0 (vercel/turbo#150)
Small nit, but if we want to listen on 0.0.0.0, then we should set that
to the default. The difference is that other computers can connect when
we listen on 0.0.0.0, while only this computer can connect if we listen
on 127.0.0.1.
2022-10-21 02:01:54 -04:00
Maia Teegarden
ff5f95fd47 Match Next.js server startup message (vercel/turbo#148)
![Screen Shot 2022-10-20 at 8 13 41
PM](https://user-images.githubusercontent.com/2865858/197102924-5970972b-7177-4c30-b7b2-35932d2c66fb.png)
2022-10-20 22:27:27 -07:00
Leah
88d0a40a96 fix tests (vercel/turbo#143) 2022-10-21 02:28:46 +02:00
Leah
276c844152 prettier fixes (vercel/turbo#41) 2022-10-21 01:46:26 +02:00
Chris Olszewski
d87b96bb49 add postcss and tailwindcss to unimplemented files (vercel/turbo#137)
Note that this doesn't completely close out
[vercel/turbo#54](https://github.com/vercel/web-tooling-internal/issues/54) as the
[tailwindcss config is
optional](https://tailwindcss.com/docs/configuration). I'm digging
deeper at additional ways to detect tailwind, but putting this up since
it's a strict improvement.

```
olszewski@chriss-mbp next-dev % cargo run -p next-dev -- /tmp/with-tailwindcss-app
   Compiling next-dev v0.1.0 (/Users/olszewski/code/vercel/the-three-body/crates/next-dev)
    Finished dev [unoptimized + debuginfo] target(s) in 11.61s
     Running `/Users/olszewski/code/vercel/the-three-body/target/debug/next-dev /tmp/with-tailwindcss-app`
server listening on: http://localhost:3000
error [unimplemented]
  /private/tmp/with-tailwindcss-app/next.config.js
    Feature not yet supported
    Handling the file `next.config.js` is currently unimplemented

  /private/tmp/with-tailwindcss-app/postcss.config.js
    Feature not yet supported
    Handling the file `postcss.config.js` is currently unimplemented

  /private/tmp/with-tailwindcss-app/tailwind.config.js
    Feature not yet supported
    Handling the file `tailwind.config.js` is currently unimplemented

[200] / (3045ms)
initial compilation 3468ms (3044ms task execution, 48380 tasks)
updated in 874ms (8990 tasks)
```
2022-10-20 19:03:17 -04:00
Will Binns-Smith
3cb06901df Derive a runtime version from NodeJsEnvironment's node_version (vercel/turbo#15)
Ported from https://github.com/vercel/turbo-tooling/pull/452.

To do:

* [x] Read and use node version from PATH

Test Plan:

Temporarily lowered the default version and verified core-js was
resolved when /page is visited.

Co-authored-by: Justin Ridgewell <justin@ridgewell.name>
2022-10-20 14:46:47 -07:00
Leah
ca98d275cf fallback page (vercel/turbo#69) 2022-10-20 22:26:53 +02:00
Leah
12d723059b prepare crates for publishing (vercel/turbo#29) 2022-10-20 19:49:35 +02:00
Florentin / 珞辰
2eae9f180c add unimplemented warning for next/babel configs (vercel/turbo#124)
PR for: 
- https://github.com/vercel/web-tooling-internal/issues/56
- https://github.com/vercel/web-tooling-internal/issues/55

Screenshot:
<img width="662" alt="CleanShot 2022-10-20 at 11 12 13@2x"
src="https://user-images.githubusercontent.com/8146736/196907628-e5c73d54-87a7-4f3a-9130-d08bc539a5b1.png">

Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
2022-10-20 18:53:27 +02:00
Tobias Koppers
3ca2fe4fd5 adds support for app directory (vercel/turbo#125)
This can be tested with https://github.com/vercel/layouts-playground

But since tailwind is not supported you need to add:

``` html
<script src="https://cdn.tailwindcss.com/3.1.6"></script>
```

into `<head>` in `app/layout.tsx`
2022-10-20 18:49:12 +02:00
Leah
4bb347ae39 error overlay (vercel/turbo#39)
transferred from https://github.com/vercel/turbo-tooling/pull/396

Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
2022-10-20 18:04:19 +02:00
Justin Ridgewell
be1537881c DeterminsticHash cleanup (vercel/turbo#108)
Fixes a few issues:

1. Removes `Hasher` impl for `Xxh3Hash64Hasher`
- Importing the `Hash` trait allows you to call `vc.hash(&mut
xxh3_hasher)`, which defeats our goal of deterministic hashing
2. Fixes hashing of 2 contiguous strings
   - `"fo"` and `"o"` should hash differently than `"f"` and `"oo"`.
3. Fixes hashes of enums
   - `Foo::Bar(1)` should hash differently than `Foo::Baz(1)`
4. Standardizes `usize`/`isize` as 8 bytes
2022-10-19 18:21:29 -04:00
Tobias Koppers
c5bc290c32 add node: prefixed aliases for polyfills (vercel/turbo#102) 2022-10-19 18:07:28 +02:00
Alex Kirszenberg
aff0a0f7c5 Fix CSS HMR for SSR (vercel/turbo#85)
Since we used to build the HTML using our own `<Document>` component, we
were previously adding a data-turbopack-chunk-id attribute to our
`<link>` tags to reconcile chunk paths with their chunk ids when
initializing HMR. However, Next.js is now responsible for building the
HTML, and it has no such mechanism.

**NOTE:** HMR is currently broken for non-Next-SSR rendering
(HtmlAsset). This PR does not fix that.
2022-10-19 18:06:40 +02:00
Tobias Koppers
381badcde3 Improvements to benchmarks (vercel/turbo#99)
* remove 100 modules form the default modules count
* rename bench_restart -> bench_hydration_cached
* add bench_startup_cached
* run npm install only once per test case and copy the result instead
* use multi-threaded copy
* Run `cached` tests only when `TURBOPACK_BENCH_CACHED` is set
* add `TURBOPACK_BENCH_BENCH` too measure the time it takes to run the
full benchmark (including startup and teardown) instead.
* add `TURBOPACK_BENCH_HEAD` to run non-headless
* add `TURBOPACK_BENCH_DEVTOOLS` to auto open devtools
* retry initial warmup change when it fails to detect that

This should make the benchmarks about 3 times faster... at least on
windows^^
2022-10-19 13:39:05 +02:00
Tobias Koppers
06ee2efe8e remove get_by_id (for performance) (vercel/turbo#88)
I also needed to remove the old html runtime, use new runtime for CSP to
update the CSS HMR code
2022-10-19 07:33:58 +02:00
Leah
0f40ec8327 ts HMR runtime (vercel/turbo#38) 2022-10-18 20:37:33 +02:00
Will Binns-Smith
50ab6dab18 [Rebased] Remove automatic core-js polyfills (vercel/turbo#91)
Rebase of vercel/turbo#68, which was merged into a now-closed PR.

Closes vercel/turbo#65.

When configured to use preset-env, this stops turbopack from inserting
dependencies on core-js. It's:

* Buggy/error-prone, at least through swc preset-env: 
  * https://github.com/vercel/the-three-body/issues/65
* setImmediate "polyfills" always inserted for this nonstandard feature
when
    React (scheduler, iirc) does feature detection of it
* Big. Updating the snapshot alone for a test that only used [].includes
  resulted in a diff with nearly 4700 line deletions
* Not done by Next.js for modern targets in the past couple of years:
https://twitter.com/timneutkens/status/1234548900272517120

Test Plan: Added [].includes to preset_env snapshot test and verified no
references to core-js are inserted.
2022-10-18 11:04:41 -07:00
Alex Kirszenberg
7bf4a27e6a Ensure Next.js uses React 18 APIs, enable styled_jsx transform in SSR (vercel/turbo#90)
This will remove the warning about using `hydrate` instead of
`hydrateRoot`, and fix a mismatch between SSR and CSR when using
styled-jsx (`<style jsx>`).
2022-10-18 19:30:46 +02:00
Alex Kirszenberg
9062ad91f4 Add polyfills to Node.js externals on the client-side (vercel/turbo#89)
We can't use the normal `ImportMap` because we stop resolving if looking
up a request within yields a result. However, for module polyfills, we
only need to look up the request when normal resolving fails. Hence the
dichotomy between the `import_map` and the `fallback_import_map`.

In a more modular architecture, we would model this as a stack of three
resolvers:

1. ImportMapResolver
2. DefaultResolver
3. FallbackImportMapResolver

I'm guessing this is what we'll have in the future, but this requires a
bigger refactoring than what I'm comfortable with implementing for now.
2022-10-18 19:30:07 +02:00
Alex Kirszenberg
59b7290933 Remove unused pages/_app and pages/_document (vercel/turbo#78)
These are no longer used, as we are now using Next.js' own components
instead.
2022-10-18 14:53:01 +02:00
Tobias Koppers
105ff16578 remove ContentSource::vary to avoid many tasks (vercel/turbo#71) 2022-10-18 13:00:10 +02:00
Justin Ridgewell
feb8c9ac39 Implement support for static assets directory (vercel/turbo#73)
Fixes https://github.com/vercel/web-tooling-internal/issues/7

Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
2022-10-18 10:05:37 +02:00
Tobias Koppers
5c1d113f1e node.js needs a fetch polyfill (vercel/turbo#58) 2022-10-18 09:56:24 +02:00
Tobias Koppers
aed7fa4d0b add basic support for browser alias field (vercel/turbo#56) 2022-10-18 03:17:06 +02:00
Leah
fcc806e1e5 embedded next.js package (vercel/turbo#37) 2022-10-17 23:33:25 +02:00
Alex Kirszenberg
44c2e1f570 Optimize Next.js SSR (vercel/turbo#48)
This PR also includes the changes in vercel/turbo#12 

This optimizes Next.js SSR by marking `react[/*]` and `next[/*]` imports
as externals in Node.js, which means that they will be `require`d
directly instead of bundled.

This optimization reduces the number of modules to analyze on the server
for a single component app from ~1000 (Next.js SSR imports a lot of
modules, including amp-optimizer which includes more) to <10.

Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
2022-10-17 19:54:19 +02:00
Tobias Koppers
2f3edac20c add introspection for assets and content sources (vercel/turbo#47)
add very simple explorer to introspect the graph via `/__turbopack__/`

Allows to "walk" through the content sources and asset graph. Some
assets allows to access inner assets, e. g. from the ecmascript chunk
you can access the entry module asset, so you can go a level deeper.

It works by a `Introspectable` trait which can be implemented by
anything we want to allow the user to inspect. In future the in browser
UI should offer a nice UI to explore your application.

In future we probably also want to add some `metrics` to the
`Introspectable` trait, e. g. to report size of an asset.

This UI is very basic currently, but that works for debugging:


![image](https://user-images.githubusercontent.com/1365881/196007862-2fb2a0e9-19ba-45c5-8a82-926418e0d479.png)
2022-10-17 17:19:29 +02:00
Tobias Koppers
3c821767ce use browser field for the browser (vercel/turbo#26)
add module field
2022-10-17 08:36:30 +02:00
Tobias Koppers
cabb72fa53 avoid emitting source maps for node.js (vercel/turbo#30) 2022-10-16 10:39:18 +02:00
Leah
f39152cef6 add From<T> impl for File (vercel/turbo#35)
transferred from https://github.com/vercel/turbo-tooling/pull/519
2022-10-15 18:42:14 +02:00
Leah
003a1ed013 add FileSystem::root() function to replace FileSystemPathVc::new(fs, path) (vercel/turbo#34)
transferred from https://github.com/vercel/turbo-tooling/pull/518
2022-10-15 18:40:02 +02:00
Tobias Koppers
280e909131 Deduplicate issues for logging (vercel/turbo#27)
see https://github.com/vercel/turbo-tooling/pull/523

Co-authored-by: Justin Ridgewell <justin@ridgewell.name>
2022-10-14 17:52:59 +02:00
Tobias Koppers
8cab8aa1d6 windows needs magic SystemRoot env var to allow to make http requests from node.js (vercel/turbo#22) 2022-10-14 00:45:39 +02:00
Tobias Koppers
79ea25f491 make less things to rely on HashSet and HashMap order 2022-10-13 18:16:12 +02:00
Tobias Koppers
4760f0dbfd improve startup error messages (vercel/turbo#524) 2022-10-13 23:38:19 +08:00
Alex Kirszenberg
0527d39665 Turn the default Document component into a class component (vercel/turbo#512)
Some code in userland can expect Document to be a class, and as such try to extend it. Extending a function will result in an invalid React component, so it must be a class component.

e.g. https://nextjs.org/docs/advanced-features/custom-document#typescript
2022-10-13 09:29:20 +08:00
Alex Kirszenberg
1d46acd4d4 Introduce PathRegex for patch matching with named parameters (vercel/turbo#511)
This is another attempt at fixing https://github.com/vercel/turbo-tooling/pull/507. It also handles the root index page properly ("pages/index.js").
2022-10-13 09:29:19 +08:00
Tobias Koppers
a28aead85b use react-refresh-utils bundled with next when available (vercel/turbo#509) 2022-10-13 09:29:19 +08:00
Tobias Koppers
d5ed7e3940 routing bugfixes (vercel/turbo#495) 2022-10-11 10:23:10 +00:00
Tobias Koppers
8589c15b95 avoid creating too many content sources (vercel/turbo#496) 2022-10-11 10:23:00 +00:00
Tobias Koppers
fb1629c542 continue preparations for .module.css (vercel/turbo#494)
split global css and module css into separate assets
2022-10-11 09:47:43 +00:00
Tobias Koppers
5e1922d397 move node.js rendering to a content source (vercel/turbo#486)
add getServerSideProps and dynamic segments

fixes vercel/web-tooling-internal#37
fixes vercel/turbo#444
2022-10-10 22:21:30 +00:00
Tobias Koppers
3a05f60d3c fix many root sources crated (vercel/turbo#485)
It's important to not create a `cell` outside of the root `source` method as this will create a new cell for each call, which means each `source` will create a separate task, and this bubbles for each cell created in `source`...
2022-10-10 13:44:42 +00:00
Alex Kirszenberg
7ebb64846c Make embed_file relative to package instead of invoker file (vercel/turbo#484)
This makes the argument to `embed_file!` relative to the package it is invoked from, instead of relative to the file it is invoked from. The latter is closer to how `include_*!` works, but it has a couple of issues:
* Since `file!` returns a path relative to the workspace, it requires knowing the full path to the workspace. However, this is undefined when the package is compiled from outside of the workspace (e.g. as a dependency of another package).
* Procedural macros don't have access to the path of the file where they were originally invoked [(although we could get it with #[feature(proc_macro_span)])](https://doc.rust-lang.org/proc_macro/struct.Span.html), which means that an `embed_dir` macro would not be able to be relative to the invoker file anyway. So this makes things more consistent for such a (to be implemented) macro.
2022-10-10 13:35:42 +00:00
Will Binns-Smith
9bc858fddd preset_env followup [1/2] (vercel/turbo#478)
Addresses some feedback from vercel/turbo#380. Together with a following PR to use swc_core (currently blocked on https://github.com/swc-project/swc/pull/6083 and a subsequent publish), will address vercel/turbo#474.

* Remove unnecessary Result type
* Remove unnecessary @swc/helpers
2022-10-10 14:46:36 +02:00
Alex Kirszenberg
ed769521f9 Support for App.getInitialProps/Page.getInitialProps (vercel/turbo#464)
This is a very simplified version of what Next.js does. It adds support for `App` and page components defining `getInitialProps`.

fixes vercel/web-tooling-internal#38
2022-10-10 09:03:25 +00:00
Justin Ridgewell
4851e09ca8 Revamp errors and logging (vercel/turbo#467)
This updates all of our Issues to have a consistent display, and changes the way we display source code and debug-level details. In particular, this makes the following changes:

1. Cleans up the title/description of existing issues
   - We were filling the `title` field with too much information, because the `desccription` field wasn't always shown.
1. Always displays the `description`
   - This used to be hidden behind the `--detail` flag
1. Always displays the code frame of the issue, if it exists
   - This used to be hidden behind the `--detail` flag
1. Fixes the `context` (file path) to display the relative path to the file
   - It was hardcoded to the FS string used by turbotrace
1. Creates a new `detail` function which can provide debug-level information about the internal Rust state
   - This is not shown by default, user must pass `--detail` flag

The format for a rendered issue roughly matches:

```
${SEVERITY} [${CATEGORY}]
  ${CONTEXT}
    ${TITLE}
    ${CODE FRAME}
    ${DESCRIPTION}
    ${DETAIL}
```

Where
- `SEVERITY` is error/warning/etc
- `CATEGORY` is a self-defined string for the phase of the compiler (eg, "parsing", "running")
- `CONTEXT` is a file path to the offending file
- `TITLE` is a short (single-line) title
- `CODE_FRAME` is an optional position that generated the issue, which will display a few context lines and highlight the offending span of code
- `DESCRIPTION` is a longer (multi-line) message that describes the issue, and what to do about it
- `DETAIL` is a (by default not shown) fully detailed, debug-level, message providing insights into the internal state of Rust
2022-10-10 06:24:54 +00:00
Tobias Koppers
9427514d69 prepare css for different types and transforms (vercel/turbo#477)
following the design of ecmascript parse and modules

fix a few nitpicks
2022-10-09 11:47:33 +00:00
Alex Kirszenberg
c3b6b0f790 Add support for pages/_document (vercel/turbo#456)
This adds preliminary support for pages/_document. The API is more complex than pages/_app, so this required a few more things in order to work.

Right now, our `next/document` shim does much, much less than the original. We will eventually have to figure out whether we should distribute our own module, or find a way to reuse Next.js' internals. There's *a lot* of stuff in there so the second option is probably best.
2022-10-07 12:49:09 +00:00
Alex Kirszenberg
839b55ff06 Add support for pages/_app (vercel/turbo#442)
This adds preliminary support for pages/_app. There's still some work to do here to support things like `App. getInitialProps`, etc., but that will come in later PRs. I've created issues for these for now.

One issue remaining is that renaming `pages/_app.js` does not switch to the default _app asset. The server needs to be restarted for this to happen. Similarly, adding an _app.js file does not switch from the default asset to it. I'm guessing there's something wrong with the way I set up the import mappings, and they aren't being invalidated properly?

fixes vercel/turbo#424
2022-10-07 11:36:44 +00:00
Tobias Koppers
39663ebc78 pass request info to content source (vercel/turbo#458)
allow the ContentSource to declare which info is required
2022-10-07 13:35:35 +02:00
Tobias Koppers
e8359f7964 refactor AssetContext (vercel/turbo#465)
remove context_path from AssetContext
remove most with_* methods from AssetContext
add ResolveOrigin trait
use ResolveOrigin to pass along context path and context for resolving
ecmascript and css module assets implement ResolveOrigin

Noteable change: Many places use `origin_path` instead of `context_path` which means it points to the issuer module path instead of the issuer module directory.
2022-10-07 13:34:31 +02:00
Will Binns-Smith
e4f92b7206 Automatic downleveling to browser targets using swc_preset_env (vercel/turbo#380)
Closes vercel/turbo#440

This uses swc's preset_env to automatically downlevel code according to the environment's browser targets, and sets next-dev to use a limited, modern target.

To do:
* [x] Add snapshot test
* [x] turbotrace test failures — looks like this has something to do with the Buffer module? Hitting swc's "multiple constructors" not implemented: f655488cfa/crates/swc_ecma_transforms_compat/src/es2015/classes/mod.rs (L545)
* [x] ~Benchmark downleveling node_modules (probably on front) and make a decision re: downleveling everything vs. just workspaces~ Filed as vercel/turbo#457
2022-10-07 06:54:21 +00:00
Tobias Koppers
d49a9c3b9d move ProcessEnv into turbo-tasks-env (vercel/turbo#462)
make ProcessEnv a trait to allow other implemenetations of it
2022-10-06 20:36:36 +02:00
LongYinan
8c80ba4f78 Migrate to pnpm (vercel/turbo#336)
### turbo tracing in pnpm projects

How pnpm link packages:

![image](https://user-images.githubusercontent.com/3468483/191022172-962af095-9b44-4b69-8e2f-1e8d440d1c31.png)

After turbo tracing:

```
dist
├── crates
│   └── turbopack
│       └── tests
│           └── node-file-trace
│               ├── integration
│               └── node_modules
│                   └── better-sqlite3 -> ../../../../../node_modules/.pnpm/better-sqlite3@7.6.2/node_modules/better-sqlite3
└── node_modules
    └── .pnpm
        ├── better-sqlite3@7.6.2
        │   └── node_modules
        │       ├── better-sqlite3
        │       │   ├── build
        │       │   │   └── Release
        │       │   └── lib
        │       │       └── methods
        │       └── bindings -> ../../bindings@1.5.0/node_modules/bindings
        ├── bindings@1.5.0
        │   └── node_modules
        │       ├── bindings
        │       └── file-uri-to-path -> ../../file-uri-to-path@1.0.0/node_modules/file-uri-to-path
        └── file-uri-to-path@1.0.0
            └── node_modules
                └── file-uri-to-path
```

No more **global .pnpm store**. The directory link will follow the original path created by pnpm.
2022-10-05 16:42:55 +00:00
Tobias Koppers
a8b0fd4f4b add layer to ChunkingContext and include that in module id and chunk paths (vercel/turbo#449)
this allows multiple versions of modules to co-exist in one chunking context e. g. RSC layer and SSR layer
2022-10-02 06:30:57 +00:00
Leah
2ffcbe38e0 simpler runtime inclusion (vercel/turbo#438) 2022-09-30 18:03:27 +00:00
Tobias Koppers
b9638d91d5 change WrapperAsset to some more general purpose VirtualAsset (vercel/turbo#447)
Wrapper is a bit of a weird name since it's not actually wrapping the existing asset. Actually it's just a virtual asset with a path below the existing path.
2022-09-30 11:58:35 +00:00
Tobias Koppers
1a5f27bd88 fixes some nitpicks (vercel/turbo#448) 2022-09-30 11:52:36 +00:00
Tobias Koppers
797bbc1a2f Refactor nodejs rendering to be more isolated and reusable (vercel/turbo#428)
(Prerequirement for `app` support)
2022-09-30 08:13:37 +00:00
Leah
9fd9163096 use embed macro (vercel/turbo#437) 2022-09-29 21:36:48 +00:00
Leah
fb76744de1 fix asset paths in server rendered pages (vercel/turbo#436)
Currently, when a server rendered page imports an asset (e.g. an image) there's a hydration mismatch
2022-09-29 17:14:15 +00:00
Tobias Koppers
3ad7c51768 use embed_file (vercel/turbo#432) 2022-09-28 19:32:09 +00:00
Tobias Koppers
a3dd9915d7 Use ValueToString for AssetReference instead of description() (vercel/turbo#430)
(Prerequirement for `app` support)
2022-09-28 19:02:39 +00:00
LongYinan
402c64be00 Introduce AssetContent to handle symlink assets (vercel/turbo#406)
* Fix DiskFileSystem::read_link

* pnpm-like integration test

* Introduce AssetContent to handle symlink assets

* Fix read_link on Windows

* Run clippy fix

* Rename `path` to `target`

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

* Split Windows specified code

* Add comments about Redirect is only represent Directory

* Handle symlink while reading content

* Clippy fix

* Revert previous changes in FileSystemPathVc::get_type

* Fix Unix read_link

* cleanup

* handle symlink while resolving native bindings

* Make LinkContent::Link contains only target

* Add LinkType to represent link type

* Cleanup VersionedAsset

* Cleanup LinkType

* Normalize the LinkContent::target

* Comments

* Revert special case workaround for sharp on Windows

* comments

* node_native_binding follow file link

* Apply CR suggestion

Co-authored-by: Justin Ridgewell <justin@ridgewell.name>
2022-09-28 22:44:32 +08:00
Tobias Koppers
3263f5e5e6 replace json with serde_json (vercel/turbo#398)
get rid of `json` in favor of only `serde_json` for consistency and less dependencies
2022-09-28 09:02:40 +00:00
Justin Ridgewell
25ca6b2e2c Implement .env loading (vercel/turbo#409)
This implements `.env` loading by taking advantage of the [dotenvy](https://docs.rs/dotenvy/latest/dotenvy/) crate. Unfortunately, this isn't as featureful as the npm `dotenv`, lacking `FOO=${BAR:-default}` default support (this might be important), `FOO=${MAYBE_UNDEFINED:-${BAR-:default}}` nested fallbacks, and `` FOO=`backtick` `` support.

This is then converted into a series of assignments for the client code. This is run before any of the user code.

```js
const env = process.env;

env["FOO"] = "bar";
//...
```

- - -

TODO:
- [x] ~~Replace `process.env.FOO`/`process.env["FOO"]` during chunk compilation~~
  - using a runtime module speeds up HMR because the code doesn't need to be recompiled.
- [x] I don't actually know how to test server rendering, so I assume it works but haven't verified.
2022-09-27 20:33:45 +00:00
Leah
b7e9d4e3f0 more type safe next-dev builder (vercel/turbo#388) 2022-09-21 17:14:24 +00:00
Leah
620a6e0aaf small fixes / improvements (vercel/turbo#341)
Many small things I found

The most important is probably the typescript transform

The remaining bits should hopefully be self-explanatory from the commit messages
2022-09-21 15:47:23 +00:00
Leah
647a87f8f0 better ssr error message (vercel/turbo#387) 2022-09-20 18:57:49 +00:00
LongYinan
b9c36e7748 Align eslint and prettier rules with turborepo (vercel/turbo#397) 2022-09-20 07:33:15 +00:00
Tobias Koppers
a9b5ada56a fail-safe bindings code for SSR (vercel/turbo#391) 2022-09-19 19:11:14 +02:00
Tobias Koppers
1f7df032e2 benchmarks need more time and skip faster when failing (vercel/turbo#393) 2022-09-19 19:01:18 +02:00
Tobias Koppers
65be8a0804 handle exceptions during waiting for events (vercel/turbo#383) 2022-09-19 15:22:05 +00:00
Alex Kirszenberg
e35ad2f2dc Use React.memo in the test/bench app (vercel/turbo#384)
With React.memo:
```
bench_hmr_to_commit/Turbopack CSR/30000 modules
                        time:   [50.608 ms 51.659 ms 52.553 ms]
```

Without React.memo:
```
bench_hmr_to_commit/Turbopack CSR/30000 modules
                        time:   [853.47 ms 1.0191 s 1.1873 s]
                        change: [+1543.4% +1872.7% +2207.8%] (p = 0.00 < 0.05)
                        Performance has regressed.
```

Since we're only ever editing the top-level triangle in our HMR benchmarks, we're incurring the time it takes for React to re-render the whole tree, which is a function of the number of components in said tree. By using `React.memo`, we can skip updating children components during HMR.
2022-09-19 15:00:22 +00:00
Tobias Koppers
00b7a92a39 measure HMR to eval and HMR to commit independent from each other (vercel/turbo#382)
HMR to commit include react-refresh time to apply the update in the react component tree
2022-09-19 14:48:18 +02:00
Tobias Koppers
6d1a83384a Benchmark summarize script, workflow and stability (vercel/turbo#381) 2022-09-19 09:24:55 +00:00
Tobias Koppers
36c3d2d80f SourceMap fixes and improvements (vercel/turbo#374)
moves the logic of creating SourceMap assets into the asset reference. This avoids depending on the chunk items in the references() method directly. It also avoids calling CodeVc::source_map() until the source map is read

avoid circular dependency in call graph

It also avoids checking `has_source_map()` and just inserts potential Source Maps assets for every chunk item. Checking `has_source_map()` seems unnecessary work to do for all chunk items, when we can just send an empty source map.

only expose SourceMaps for chunk items when HMR is enabled
2022-09-16 15:08:00 +00:00
Tobias Koppers
7795fafdc7 add typescript support (vercel/turbo#370)
picked typescript transform from https://github.com/vercel/turbo-tooling/pull/341

add resolve options context as global resolve config

enable typescript only for next-dev

move emulating logic from environment to resolve options context

Co-authored-by: Leah <8845940+ForsakenHarmony@users.noreply.github.com>
2022-09-16 09:22:37 +00:00
Tobias Koppers
86f1831b06 fix compare action (vercel/turbo#373) 2022-09-16 08:06:54 +02:00
Will Binns-Smith
cf1eadb5ac Implement styled-jsx with swc's styled_jsx (vercel/turbo#367)
This reverts commit ccf6c112d541f0a1a9f4e691f6220363550aaf01.
2022-09-15 13:51:45 -07:00