Skip to content

fix(cli): resolve pnpm catalog references in templates - #565

Open
kunalgoesbyken wants to merge 1 commit into
stackblitz-labs:mainfrom
kunalgoesbyken:fix/template-catalogs
Open

kunalgoesbyken wants to merge 1 commit into
stackblitz-labs:mainfrom
kunalgoesbyken:fix/template-catalogs

Conversation

@kunalgoesbyken

Copy link
Copy Markdown

Fixes #489

Templates passed with --template are uploaded with their package.json as-is, so catalog: specifiers reach StackBlitz unresolved and the install fails. --pnpm only helps for the published packages, because pnpm pack resolves catalogs there, but templates are never packed.

This change resolves catalog references in each template before upload, following pnpm's rules:

  • catalog: and catalog:default resolve from catalog, or from catalogs.default
  • catalog:<name> resolves from catalogs.<name>
  • applies to dependencies, devDependencies, peerDependencies and optionalDependencies
  • the workspace file is the pnpm-workspace.yaml nearest to the template (found with pkg-types' findNearestFile) and is parsed with confbox, which pkg-types already uses
  • specifiers with no matching catalog entry are kept unchanged, and templates outside a pnpm workspace are not touched

As before, the template's package.json is restored once its files are collected, and packages being published still get their pkg.pr.new URLs.

Testing

  • packages/cli/catalog.test.ts covers the default catalog, catalogs.default, named catalogs across all dependency fields, unresolvable specifiers and the no-workspace case
  • Ran the built CLI with fetch mocked on a fixture workspace (vite: "catalog:", react: "catalog:react18", lib: "workspace:*"). Before the fix the uploaded template kept catalog:; after it, it gets ^6.0.0 and ^18.3.1, lib still points to its pkg.pr.new URL, and the template's package.json on disk is restored afterward
  • pnpm run lint:js, pnpm run lint:format and pnpm install --frozen-lockfile pass

This branch has not been deployed

No deployments
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.

--template does not resolve pnpm catalog: references before uploading to StackBlitz

1 participant