feat: generate cache-life types during next build#90146
feat: generate cache-life types during next build#90146bgub wants to merge 1 commit intovercel:canaryfrom
Conversation
Previously, custom cacheLife profile types were generated during dev (setup-dev-bundler) and via `next typegen`, but not during `next build`. This adds the missing call so production builds also emit `.next/types/cache-life.d.ts` when cacheLife profiles are configured. Also replaces the magic number 0xfffffffe with the INFINITE_CACHE constant in cache-life-type-utils.ts for consistency with the rest of the codebase.
|
Allow CI Workflow Run
Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer |
There was a problem hiding this comment.
Pull request overview
This PR addresses a gap in type generation by ensuring that cache-life type definitions are generated during production builds, not just in development mode and via the next typegen command. It also improves code maintainability by replacing a magic number with a named constant.
Changes:
- Added cache-life type generation to production builds in
build/index.ts - Replaced magic number
0xfffffffewithINFINITE_CACHEconstant across multiple comparisons incache-life-type-utils.ts - Added
cacheLifeConfigfield toRouteTypesManifestinterface and a wrapper functionwriteCacheLifeTypesFileinroute-types-utils.ts
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/next/src/build/index.ts | Generates cache-life.d.ts during production builds when cacheLife profiles are configured |
| packages/next/src/server/lib/router-utils/route-types-utils.ts | Adds cacheLifeConfig field to manifest interface and wrapper function for writing cache-life types |
| packages/next/src/server/lib/router-utils/cache-life-type-utils.ts | Replaces magic number with INFINITE_CACHE constant for better code clarity |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| export async function writeCacheLifeTypesFile( | ||
| manifest: RouteTypesManifest, | ||
| filePath: string | ||
| ) { | ||
| writeCacheLifeTypes(manifest.cacheLifeConfig, filePath) | ||
| } |
There was a problem hiding this comment.
The writeCacheLifeTypesFile function is declared as async but does not await anything. The underlying writeCacheLifeTypes function uses synchronous file operations (fs.writeFileSync). This creates an inconsistency with other similar functions in this file like writeRouteTypesManifest and writeValidatorFile which use fs.promises.writeFile and are truly async.
Either:
- Remove the
asynckeyword fromwriteCacheLifeTypesFile(and removeawaitwhen calling it in build/index.ts), OR - Update
writeCacheLifeTypesin cache-life-type-utils.ts to use async file operations and await it here
Option 2 would be more consistent with the other write functions in this file.
eps1lon
left a comment
There was a problem hiding this comment.
Why isn't that going through the same codepaths as next typegen
|
@eps1lon sorry, will address that. I meant but forgot to switch the PR to a draft -- it's not quite ready for review yet. |
Summary
writeCacheLifeTypesFilefrombuild/index.tsso production builds emit.next/types/cache-life.d.tswhen customcacheLifeprofiles are configuredsetup-dev-bundler) and vianext typegen, leaving a gap for production builds0xfffffffeincache-life-type-utils.tswith theINFINITE_CACHEconstant for consistencyTest plan
pnpm test-unit packages/next/src/server/lib/router-utils/cache-life-type-utils.test.ts.next/types/cache-life.d.tsis generated afternext buildwhencacheLifeprofiles are defined innext.config.js