Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

Commit

Permalink
feat: can config to not sync deleted versions (#1282)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 authored Jan 7, 2018
1 parent 5e264be commit 4210b7b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
2 changes: 2 additions & 0 deletions config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ var config = {

// sync devDependencies or not, default is false
syncDevDependencies: false,
// try to remove all deleted versions from original registry
syncDeletedVersions: true,

// changes streaming sync
syncChangesStream: false,
Expand Down
25 changes: 17 additions & 8 deletions controllers/sync_module_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,10 @@ SyncModuleWorker.prototype._unpublished = function* (name, unpublishedInfo) {
this.log(' [%s] publish on local cnpm registry, don\'t sync', name);
return [];
}
if (!config.syncDeletedVersions) {
this.log(' [%s] `config.syncDeletedVersions=false`, don\'t sync unpublished info', name);
return [];
}

var r = yield packageService.saveUnpublishedModule(name, unpublishedInfo);
this.log(' [%s] save unpublished info: %j to row#%s',
Expand Down Expand Up @@ -879,16 +883,21 @@ SyncModuleWorker.prototype._sync = function* (name, pkg) {
}
}

if (deletedVersionNames.length === 0) {
that.log(' [%s] no versions need to deleted', name);
if (config.syncDeletedVersions) {
if (deletedVersionNames.length === 0) {
that.log(' [%s] no versions need to deleted', name);
} else {
that.log(' [%s] %d versions: %j need to deleted',
name, deletedVersionNames.length, deletedVersionNames);
try {
yield packageService.removeModulesByNameAndVersions(name, deletedVersionNames);
} catch (err) {
that.log(' [%s] delete error, %s: %s', name, err.name, err.message);
}
}
} else {
that.log(' [%s] %d versions: %j need to deleted',
that.log(' [%s] %d versions: %j need to deleted, but we won\'t delete them because `config.syncDeletedVersions=false`',
name, deletedVersionNames.length, deletedVersionNames);
try {
yield packageService.removeModulesByNameAndVersions(name, deletedVersionNames);
} catch (err) {
that.log(' [%s] delete error, %s: %s', name, err.name, err.message);
}
}

// sync missing descriptions
Expand Down

0 comments on commit 4210b7b

Please sign in to comment.