@travetto/manifest 4.0.0-rc.5 → 4.0.0-rc.7
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 +3 -2
- package/package.json +1 -1
- package/src/delta.ts +1 -1
- package/src/module.ts +11 -2
- package/src/package.ts +1 -1
- package/src/runtime.ts +9 -4
- package/src/types/common.ts +3 -3
- package/src/types/package.ts +1 -1
- package/support/transformer.function-metadata.ts +19 -10
package/README.md
CHANGED
|
@@ -53,7 +53,7 @@ const tslib_1 = require("tslib");
|
|
|
53
53
|
const Ⲑ_runtime_1 = tslib_1.__importStar(require("@travetto/manifest/src/runtime.js"));
|
|
54
54
|
var ᚕf = "@travetto/manifest/doc/test-class.js";
|
|
55
55
|
class TestClass {
|
|
56
|
-
static Ⲑinit = Ⲑ_runtime_1.RuntimeIndex.registerFunction(TestClass, ᚕf, 197152026, { doStuff: { hash: 51337554 } }, false, false);
|
|
56
|
+
static Ⲑinit = Ⲑ_runtime_1.RuntimeIndex.registerFunction(TestClass, ᚕf, { hash: 197152026, lines: [1, 3] }, { doStuff: { hash: 51337554, lines: [2, 2] } }, false, false);
|
|
57
57
|
async doStuff() { }
|
|
58
58
|
}
|
|
59
59
|
exports.TestClass = TestClass;
|
|
@@ -67,7 +67,8 @@ $ trv main ./doc/lookup.ts
|
|
|
67
67
|
id: '@travetto/manifest:doc/test-class○TestClass',
|
|
68
68
|
source: './doc/test-class.ts',
|
|
69
69
|
hash: 197152026,
|
|
70
|
-
|
|
70
|
+
lines: [ 1, 3 ],
|
|
71
|
+
methods: { doStuff: { hash: 51337554, lines: [Array] } },
|
|
71
72
|
abstract: false,
|
|
72
73
|
synthetic: false
|
|
73
74
|
}
|
package/package.json
CHANGED
package/src/delta.ts
CHANGED
|
@@ -35,7 +35,7 @@ export class ManifestDeltaUtil {
|
|
|
35
35
|
|
|
36
36
|
const root = path.resolve(ctx.workspace.path, ctx.build.outputFolder, left.outputFolder);
|
|
37
37
|
const right = new Set(
|
|
38
|
-
(await ManifestModuleUtil.scanFolder(root, left.main))
|
|
38
|
+
(await ManifestModuleUtil.scanFolder(ctx, root, left.main))
|
|
39
39
|
.filter(x => {
|
|
40
40
|
const type = ManifestModuleUtil.getFileType(x);
|
|
41
41
|
return VALID_SOURCE_TYPE.has(type);
|
package/src/module.ts
CHANGED
|
@@ -44,7 +44,7 @@ export class ManifestModuleUtil {
|
|
|
44
44
|
/**
|
|
45
45
|
* Simple file scanning
|
|
46
46
|
*/
|
|
47
|
-
static async scanFolder(folder: string, full = false): Promise<string[]> {
|
|
47
|
+
static async scanFolder(ctx: ManifestContext, folder: string, full = false): Promise<string[]> {
|
|
48
48
|
const key = `${folder}|${full}`;
|
|
49
49
|
if (key in this.#scanCache) {
|
|
50
50
|
return this.#scanCache[key];
|
|
@@ -56,6 +56,12 @@ export class ManifestModuleUtil {
|
|
|
56
56
|
|
|
57
57
|
const out: string[] = [];
|
|
58
58
|
|
|
59
|
+
const exclude = new Set([
|
|
60
|
+
path.resolve(ctx.workspace.path, ctx.build.compilerFolder),
|
|
61
|
+
path.resolve(ctx.workspace.path, ctx.build.outputFolder),
|
|
62
|
+
path.resolve(ctx.workspace.path, ctx.build.toolFolder),
|
|
63
|
+
]);
|
|
64
|
+
|
|
59
65
|
const stack: [string, number][] = [[folder, 0]];
|
|
60
66
|
while (stack.length) {
|
|
61
67
|
const popped = stack.pop();
|
|
@@ -69,6 +75,9 @@ export class ManifestModuleUtil {
|
|
|
69
75
|
if (top !== folder && await fs.stat(`${top}/package.json`).catch(() => false)) {
|
|
70
76
|
continue;
|
|
71
77
|
}
|
|
78
|
+
if (exclude.has(top)) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
72
81
|
|
|
73
82
|
for (const sub of await fs.readdir(top)) {
|
|
74
83
|
const valid = !sub.startsWith('.') && (depth > 0 || full);
|
|
@@ -177,7 +186,7 @@ export class ManifestModuleUtil {
|
|
|
177
186
|
|
|
178
187
|
const files: ManifestModule['files'] = {};
|
|
179
188
|
|
|
180
|
-
for (const file of await this.scanFolder(sourcePath, rest.main)) {
|
|
189
|
+
for (const file of await this.scanFolder(ctx, sourcePath, rest.main)) {
|
|
181
190
|
// Group by top folder
|
|
182
191
|
const moduleFile = file.replace(`${sourcePath}/`, '');
|
|
183
192
|
const entry = await this.transformFile(moduleFile, file);
|
package/src/package.ts
CHANGED
package/src/runtime.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { path } from './path';
|
|
2
2
|
import { ManifestIndex } from './manifest-index';
|
|
3
3
|
|
|
4
|
-
import type { FunctionMetadata } from './types/common';
|
|
4
|
+
import type { FunctionMetadata, FunctionMetadataTag } from './types/common';
|
|
5
5
|
import type { IndexedModule, ManifestModule } from './types/manifest';
|
|
6
6
|
import type { ManifestContext } from './types/context';
|
|
7
7
|
|
|
@@ -52,16 +52,21 @@ class $RuntimeIndex extends ManifestIndex {
|
|
|
52
52
|
* @param cls Class
|
|
53
53
|
* @param `file` Filename
|
|
54
54
|
* @param `hash` Hash of class contents
|
|
55
|
+
* @param `line` Line number in source
|
|
55
56
|
* @param `methods` Methods and their hashes
|
|
56
57
|
* @param `abstract` Is the class abstract
|
|
58
|
+
* @param `synthetic` Is this code generated at build time
|
|
57
59
|
*/
|
|
58
|
-
registerFunction(
|
|
60
|
+
registerFunction(
|
|
61
|
+
cls: Function, fileOrImport: string, tag: FunctionMetadataTag,
|
|
62
|
+
methods?: Record<string, FunctionMetadataTag>, abstract?: boolean, synthetic?: boolean
|
|
63
|
+
): boolean {
|
|
59
64
|
const source = this.getSourceFile(fileOrImport);
|
|
60
65
|
const id = this.getId(source, cls.name);
|
|
61
66
|
Object.defineProperty(cls, 'Ⲑid', { value: id });
|
|
62
67
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
63
|
-
(cls as unknown as Metadated)[METADATA] = { id, source,
|
|
64
|
-
this.#metadata.set(id, { id, source,
|
|
68
|
+
(cls as unknown as Metadated)[METADATA] = { id, source, ...tag, methods, abstract, synthetic };
|
|
69
|
+
this.#metadata.set(id, { id, source, ...tag, methods, abstract, synthetic });
|
|
65
70
|
return true;
|
|
66
71
|
}
|
|
67
72
|
|
package/src/types/common.ts
CHANGED
|
@@ -10,11 +10,11 @@ export type ManifestModuleFolderType =
|
|
|
10
10
|
|
|
11
11
|
export type ManifestModuleRole = 'std' | 'test' | 'doc' | 'compile' | 'build';
|
|
12
12
|
|
|
13
|
-
export type
|
|
13
|
+
export type FunctionMetadataTag = { hash: number, lines: [number, number] };
|
|
14
|
+
export type FunctionMetadata = FunctionMetadataTag & {
|
|
14
15
|
id: string;
|
|
15
16
|
source: string;
|
|
16
|
-
|
|
17
|
-
methods?: Record<string, { hash: number }>;
|
|
17
|
+
methods?: Record<string, FunctionMetadataTag>;
|
|
18
18
|
synthetic?: boolean;
|
|
19
19
|
abstract?: boolean;
|
|
20
20
|
};
|
package/src/types/package.ts
CHANGED
|
@@ -5,6 +5,8 @@ import {
|
|
|
5
5
|
AfterFunction, CoreUtil, SystemUtil, Import
|
|
6
6
|
} from '@travetto/transformer';
|
|
7
7
|
|
|
8
|
+
import type { FunctionMetadataTag } from '../src/types/common';
|
|
9
|
+
|
|
8
10
|
const MANIFEST_MOD = '@travetto/manifest';
|
|
9
11
|
const MANIFEST_IDX = `${MANIFEST_MOD}/__index__`;
|
|
10
12
|
|
|
@@ -18,10 +20,8 @@ const runtimeIdx = Symbol.for(`${MANIFEST_MOD}:runtimeIndex`);
|
|
|
18
20
|
|
|
19
21
|
interface MetadataInfo {
|
|
20
22
|
[runtimeIdx]?: Import;
|
|
21
|
-
[methods]?:
|
|
22
|
-
|
|
23
|
-
};
|
|
24
|
-
[cls]?: number;
|
|
23
|
+
[methods]?: Record<string, FunctionMetadataTag>;
|
|
24
|
+
[cls]?: FunctionMetadataTag;
|
|
25
25
|
[fn]?: number;
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -30,6 +30,16 @@ interface MetadataInfo {
|
|
|
30
30
|
*/
|
|
31
31
|
export class RegisterTransformer {
|
|
32
32
|
|
|
33
|
+
static #tag(state: TransformerState, node: ts.Node): FunctionMetadataTag {
|
|
34
|
+
const hash = SystemUtil.naiveHash(node.getText());
|
|
35
|
+
try {
|
|
36
|
+
const range = CoreUtil.getRangeOf(state.source, node) ?? [0, 0];
|
|
37
|
+
return { hash, lines: range };
|
|
38
|
+
} catch (err) {
|
|
39
|
+
return { hash, lines: [0, 0] };
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
33
43
|
static #valid({ importName: imp }: TransformerState): boolean {
|
|
34
44
|
return !imp.startsWith(MANIFEST_MOD) || !(/[/](src|support)[/]/.test(imp) || imp === MANIFEST_IDX);
|
|
35
45
|
}
|
|
@@ -42,7 +52,7 @@ export class RegisterTransformer {
|
|
|
42
52
|
if (!this.#valid(state)) {
|
|
43
53
|
return node; // Exclude self
|
|
44
54
|
}
|
|
45
|
-
state[cls] =
|
|
55
|
+
state[cls] = this.#tag(state, node);
|
|
46
56
|
return node;
|
|
47
57
|
}
|
|
48
58
|
|
|
@@ -52,10 +62,8 @@ export class RegisterTransformer {
|
|
|
52
62
|
@OnMethod()
|
|
53
63
|
static collectMethodMetadata(state: TransformerState & MetadataInfo, node: ts.MethodDeclaration): ts.MethodDeclaration {
|
|
54
64
|
if (state[cls] && ts.isIdentifier(node.name) && !CoreUtil.isAbstract(node) && ts.isClassDeclaration(node.parent)) {
|
|
55
|
-
const hash = SystemUtil.naiveHash(node.getText());
|
|
56
|
-
const conf = { hash };
|
|
57
65
|
state[methods] ??= {};
|
|
58
|
-
state[methods]![node.name.escapedText.toString()] =
|
|
66
|
+
state[methods]![node.name.escapedText.toString()] = this.#tag(state, node);
|
|
59
67
|
}
|
|
60
68
|
return node;
|
|
61
69
|
}
|
|
@@ -80,7 +88,7 @@ export class RegisterTransformer {
|
|
|
80
88
|
[
|
|
81
89
|
state.createIdentifier(name),
|
|
82
90
|
state.getFilenameIdentifier(),
|
|
83
|
-
state.fromLiteral(state[cls]
|
|
91
|
+
state.fromLiteral(state[cls]),
|
|
84
92
|
state.extendObjectLiteral(state[methods] || {}),
|
|
85
93
|
state.fromLiteral(CoreUtil.isAbstract(node)),
|
|
86
94
|
state.fromLiteral(name.endsWith(TransformerState.SYNTHETIC_EXT))
|
|
@@ -116,13 +124,14 @@ export class RegisterTransformer {
|
|
|
116
124
|
// If we have a class like function
|
|
117
125
|
state[runtimeIdx] ??= state.importFile(RUNTIME_IDX_IMPORT);
|
|
118
126
|
const ident = state.createAccess(state[runtimeIdx].ident, RUNTIME_IDX_CLS);
|
|
127
|
+
const tag = this.#tag(state, node);
|
|
119
128
|
const meta = state.factory.createCallExpression(
|
|
120
129
|
state.createAccess(ident, 'registerFunction'),
|
|
121
130
|
[],
|
|
122
131
|
[
|
|
123
132
|
state.createIdentifier(node.name),
|
|
124
133
|
state.getFilenameIdentifier(),
|
|
125
|
-
state.fromLiteral(
|
|
134
|
+
state.fromLiteral(tag),
|
|
126
135
|
]
|
|
127
136
|
);
|
|
128
137
|
state.addStatements([state.factory.createExpressionStatement(meta)]);
|