Skip to content

Commit

Permalink
refactor: unpublish logic (#467)
Browse files Browse the repository at this point in the history
> Adjust the logic for unpublishing a package
* 🧶 Determine if a call to unpublish within the removePackageVersion
function
* ♻️ Remove`forceRefresh` in unpublishPackage
-------
> 调整 unpublish package 逻辑
* 🧶 removePackageVersion 内判断是否需要调用 unpublish
* ♻️ unpublishPackage 删除 forceRefresh 逻辑
  • Loading branch information
elrrrrrrr committed May 18, 2023
1 parent 0a5b0c7 commit 80ab054
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions app/core/service/PackageManagerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,10 +504,10 @@ export class PackageManagerService extends AbstractService {
await this.packageRepository.removePackageVersion(pkgVersion);
}

public async unpublishPackage(pkg: Package, forceRefresh = false) {
public async unpublishPackage(pkg: Package) {
const pkgVersions = await this.packageRepository.listPackageVersions(pkg.packageId);
// already unpublished
if (pkgVersions.length === 0 && !forceRefresh) {
if (pkgVersions.length === 0) {
this.logger.info(`[packageManagerService.unpublishPackage:skip] ${pkg.packageId} already unpublished`);
return;
}
Expand All @@ -533,8 +533,14 @@ export class PackageManagerService extends AbstractService {
}

public async removePackageVersion(pkg: Package, pkgVersion: PackageVersion, skipRefreshPackageManifests = false) {
const currentVersions = await this.packageRepository.listPackageVersionNames(pkg.packageId);
// only one version, unpublish the package
if (currentVersions.length === 1 && currentVersions[0] === pkgVersion.version) {
await this.unpublishPackage(pkg);
return;
}
// remove version & update tags
await this._removePackageVersionAndDist(pkgVersion);
// all versions removed
const versions = await this.packageRepository.listPackageVersionNames(pkg.packageId);
if (versions.length > 0) {
let updateTag: string | undefined;
Expand All @@ -555,8 +561,6 @@ export class PackageManagerService extends AbstractService {
}
return;
}
// unpublish
await this.unpublishPackage(pkg, true);
}

public async savePackageTag(pkg: Package, tag: string, version: string, skipEvent = false) {
Expand Down

0 comments on commit 80ab054

Please sign in to comment.