@travetto/registry 5.0.0-rc.1 → 5.0.0-rc.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/README.md +4 -4
- package/package.json +4 -4
- package/src/decorator.ts +2 -3
- package/src/internal/commonjs-loader.ts +3 -3
- package/src/internal/file-loader.ts +3 -3
- package/src/proxy.ts +1 -1
- package/src/registry.ts +1 -1
- package/src/service/metadata.ts +1 -1
- package/src/service/root.ts +1 -1
- package/src/source/class-source.ts +8 -8
- package/src/source/method-source.ts +3 -4
- package/support/transformer.register.ts +4 -2
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@ This flow ensures all files are loaded and processed before application starts.
|
|
|
27
27
|
|
|
28
28
|
**Code: Sample Registry**
|
|
29
29
|
```typescript
|
|
30
|
-
import { Class } from '@travetto/
|
|
30
|
+
import { Class } from '@travetto/runtime';
|
|
31
31
|
import { MetadataRegistry } from '@travetto/registry';
|
|
32
32
|
|
|
33
33
|
interface Group {
|
|
@@ -112,9 +112,9 @@ As mentioned in [Manifest](https://github.com/travetto/travetto/tree/main/module
|
|
|
112
112
|
changes += 1;
|
|
113
113
|
this.emit({ type: 'added', curr: next.get(k)! });
|
|
114
114
|
} else {
|
|
115
|
-
const
|
|
116
|
-
const
|
|
117
|
-
if (
|
|
115
|
+
const prevHash = describeFunction(prev.get(k)!)?.hash;
|
|
116
|
+
const nextHash = describeFunction(next.get(k)!)?.hash;
|
|
117
|
+
if (prevHash !== nextHash) {
|
|
118
118
|
changes += 1;
|
|
119
119
|
this.emit({ type: 'changed', curr: next.get(k)!, prev: prev.get(k) });
|
|
120
120
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/registry",
|
|
3
|
-
"version": "5.0.0-rc.
|
|
3
|
+
"version": "5.0.0-rc.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/
|
|
30
|
+
"@travetto/runtime": "^5.0.0-rc.3"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@travetto/cli": "^5.0.0-rc.
|
|
34
|
-
"@travetto/transformer": "^5.0.0-rc.
|
|
33
|
+
"@travetto/cli": "^5.0.0-rc.3",
|
|
34
|
+
"@travetto/transformer": "^5.0.0-rc.2"
|
|
35
35
|
},
|
|
36
36
|
"peerDependenciesMeta": {
|
|
37
37
|
"@travetto/transformer": {
|
package/src/decorator.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Class } from '@travetto/
|
|
2
|
-
import { RuntimeIndex } from '@travetto/manifest';
|
|
1
|
+
import { Class, Runtime } from '@travetto/runtime';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* Register a class as pending
|
|
@@ -12,7 +11,7 @@ class $PendingRegister {
|
|
|
12
11
|
* Register class as pending
|
|
13
12
|
*/
|
|
14
13
|
add(cls: Class): void {
|
|
15
|
-
const src =
|
|
14
|
+
const src = Runtime.getSource(cls);
|
|
16
15
|
if (!this.map.has(src)) {
|
|
17
16
|
const sub: Class[] = [];
|
|
18
17
|
this.map.set(src, sub);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Module } from 'node:module';
|
|
2
2
|
|
|
3
|
-
import { path
|
|
4
|
-
import {
|
|
3
|
+
import { path } from '@travetto/manifest';
|
|
4
|
+
import { Runtime, RuntimeIndex } from '@travetto/runtime';
|
|
5
5
|
|
|
6
6
|
import { RetargettingProxy } from '../proxy';
|
|
7
7
|
|
|
@@ -32,7 +32,7 @@ export class DynamicCommonjsLoader {
|
|
|
32
32
|
mod = moduleLoad.apply(null, [request, parent]);
|
|
33
33
|
} catch (err: unknown) {
|
|
34
34
|
const name = Module._resolveFilename!(request, parent);
|
|
35
|
-
if (err instanceof Error &&
|
|
35
|
+
if (err instanceof Error && Runtime.dynamic && !name.startsWith('test/')) {
|
|
36
36
|
const errMsg = err.message;
|
|
37
37
|
console.debug(`Unable to load ${name}: stubbing out with error proxy.`, errMsg);
|
|
38
38
|
const e = (): never => { throw new Error(errMsg); };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ManifestModuleUtil
|
|
2
|
-
import { watchCompiler, WatchEvent,
|
|
1
|
+
import { ManifestModuleUtil } from '@travetto/manifest';
|
|
2
|
+
import { watchCompiler, WatchEvent, Runtime, RuntimeIndex } from '@travetto/runtime';
|
|
3
3
|
|
|
4
4
|
interface ModuleLoader {
|
|
5
5
|
init?(): Promise<void>;
|
|
@@ -24,7 +24,7 @@ class $DynamicFileLoader {
|
|
|
24
24
|
await this.#loader.unload(ev.output);
|
|
25
25
|
}
|
|
26
26
|
if (ev.action === 'create' || ev.action === 'delete') {
|
|
27
|
-
RuntimeIndex.reinitForModule(
|
|
27
|
+
RuntimeIndex.reinitForModule(Runtime.main.name);
|
|
28
28
|
}
|
|
29
29
|
if (ev.action === 'create' || ev.action === 'update') {
|
|
30
30
|
await this.#loader.load(ev.output);
|
package/src/proxy.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2
2
|
type ConcreteClass<T = any> = new (...args: any[]) => T;
|
|
3
|
-
const ProxyTargetⲐ = Symbol.for('@travetto/
|
|
3
|
+
const ProxyTargetⲐ = Symbol.for('@travetto/runtime:proxy-target');
|
|
4
4
|
|
|
5
5
|
const AsyncGeneratorFunction = Object.getPrototypeOf(async function* () { });
|
|
6
6
|
const GeneratorFunction = Object.getPrototypeOf(function* () { });
|
package/src/registry.ts
CHANGED
package/src/service/metadata.ts
CHANGED
package/src/service/root.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EventEmitter } from 'node:events';
|
|
2
2
|
|
|
3
|
-
import { type FindConfig
|
|
4
|
-
import { Class, Env } from '@travetto/
|
|
3
|
+
import { type FindConfig } from '@travetto/manifest';
|
|
4
|
+
import { Class, Env, Runtime, RuntimeIndex, describeFunction } from '@travetto/runtime';
|
|
5
5
|
|
|
6
6
|
import { DynamicFileLoader } from '../internal/file-loader';
|
|
7
7
|
import { ChangeSource, ChangeEvent, ChangeHandler } from '../types';
|
|
@@ -11,7 +11,7 @@ const moduleFindConfig: FindConfig = {
|
|
|
11
11
|
module: (m) => {
|
|
12
12
|
const role = Env.TRV_ROLE.val;
|
|
13
13
|
return m.roles.includes('std') && (
|
|
14
|
-
!
|
|
14
|
+
!Runtime.production || m.prod ||
|
|
15
15
|
((role === 'doc' || role === 'test') && m.roles.includes(role))
|
|
16
16
|
);
|
|
17
17
|
},
|
|
@@ -43,7 +43,7 @@ export class ClassSource implements ChangeSource<Class> {
|
|
|
43
43
|
}
|
|
44
44
|
this.#classes.set(file, new Map());
|
|
45
45
|
for (const cls of classes) {
|
|
46
|
-
const src =
|
|
46
|
+
const src = Runtime.getSource(cls);
|
|
47
47
|
this.#classes.get(src)!.set(cls.Ⲑid, cls);
|
|
48
48
|
this.emit({ type: 'added', curr: cls });
|
|
49
49
|
}
|
|
@@ -83,9 +83,9 @@ export class ClassSource implements ChangeSource<Class> {
|
|
|
83
83
|
changes += 1;
|
|
84
84
|
this.emit({ type: 'added', curr: next.get(k)! });
|
|
85
85
|
} else {
|
|
86
|
-
const
|
|
87
|
-
const
|
|
88
|
-
if (
|
|
86
|
+
const prevHash = describeFunction(prev.get(k)!)?.hash;
|
|
87
|
+
const nextHash = describeFunction(next.get(k)!)?.hash;
|
|
88
|
+
if (prevHash !== nextHash) {
|
|
89
89
|
changes += 1;
|
|
90
90
|
this.emit({ type: 'changed', curr: next.get(k)!, prev: prev.get(k) });
|
|
91
91
|
}
|
|
@@ -111,7 +111,7 @@ export class ClassSource implements ChangeSource<Class> {
|
|
|
111
111
|
* Initialize
|
|
112
112
|
*/
|
|
113
113
|
async init(): Promise<void> {
|
|
114
|
-
if (
|
|
114
|
+
if (Runtime.dynamic) {
|
|
115
115
|
DynamicFileLoader.onLoadEvent(ev => {
|
|
116
116
|
for (const [file, classes] of PendingRegister.flush(true)) {
|
|
117
117
|
this.#handleFileChanges(file, classes);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { EventEmitter } from 'node:events';
|
|
2
2
|
|
|
3
|
-
import { Class } from '@travetto/
|
|
4
|
-
import { RuntimeIndex } from '@travetto/manifest';
|
|
3
|
+
import { Class, describeFunction } from '@travetto/runtime';
|
|
5
4
|
|
|
6
5
|
import { ChangeSource, ChangeEvent, ChangeHandler } from '../types';
|
|
7
6
|
|
|
@@ -30,8 +29,8 @@ export class MethodSource implements ChangeSource<[Class, Function]> {
|
|
|
30
29
|
* On a class being emitted, check methods
|
|
31
30
|
*/
|
|
32
31
|
onClassEvent(e: ChangeEvent<Class>): void {
|
|
33
|
-
const next =
|
|
34
|
-
const prev =
|
|
32
|
+
const next = describeFunction(e.curr!)?.methods ?? {};
|
|
33
|
+
const prev = describeFunction(e.prev!)?.methods ?? {};
|
|
35
34
|
|
|
36
35
|
/**
|
|
37
36
|
* Go through each method, comparing hashes. To see added/removed and changed
|
|
@@ -3,7 +3,8 @@ import ts from 'typescript';
|
|
|
3
3
|
import { TransformerState, AfterClass, DecoratorUtil } from '@travetto/transformer';
|
|
4
4
|
|
|
5
5
|
const REGISTER_MOD = '@travetto/registry/src/decorator';
|
|
6
|
-
const SKIP_SRC = /^@travetto\/(
|
|
6
|
+
const SKIP_SRC = /^@travetto\/(runtime|manifest)\/(src|support)/;
|
|
7
|
+
const SKIP_FUNCTION = /^@travetto\/registry\/src\/function/;
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Registration of all classes to support the registry
|
|
@@ -17,7 +18,8 @@ export class RegisterTransformer {
|
|
|
17
18
|
static registerClass(state: TransformerState, node: ts.ClassDeclaration): ts.ClassDeclaration {
|
|
18
19
|
if (
|
|
19
20
|
state.importName === REGISTER_MOD ||
|
|
20
|
-
SKIP_SRC.test(state.importName)
|
|
21
|
+
SKIP_SRC.test(state.importName) ||
|
|
22
|
+
SKIP_FUNCTION.test(state.importName)
|
|
21
23
|
) { // Cannot process self
|
|
22
24
|
return node;
|
|
23
25
|
}
|