Skip to content

Commit

Permalink
fix: dup clz name (#711)
Browse files Browse the repository at this point in the history
> https://github.com/eggjs/tegg/pull/242/files 
* 🤖 Updated the duplicate class name, fix the error when dev.
------
> https://github.com/eggjs/tegg/pull/242/files 
* 🤖 修改同名 class 名称定义,修复本地启动报错 

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Enhanced clarity in event handling by renaming various package-related
event classes for better understanding.

- **Bug Fixes**
- Updated test cases to reflect the renamed event classes, ensuring
accurate functionality in the testing framework.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
elrrrrrrr authored Oct 10, 2024
1 parent e6ed221 commit f7c49e5
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 34 deletions.
22 changes: 11 additions & 11 deletions app/core/event/CacheCleaner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,77 +24,77 @@ class CacheCleanerEvent {
}

@Event(PACKAGE_UNPUBLISHED)
export class PackageUnpublished extends CacheCleanerEvent {
export class PackageUnpublishedCacheCleanEvent extends CacheCleanerEvent {
async handle(fullname: string) {
await this.removeCache(fullname);
}
}

@Event(PACKAGE_BLOCKED)
export class PackageBlocked extends CacheCleanerEvent {
export class PackageBlockedCacheCleanEvent extends CacheCleanerEvent {
async handle(fullname: string) {
await this.removeCache(fullname);
}
}

@Event(PACKAGE_UNBLOCKED)
export class PackageUnblocked extends CacheCleanerEvent {
export class PackageUnblockedCacheCleanEvent extends CacheCleanerEvent {
async handle(fullname: string) {
await this.removeCache(fullname);
}
}

@Event(PACKAGE_VERSION_ADDED)
export class PackageVersionAdded extends CacheCleanerEvent {
export class PackageVersionAddedCacheCleanEvent extends CacheCleanerEvent {
async handle(fullname: string) {
await this.removeCache(fullname);
}
}

@Event(PACKAGE_VERSION_REMOVED)
export class PackageVersionRemoved extends CacheCleanerEvent {
export class PackageVersionRemovedCacheCleanEvent extends CacheCleanerEvent {
async handle(fullname: string) {
await this.removeCache(fullname);
}
}

@Event(PACKAGE_TAG_ADDED)
export class PackageTagAdded extends CacheCleanerEvent {
export class PackageTagAddedCacheCleanEvent extends CacheCleanerEvent {
async handle(fullname: string) {
await this.removeCache(fullname);
}
}

@Event(PACKAGE_TAG_CHANGED)
export class PackageTagChanged extends CacheCleanerEvent {
export class PackageTagChangedCacheCleanEvent extends CacheCleanerEvent {
async handle(fullname: string) {
await this.removeCache(fullname);
}
}

@Event(PACKAGE_TAG_REMOVED)
export class PackageTagRemoved extends CacheCleanerEvent {
export class PackageTagRemovedCacheCleanEvent extends CacheCleanerEvent {
async handle(fullname: string) {
await this.removeCache(fullname);
}
}

@Event(PACKAGE_MAINTAINER_CHANGED)
export class PackageMaintainerChanged extends CacheCleanerEvent {
export class PackageMaintainerChangedCacheCleanEvent extends CacheCleanerEvent {
async handle(fullname: string) {
await this.removeCache(fullname);
}
}

@Event(PACKAGE_MAINTAINER_REMOVED)
export class PackageMaintainerRemoved extends CacheCleanerEvent {
export class PackageMaintainerRemovedCacheCleanEvent extends CacheCleanerEvent {
async handle(fullname: string) {
await this.removeCache(fullname);
}
}

@Event(PACKAGE_META_CHANGED)
export class PackageMetaChanged extends CacheCleanerEvent {
export class PackageMetaChangedCacheCleanEvent extends CacheCleanerEvent {
async handle(fullname: string) {
await this.removeCache(fullname);
}
Expand Down
18 changes: 9 additions & 9 deletions app/core/event/ChangesStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ChangesStreamEvent {
}

@Event(PACKAGE_UNPUBLISHED)
export class PackageUnpublished extends ChangesStreamEvent {
export class PackageUnpublishedChangesStreamEvent extends ChangesStreamEvent {
async handle(fullname: string) {
const change = await this.addChange(PACKAGE_UNPUBLISHED, fullname, {});
if (this.hookEnable) {
Expand All @@ -55,7 +55,7 @@ export class PackageUnpublished extends ChangesStreamEvent {
}

@Event(PACKAGE_VERSION_ADDED)
export class PackageVersionAdded extends ChangesStreamEvent {
export class PackageVersionAddedChangesStreamEvent extends ChangesStreamEvent {
async handle(fullname: string, version: string, tag?: string) {
const change = await this.addChange(PACKAGE_VERSION_ADDED, fullname, { version });
if (this.hookEnable) {
Expand All @@ -66,7 +66,7 @@ export class PackageVersionAdded extends ChangesStreamEvent {
}

@Event(PACKAGE_VERSION_REMOVED)
export class PackageVersionRemoved extends ChangesStreamEvent {
export class PackageVersionRemovedChangesStreamEvent extends ChangesStreamEvent {
async handle(fullname: string, version: string, tag?: string) {
const change = await this.addChange(PACKAGE_VERSION_REMOVED, fullname, { version });
if (this.hookEnable) {
Expand All @@ -77,7 +77,7 @@ export class PackageVersionRemoved extends ChangesStreamEvent {
}

@Event(PACKAGE_TAG_ADDED)
export class PackageTagAdded extends ChangesStreamEvent {
export class PackageTagAddedChangesStreamEvent extends ChangesStreamEvent {
async handle(fullname: string, tag: string) {
const change = await this.addChange(PACKAGE_TAG_ADDED, fullname, { tag });
if (this.hookEnable) {
Expand All @@ -88,7 +88,7 @@ export class PackageTagAdded extends ChangesStreamEvent {
}

@Event(PACKAGE_TAG_CHANGED)
export class PackageTagChanged extends ChangesStreamEvent {
export class PackageTagChangedChangesStreamEvent extends ChangesStreamEvent {
async handle(fullname: string, tag: string) {
const change = await this.addChange(PACKAGE_TAG_CHANGED, fullname, { tag });
if (this.hookEnable) {
Expand All @@ -99,7 +99,7 @@ export class PackageTagChanged extends ChangesStreamEvent {
}

@Event(PACKAGE_TAG_REMOVED)
export class PackageTagRemoved extends ChangesStreamEvent {
export class PackageTagRemovedChangesStreamEvent extends ChangesStreamEvent {
async handle(fullname: string, tag: string) {
const change = await this.addChange(PACKAGE_TAG_REMOVED, fullname, { tag });
if (this.hookEnable) {
Expand All @@ -110,7 +110,7 @@ export class PackageTagRemoved extends ChangesStreamEvent {
}

@Event(PACKAGE_MAINTAINER_CHANGED)
export class PackageMaintainerChanged extends ChangesStreamEvent {
export class PackageMaintainerChangedChangesStreamEvent extends ChangesStreamEvent {
async handle(fullname: string, maintainers: User[]) {
const change = await this.addChange(PACKAGE_MAINTAINER_CHANGED, fullname, {});
// TODO 应该比较差值,而不是全量推送
Expand All @@ -124,7 +124,7 @@ export class PackageMaintainerChanged extends ChangesStreamEvent {
}

@Event(PACKAGE_MAINTAINER_REMOVED)
export class PackageMaintainerRemoved extends ChangesStreamEvent {
export class PackageMaintainerRemovedChangesStreamEvent extends ChangesStreamEvent {
async handle(fullname: string, maintainer: string) {
const change = await this.addChange(PACKAGE_MAINTAINER_REMOVED, fullname, { maintainer });
if (this.hookEnable) {
Expand All @@ -135,7 +135,7 @@ export class PackageMaintainerRemoved extends ChangesStreamEvent {
}

@Event(PACKAGE_META_CHANGED)
export class PackageMetaChanged extends ChangesStreamEvent {
export class PackageMetaChangedChangesStreamEvent extends ChangesStreamEvent {
async handle(fullname: string, meta: PackageMetaChange) {
const change = await this.addChange(PACKAGE_META_CHANGED, fullname, { ...meta });
const { deprecateds } = meta;
Expand Down
2 changes: 1 addition & 1 deletion app/core/event/StoreManifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class StoreManifestEvent {
}

@Event(PACKAGE_VERSION_ADDED)
export class PackageVersionAdded extends StoreManifestEvent {
export class PackageVersionAddedStoreManifestEvent extends StoreManifestEvent {
async handle(fullname: string, version: string) {
await this.savePackageVersionManifest(fullname, version);
}
Expand Down
4 changes: 2 additions & 2 deletions app/core/event/SyncESPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class SyncESPackage {

@Event(PACKAGE_UNPUBLISHED)
@Event(PACKAGE_BLOCKED)
export class PackageUnpublished extends SyncESPackage {
export class PackageUnpublishedSyncESEvent extends SyncESPackage {
async handle(fullname: string) {
if (!this.config.cnpmcore.enableElasticsearch) return;
await this.packageSearchService.removePackage(fullname);
Expand All @@ -49,7 +49,7 @@ export class PackageUnpublished extends SyncESPackage {
@Event(PACKAGE_MAINTAINER_CHANGED)
@Event(PACKAGE_MAINTAINER_REMOVED)
@Event(PACKAGE_UNBLOCKED)
export class PackageVersionAdded extends SyncESPackage {
export class PackageVersionAddedSyncESEvent extends SyncESPackage {
async handle(fullname: string) {
await this.syncPackage(fullname);
}
Expand Down
6 changes: 3 additions & 3 deletions app/core/event/SyncPackageVersionFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,22 @@ class SyncPackageVersionFileEvent {
}

@Event(PACKAGE_VERSION_ADDED)
export class PackageVersionAdded extends SyncPackageVersionFileEvent {
export class PackageVersionAddedSyncPackageVersionFileEvent extends SyncPackageVersionFileEvent {
async handle(fullname: string, version: string) {
await this.syncPackageVersionFile(fullname, version);
}
}

@Event(PACKAGE_TAG_ADDED)
export class PackageTagAdded extends SyncPackageVersionFileEvent {
export class PackageTagAddedSyncPackageVersionFileEvent extends SyncPackageVersionFileEvent {
async handle(fullname: string, tag: string) {
if (tag !== 'latest') return;
await this.syncPackageReadmeToLatestVersion(fullname);
}
}

@Event(PACKAGE_TAG_CHANGED)
export class PackageTagChanged extends SyncPackageVersionFileEvent {
export class PackageTagChangedSyncPackageVersionFileEvent extends SyncPackageVersionFileEvent {
async handle(fullname: string, tag: string) {
if (tag !== 'latest') return;
await this.syncPackageReadmeToLatestVersion(fullname);
Expand Down
10 changes: 5 additions & 5 deletions test/core/event/ChangesStream.test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { PackageVersionAdded } from '../../../app/core/event/ChangesStream';
import { PackageVersionAddedChangesStreamEvent } from '../../../app/core/event/ChangesStream';
import { app, mock } from 'egg-mock/bootstrap';

describe('test/core/event/BugVersionFixHandler.test.ts', () => {
let packageVersionAdded: PackageVersionAdded;
let packageVersionAddedChangesStreamEvent: PackageVersionAddedChangesStreamEvent;

before(async () => {
packageVersionAdded = await app.getEggObject(PackageVersionAdded);
packageVersionAddedChangesStreamEvent = await app.getEggObject(PackageVersionAddedChangesStreamEvent);
});

it('should trigger hook', async () => {
app.mockLog();
mock(app.config.cnpmcore, 'hookEnable', true);
await packageVersionAdded.handle('banana', '1.0.0');
await packageVersionAddedChangesStreamEvent.handle('banana', '1.0.0');
app.expectLog(/TaskService\.createTask:new/);
});

it('should ignore hook when disable', async () => {
app.mockLog();
mock(app.config.cnpmcore, 'hookEnable', false);
await packageVersionAdded.handle('banana', '1.0.0');
await packageVersionAddedChangesStreamEvent.handle('banana', '1.0.0');
app.notExpectLog(/TaskService\.createTask:new/);
});
});
6 changes: 3 additions & 3 deletions test/port/controller/PackageVersionFileController/raw.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { setTimeout } from 'node:timers/promises';
import { app, mock } from 'egg-mock/bootstrap';
import { TestUtil } from '../../../../test/TestUtil';
import { calculateIntegrity } from '../../../../app/common/PackageUtil';
import { PackageTagChanged, PackageTagAdded } from '../../../../app/core/event/SyncPackageVersionFile';
import { PackageTagChangedSyncPackageVersionFileEvent, PackageTagAddedSyncPackageVersionFileEvent } from '../../../../app/core/event/SyncPackageVersionFile';

describe('test/port/controller/PackageVersionFileController/raw.test.ts', () => {
let publisher;
Expand Down Expand Up @@ -368,7 +368,7 @@ describe('test/port/controller/PackageVersionFileController/raw.test.ts', () =>
// console.log(res.body);
assert.equal(res.body.files.find(file => file.path === '/.'), undefined);
assert(res.body.files.find(file => file.path === '/dist'));
const packageTagAdded = await app.getEggObject(PackageTagAdded);
const packageTagAdded = await app.getEggObject(PackageTagAddedSyncPackageVersionFileEvent);
await packageTagAdded.handle(pkg.name, 'foo');
await packageTagAdded.handle(pkg.name, 'latest');
res = await app.httpRequest()
Expand Down Expand Up @@ -429,7 +429,7 @@ describe('test/port/controller/PackageVersionFileController/raw.test.ts', () =>
.expect(200);
assert.notEqual(res.body.readme, oldReadme);
assert.match(res.body.readme, /The Javascript Database that Syncs/);
const packageTagChanged = await app.getEggObject(PackageTagChanged);
const packageTagChanged = await app.getEggObject(PackageTagChangedSyncPackageVersionFileEvent);
await packageTagChanged.handle(pkg.name, 'foo');
await packageTagChanged.handle(pkg.name, 'latest');
// pkg version change too
Expand Down

0 comments on commit f7c49e5

Please sign in to comment.