Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: get package available version error #4220

Merged
merged 1 commit into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/tender-balloons-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@modern-js/generator-utils': patch
---

fix: get package available version error

fix: 修复获取包可用版本时报错
14 changes: 9 additions & 5 deletions packages/generator/generator-utils/src/utils/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ import { canUseNpm, execa, logger, semver, stripAnsi } from '@modern-js/utils';
// 判断包是否存在
export async function isPackageExist(packageName: string, registry?: string) {
if (await canUseNpm()) {
const args = ['view', packageName, 'version'];
if (registry) {
args.push(`--registry=${registry}`);
try {
const args = ['view', packageName, 'version'];
if (registry) {
args.push(`--registry=${registry}`);
}
const result = await execa('npm', args);
return stripAnsi(result.stdout);
} catch (e) {
return false;
}
const result = await execa('npm', args);
return stripAnsi(result.stdout);
}
throw new Error('not found npm, please install npm before');
}
Expand Down
Loading