Skip to content

Commit 70bba63

Browse files
committed
refactor(registry): improve UpdaterRegistry
- Replaced `loadUpdaters` with `ensureInitialized` - Added initialization promise - Improved initialization logic
1 parent f04d947 commit 70bba63

5 files changed

Lines changed: 17 additions & 7 deletions

File tree

dist/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Author: Taj <[email protected]>
77
* Homepage: https://github.com/taj54/universal-version-bump#readme
88
* License: MIT
9-
* Generated on Wed, 27 Aug 2025 09:27:33 GMT
9+
* Generated on Wed, 27 Aug 2025 09:46:33 GMT
1010
*/
1111
require('./sourcemap-register.js');/******/ (() => { // webpackBootstrap
1212
/******/ var __webpack_modules__ = ({
@@ -32784,7 +32784,7 @@ async function run() {
3278432784
const releaseType = config_1.RELEASE_TYPE;
3278532785
const targetPlatform = config_1.TARGET_PLATFORM;
3278632786
const updaterRegistry = new registry_1.UpdaterRegistry();
32787-
await updaterRegistry.loadUpdaters();
32787+
await updaterRegistry.ensureInitialized();
3278832788
const updaterService = new services_1.UpdaterService(updaterRegistry);
3278932789
const gitService = new services_1.GitService();
3279032790
const fileHandler = new utils_1.FileHandler();
@@ -32911,6 +32911,10 @@ class UpdaterRegistry {
3291132911
constructor() {
3291232912
this.updaters = new Map();
3291332913
this.fileHandler = new fileHandler_1.FileHandler();
32914+
this.initializationPromise = this.loadUpdaters();
32915+
}
32916+
async ensureInitialized() {
32917+
await this.initializationPromise;
3291432918
}
3291532919
/**
3291632920
* Dynamically loads and registers all updaters from the updaters directory.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ async function run() {
1717
const targetPlatform = TARGET_PLATFORM;
1818

1919
const updaterRegistry = new UpdaterRegistry();
20-
await updaterRegistry.loadUpdaters();
21-
20+
await updaterRegistry.ensureInitialized();
2221
const updaterService = new UpdaterService(updaterRegistry);
2322
const gitService = new GitService();
2423
const fileHandler = new FileHandler();

src/registry/updaterRegistry.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@ export class UpdaterRegistry {
99
private updaters: Map<string, IUpdater> = new Map();
1010
private fileHandler: FileHandler;
1111

12+
private initializationPromise: Promise<void>;
13+
1214
constructor() {
1315
this.fileHandler = new FileHandler();
16+
this.initializationPromise = this.loadUpdaters();
17+
}
18+
19+
public async ensureInitialized(): Promise<void> {
20+
await this.initializationPromise;
1421
}
1522

1623
/**

tests/registry/updaterRegistry.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { describe, it, expect } from 'vitest';
22
import { UpdaterRegistry } from '../../src/registry';
33

44
describe('UpdaterRegistry', () => {
5-
it('should load all updaters from the updaters directory', async () => {
5+
it('should load all updaters on instantiation', async () => {
66
const registry = new UpdaterRegistry();
7-
await registry.loadUpdaters();
7+
await registry.ensureInitialized();
88
const allUpdaters = registry.getAllUpdaters();
99

1010
// There are 6 updaters in the src/updaters directory

0 commit comments

Comments
 (0)