Commit Graph

9 Commits

Author SHA1 Message Date
Will Binns-Smith 12bf495e0e Expand Turbopack dev cleanup (#97833)
## Summary

Builds on #97591. Webpack currently removes most of `.next` on devserver
startup. We can remove more as well.

This keeps the age-based removal introduced in #97591 and expands it to
`traces`, logs, etc. However, for any other directory that is not
`cache` or `lock`, completely remove it on startup. This includes types,
etc.

Apply age-based deletion to Turbopack-owned output that can be restored
from cache or recomputed, including route entries, chunks, assets,
service workers, middleware, and instrumentation. Completely remove
other dev output so logs, traces, generated types, diagnostics, and
future framework-owned output cannot be left as mixed generations.

Use exact-path exclusion sets in `recursiveDeleteSyncWithAsyncRetries`.
The complete pass retains `cache`, `lock`, and Turbopack-owned paths;
the age-based pass then sweeps those Turbopack paths. Both passes finish
before project creation.

## Verification

- `pnpm test-unit test/unit/recursive-delete.test.ts`
- `pnpm --filter=next types`

---------

Co-authored-by: vercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
Co-authored-by: Will Binns-Smith <755844+wbinnssmith@users.noreply.github.com>
2026-08-27 14:54:23 -07:00
Will Binns-Smith 2cee98ab97 Sweep stale Turbopack output from distDir on dev startup (#97591)
## Summary

Turbopack dev never removes the content-hashed chunks it supersedes, so
`.next/dev` grows without bound. Webpack dev avoids this by wiping
`distDir` on every start.

Adds a `maxAgeMs` argument to `recursiveDeleteSyncWithAsyncRetries`:
delete files whose mtime is at least that old, remove directories once
empty. Turbopack dev passes one week.

## Verification

- `pnpm test-unit test/unit/recursive-delete.test.ts`
- ~Not run:~ dev-server behavior against a real `.next/dev`

<!-- NEXT_JS_LLM -->
2026-08-24 14:19:25 -07:00
Benjamin Woodruff 3e65babdea perf: Use synchronous IO when cleaning distDir in next dev and next build (#84472)
This is blocking the critical path for starting `next build` (on both webpack and Turbopack) and `next dev` (only on webpack).

## Testing

Run

```
pnpm next build --turbopack --experimental-build-mode compile
```

a couple of times in `~/front/apps/conf-2025` (small-medium size app).

### Before

![Screenshot 2025-10-02 at 3.09.31 PM.png](https://app.graphite.dev/user-attachments/assets/ad56ebc1-a9dd-4b18-ba51-50435c9e6584.png)

### After

![Screenshot 2025-10-02 at 3.03.25 PM.png](https://app.graphite.dev/user-attachments/assets/39170ed1-7379-48ac-aeed-638b57322a6a.png)
2025-10-03 13:06:01 -07:00
Benjamin Woodruff f53da71313 perf: Use a more aggressive retry loop for recursiveDelete (#84444)
**Update:** This also fixes a bug pointed out by Graphite where the deletion function could hang forever because the `t` variable used for tracking attempts wasn't properly incremented.

---

https://vercel.slack.com/archives/C04KC8A53T7/p1759360239193629

This is a critical path for `next dev` and `next build` initialization.

On Windows, it's quite common to get an error while trying to recursively delete directories for one of two reasons:

**Temporarily open files:**
1. You open the directory.
2. The user's AV detects the directory as opened and quickly scans the files in that directory.
3. You try to delete a file, but on Windows, files cannot be deleted when open.

**Deletion is not instant/atomic:** It can take some time after deleting files for the directory to become empty.

For this reason, we perform two retries with a 100ms delay after the first attempt and a 200ms delay after the second attempt.

* Node does not use retries by default, but has an option to do so with a `100ms * attemptNumber` (linear backoff) delay, similar to what we do: https://github.com/nodejs/node/blob/b5638e1765d3d1241d07457e767f27e3ee6b9dd2/lib/internal/fs/utils.js#L774-L779
* Node used to use 3 retries by default, but that was changed in v14: https://github.com/nodejs/node/commit/7e85f068a48b284a253abcb5eb3173320869b8fe
* Rust tries to delete 64 times in a loop without sleeping, but with a call to `thread::yield_now`: https://github.com/rust-lang/rust/blob/4da69dfff1929cc79872b3d05ab7112d84753dba/library/std/src/sys/fs/windows/remove_dir_all.rs#L154-L171

In the vein of reducing time spent sleeping in the critical initialization path (@timneutkens), I think we should be more aggressive, I'm thinking using a 10ms delay (arbitrary number), but with an exponential backoff, so that we still retry over the same 300ms period as we currently do? Thoughts?

The difficulty is that this is on Windows, so it's hard for me to get good numbers about what impact this would have (if any).
2025-10-02 13:08:46 -07:00
Wyatt Johnson 0f822373ee File Reader Improvements (#54645)
This replaces the existing recursive directory reading beheviour with a more efficient implementation. Rather than previously doing actual recursion with the function calls to go deeper into each directory, this has been rewritten to instead use a while loop and a stack. This should improve memory usage for projects with very deep directory structures. 

The updated design that performs directory scanning on all directories found at each layer, allowing more filesystem calls to be sent to the OS instead of waiting like the previous implementation did.

**Currently the new implementation is about 3x faster.**
2023-08-28 18:09:56 +00:00
JJ Kasper 975fb1f466 Fix windows unit tests (#53412)
Fixes differences in tests to handle windows now that we've fixed them
not being run.

x-ref:
https://github.com/vercel/next.js/pull/53408/checks?check_run_id=15501915673
2023-07-31 18:06:18 -07:00
Jiachi Liu 36ca1598d5 Support static file robots.txt and sitemap.xml as metadata route (#46963)
Support top level static `robots.txt` and `sitemap.xml` as metadata
route in app directory. When those files are placed in top root
directory

Refactored a bit the page files matching logic, to reuse it between dev
server and build

Closes NEXT-267
2023-03-09 11:10:18 -08:00
JJ Kasper eb7b40171a Add initial standalone build handling (#31003)
* Add initial standalone handling

* apply suggestions

* Apply suggestions from code review

Co-authored-by: Steven <steven@ceriously.com>
2021-11-09 11:03:20 -06:00
JJ Kasper 005b13f1ac Move unit tests to one folder and migrate them to TypeScript (#28427)
* Move unit tests to one folder

* Migrate unit tests to TypeScript

* add test types to lint

* Ensure ts(x) tests are run with util

* Add tsx extension to jest config

* bump
2021-08-24 07:52:45 -05:00