Skip to content

Commit

Permalink
fix: install failure on pnpm deploy when using catalogs
Browse files Browse the repository at this point in the history
  • Loading branch information
gluxon committed Jul 10, 2024
1 parent a2e9bdc commit 1ac91e8
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg-manager/plugin-commands-installation/src/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ export type InstallCommandOptions = Pick<Config,
| 'autoInstallPeers'
| 'bail'
| 'bin'
| 'catalogs'
| 'cliOptions'
| 'dedupeDirectDeps'
| 'dedupePeerDependents'
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions releasing/plugin-commands-deploy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
"@pnpm/workspace.filter-packages-from-dir": "workspace:*"
},
"dependencies": {
"@pnpm/catalogs.resolver": "workspace:*",
"@pnpm/catalogs.types": "workspace:*",
"@pnpm/cli-utils": "workspace:*",
"@pnpm/common-cli-options-help": "workspace:*",
"@pnpm/directory-fetcher": "workspace:*",
Expand Down
4 changes: 3 additions & 1 deletion releasing/plugin-commands-deploy/src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import { FILTERING } from '@pnpm/common-cli-options-help'
import { PnpmError } from '@pnpm/error'
import rimraf from '@zkochan/rimraf'
import renderHelp from 'render-help'
import { deployHook } from './deployHook'
import { deployCatalogHook, deployHook } from './deployHook'
import { logger } from '@pnpm/logger'
import { resolveFromCatalog } from '@pnpm/catalogs.resolver'

Check failure on line 14 in releasing/plugin-commands-deploy/src/deploy.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 20

'resolveFromCatalog' is defined but never used

Check failure on line 14 in releasing/plugin-commands-deploy/src/deploy.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 18.12

'resolveFromCatalog' is defined but never used

Check failure on line 14 in releasing/plugin-commands-deploy/src/deploy.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 18.12

'resolveFromCatalog' is defined but never used

Check failure on line 14 in releasing/plugin-commands-deploy/src/deploy.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 20

'resolveFromCatalog' is defined but never used

Check failure on line 14 in releasing/plugin-commands-deploy/src/deploy.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 21

'resolveFromCatalog' is defined but never used

Check failure on line 14 in releasing/plugin-commands-deploy/src/deploy.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 21

'resolveFromCatalog' is defined but never used

export const shorthands = install.shorthands

Expand Down Expand Up @@ -101,6 +102,7 @@ export async function handler (
readPackage: [
...(opts.hooks?.readPackage ?? []),
deployHook,
deployCatalogHook.bind(null, opts.catalogs ?? {}),
],
},
frozenLockfile: false,
Expand Down
27 changes: 27 additions & 0 deletions releasing/plugin-commands-deploy/src/deployHook.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { matchCatalogResolveResult, resolveFromCatalog } from '@pnpm/catalogs.resolver'
import { type Catalogs } from '@pnpm/catalogs.types'
import { type ProjectManifest, DEPENDENCIES_FIELDS } from '@pnpm/types'

export function deployHook (pkg: ProjectManifest): ProjectManifest {
Expand All @@ -13,3 +15,28 @@ export function deployHook (pkg: ProjectManifest): ProjectManifest {
}
return pkg
}

export function deployCatalogHook (catalogs: Catalogs, pkg: ProjectManifest): ProjectManifest {
for (const depField of DEPENDENCIES_FIELDS) {
const depsBlock = pkg[depField]

if (depsBlock == null) {
continue
}

for (const [alias, pref] of Object.entries(depsBlock)) {
matchCatalogResolveResult(resolveFromCatalog(catalogs, { alias, pref }), {
unused: () => undefined,
misconfiguration: (result) => {
throw result.error
},

found: (result) => {
depsBlock[alias] = result.resolution.specifier
},
})
}
}

return pkg
}
6 changes: 6 additions & 0 deletions releasing/plugin-commands-deploy/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
{
"path": "../../__utils__/prepare"
},
{
"path": "../../catalogs/resolver"
},
{
"path": "../../catalogs/types"
},
{
"path": "../../cli/cli-utils"
},
Expand Down

0 comments on commit 1ac91e8

Please sign in to comment.