[build-utils] Handle case of not having lockfile#11697
Conversation
🦋 Changeset detectedLatest commit: 7f34f89 The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The cliType is determined in scanParentDirs (https://github.com/vercel/vercel/blob/main/packages/build-utils/src/fs/run-user-scripts.ts#L355) this function doesn't get passed in the env which makes it harder to detect whether corepack is enabled. this gives us a few options:
in this PR, we chose to move forward with 1. |
| return 'npm'; | ||
| default: | ||
| throw new Error( | ||
| `Unknown package manager "${corepackPackageManager?.packageName}". Change your package.json "packageManager" field to a known package manager.` |
There was a problem hiding this comment.
suggestion (soft-blocking): mention the known package managers
Errors like these are useful, but they can be more so if you tell the user what the valid values are in the message.
| `Unknown package manager "${corepackPackageManager?.packageName}". Change your package.json "packageManager" field to a known package manager.` | |
| `Unknown package manager "${corepackPackageManager?.packageName}". Change your package.json "packageManager" field to a known package manager: npm, pnpm, yarn, bun.` |
This does make the list a bit brittle, though. We could extract it further into a single source of truth for that list, but I don't think we need to go that far right here.
| const packageJsonPackageManager = packageJson.packageManager; | ||
| if (usingCorepack(process.env, packageJsonPackageManager)) { | ||
| const corepackPackageManager = validateVersionSpecifier( | ||
| packageJsonPackageManager as string |
There was a problem hiding this comment.
suggestion (soft-blocking): tweak types
Oh, this was complaining because of type checking before? I think we can have validateVersionSpecifier accept a string | undefined instead. I prefer not to use as anywhere, if possible. It damages the type safety of the program--in a small way, but still non-zero.
Two minor improvements missed from the review of #11697: - [Include supported package manager names in error message](#11697 (comment)) - [Avoid `as` to improve type safety](#11697 (comment))
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## @vercel/build-utils@8.2.2 ### Patch Changes - Change node 16.x EOL for Vercel ([#11704](#11704)) - Improve error message and refactor ([#11706](#11706)) - [built-utils] Handle case of not having lockfile when corepack is enabled ([#11697](#11697)) ## vercel@34.2.6 ### Patch Changes - [built-utils] Handle case of not having lockfile when corepack is enabled ([#11697](#11697)) - Updated dependencies \[[`5c12ed695`](5c12ed6), [`21444a38e`](21444a3), [`fa9789a93`](fa9789a), [`c925dc4a1`](c925dc4), [`06d2d860e`](06d2d86), [`b735f37fd`](b735f37)]: - @vercel/build-utils@8.2.2 - @vercel/next@4.2.16 - @vercel/redwood@2.0.10 - @vercel/remix-builder@2.1.7 - @vercel/node@3.1.7 - @vercel/static-build@2.5.11 ## @vercel/client@13.2.9 ### Patch Changes - Updated dependencies \[[`5c12ed695`](5c12ed6), [`21444a38e`](21444a3), [`06d2d860e`](06d2d86)]: - @vercel/build-utils@8.2.2 ## @vercel/gatsby-plugin-vercel-builder@2.0.33 ### Patch Changes - Updated dependencies \[[`5c12ed695`](5c12ed6), [`21444a38e`](21444a3), [`06d2d860e`](06d2d86)]: - @vercel/build-utils@8.2.2 ## @vercel/next@4.2.16 ### Patch Changes - prevent /index from being incorrectly normalized in rewrites ([#11707](#11707)) - Upgrade to @vercel/nft 0.27.2 with browser remapping support ([#11700](#11700)) - ensure unmatched rsc rewrites are routed to correct handler ([#11688](#11688)) ## @vercel/node@3.1.7 ### Patch Changes - Upgrade to @vercel/nft 0.27.2 with browser remapping support ([#11700](#11700)) - Updated dependencies \[[`5c12ed695`](5c12ed6), [`21444a38e`](21444a3), [`06d2d860e`](06d2d86)]: - @vercel/build-utils@8.2.2 ## @vercel/redwood@2.0.10 ### Patch Changes - Upgrade to @vercel/nft 0.27.2 with browser remapping support ([#11700](#11700)) ## @vercel/remix-builder@2.1.7 ### Patch Changes - Upgrade to @vercel/nft 0.27.2 with browser remapping support ([#11700](#11700)) ## @vercel/static-build@2.5.11 ### Patch Changes - Updated dependencies \[]: - @vercel/gatsby-plugin-vercel-builder@2.0.33 ## @vercel-internals/types@1.0.38 ### Patch Changes - Updated dependencies \[[`5c12ed695`](5c12ed6), [`21444a38e`](21444a3), [`06d2d860e`](06d2d86)]: - @vercel/build-utils@8.2.2 Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
In the scenario where we don't have a lockfile, cliType was detected by build utils as npm regardless of what's set in corepack. This fixes that.