Files
Benjamin Woodruff ‮ 469a7c5573 Turbopack: Add symlinks and additional roots to NFT metadata (#98469)
Implements the following extension:

```typescript
export interface NftFileList {
  // File paths relative to the directory containing the `.nft.json` file, or
  // the current root (if inside of `NftAdditionalRoot`).
  //
  // When using webpack, these paths may exist outside of the tracing root. The
  // [`@vercel/next` package ignores these paths][vc-next].
  //
  // When using Turbopack, these paths are all guaranteed to exist within the
  // `turbopack.root` specified or inferred from the `next.config.js` file.
  //
  // [vc-next]: https://github.com/vercel/vercel/blob/%40vercel/next%404.20.5/packages/next/src/server-build.ts#L1022-L1026
  files: string[]
  // Turbopack extension: A parallel array to `files` (same indices and length)
  // with file content hashes. For symlinks, the hash of the path of the target
  // is stored.
  fileHashes?: string[]
  // Turbopack extension: Explicit symlink mapping information.
  //
  // If included, it's safe to assume that if a file is not in `symlinks` that
  // it is not a symlink. If this is an empty array, there are no symlinks.
  //
  // If omitted, the processor of the nft file must call `read_link` on every
  // file to determine if it is a symlink and determine the target path.
  //
  // This field is always included if `NftJson` includes `additionalRoots`, and
  // it is always included on `NftAdditionalRoot`.
  symlinks?: NftSymlink[]
}

export interface NftJson extends NftFileList {
  version: 1
  // Turbopack extension: A hash of the entrypoint that refers to these traced
  // files. This hash only depends on the content of the entrypoint file, and
  // not all of its traced dependencies.
  entryHash?: string
  // Turbopack extension: Paths stored with different base paths, typically
  // outside of the tracing root.
  additionalRoots?: NftAdditionalRoot[]
}

// Turbopack extension: A collection of paths stored with a different base path.
export interface NftAdditionalRoot extends NftFileList {
  // Stable unique identifier provided in the `next.config.js`. This can be used
  // to generate the output path where these files are copied to (e.g.
  // `.additionalRoots/$[name}`).
  //
  // This is guaranteed to use a character set that is valid on most
  // filesystems, and the identifiers are guaranteed to not have overlaps on
  // case-insensitive filesystems.
  name: string
  // A source path on the build machine that the paths in `files` are relative
  // to. The final build output directory should not depend on this path.
  absolutePath: string
  // Always specified on NftAdditionalRoot.
  symlinks: NftSymlink[]
}

// Turbopack extension: Information on a symlink, including which additional
// root it maps to. Symlinks that do not cross root boundaries (the common case)
// omit the index into `additionalRoots`.
//
// It is often complicated to transform raw symlink targets to root-relative
// paths, and including this information here ensures that the NFT reader gets
// the same result that Turbopack's tracing system expects.
//
// Because the link target type is unspecified, on Windows the reader needs to
// call `stat` to determine if a link target is a directory or file.
export type NftSymlink =
  | [
      // Index of `files` that refers to a symlink.
      number,
      // The target path of the link. In `NftJson`, this path is relative to the
      // directory containing the `.nft.json` file. In `NftAdditionalRoot`, this
      // is relative to the current root.
      string,
    ]
  | [
      // Index of `files` that refers to a symlink.
      number,
      // The target path of the link relative to the specified root.
      string,
      // An index into `additionalRoots`, -1 if the target path is relative to
      // the `.nft.json` file's directory,
      //
      // If the symlink target is relative to the same root as the symlink
      // itself (the "current root"), this field is omitted.
      number,
    ]
```

Nothing currently populates `additionalRoots`.
https://github.com/vercel/next.js/pull/98003 will do it.
2026-09-18 17:08:39 -07:00
..