Skip to content

[build-utils] Handle case of not having lockfile#11697

Merged
kodiakhq[bot] merged 5 commits intomainfrom
austinmerrick/zero-2103-package-manager-cli-type-detection-should-take-into-account
Jun 5, 2024
Merged

[build-utils] Handle case of not having lockfile#11697
kodiakhq[bot] merged 5 commits intomainfrom
austinmerrick/zero-2103-package-manager-cli-type-detection-should-take-into-account

Conversation

@onsclom
Copy link
Contributor

@onsclom onsclom commented Jun 4, 2024

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.

@changeset-bot
Copy link

changeset-bot bot commented Jun 4, 2024

🦋 Changeset detected

Latest commit: 7f34f89

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@vercel/build-utils Patch
vercel Patch
@vercel/client Patch
@vercel/gatsby-plugin-vercel-builder Patch
@vercel/node Patch
@vercel/static-build Patch
@vercel-internals/types Patch

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

@onsclom onsclom changed the title [built-utils] Handle case of not having lockfile [build-utils] Handle case of not having lockfile Jun 4, 2024
@erikareads
Copy link
Contributor

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:

  1. we can just use process.env inside the function
  2. we can change the call signature to include env
  3. we can change the call signature to include corepackEnabled or some boolean

in this PR, we chose to move forward with 1.

EndangeredMassa
EndangeredMassa previously approved these changes Jun 5, 2024
return 'npm';
default:
throw new Error(
`Unknown package manager "${corepackPackageManager?.packageName}". Change your package.json "packageManager" field to a known package manager.`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
`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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@kodiakhq kodiakhq bot merged commit 06d2d86 into main Jun 5, 2024
@kodiakhq kodiakhq bot deleted the austinmerrick/zero-2103-package-manager-cli-type-detection-should-take-into-account branch June 5, 2024 20:23
kodiakhq bot pushed a commit that referenced this pull request Jun 6, 2024
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))
EndangeredMassa pushed a commit that referenced this pull request Jun 7, 2024
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants