返回提示词目录第 1501 页

迁移前端项目包管理工具

盘点并迁移包管理配置与锁文件,核对依赖版本变化,同步更新构建部署流程并验证运行结果。

完整提示词

<context>
A package manager switch looks like swapping one command for another, but the real risks are an accidental upgrade of hundreds of transitive dependencies and code that only worked because of npm-style hoisting. What experienced people know: regenerating a lockfile from scratch re-resolves every range, so convert the existing lockfile instead (pnpm and Yarn can import an npm lockfile; Bun reads existing lockfiles on first install) and diff resolved versions afterwards. pnpm's strict `node_modules` exposes phantom dependencies (packages imported but not declared), which then fail at runtime or build; the fix is declaring them, with `public-hoist-pattern` or a hoisted linker as a temporary escape hatch. Yarn Berry defaults to Plug'n'Play, which many tools do not support, so `nodeLinker: node-modules` is the usual first step. Workspaces are declared differently (`pnpm-workspace.yaml` vs the `workspaces` field), the `workspace:` protocol changes publishing, and overrides use different keys (`overrides`, `resolutions`, `pnpm.overrides`). Recent pnpm versions do not run dependency install scripts unless the package is allowed, and Bun runs them only for trusted packages (its own default list plus those you add), which can break native modules quietly. The `packageManager` field pins the tool for Corepack and some hosts. Frozen-lockfile install commands differ per tool, and CI caches, Dockerfiles and deploy platforms each detect the package manager their own way.
</context>

<task>
Switch this project to {{target}}.
{{#notes}}
Notes:
{{notes}}
{{/notes}}

1. Inventory every place the current tool is assumed: lockfiles, `packageManager`, `.npmrc` or `.yarnrc*`, workspace config, overrides or resolutions, scripts calling the tool by name (`npm run`, `npx`, `yarn`), Dockerfiles, CI workflows and caches, deploy platform settings, docs and git hooks.
2. Record the baseline: install with the current frozen-lockfile command, run build and tests, and save a list of resolved package versions.
3. Convert the lockfile with the target tool's import or migration path rather than deleting it. Set `packageManager` and any required settings (linker mode, allowed build scripts, registry and auth).
4. Map workspaces, overrides and peer dependency settings to the target format. Translate scripts that call the old tool.
5. Install, then compare resolved versions with the baseline. Explain every change in a direct dependency, and any large transitive drift; pin back where needed.
6. Fix phantom dependency failures by declaring the missing packages in the right workspace. Use hoisting settings only as a documented temporary measure.
7. Update Dockerfiles, CI install commands and caches, deploy settings and contributor docs. Remove the old lockfile and config only after builds and tests pass.
8. Run build, tests and a production-like start, in CI as well as locally.
</task>

<constraints>
- Do not delete the old lockfile and resolve from scratch unless the user accepts the version drift that causes.
- Do not paper over strict-mode failures with blanket hoisting without listing what it hides.
- Do not run install scripts from packages the project did not run before without saying so.
- Never print or commit registry tokens from `.npmrc` files.

{{> guardrails/verify-before-done}}
{{> guardrails/scope-discipline}}
</constraints>

<output_format>
## Starting point
Current tool and version, workspace layout, every place it is referenced.
## Differences that matter
Hoisting, install scripts, workspace protocol, overrides: what applies here.
## Changes made
Files added, changed and removed; commands mapped.
## Version parity
Direct dependency changes and notable transitive drift, with reasons.
## Verification
Install, build, test and CI results; Docker image build.
</output_format>

可替换内容

  • {{target}}
  • {{#notes}}
  • {{notes}}
  • {{/notes}}
  • {{> guardrails/verify-before-done}}
  • {{> guardrails/scope-discipline}}

分类与标签

编程开发、包管理器迁移、锁文件转换、工作区配置、持续集成、依赖版本核对

前往 AI 图片创作