Fixed version bumping for devDependencies
Summary: Fixed bumping versions for local packages added as devDependencies Reviewed By: passy Differential Revision: D21154758 fbshipit-source-id: 234fdf073b9bc166eb9deb78a879bc1380d0d1bc
This commit is contained in:
committed by
Facebook GitHub Bot
parent
4b54eb3ec6
commit
75fb681eb8
@@ -68,33 +68,48 @@ async function savePackageJson({dir, json}: Package) {
|
||||
});
|
||||
}
|
||||
|
||||
function updateDependencies(
|
||||
dependencies: {[key: string]: string},
|
||||
packagesToUpdate: string[],
|
||||
newVersion: string,
|
||||
): boolean {
|
||||
if (!dependencies) {
|
||||
return false;
|
||||
}
|
||||
let updated = false;
|
||||
for (const packageName of packagesToUpdate) {
|
||||
if (
|
||||
dependencies[packageName] !== undefined &&
|
||||
dependencies[packageName] !== newVersion
|
||||
) {
|
||||
dependencies[packageName] = newVersion;
|
||||
updated = true;
|
||||
}
|
||||
}
|
||||
return updated;
|
||||
}
|
||||
|
||||
async function bumpWorkspaceVersions(
|
||||
{rootPackage, packages}: Workspaces,
|
||||
newVersion?: string,
|
||||
): Promise<string> {
|
||||
newVersion = newVersion || (rootPackage.json.version as string);
|
||||
if (rootPackage.json.version !== newVersion) {
|
||||
rootPackage.json.version = newVersion;
|
||||
await savePackageJson(rootPackage);
|
||||
}
|
||||
const allPackages = [rootPackage, ...packages];
|
||||
const localPackageNames = packages.map(({json}) => json.name as string);
|
||||
for (const pkg of packages) {
|
||||
for (const pkg of allPackages) {
|
||||
const json = pkg.json;
|
||||
let changed = false;
|
||||
if (json.version !== newVersion) {
|
||||
json.version = newVersion;
|
||||
changed = true;
|
||||
}
|
||||
if (json.dependencies) {
|
||||
for (const localPackageName of localPackageNames) {
|
||||
if (
|
||||
json.dependencies[localPackageName] !== undefined &&
|
||||
json.dependencies[localPackageName] !== newVersion
|
||||
) {
|
||||
json.dependencies[localPackageName] = newVersion;
|
||||
if (updateDependencies(json.dependencies, localPackageNames, newVersion)) {
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if (
|
||||
updateDependencies(json.devDependencies, localPackageNames, newVersion)
|
||||
) {
|
||||
changed = true;
|
||||
}
|
||||
if (changed) {
|
||||
await savePackageJson(pkg);
|
||||
|
||||
Reference in New Issue
Block a user