Commit graph

342 commits

Author SHA1 Message Date
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
Tobias Koppers
22e996b90c ensure that HMR is really happening while measuring (vercel/turbo#365)
no need to test all module counts
2022-09-15 09:54:07 +00:00
Will Binns-Smith
b6d38cd4fd Revert "Implement styled-jsx with swc's styled_jsx" (vercel/turbo#366)
Revert "Implement styled-jsx with swc's styled_jsx (vercel/turbo#354)"

This reverts commit 255a38b07c98252bfe442ee363f07924da45288a.
2022-09-15 02:24:08 +02:00
Tobias Koppers
f4e28a07ef enable react refresh for vite (vercel/turbo#364)
It was doing a full refresh before
2022-09-15 00:04:49 +00:00
Will Binns-Smith
d4192f4bd5 Implement styled-jsx with swc's styled_jsx (vercel/turbo#354)
This implements support for styled-jsx in next-dev using swc's styled_jsx crate.

It's only applied in next-dev, and is only applied as a transform to app code, much like the react-refresh transform.

To do:
* [x] The transform doesn't seem to be applied. Pass the added test.

Test Plan: `cargo test -p next-dev --
test_crates_next_dev_tests_integration_turbopack_basic_styled_jsx
--nocapture`
2022-09-14 23:46:18 +00:00
Tobias Koppers
826998cf07 increase benchmark timeouts to be able to benchmark larger module counts (vercel/turbo#362) 2022-09-14 23:17:14 +00:00
Alex Kirszenberg
50aa9cc261 Initial support for getStaticProps (vercel/turbo#345)
Remaining questions:
* Should we have some static analysis for `getStaticProps` instead of looking into exports at runtime?
* For now, the output of `getStaticProps` (if defined) will always trump the value passed in as `data`. If we consider `data` to be the cached output of `getStaticProps` (in the future, as this is not yet implemented), this logic should be adapted.
2022-09-14 21:31:14 +00:00
Will Binns-Smith
eb93985d95 Benchmarks: allow simultaneously installing multiple packages from npm (vercel/turbo#339)
Previously, we ran multiple `npm install` operations in serial using multiple calls to `install_from_npm`. Instead, this allows us to express dependencies all at once as a single command to the npm cli, which should reduce the time we spend installing from npm and updating package.json.

Test Plan: Manually confirmed that package.json was updated correctly.  `cargo bench`.
2022-09-12 12:34:26 -07:00
Will Binns-Smith
aaa640def6 Benchmark Webpack (vercel/turbo#338)
This adds webpack 5 to the benchmark suite.

Test Plan: Manually confirmed package.json updates and webpack config written to temp dir correctly. `cargo bench`.
2022-09-12 11:09:26 -07:00
Will Binns-Smith
361ca5eca8 Split benchmark code into more modules (vercel/turbo#337)
This splits the benchmark code into more modules. Notes:

* ~Moved/left `get_bundlers()` and `get_module_counts()` to/in mod.rs. In particular, moving `get_bundlers()` to either bundle.rs or util.rs would lead to a circular dependency. These both also rely on env var configuration, so I figured this was a reasonable place for them.~
* The Bundler trait has its own module (not moved to util), since it's a top-level concern and not really a miscellaneous utility.
* Each bundler has its own module file.

Test Plan: `TURBOPACK_BENCH_BUNDLERS=all cargo test --benches -p next-dev -- --nocapture` and verify same output as before change.
2022-09-09 16:35:12 -07:00
Tobias Koppers
ecaf59b3e6 improve startup metric measurement (vercel/turbo#331)
This fixes the `startup` benchmark metric to show the time until first render, instead of being equal to hydration.

It also skips `hydration` for CSR bundlers since it's equal first render for them.

It now correctly measures the initial SSR as `startup`, so CLI start until page visible:
![image](https://user-images.githubusercontent.com/1365881/189152420-396b181b-5a3e-4902-881d-7c247fa43bd8.png)
2022-09-08 16:00:15 +00:00
Alex Kirszenberg
0a112ccb14 Fix Next.js 11 React version (vercel/turbo#333) 2022-09-08 15:18:53 +00:00
Tobias Koppers
378adc7112 cleanup nitpicks (vercel/turbo#330) 2022-09-08 14:54:09 +00:00
Tobias Koppers
6f312afedc allow to pass module counts list via env var (vercel/turbo#332)
add custom benchmark workflow

run large counts in CI
2022-09-08 16:46:19 +02:00
Alex Kirszenberg
a45572b642 Ensure pages close before app does (vercel/turbo#329) 2022-09-08 15:02:48 +02:00
Alex Kirszenberg
6f0fc67cab Stop processes gracefully when possible, add drop guard to pages (vercel/turbo#328) 2022-09-08 12:00:19 +00:00
Will Binns-Smith
dd217c71b9 Benchmark Parcel (vercel/turbo#322)
* Benchmark Parcel

* add Parcel to the CI benchmarks

* move some turbopack dependencies to the bundler as they conflict with other bundlers

Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
2022-09-08 13:08:25 +02:00
Will Binns-Smith
abcdd78623 Benchmark Next.js 11 and 12 (vercel/turbo#304)
This implements benchmark support for Next.js 12. Next.js (the tool) expects to be able to resolve from the `next` package in the cwd, so it must be installed alongside the other node_modules in the test.  `prepare` was added to the Bundler trait to handle this case.

Test Plan: `TURBOPACK_BENCH_ALL=all cargo bench -p next-dev`


Co-authored-by: Alex Kirszenberg <1621758+alexkirsz@users.noreply.github.com>
Co-authored-by: Tobias Koppers <1365881+sokra@users.noreply.github.com>
2022-09-08 05:00:32 +00:00
Tobias Koppers
512539821d fix runtime code for server rendered content source (vercel/turbo#315)
move transition into turbopack
2022-09-07 15:56:10 +02:00
Will Binns-Smith
12e5f19a84 Benchmark against Vite (vercel/turbo#299)
This adds a comparison against Vite to our benchmark suite, running the startup, change, and restart benchmarks.

Test Plan: `cargo bench`


Co-authored-by: Tobias Koppers <1365881+sokra@users.noreply.github.com>
2022-09-07 00:09:06 +00:00
Tobias Koppers
b78ede6099 fix benchmark compare actions (vercel/turbo#318)
The benchmark github action didn't correctly copy and use the executables used in benchmarks via CARGO_BIN_EXE_*.

This adds a CARGO_BIN_EXE_* runtime override to the github action to allow to use correct executable.

It will show correct results for next-dev benchmarks too, e. g. here an example of reverting vercel/turbo#295 
![image](https://user-images.githubusercontent.com/1365881/188696769-d393cd45-b08f-4fd5-ad69-2d38a54bcd92.png)
2022-09-06 17:34:51 +00:00
Tobias Koppers
7df0c410fc improve HMR update performance (vercel/turbo#295)
* avoid cloning Strings and reading/calling many functions when building ecmascript chunk content
* introduce `ReadRef` to allow storing snapshot of a value in values
* use snapshot trees to allow caching more function calls and reads

Before:
```
updated in 35ms (18 tasks)
updated in 34ms (18 tasks)
updated in 37ms (18 tasks)
updated in 31ms (18 tasks)
updated in 40ms (19 tasks)
updated in 37ms (18 tasks)
updated in 37ms (18 tasks)
updated in 34ms (18 tasks)
updated in 35ms (18 tasks)
updated in 52ms (18 tasks)
```

After:
```
updated in 6.105ms (19 tasks)
updated in 5.279ms (18 tasks)
updated in 10.471ms (19 tasks)
updated in 6.863ms (18 tasks)
updated in 4.593ms (18 tasks)
updated in 4.173ms (18 tasks)
updated in 5.352ms (18 tasks)
updated in 10.69ms (18 tasks)
updated in 5.065ms (18 tasks)
updated in 6.309ms (19 tasks)
```

a 5x performance improvement
2022-09-06 14:02:07 +00:00
Will Binns-Smith
aab23b38da Parameterize devserver used in benchmarks (vercel/turbo#298)
This implements the basics of parameterizing the tool/devserver used in these tests. Following PRs will implement benchmarking of Vite, bun, Parcel, etc.

Test Plan: `cargo bench -p next-dev` and verify no change in performance.
2022-09-06 09:39:11 +00:00
Will Binns-Smith
7d79ce5029 Benchmark restart time for dev server (vercel/turbo#244)
This implements a benchmark of restarting the devserver after successfully starting it and shutting it down.

## Question/TODO: 

Since our goal is metrics that don't scale with project size, should we
assert that the small/medium benchmark results don't differ?

Test Plan: `cargo bench -p next-dev`
2022-09-06 08:30:08 +00:00
Will Binns-Smith
80d0a86655 Basic change bench for dev server (vercel/turbo#297)
This builds on vercel/turbo#240, starting up a server and then benchmarking the response to a small file change.

This change does not introduce nor remove any dependencies. A followup
benchmark should do so.

Test Plan: cargo bench -p next-dev


Co-authored-by: Tobias Koppers <1365881+sokra@users.noreply.github.com>
2022-09-06 07:34:25 +00:00
Tobias Koppers
d78084a0b4 Test benchmark cases in separate job (vercel/turbo#311)
Move benchmark test into separate job and run them for windows and macOS too
2022-09-06 06:48:01 +00:00
Alex Kirszenberg
e55a098efd CSS HMR (vercel/turbo#296)
Implements HMR for CSS chunks and paves the way for accepting HMR updates for the HTML entry point as well.
2022-09-03 11:38:14 +00:00
Tobias Koppers
42dda2f181 improve vizualization (vercel/turbo#225) 2022-08-30 16:31:35 +00:00
Alex Kirszenberg
1e8d63d10d Postfix join and try_join (vercel/turbo#300)
Instead of dropping back to prefix calling form in `try_join_all(iterator_of_intofutures).await?`, we now use postfix form `iterator_of_intofutures.try_join().await?`.
2022-08-30 15:15:06 +00:00
Will Binns-Smith
43f25065c8 Benchmarks: assert that no runtime errors occur when loading pages (vercel/turbo#285)
This adds an assertion that no runtime (browser) errors occurred when
loading a benchmark page.

Test Plan: Temporarily removed the npm install for the test app and
verified the benchmark failed as the test app requires react, react-dom.
Restored the npm install and verified the benchmark runs to completion.
2022-08-29 16:18:26 -07:00
Will Binns-Smith
2ee6039ad0 Benchmarks: Install node_modules and reuse test directories (vercel/turbo#284)
This:

* Runs `npm install` in test directories to provide turbopack with modules necessary to bundle them.
* Reuses test directories for iterations across the given benchmark. This prevents unnecessary file writing and `npm install` for each iteration, improving the times to run benchmarks.

Currently cherry-picks vercel/turbo#278 as it's necessary along with vercel/turbo#277.

Test Plan: Connected to the running devserver mid-test and confirmed no errors are thrown and the triangle is rendered correctly.
2022-08-29 15:41:26 -07:00
Alex Kirszenberg
8f54f35e90 HMR support + React Refresh (vercel/turbo#252)
This PR implements HMR support with React Refresh built-in.

For now, in order for React Refresh to be enabled, you'll need the `@next/react-refresh-utils` package to be resolveable: `yarn add @next/react-refresh-utils` in your app folder.

* Depends on vercel/turbo#266 
* Integrated both HMR-and-React-Refresh-specific logic directly into the ES chunks' runtime. Webpack has more complex setup here, but for now this makes the logic much more easy to follow since everything is in one place. I have yet to implement the "dependencies" signature for `hot.accept`/`hot.dispose`, since React Refresh does not depend on them. We'll have to see if they're even used in the wild or if we should deprecate them.
* Only implemented the [module API](https://webpack.js.org/api/hot-module-replacement/#module-api), not the [management API](https://webpack.js.org/api/hot-module-replacement/#management-api). We apply all updates as soon as we receive them.
* Added support for "runtime entries" to ES chunks. These are assets that will be executed *before* the main entry of an ES chunk. They'll be useful for polyfills in the future, but for now they're here to evaluate the react refresh runtime before any module is instantiated.

Next steps for HMR:
* Implement CSS HMR
* Implement (or decide to deprecate) the [dependencies form](https://webpack.js.org/api/hot-module-replacement/#accept) of `hot.accept`/`hot.dispose`
* Clean up `runtime.js` some more: switch to TypeScript, split into multiple files, etc. It'd be nice if all of this could be done at compile time, but how to achieve this is unclear at the moment. _Can we run turbopack to compile turbopack?_
2022-08-26 16:30:04 +00:00
Tobias Koppers
32d10a037a resolve entrypoint to allow it to select jsx automatically (vercel/turbo#278) 2022-08-26 11:26:58 +00:00
Tobias Koppers
3148d3b67b fix windows path separators (vercel/turbo#281) 2022-08-25 15:44:11 +00:00
Tobias Koppers
5156dcfc25 add root_dir to support monorepos (vercel/turbo#260)
This adds an option to pass the root dir from CLI, before it was always the current directory
2022-08-24 18:41:16 +00:00
Will Binns-Smith
e783ec8302 Benchmark startup time for bundling many modules (vercel/turbo#240)
* Basic startup bench for dev server

* fixes to benchmarking (vercel/turbo#268)

* use bench profile for benchmarking

* make setup and teardown not part of the measurement

add support for async setup and teardown

share browser between measurements

* updates for changes TestApp

Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
2022-08-24 11:36:08 -07:00
Justin Ridgewell
77e46e2670 Normalize Windows paths into Unix paths (vercel/turbo#251)
The snapshot tests were failing because Windows paths were sneaking into the `FileSystemPathVc::path`. Reviewing, the `::new` method didn't normalize `\` into `/`, and the various `::join` methods didn't either. This came up in both the chunk ids, and the request pathnames used by the server.

No path with backslash should enter the FileSystemPath APIs, they should be normalized during conversion from `Path` to `String`

Co-authored-by: Tobias Koppers <1365881+sokra@users.noreply.github.com>
2022-08-23 16:10:38 +00:00
Tobias Koppers
44eec9b9e0 only create pages for .js etc. files in pages (vercel/turbo#255) 2022-08-23 13:24:25 +00:00
Tobias Koppers
078f4d8191 Do not execute .css during server rendering (vercel/turbo#254)
Ignore any non-code chunks for server rendering
2022-08-23 11:47:39 +00:00
Tobias Koppers
4935008b88 single thread for test cases (vercel/turbo#264) 2022-08-22 16:02:09 +00:00
LongYinan
e16bd1b584 Group and prettier log messages (vercel/turbo#245)
### Default flags

`cargo run --bin node-file-trace -- build --context-directory crates/turbopack/tests/node-file-trace  ./crates/turbopack/tests/node-file-trace/integration/loopback.js`

<img width="1201" alt="image" src="https://user-images.githubusercontent.com/3468483/184812301-3aa644c8-edcc-43f5-9b07-1a0c11102d4b.png">

### `--show-all`

`cargo run --bin node-file-trace -- build --show-all --context-directory crates/turbopack/tests/node-file-trace  ./crates/turbopack/tests/node-file-trace/integration/loopback.js`

<img width="1435" alt="image" src="https://user-images.githubusercontent.com/3468483/184812439-14543700-f3c9-4b11-924b-68d6b42bd545.png">

### `--log-detail`

`cargo run --bin node-file-trace -- build --log-detail --context-directory crates/turbopack/tests/node-file-trace  ./crates/turbopack/tests/node-file-trace/integration/loopback.js`

<img width="1257" alt="image" src="https://user-images.githubusercontent.com/3468483/184812582-ab62ae77-2726-4387-872c-df38c4337d40.png">




Co-authored-by: Tobias Koppers <1365881+sokra@users.noreply.github.com>
2022-08-22 09:35:09 +00:00
Leah
c867a32ba1 fix: fs errors when running next-dev with pages (vercel/turbo#253) 2022-08-18 14:12:40 +00:00
Tobias Koppers
c7ff4150c8 fix consistency issues (vercel/turbo#224)
There are a bunch or problems with invalidations:

* The fs impl watches path case-insenstive. This means two paths might conflict when on a case-sensitive filesystem. It uses an array of Invalidators now
* Move the next-dev bootstrapping logic out of the run_once scope (which is not updated when invalidations occur). Instead it's executed inside the request handling resp. update stream where changes can be handled.
* `TransientValue` was not an Value type actually. This fixes that.
* Adds a new `TransientInstance` wrapper to pass transient by reference.
* `strongly_consistent` was broken when using nested TaskScopes. This fixes that.
2022-08-16 13:12:09 +00:00
Tobias Koppers
eab61f3c65 add basic next pages support (vercel/turbo#223)
Server Rendering:

* This adds an additional ContentSource to next-dev which takes care of handling the `pages` directory.
* The content source creates a ServerRenderedAsset from each file in the `src/pages` or `pages` directory and a AssetGraphContentSource for that.
* The ServerRenderedAsset will reference an underlying asset for the node.js context which will be passed to the node executable for rendering. It uses a WrapperAsset to add additional communication logic.

Client Transition:

* When annotating `import`s with `transition: "next-client"` the NextClientTransition is used
* This transition changes the environment to browser
* It wraps the referenced asset with a next-hyrdation wrapper asset
* It leaves a little module in the previous context which exports a list of URLs for chunks needed.
* The NextClientTransition takes a client_chunking_context as argument which specifies how the client code is chunked.
2022-08-15 17:26:37 +00:00
Will Binns-Smith
935e46f995 next-dev test runner: ask os for free port (vercel/turbo#238)
These integration tests have been flaky, failing when a "free" port turns out to be in use. Since nextest parallelizes test runs and portpicker guesses and checks free ports [0], I'm guessing that there's a collision occurring. 

Instead, ask the operating system for a free port by binding to port 0 and read the port back from the resulting address.

Test Plan: Tried local runs with nextest, but those succeeded before as well. I'll probably retry things on CI a few times.

[0] 912f913ac3/src/lib.rs (L53)
2022-08-12 21:21:21 +00:00
Will Binns-Smith
c2fb81dd37 next-dev test runner: Ensure skipped tests fail (vercel/turbo#216)
This adds test runs for integration tests in `__skipped__` directories,
ensuring that they fail, otherwise they should probably be unskipped.

Test Plan: Temporarily moved a succeeding test into a `__skipped__`
directory and ensured that cargo test began failing that test.
2022-08-11 09:39:32 -07:00
Will Binns-Smith
4778270305 next-dev test runner: Check in and use webpack's chunk test cases (vercel/turbo#212)
This commits webpack's chunk tests (test/cases/chunks) and skips those
that do not pass yet.

Test Plan: `cargo test -p next-dev -- --nocapture` and verify the
non-skipped tests run.
2022-08-11 09:33:25 -07:00
Alex Kirszenberg
1d8b74c655 Introduce FileContent, Versioned, and refactor dev server updates (vercel/turbo#209)
This prepares the way for HMR (vercel/turbo#160) by letting us diff assets between
versions.

1. Add `Asset::versioned_content` which returns a `VersionedContentVc`.
2. `VersionedContent`s have a built-in versioning mechanism as they must implement `version() -> VersionVc`. `Version` is a trait, so `VersionVc` can contain a specific version implementation by asset type. This is particularly important because... 
3. A `VersionedContentVc` can be diffed with a `VersionVc` from the same underlying `VersionedContent` type with `content.update(from: version)`. This returns an `UpdateVc` which describes the steps necessary to update from one verson to the next. In the case of ES chunks, this will be a map of added, and modified module IDs, with their respective factories, and a set of deleted module IDs.
4. Implement diffing for ES chunks.
2022-08-11 08:03:38 +00:00
Will Binns-Smith
51c69f20f8 next-dev test runner: Implement manual debug mode (vercel/turbo#211)
This implements a manual debug mode for next-dev tests, enabled by
setting the environment variable TURBOPACK_DEBUG_BROWSER to any value.

It launches the test browser in non-headless mode and holds it open
~~indefinitely~~ until the user closes it, so it can be inspected.

Test Plan: `TURBOPACK_DEBUG_BROWSER=1 cargo test -p next-dev --
test_crates_next_dev_tests_integration_chunks_circular_correctness
--nocapture` and verify the browser is opened non-headless and is held
open
2022-08-10 10:14:01 +00:00
Alex Kirszenberg
1a5d175d8d Update toolchain to 2022-08-02 (vercel/turbo#215)
* Update toolchain to 2022-08-02

* Fix warnings
2022-08-09 19:38:05 +02:00
Will Binns-Smith
7bd5321b09 next-dev test runner (vercel/turbo#172)
This is a very early version of the next-dev test runner. I'm opening this early to get thoughts from folks re: the direction of the design and implementation.

Fixes vercel/turbo#204 

Currently it:
* Discovers integration test fixtures from the filesystem. Right now these are expected to be single files that get bundled and will eventually include assertions. This is powered by the test-generator crate, which allows us not to have to manually enumerate each case. We could consider using this for the node-file-trace tests as well.
* Starts the dev server on a free port and opens a headless browser to its root. The browser control is implemented with the https://crates.io/crates/chromiumoxide crate, which expects Chrome or Chromium to already be available.

Eventually it will:
* [x] Implement a minimal test environment loaded in the browser so that assertions can be run there from bundled code.
* [x] Report back the results of these assertions to rust, where we can pass/fail cargo tests with those results.

In the future it could:
* Possibly include snapshot-style tests to assert on transformed results. This could be in the form of fixture directories instead of files cc @jridgewell
* Support expressing special configuration of turbopack in a fixture, possibly as another file in the fixture directory.
* [x] ~Possibly support distributing tests to a pool of open browsers instead of opening and closing for each test.~

Test Plan: See next PRs
2022-08-09 16:20:30 +00:00
Tobias Koppers
659a5fd83d add issue reporting to next dev (vercel/turbo#208) 2022-08-08 07:39:52 +00:00
Leah
1277c36e35 refactor turbo-tasks-macros (vercel/turbo#198)
Changes attribute/argument parsing to the more usual `field = "value"` / `turbo_tasks(trace_ignore)`
2022-08-05 06:26:22 +00:00
Leah
5e4ba91c7c rename ModuleAsset (vercel/turbo#206) 2022-08-05 06:20:42 +00:00
Leah
71429b9beb simplify turbo_tasks::value (vercel/turbo#196)
Removes the trait arguments and registers them separately
2022-08-04 21:58:32 +00:00
Leah
64bb520332 add open-browser option (vercel/turbo#199)
Fixes https://github.com/vercel/turbo-tooling/issues/171
2022-08-04 21:58:19 +00:00
Tobias Koppers
796f605301 track processing path for issues (vercel/turbo#205)
allow to attach context at any point

show processing path in output

move cli issue display into separate crate
2022-08-04 21:14:09 +00:00
Leah
1d4821382b fix css layer import (vercel/turbo#195)
kdy1 fixes this upstream
2022-08-03 03:37:56 +00:00
Will Binns-Smith
01a7e41834 Extract server creation into own function and module (vercel/turbo#191)
* Extract server creation into fn

* Use builder pattern and anyhow context
2022-08-02 16:28:11 -07:00
Alex Kirszenberg
8fad8a6881 Custom debug implementation for Vcs (vercel/turbo#193)
This PR builds our own `Debug`-like derive-macro machinery for formatting structs, relying on `std::fmt::Formatter` for the actual formatting.

### Usage

A new `ValueDebug` trait is automatically implemented for all `#[turbo_tasks::value]`s, which has a single `.dbg()` method which resolves to a debug representation that can then be printed to the screen. `#[turbo_tasks::value_trait]` also implement the `.dbg()` method directly.

```rust
dbg!(any_vc.dbg().await?);
```

If you have a `#[turbo_tasks::value]` struct with a field that doesn't implement `Debug`, you'll want to declare that field as `#[debug_ignore]`. For instance:

```rust
#[turbo_tasks::value(ContentSource, serialization: none, eq: manual, cell: new, into: new)]
pub struct TurboTasksSource {
    #[debug_ignore]
    #[trace_ignore]
    pub turbo_tasks: Arc<TurboTasks<MemoryBackend>>,
}
```

### Why not use `Debug` directly?

We can't use `Debug` because our values are resolved asynchronously and can nest `Vc`s arbitrarily. I tried using `futures::executor::block_on` to resolve them synchronously in a `Debug` implementation but that causes deadlocks.
2022-08-02 17:36:48 +00:00
Tobias Koppers
12d720ff48 refactor lazy asset to lazy graph content source (vercel/turbo#186) 2022-08-01 07:53:09 +00:00
Tobias Koppers
41c2dfd2de introduce ContentSource as source for the dev server (vercel/turbo#185)
and potentially a next build in future
2022-08-01 07:02:53 +00:00
Tobias Koppers
52557b1c4d introduce an Environment and track that for the graph and Assets (vercel/turbo#167) 2022-07-27 22:33:14 +00:00
Will Binns-Smith
45b409393d Move browser opening to next-dev cli (vercel/turbo#169)
Cherry-picking this from my work on the next-dev test runner.

This moves browser opening from the turbopack-dev-server crate into the next-dev crate, which has the cli entrypoint that runs the dev server. It looks like the dev server package is meant to be used as a library (it's only a library crate), and having this external side effect feels unexpected and makes it difficult to use this crate in situations like a test runner for next-dev, where we should test with a headless web browser.

Alternatively, opening the browser could be an option passed when creating the dev server, but this feels a bit cleaner to me.

Test Plan: `cargo run -p next-dev` and verify the browser still opens and successfully connects to the dev server.
2022-07-27 19:09:11 +00:00
Tobias Koppers
eb417b1e25 cleanup compile target (vercel/turbo#157) 2022-07-27 11:36:10 +02:00
Tobias Koppers
d4a50bfd0c reduce number of clippy warnings (vercel/turbo#164) 2022-07-27 08:13:29 +00:00
LongYinan
a55a831b39 Node Module Trace webpack plugin (vercel/turbo#140)
* Initialize Node.js/TypeScript workspace

* node-module-trace Webpack plugin

* Add new fmt checks to pipeline

* Popup unwind error

* Implement --exact flag

* Yarn 3.2.2

* Reformat toml files

* Fix socket io test, 100ms timeout is too long

* remove unnecessary CI cache config

* regenerate lockfile from old lockfile, align the dependencies version

* Run nmt tests in system tmp dir

* Apply code review suggestions

* allow to wait for task completion and propagate errors and panics

* revert method addition

* spawn_root_task should be sync

Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
2022-07-22 12:36:08 +02:00
Tobias Koppers
144e95bc4e allow to switch to eager compiling 2022-07-21 13:22:42 +02:00
Tobias Koppers
fb1bc5a55f make websocket task special as it never completes
aggregate timings before displaying
2022-07-20 19:49:27 +02:00
Tobias Koppers
a12541a06a add performance table 2022-07-19 10:54:53 +02:00
Justin Ridgewell
099e5c7c4b next-dev: Fix watching relative directories
Fixes vercel/turbo#107
2022-07-18 17:56:26 -04:00
Tobias Koppers
aa64055055 add util for formating durations 2022-07-18 21:39:55 +02:00
Tobias Koppers
f134e1104c fixup paths 2022-07-18 18:11:13 +02:00
Tobias Koppers
85ae4b5036 add bootstrap logic for chunks 2022-07-13 08:37:12 +02:00
Leah
2909fd07ca fmt 2022-07-12 17:17:23 +02:00
Leah
cd647d7fc4 match next dev args 2022-07-12 17:09:16 +02:00
Tobias Koppers
99e015c41f complete strongly consistent read
performance improvements
2022-07-08 15:05:51 +02:00
Tobias Koppers
878dd09578 improve visualization
make TransientValue functional
make console-subscriber an optional feature
avoid cloning when calling a function
capture timings of task executions
fix LazyAsset
expose graph from dev server
2022-07-08 14:52:28 +02:00
Tobias Koppers
89f6ad1151 cleanup and documentation 2022-06-30 13:54:04 +02:00
Leah
667507c5ca don't like these quoted names lol 2022-06-29 18:09:41 +02:00
Tobias Koppers
db41ef8432 place the persistent cache behind a feature flag 2022-06-29 09:40:11 +02:00
Tobias Koppers
54985ab83d chunking and bugfixes 2022-06-28 10:21:04 +02:00
Tobias Koppers
b3df7a862e abstract lazy graph into Asset decorator
enable watching for dev server
2022-06-14 12:53:46 +02:00
Tobias Koppers
e7c2d1e932 add initial dev-server and next-dev cli 2022-06-14 12:53:46 +02:00