Skip to content

Commit bc573fc

Browse files
Copilotjaviercn
andcommitted
Add error handling to npm version command in pack-workspace script
Co-authored-by: javiercn <[email protected]>
1 parent 4eee291 commit bc573fc

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

eng/scripts/npm/update-dependency-versions.mjs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,18 @@ function applyPackageVersion(packagesToPack, defaultPackageVersion) {
5252
renames.push([`${packagePath}.bak`, packagePath]);
5353

5454
process.chdir(packageDir);
55-
execSync(`npm version ${packageVersion} --no-git-tag-version --allow-same-version`, { stdio: 'inherit' });
55+
try {
56+
execSync(`npm version ${packageVersion} --no-git-tag-version --allow-same-version`, { stdio: 'inherit' });
57+
console.log(`Applied version ${packageVersion} to ${packageName} in ${packageDir}...`);
58+
} catch (error) {
59+
console.warn(`Failed to run npm version command for ${packageName}, falling back to manual version update...`);
60+
// Fallback: manually update the version in package.json
61+
const packageJson = fs.readJsonSync(packagePath);
62+
packageJson.version = packageVersion;
63+
fs.writeJsonSync(packagePath, packageJson, { spaces: 2 });
64+
console.log(`Manually applied version ${packageVersion} to ${packageName} in ${packageDir}...`);
65+
}
5666
process.chdir(currentDir);
57-
console.log(`Applied version ${packageVersion} to ${packageName} in ${packageDir}...`);
5867
}
5968

6069
return renames;

0 commit comments

Comments
 (0)