@travetto/registry 4.0.1 → 4.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/registry",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.3",
|
|
4
4
|
"description": "Patterns and utilities for handling registration of metadata and functionality for run-time use",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ast-transformations",
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
"directory": "module/registry"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@travetto/base": "^4.0.
|
|
30
|
+
"@travetto/base": "^4.0.2"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@travetto/cli": "^4.0.
|
|
34
|
-
"@travetto/transformer": "^4.0.
|
|
33
|
+
"@travetto/cli": "^4.0.4",
|
|
34
|
+
"@travetto/transformer": "^4.0.2"
|
|
35
35
|
},
|
|
36
36
|
"peerDependenciesMeta": {
|
|
37
37
|
"@travetto/transformer": {
|
|
@@ -42,10 +42,11 @@ export class DynamicCommonjsLoader {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
const
|
|
45
|
+
const file = Module._resolveFilename!(request, parent);
|
|
46
|
+
const src = RuntimeIndex.getEntry(file)?.sourceFile;
|
|
46
47
|
// Only proxy workspace modules
|
|
47
|
-
if (RuntimeIndex.getModuleFromSource(
|
|
48
|
-
return proxyModuleLoad ? proxyModuleLoad(
|
|
48
|
+
if (src && RuntimeIndex.getModuleFromSource(src)?.workspace) {
|
|
49
|
+
return proxyModuleLoad ? proxyModuleLoad(file, mod) : mod;
|
|
49
50
|
} else {
|
|
50
51
|
return mod;
|
|
51
52
|
}
|
package/src/registry.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EventEmitter } from 'node:events';
|
|
2
|
-
import { Class } from '@travetto/base';
|
|
2
|
+
import { Class, Env } from '@travetto/base';
|
|
3
3
|
import { ChangeSource, ChangeEvent, ChangeHandler } from './types';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -32,6 +32,11 @@ export abstract class Registry implements ChangeSource<Class> {
|
|
|
32
32
|
*/
|
|
33
33
|
#uid: string;
|
|
34
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Are we in a mode that should have enhanced debug info
|
|
37
|
+
*/
|
|
38
|
+
trace = Env.DEBUG.val?.includes('@travetto/registry');
|
|
39
|
+
|
|
35
40
|
/**
|
|
36
41
|
* Creates a new registry, with it's parents specified
|
|
37
42
|
*/
|
|
@@ -56,7 +61,9 @@ export abstract class Registry implements ChangeSource<Class> {
|
|
|
56
61
|
async #runInit(): Promise<void> {
|
|
57
62
|
try {
|
|
58
63
|
this.#resolved = false;
|
|
59
|
-
|
|
64
|
+
if (this.trace) {
|
|
65
|
+
console.debug('Initializing', { id: this.constructor.Ⲑid, uid: this.#uid });
|
|
66
|
+
}
|
|
60
67
|
|
|
61
68
|
// Handle top level when dealing with non-registry
|
|
62
69
|
const waitFor = this.#parents.filter(x => !(x instanceof Registry));
|
|
@@ -100,7 +107,9 @@ export abstract class Registry implements ChangeSource<Class> {
|
|
|
100
107
|
* Initialize, with a built-in latch to prevent concurrent initializations
|
|
101
108
|
*/
|
|
102
109
|
async init(): Promise<unknown> {
|
|
103
|
-
|
|
110
|
+
if (this.trace) {
|
|
111
|
+
console.debug('Trying to initialize', { id: this.constructor.Ⲑid, uid: this.#uid, initialized: !!this.#initialized });
|
|
112
|
+
}
|
|
104
113
|
|
|
105
114
|
if (!this.#initialized) {
|
|
106
115
|
this.#initialized = this.#runInit();
|
|
@@ -150,7 +159,9 @@ export abstract class Registry implements ChangeSource<Class> {
|
|
|
150
159
|
* Listen for events from the parent
|
|
151
160
|
*/
|
|
152
161
|
onEvent(event: ChangeEvent<Class>): void {
|
|
153
|
-
|
|
162
|
+
if (this.trace) {
|
|
163
|
+
console.debug('Received', { id: this.constructor.Ⲑid, type: event.type, targetId: (event.curr ?? event.prev)!.Ⲑid });
|
|
164
|
+
}
|
|
154
165
|
|
|
155
166
|
switch (event.type) {
|
|
156
167
|
case 'removing':
|
package/src/service/metadata.ts
CHANGED
|
@@ -157,7 +157,9 @@ export abstract class MetadataRegistry<C extends { class: Class }, M = unknown,
|
|
|
157
157
|
*/
|
|
158
158
|
onInstall(cls: Class, e: ChangeEvent<Class>): void {
|
|
159
159
|
if (this.pending.has(cls.Ⲑid) || this.pendingFields.has(cls.Ⲑid)) {
|
|
160
|
-
|
|
160
|
+
if (this.trace) {
|
|
161
|
+
console.debug('Installing', { service: this.constructor.name, id: cls.Ⲑid });
|
|
162
|
+
}
|
|
161
163
|
const result = this.onInstallFinalize(cls);
|
|
162
164
|
this.pendingFields.delete(cls.Ⲑid);
|
|
163
165
|
this.pending.delete(cls.Ⲑid);
|
|
@@ -172,7 +174,9 @@ export abstract class MetadataRegistry<C extends { class: Class }, M = unknown,
|
|
|
172
174
|
*/
|
|
173
175
|
onUninstall(cls: Class, e: ChangeEvent<Class>): void {
|
|
174
176
|
if (this.entries.has(cls.Ⲑid)) {
|
|
175
|
-
|
|
177
|
+
if (this.trace) {
|
|
178
|
+
console.debug('Uninstalling', { service: this.constructor.name, id: cls.Ⲑid });
|
|
179
|
+
}
|
|
176
180
|
this.expired.set(cls.Ⲑid, this.entries.get(cls.Ⲑid)!);
|
|
177
181
|
this.entries.delete(cls.Ⲑid);
|
|
178
182
|
this.onUninstallFinalize(cls);
|
|
@@ -28,6 +28,11 @@ export class ClassSource implements ChangeSource<Class> {
|
|
|
28
28
|
#classes = new Map<string, Map<string, Class>>();
|
|
29
29
|
#emitter = new EventEmitter();
|
|
30
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Are we in a mode that should have enhanced debug info
|
|
33
|
+
*/
|
|
34
|
+
trace = Env.DEBUG.val?.includes('@travetto/registry');
|
|
35
|
+
|
|
31
36
|
/**
|
|
32
37
|
* Flush classes
|
|
33
38
|
*/
|
|
@@ -96,7 +101,9 @@ export class ClassSource implements ChangeSource<Class> {
|
|
|
96
101
|
* Emit a change event
|
|
97
102
|
*/
|
|
98
103
|
emit(e: ChangeEvent<Class>): void {
|
|
99
|
-
|
|
104
|
+
if (this.trace) {
|
|
105
|
+
console.debug('Emitting change', { type: e.type, curr: e.curr?.Ⲑid, prev: e.prev?.Ⲑid });
|
|
106
|
+
}
|
|
100
107
|
this.#emitter.emit('change', e);
|
|
101
108
|
}
|
|
102
109
|
|