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(
|
async function bumpWorkspaceVersions(
|
||||||
{rootPackage, packages}: Workspaces,
|
{rootPackage, packages}: Workspaces,
|
||||||
newVersion?: string,
|
newVersion?: string,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
newVersion = newVersion || (rootPackage.json.version as string);
|
newVersion = newVersion || (rootPackage.json.version as string);
|
||||||
if (rootPackage.json.version !== newVersion) {
|
const allPackages = [rootPackage, ...packages];
|
||||||
rootPackage.json.version = newVersion;
|
|
||||||
await savePackageJson(rootPackage);
|
|
||||||
}
|
|
||||||
const localPackageNames = packages.map(({json}) => json.name as string);
|
const localPackageNames = packages.map(({json}) => json.name as string);
|
||||||
for (const pkg of packages) {
|
for (const pkg of allPackages) {
|
||||||
const json = pkg.json;
|
const json = pkg.json;
|
||||||
let changed = false;
|
let changed = false;
|
||||||
if (json.version !== newVersion) {
|
if (json.version !== newVersion) {
|
||||||
json.version = newVersion;
|
json.version = newVersion;
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
if (json.dependencies) {
|
if (updateDependencies(json.dependencies, localPackageNames, newVersion)) {
|
||||||
for (const localPackageName of localPackageNames) {
|
|
||||||
if (
|
|
||||||
json.dependencies[localPackageName] !== undefined &&
|
|
||||||
json.dependencies[localPackageName] !== newVersion
|
|
||||||
) {
|
|
||||||
json.dependencies[localPackageName] = newVersion;
|
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
}
|
if (
|
||||||
|
updateDependencies(json.devDependencies, localPackageNames, newVersion)
|
||||||
|
) {
|
||||||
|
changed = true;
|
||||||
}
|
}
|
||||||
if (changed) {
|
if (changed) {
|
||||||
await savePackageJson(pkg);
|
await savePackageJson(pkg);
|
||||||
|
|||||||
Reference in New Issue
Block a user