Skip to content

Commit

Permalink
feat: upgrade generator support handle special package (#4839)
Browse files Browse the repository at this point in the history
  • Loading branch information
caohuilin authored Oct 24, 2023
1 parent ce967bb commit c90a91a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
7 changes: 7 additions & 0 deletions .changeset/witty-turkeys-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@modern-js/upgrade-generator': patch
---

feat: upgrade generator support handle special package

feat: upgrade 生成器支持处理特殊的插件包版本
45 changes: 35 additions & 10 deletions packages/generator/generators/upgrade-generator/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
execa,
semver,
fs,
isPackageExist,
getPackageVersion,
} from '@modern-js/generator-utils';
import {
PackageManager,
Expand All @@ -20,6 +22,17 @@ import {
} from '@modern-js/generator-common';
import { i18n, localeKeys } from './locale';

// Special modern.js dependencies, the plugin version maybe not same with other modern.js plugin
const SpecialModernDeps = ['@modern-js/plugin-storybook'];

const handleSpecialModernDeps = async (dep: string, modernVersion: string) => {
const version = await getAvailableVersion(dep, modernVersion);
if (!(await isPackageExist(`${dep}@${version}`))) {
return getPackageVersion(dep);
}
return version;
};

export const handleTemplateFile = async (
context: GeneratorContext,
generator: GeneratorCore,
Expand Down Expand Up @@ -124,23 +137,35 @@ export const handleTemplateFile = async (
}).start();

await Promise.all(
modernDeps.map(
async dep =>
(updateInfo[`dependencies.${dep}`] = await getAvailableVersion(
modernDeps.map(async dep => {
if (SpecialModernDeps.includes(dep)) {
updateInfo[`dependencies.${dep}`] = await handleSpecialModernDeps(
dep,
modernVersion,
);
} else {
updateInfo[`dependencies.${dep}`] = await getAvailableVersion(
dep,
modernVersion,
)),
),
);
}
}),
);

await Promise.all(
modernDevDeps.map(
async dep =>
(updateInfo[`devDependencies.${dep}`] = await getAvailableVersion(
modernDevDeps.map(async dep => {
if (SpecialModernDeps.includes(dep)) {
updateInfo[`devDependencies.${dep}`] = await handleSpecialModernDeps(
dep,
modernVersion,
)),
),
);
} else {
updateInfo[`devDependencies.${dep}`] = await getAvailableVersion(
dep,
modernVersion,
);
}
}),
);
await jsonAPI.update(
context.materials.default.get(path.join(appDir, 'package.json')),
Expand Down

0 comments on commit c90a91a

Please sign in to comment.