Skip to content

Commit

Permalink
fix: stdout bug when zero dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
narol1024 committed Jun 3, 2024
1 parent 6d50ef8 commit e810897
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion jest-global-mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const dependantsHtml = `
stdout: `{ "@vue/shared": "3.4.27", "@vue/compiler-dom": "3.4.27", "@vue/compiler-sfc": "3.4.27", "@vue/runtime-dom": "3.4.27", "@vue/server-renderer": "3.4.27" }`,
});
} else {
callback(null, { stdout: '{}' });
callback(null, { stdout: '' });
}
});

Expand Down
8 changes: 7 additions & 1 deletion src/platforms/npm-package/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ export async function readNpmPackageDependencies(packageName: string): Promise<N
const npmViewPromise = execAsync(`npm view ${packageName} dependencies --json`).then(
(result: any): Promise<void> => {
try {
const resultJson = JSON.parse(result.stdout) as any;
const resultStdout = result.stdout;
// it means zero dependency.
if (resultStdout === '') {
resolve([]);
return Promise.resolve();
}
const resultJson = JSON.parse(resultStdout) as any;
if (!!resultJson.error) {
throw new Error(`Cannot read ${packageName}.`);
}
Expand Down

0 comments on commit e810897

Please sign in to comment.