Skip to content

Commit ac4d9df

Browse files
fix(create-email): validate npm registry response and exit on invalid version (#3741)
Signed-off-by: Tyagiquamar <mohdquamartyagi@gmail.com> Co-authored-by: Felipe Freitag <felipe.freitag@resend.com>
1 parent 2a6e13a commit ac4d9df

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-email": patch
3+
---
4+
5+
Exit with an error when the npm registry request fails or returns an invalid version, instead of writing `undefined` into the starter's package.json.

‎packages/create-email/src/index.js‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,24 @@ const getLatestVersionOfTag = async (packageName, tag) => {
1919
const response = await fetch(
2020
`https://registry.npmjs.org/${packageName}/${tag}`,
2121
);
22-
const data = await response.json();
2322

24-
if (typeof data === 'string' && data.startsWith('version not found')) {
23+
if (response.status === 404) {
2524
console.error(`Tag ${tag} does not exist for ${packageName}.`);
2625
process.exit(1);
2726
}
2827

29-
const { version } = data;
28+
if (!response.ok) {
29+
console.error(
30+
`Failed to fetch tag ${tag} for ${packageName}: HTTP ${response.status}`,
31+
);
32+
process.exit(1);
33+
}
3034

31-
if (!/^\d+\.\d+\.\d+.*$/.test(version)) {
35+
const { version } = await response.json();
36+
37+
if (!version || !/^\d+\.\d+\.\d+.*$/.test(version)) {
3238
console.error('Invalid version received, something has gone very wrong.');
39+
process.exit(1);
3340
}
3441

3542
return version;

0 commit comments

Comments
 (0)