Commit Graph

3 Commits

Author SHA1 Message Date
Sebastian "Sebbie" Silbermann 2aba93f005 [scripts] Write pnpm overrides for pnpm projects in pack/patch helpers (#94747) 2026-06-22 17:12:14 +02:00
Tobias Koppers 9c939729d1 Fix preview tarball script to include @next/swc-linux-x64-gnu (#91099)
### What?

Adds `@next/swc-linux-x64-gnu` to the preview tarball patching script
(`scripts/patch-preview-tarball.mjs`):

1. Adds the package to the `PACKAGES_TO_PATCH` list so its tarball URL
is fetched.
2. Adds the package as an explicit dependency in the patched
`package.json`, in addition to the overrides/resolutions.

### Why?

The `@next/swc-linux-x64-gnu` native binary package is an optional
dependency of `next` and may not be installed automatically depending on
the platform/package manager. When testing preview tarballs (e.g., in CI
or on Linux environments), the SWC binary needs to be explicitly present
for Next.js to function correctly. Without this change, preview tarball
testing on Linux x64 could fail because the native binary isn't resolved
from the preview build.

Adding it as a direct dependency (not just an override/resolution)
ensures the package manager actually installs it, since optional
dependencies from overridden tarballs may not be auto-resolved.

### How?

- Added `'@next/swc-linux-x64-gnu'` to the `PACKAGES_TO_PATCH` array so
the script fetches its tarball URL.
- After writing overrides/resolutions, the script now also adds
`@next/swc-linux-x64-gnu` as an explicit entry in `pkg.dependencies`
pointing to the tarball URL.

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 14:32:12 +01:00
Tobias Koppers 5e965bbb2d Add script to patch project with preview tarball URLs (#91057)
### What?

Adds a new script `scripts/patch-preview-tarball.mjs` that patches a
target project's `package.json` to use Next.js preview tarballs from
`vercel-packages.vercel.app`.

### Why?

When testing unreleased Next.js changes against external projects (e.g.,
reproducing bugs, verifying fixes), there's no convenient way to point a
project at a specific Next.js commit's build artifacts. This script
automates the process of wiring up preview tarball URLs into a project's
dependency overrides.

### How?

The script:

1. **Resolves a commit SHA** via one of three methods:
   - `--commit <sha>` — use an explicit commit
- `--branch <name>` — look up the branch tip via the GitHub API (`gh`)
   - *(default)* — use the local `git rev-parse HEAD`

2. **Builds tarball URLs** for `next`, `@next/mdx`, `@next/env`, and
`@next/bundle-analyzer` using the
`vercel-packages.vercel.app/next/commits/<sha>/<pkg>` pattern.

3. **Verifies** that the preview tarball exists (HEAD request to the
`next` tarball URL).

4. **Patches `package.json`** in the target project (or its workspace
root) by setting both `overrides` (npm/pnpm) and `resolutions` (yarn)
for the packages.

**Usage:**

```bash
node scripts/patch-preview-tarball.mjs --project <path> [--commit <sha> | --branch <name>]
```
2026-03-09 10:13:48 +01:00