storybook [Bug]: npx sb@latest升级后取消固定依赖项

zsbz8rwp  于 4个月前  发布在  其他
关注(0)|答案(1)|浏览(35)

描述bug

如果你在 package.json 中固定了依赖项

"@storybook/addon-essentials": "8.1.5",
"@storybook/addon-interactions": "8.1.5",
"@storybook/addon-links": "8.1.5",
"@storybook/blocks": "8.1.5",
"@storybook/preview-api": "8.1.5",
"@storybook/react": "8.1.5",
"@storybook/react-vite": "8.1.5",
"@storybook/test": "8.1.5",
"@storybook/theming": "8.1.5",
"@storybook/types": "8.1.5",
"storybook": "8.1.5",

当运行 npx sb@latest upgrade 时,依赖项应该保持固定。

"@storybook/addon-essentials": "8.2.2",
"@storybook/addon-interactions": "8.2.2",
"@storybook/addon-links": "8.2.2",
"@storybook/blocks": "8.2.2",
"@storybook/preview-api": "8.2.2",
"@storybook/react": "8.2.2",
"@storybook/react-vite": "8.2.2",
"@storybook/test": "8.2.2",
"@storybook/theming": "8.2.2",
"@storybook/types": "8.2.2",
"storybook": "8.2.2",

但它目前在版本前添加了一个 ^ 的插入符号:

"@storybook/addon-essentials": "^8.2.2",
"@storybook/addon-interactions": "^8.2.2",
"@storybook/addon-links": "^8.2.2",
"@storybook/blocks": "^8.2.2",
"@storybook/preview-api": "^8.2.2",
"@storybook/react": "^8.2.2",
"@storybook/react-vite": "^8.2.2",
"@storybook/test": "^8.2.2",
"@storybook/theming": "^8.2.2",
"@storybook/types": "^8.2.2",
"storybook": "^8.2.2",

复现链接

https://storybook.js.org/docs/configure/upgrading

复现步骤

  1. 在 package.json 中使用之前版本的 storybook 固定依赖项
  2. 运行 npx sb@latest upgrade

系统

Storybook Environment Info:

  System:
    OS: macOS 14.5
    CPU: (12) arm64 Apple M2 Pro
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.11.0 - ~/.nvm/versions/node/v20.11.0/bin/node
    npm: 10.8.1 - ~/.nvm/versions/node/v20.11.0/bin/npm <----- active
    pnpm: 8.1.0 - ~/.nvm/versions/node/v20.11.0/bin/pnpm
  Browsers:
    Chrome: 126.0.6478.127
    Safari: 17.5
  npmPackages:
    @storybook/addon-essentials: 8.2.2 => 8.2.2 
    @storybook/addon-interactions: 8.2.2 => 8.2.2 
    @storybook/addon-links: 8.2.2 => 8.2.2 
    @storybook/blocks: 8.2.2 => 8.2.2 
    @storybook/preview-api: 8.2.2 => 8.2.2 
    @storybook/react: 8.2.2 => 8.2.2 
    @storybook/react-vite: 8.2.2 => 8.2.2 
    @storybook/test: 8.2.2 => 8.2.2 
    @storybook/theming: 8.2.2 => 8.2.2 
    @storybook/types: 8.2.2 => 8.2.2 
    chromatic: 11.5.5 => 11.5.5 
    eslint-plugin-storybook: 0.8.0 => 0.8.0 
    storybook: 8.2.2 => 8.2.2 
    storybook-dark-mode: 4.0.2 => 4.0.2 
    storybook-react-i18next: 3.1.1 => 3.1.1

其他上下文

  • 无响应*
zsohkypk

zsohkypk1#

免责声明

由于信息是自动生成的,可能存在不准确的情况。
为了解决升级过程中未固定依赖项的问题,请修改 upgrade.ts 中的 doUpgrade 函数,使其遵循 package.json 中现有的版本格式。具体来说,更新 toUpgradedDependencies 函数以检查当前版本是否已固定并保持该格式。以下是操作步骤:

  1. upgrade.ts 中,找到 toUpgradedDependencies 函数。
  2. 修改该函数以保留现有的版本格式:
const toUpgradedDependencies = (deps: Record<string, any>) => {
  const monorepoDependencies = Object.keys(deps || {}).filter((dependency) => {
    return dependency in versions;
  }) as Array<keyof typeof versions>;
  return monorepoDependencies.map((dependency) => {
    const currentVersion = deps[dependency];
    const isPinned = !currentVersion.startsWith('^');
    const newVersion = versions[dependency];
    return `${dependency}@${isPinned ? '' : '^'}${newVersion}`;
  });
};
  1. 更新 upgrade.test.ts 中的测试用例,包括具有固定依赖项的场景,并验证升级是否保持了固定格式。

参考资料

/code/lib/cli/src/upgrade.ts
/code/lib/cli/src/upgrade.test.ts

关于 Greptile

此响应为您提供研究起点,而非精确解决方案。
帮助我们改进!如果这有帮助,请留下一个 👍,如果无关紧要,请留下一个 👎。

相关问题