fix(init): align template package manager with user selection#1330
fix(init): align template package manager with user selection#1330benjamincanac wants to merge 1 commit into
Conversation
commit: |
atinux
left a comment
There was a problem hiding this comment.
Approving as I was involved in pair-programming on this one 😊
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThe PR adds package manager alignment to the init command. When a user initializes a new project and selects a package manager, the Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
is there a reason you don't want to remove the lockfile from the template? if it is because it contains workspace config |
|
@danielroe not sure to understand, it does remove the lockfile 🤔 https://github.com/nuxt/cli/pull/1330/changes#diff-02bf0f3c4f7503f4ebacc612fc62c0c6fc3d2e6fb806b5a52afdc72cd939a062R624 |
Templates may ship with a hardcoded `packageManager` field (e.g. `pnpm@x`), a lockfile and marker files (`pnpm-workspace.yaml`) that don't match the package manager the user picks during `nuxi init`. Detect the template's package manager and, on mismatch, drop its lockfile, marker files and the `packageManager` field so the install generates a fresh, correct lockfile. Co-Authored-By: Sébastien Chopin <atinux@gmail.com>
5b51db0 to
e44e97e
Compare
|
I mean, in the repository which is the template, rather than in nuxt/cli. |
|
Well yes all Nuxt UI templates are deployed on Vercel: https://github.com/nuxt-ui-templates/dashboard. I use renovate to keep the deps up-to-date on a weekly basis to make sure they continue working. It wouldn't be possible without a lockfile. |
|
it feels like the right fix is to ship a template without a lockfile in the first place, rather than remove it after the fact when nuxt/cli clones it. I understand you deploy it, and that's great, but how about deploying it without a lockfile? (that way you're always on the latest versions?) or you could have a separate branch or folder which didn't contain the lockfile. but it's about more than the lockfile. for example, if your the same might be true for other things and makes me wonder if we're approaching this the wrong way round by 'fixing' it in nuxt/cli. even if we make it work for that particular nuxt/ui template, I'm not sure it would be desired behaviour in general |
|
I don't think it's a good idea to ship a template without a lockfile, first of all it's not practical in development and since any release can break it is not a good experience for the user. It is fine for a starter with a This PR only removes the lockfile when the user chooses a different package manager than the one defined in the template. Should I close this then? |
|
Actually, most of the templates listed on https://nuxt.com/templates or https://hub.nuxt.com/templates also have lock files as this is the most convenient for any developers building a template. The case of a very specific workspace is very rare IMO, but we could display a |
Summary
Closes #1187.
Some starter templates (e.g. the Nuxt UI starter) ship with a hardcoded
packageManagerfield inpackage.json(likepnpm@x), plus apnpm-lock.yamlandpnpm-workspace.yaml. The package manager prompt innuxi initis seeded fromnpm_config_user_agent, not the template, so when you pick a different package manager none of that gets cleaned up. you end up with a project still pinned to pnpm even though you chose npm/yarn/bun, which can break installs and confuse later tooling.This adds an
alignPackageManagerstep that runs right after the package manager is resolved (before install):detectPackageManager(scoped to the template dir withincludeParentDirs: falseandignoreArgv: true)pnpm-workspace.yaml) so install generates a fresh, correct lockfile and nypm won't mis-detect the PM laterpackageManagerfield frompackage.jsonTest plan
packages/nuxi/test/unit/commands/init.spec.tscovering mismatch, match, lockfile-without-field, and no-pin casespnpm test