Skip to content

Commit 94c7d8a

Browse files
authored
fix: improve invalid package version error handling (#159)
* chore: add test case for invalid package versions * fix: add improved errors for invalid package versions
1 parent 839215f commit 94c7d8a

3 files changed

Lines changed: 13 additions & 0 deletions

File tree

build/setup/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67019,6 +67019,10 @@ async function resolvePackage(name, range) {
6701967019
catch (error) {
6702067020
throw new Error(`Could not resolve ${name}@${range}, reason:\n${error.message || error}`);
6702167021
}
67022+
// thanks npm, for returning a "" json string value for invalid versions
67023+
if (!stdout) {
67024+
throw new Error(`Could not resolve ${name}@${range}, reason:\nInvalid version`);
67025+
}
6702267026
// thanks npm, for returning a "x.x.x" json value...
6702367027
if (stdout.startsWith('"')) {
6702467028
stdout = `[${stdout}]`;

src/packager.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ export async function resolvePackage(name: string, range: string): Promise<strin
1717
throw new Error(`Could not resolve ${name}@${range}, reason:\n${error.message || error}`);
1818
}
1919

20+
// thanks npm, for returning a "" json string value for invalid versions
21+
if (!stdout) {
22+
throw new Error(`Could not resolve ${name}@${range}, reason:\nInvalid version`);
23+
}
24+
2025
// thanks npm, for returning a "x.x.x" json value...
2126
if (stdout.startsWith('"')) {
2227
stdout = `[${stdout}]`;

tests/packager.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,8 @@ describe(resolvePackage, () => {
2222
'Could not resolve'
2323
);
2424
});
25+
26+
it('rejects expo-cli@9999999 with proper error', async () => {
27+
await expect(resolvePackage('expo-cli', '9999999')).rejects.toThrow('Could not resolve');
28+
});
2529
});

0 commit comments

Comments
 (0)