Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed May 18, 2024
1 parent e23080b commit 344bf2d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 6 additions & 2 deletions app/core/event/SyncPackageVersionFile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Event, Inject } from '@eggjs/tegg';
import {
EggAppConfig,
EggAppConfig, EggLogger,
} from 'egg';
import { ForbiddenError } from 'egg-errors';
import { PACKAGE_VERSION_ADDED, PACKAGE_TAG_ADDED, PACKAGE_TAG_CHANGED } from './index';
Expand All @@ -12,6 +12,8 @@ class SyncPackageVersionFileEvent {
@Inject()
protected readonly config: EggAppConfig;
@Inject()
protected readonly logger: EggLogger;
@Inject()
private readonly packageManagerService: PackageManagerService;
@Inject()
private readonly packageVersionFileService: PackageVersionFileService;
Expand All @@ -30,7 +32,9 @@ class SyncPackageVersionFileEvent {
await this.packageVersionFileService.syncPackageVersionFiles(packageVersion);
} catch (err) {
if (err instanceof ForbiddenError) {
// ignore it
this.logger.info('[SyncPackageVersionFileEvent.syncPackageVersionFile] ignore sync files, cause: %s',
err.message,
);
return;
}
throw err;
Expand Down
5 changes: 3 additions & 2 deletions app/core/service/PackageVersionFileService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,14 @@ export class PackageVersionFileService extends AbstractService {
}
}

async updateUnpkgWhiteList() {
async #updateUnpkgWhiteList() {
if (!this.config.cnpmcore.enableSyncUnpkgFilesWhiteList) return;
const whiteListScope = '';
const whiteListPackageName = 'unpkg-white-list';
const whiteListPackageVersion = await this.packageVersionRepository.findVersionByTag(
whiteListScope, whiteListPackageName, 'latest');
if (!whiteListPackageVersion) return;
// same version, skip update for performance
if (this.#unpkgWhiteListCurrentVersion === whiteListPackageVersion) return;

// update the new version white list
Expand All @@ -104,7 +105,7 @@ export class PackageVersionFileService extends AbstractService {

async #checkPackageVersionInUnpkgWhiteList(pkgScope: string, pkgName: string, pkgVersion: string) {
if (!this.config.cnpmcore.enableSyncUnpkgFilesWhiteList) return;
await this.updateUnpkgWhiteList();
await this.#updateUnpkgWhiteList();

// check allow scopes
if (this.#unpkgWhiteListAllowScopes.includes(pkgScope)) return;
Expand Down

0 comments on commit 344bf2d

Please sign in to comment.