From 101c9b30b5e3c45b251e847a4bd562782fbd8152 Mon Sep 17 00:00:00 2001 From: fengmk2 <suqian.yf@antgroup.com> Date: Tue, 14 May 2024 14:46:26 +0800 Subject: [PATCH] fix: allow to disable sync unpkg files (#679) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added a new configuration option `enableSyncUnpkgFiles` for enhanced synchronization control. - **Improvements** - Improved synchronization logic to check both `enableUnpkg` and `enableSyncUnpkgFiles` settings before proceeding. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- app/core/event/SyncPackageVersionFile.ts | 2 ++ app/port/config.ts | 4 ++++ config/config.default.ts | 1 + 3 files changed, 7 insertions(+) diff --git a/app/core/event/SyncPackageVersionFile.ts b/app/core/event/SyncPackageVersionFile.ts index 6cf38c61..5dc7d20d 100644 --- a/app/core/event/SyncPackageVersionFile.ts +++ b/app/core/event/SyncPackageVersionFile.ts @@ -16,7 +16,9 @@ class SyncPackageVersionFileEvent { private readonly packageVersionFileService: PackageVersionFileService; protected async syncPackageVersionFile(fullname: string, version: string) { + // must set enableUnpkg and enableSyncUnpkgFiles = true both if (!this.config.cnpmcore.enableUnpkg) return; + if (!this.config.cnpmcore.enableSyncUnpkgFiles) return; // ignore sync on unittest if (this.config.env === 'unittest' && fullname !== '@cnpm/unittest-unpkg-demo') return; const [ scope, name ] = getScopeAndName(fullname); diff --git a/app/port/config.ts b/app/port/config.ts index 8a763afe..867f2424 100644 --- a/app/port/config.ts +++ b/app/port/config.ts @@ -145,6 +145,10 @@ export type CnpmcoreConfig = { * enable unpkg features, https://github.com/cnpm/cnpmcore/issues/452 */ enableUnpkg: boolean, + /** + * enable sync unpkg files + */ + enableSyncUnpkgFiles: boolean; /** * enable this would make sync specific version task not append latest version into this task automatically,it would mark the local latest stable version as latest tag. * in most cases, you should set to false to keep the same behavior as source registry. diff --git a/config/config.default.ts b/config/config.default.ts index cc6729a0..1c090583 100644 --- a/config/config.default.ts +++ b/config/config.default.ts @@ -53,6 +53,7 @@ export const cnpmcoreConfig: CnpmcoreConfig = { syncNotFound: false, redirectNotFound: true, enableUnpkg: true, + enableSyncUnpkgFiles: true, strictSyncSpecivicVersion: false, enableElasticsearch: !!process.env.CNPMCORE_CONFIG_ENABLE_ES, elasticsearchIndex: 'cnpmcore_packages',