@travetto/runtime 7.0.3 → 7.0.5
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 +5 -5
- package/package.json +3 -3
- package/src/binary.ts +1 -1
- package/src/debug.ts +1 -1
- package/src/file-loader.ts +1 -1
- package/src/json.ts +1 -1
- package/src/resources.ts +3 -3
- package/src/types.ts +2 -2
- package/src/watch.ts +8 -8
- package/support/transformer/metadata.ts +2 -2
- package/support/transformer.concrete-type.ts +7 -4
- package/support/transformer.console-log.ts +13 -13
- package/support/transformer.debug-method.ts +6 -3
- package/support/transformer.dynamic-import.ts +5 -2
- package/support/transformer.function-metadata.ts +8 -5
- package/support/transformer.rewrite-path-import.ts +5 -2
package/README.md
CHANGED
|
@@ -214,18 +214,18 @@ export function work() {
|
|
|
214
214
|
```javascript
|
|
215
215
|
import * as Δfunction from "@travetto/runtime/src/function.js";
|
|
216
216
|
import * as Δconsole from "@travetto/runtime/src/console.js";
|
|
217
|
-
var
|
|
217
|
+
var Δm_1 = ["@travetto/runtime", "doc/transpile.ts"];
|
|
218
218
|
export function work() {
|
|
219
|
-
Δconsole.log({ level: "debug", import:
|
|
219
|
+
Δconsole.log({ level: "debug", import: Δm_1, line: 2, scope: "work", args: ['Start Work'] });
|
|
220
220
|
try {
|
|
221
221
|
1 / 0;
|
|
222
222
|
}
|
|
223
223
|
catch (error) {
|
|
224
|
-
Δconsole.log({ level: "error", import:
|
|
224
|
+
Δconsole.log({ level: "error", import: Δm_1, line: 7, scope: "work", args: ['Divide by zero', { error }] });
|
|
225
225
|
}
|
|
226
|
-
Δconsole.log({ level: "debug", import:
|
|
226
|
+
Δconsole.log({ level: "debug", import: Δm_1, line: 9, scope: "work", args: ['End Work'] });
|
|
227
227
|
}
|
|
228
|
-
Δfunction.registerFunction(work,
|
|
228
|
+
Δfunction.registerFunction(work, Δm_1, { hash: 159357293, lines: [1, 10, 2] });
|
|
229
229
|
```
|
|
230
230
|
|
|
231
231
|
#### Filtering Debug
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/runtime",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Runtime for travetto applications.",
|
|
6
6
|
"keywords": [
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
"directory": "module/runtime"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@travetto/manifest": "^7.0.
|
|
29
|
+
"@travetto/manifest": "^7.0.4",
|
|
30
30
|
"@types/debug": "^4.1.12",
|
|
31
31
|
"debug": "^4.4.3"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@travetto/transformer": "^7.0.
|
|
34
|
+
"@travetto/transformer": "^7.0.5"
|
|
35
35
|
},
|
|
36
36
|
"peerDependenciesMeta": {
|
|
37
37
|
"@travetto/transformer": {
|
package/src/binary.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { ReadableStream } from 'node:stream/web';
|
|
|
8
8
|
import { text as toText, arrayBuffer as toArrayBuffer } from 'node:stream/consumers';
|
|
9
9
|
import { isArrayBuffer } from 'node:util/types';
|
|
10
10
|
|
|
11
|
-
import { BinaryInput, BlobMeta, hasFunction } from './types.ts';
|
|
11
|
+
import { type BinaryInput, type BlobMeta, hasFunction } from './types.ts';
|
|
12
12
|
import { Util } from './util.ts';
|
|
13
13
|
|
|
14
14
|
const BlobMetaSymbol = Symbol();
|
package/src/debug.ts
CHANGED
package/src/file-loader.ts
CHANGED
package/src/json.ts
CHANGED
package/src/resources.ts
CHANGED
|
@@ -8,16 +8,16 @@ import { FileLoader } from './file-loader.ts';
|
|
|
8
8
|
class $RuntimeResources extends FileLoader {
|
|
9
9
|
#computed: string[];
|
|
10
10
|
#env: string;
|
|
11
|
-
#
|
|
11
|
+
#module: string;
|
|
12
12
|
|
|
13
13
|
constructor() {
|
|
14
14
|
super([]);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
override get searchPaths(): readonly string[] {
|
|
18
|
-
if (!this.#computed || this.#env !== Env.TRV_RESOURCES.value || this.#
|
|
18
|
+
if (!this.#computed || this.#env !== Env.TRV_RESOURCES.value || this.#module !== Env.TRV_MODULE.value) {
|
|
19
19
|
this.#env = Env.TRV_RESOURCES.value!;
|
|
20
|
-
this.#
|
|
20
|
+
this.#module = Env.TRV_MODULE.value!;
|
|
21
21
|
this.#computed = Runtime.resourcePaths();
|
|
22
22
|
}
|
|
23
23
|
return this.#computed;
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Readable } from 'node:stream';
|
|
2
|
-
import { ReadableStream } from 'node:stream/web';
|
|
1
|
+
import type { Readable } from 'node:stream';
|
|
2
|
+
import type { ReadableStream } from 'node:stream/web';
|
|
3
3
|
|
|
4
4
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
5
|
export type Any = any;
|
package/src/watch.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { ChildProcess } from 'node:child_process';
|
|
1
|
+
import type { ChildProcess } from 'node:child_process';
|
|
2
2
|
|
|
3
|
-
import type { CompilerEventPayload, CompilerEventType } from '@travetto/compiler
|
|
3
|
+
import type { CompilerEventPayload, CompilerEventType } from '@travetto/compiler';
|
|
4
4
|
|
|
5
|
-
import { AppError } from './error';
|
|
6
|
-
import { Util } from './util';
|
|
7
|
-
import { RuntimeIndex } from './manifest-index';
|
|
8
|
-
import { ShutdownManager } from './shutdown';
|
|
9
|
-
import { castTo } from './types';
|
|
5
|
+
import { AppError } from './error.ts';
|
|
6
|
+
import { Util } from './util.ts';
|
|
7
|
+
import { RuntimeIndex } from './manifest-index.ts';
|
|
8
|
+
import { ShutdownManager } from './shutdown.ts';
|
|
9
|
+
import { castTo } from './types.ts';
|
|
10
10
|
|
|
11
11
|
type RetryRunState = {
|
|
12
12
|
iteration: number;
|
|
@@ -115,7 +115,7 @@ export class WatchUtil {
|
|
|
115
115
|
filter?: (input: T) => boolean,
|
|
116
116
|
options?: Partial<RetryRunConfig>,
|
|
117
117
|
): Promise<void> {
|
|
118
|
-
const { CompilerClient } = await import('@travetto/compiler/
|
|
118
|
+
const { CompilerClient } = await import('@travetto/compiler/src/server/client.ts');
|
|
119
119
|
const client = new CompilerClient(RuntimeIndex.manifest, console);
|
|
120
120
|
|
|
121
121
|
return this.runWithRetry(async ({ signal }) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { CoreUtil, type Import, SystemUtil, type TransformerState } from '@travetto/transformer';
|
|
4
|
+
import { type FunctionMetadataTag } from '../../src/function.ts';
|
|
5
5
|
|
|
6
6
|
const RegisterImportSymbol = Symbol();
|
|
7
7
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
2
|
|
|
3
|
-
import { TransformerState,
|
|
3
|
+
import { type TransformerState, TransformerHandler } from '@travetto/transformer';
|
|
4
4
|
|
|
5
5
|
import { MetadataRegistrationUtil } from './transformer/metadata.ts';
|
|
6
6
|
|
|
@@ -11,6 +11,12 @@ const SRC = '@travetto/runtime/src/types.ts';
|
|
|
11
11
|
*/
|
|
12
12
|
export class ConcreteTransformer {
|
|
13
13
|
|
|
14
|
+
static {
|
|
15
|
+
TransformerHandler(this, this.onInterface, 'before', 'interface');
|
|
16
|
+
TransformerHandler(this, this.onTypeAlias, 'before', 'type');
|
|
17
|
+
TransformerHandler(this, this.onToConcreteCall, 'before', 'call');
|
|
18
|
+
}
|
|
19
|
+
|
|
14
20
|
static #isConcreteSimple(node: ts.InterfaceDeclaration | ts.TypeAliasDeclaration): boolean {
|
|
15
21
|
return /^\s*[*]\s+@concrete\s*$/gm.test(node.getFullText());
|
|
16
22
|
}
|
|
@@ -46,7 +52,6 @@ export class ConcreteTransformer {
|
|
|
46
52
|
/**
|
|
47
53
|
* Handle concrete interface
|
|
48
54
|
*/
|
|
49
|
-
@OnInterface()
|
|
50
55
|
static onInterface(state: TransformerState, node: ts.InterfaceDeclaration): typeof node {
|
|
51
56
|
if (this.#isConcreteSimple(node)) {
|
|
52
57
|
const func = this.#createConcreteFunction(state, node.name);
|
|
@@ -58,7 +63,6 @@ export class ConcreteTransformer {
|
|
|
58
63
|
/**
|
|
59
64
|
* Handle type alias
|
|
60
65
|
*/
|
|
61
|
-
@OnTypeAlias()
|
|
62
66
|
static onTypeAlias(state: TransformerState, node: ts.TypeAliasDeclaration): typeof node {
|
|
63
67
|
if (this.#isConcreteSimple(node)) {
|
|
64
68
|
const func = this.#createConcreteFunction(state, node.name);
|
|
@@ -67,7 +71,6 @@ export class ConcreteTransformer {
|
|
|
67
71
|
return node;
|
|
68
72
|
}
|
|
69
73
|
|
|
70
|
-
@OnCall()
|
|
71
74
|
static onToConcreteCall(state: TransformerState, node: ts.CallExpression): typeof node {
|
|
72
75
|
if (ts.isIdentifier(node.expression) && node.expression.text === 'toConcrete' && node.typeArguments?.length && node.arguments.length === 0) {
|
|
73
76
|
const type = state.resolveType(node.expression);
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
TransformerState, OnCall, LiteralUtil, OnClass, AfterClass, OnMethod, AfterMethod,
|
|
5
|
-
AfterFunction, OnFunction, OnStaticMethod, AfterStaticMethod
|
|
6
|
-
} from '@travetto/transformer';
|
|
3
|
+
import { type TransformerState, LiteralUtil, TransformerHandler } from '@travetto/transformer';
|
|
7
4
|
|
|
8
5
|
const CONSOLE_IMPORT = '@travetto/runtime/src/console.ts';
|
|
9
6
|
|
|
@@ -25,25 +22,33 @@ const VALID_LEVELS: Record<string, string> = {
|
|
|
25
22
|
*/
|
|
26
23
|
export class ConsoleLogTransformer {
|
|
27
24
|
|
|
25
|
+
static {
|
|
26
|
+
TransformerHandler(this, this.startClassForLog, 'before', 'class');
|
|
27
|
+
TransformerHandler(this, this.leaveClassForLog, 'after', 'class');
|
|
28
|
+
TransformerHandler(this, this.startMethodForLog, 'before', 'method');
|
|
29
|
+
TransformerHandler(this, this.startMethodForLog, 'before', 'static-method');
|
|
30
|
+
TransformerHandler(this, this.leaveMethodForLog, 'after', 'method');
|
|
31
|
+
TransformerHandler(this, this.leaveMethodForLog, 'after', 'static-method');
|
|
32
|
+
TransformerHandler(this, this.startFunctionForLog, 'before', 'function');
|
|
33
|
+
TransformerHandler(this, this.leaveFunctionForLog, 'after', 'function');
|
|
34
|
+
TransformerHandler(this, this.onLogCall, 'before', 'call');
|
|
35
|
+
}
|
|
36
|
+
|
|
28
37
|
static initState(state: CustomState): void {
|
|
29
38
|
state.scope = state.scope ?? [];
|
|
30
39
|
}
|
|
31
40
|
|
|
32
|
-
@OnClass()
|
|
33
41
|
static startClassForLog(state: CustomState, node: ts.ClassDeclaration): typeof node {
|
|
34
42
|
this.initState(state);
|
|
35
43
|
state.scope.push({ type: 'class', name: node.name?.text ?? 'unknown' });
|
|
36
44
|
return node;
|
|
37
45
|
}
|
|
38
46
|
|
|
39
|
-
@AfterClass()
|
|
40
47
|
static leaveClassForLog(state: CustomState, node: ts.ClassDeclaration): typeof node {
|
|
41
48
|
state.scope.pop();
|
|
42
49
|
return node;
|
|
43
50
|
}
|
|
44
51
|
|
|
45
|
-
@OnStaticMethod()
|
|
46
|
-
@OnMethod()
|
|
47
52
|
static startMethodForLog(state: CustomState, node: ts.MethodDeclaration): typeof node {
|
|
48
53
|
this.initState(state);
|
|
49
54
|
let name = 'unknown';
|
|
@@ -54,27 +59,22 @@ export class ConsoleLogTransformer {
|
|
|
54
59
|
return node;
|
|
55
60
|
}
|
|
56
61
|
|
|
57
|
-
@AfterStaticMethod()
|
|
58
|
-
@AfterMethod()
|
|
59
62
|
static leaveMethodForLog(state: CustomState, node: ts.MethodDeclaration): typeof node {
|
|
60
63
|
state.scope.pop();
|
|
61
64
|
return node;
|
|
62
65
|
}
|
|
63
66
|
|
|
64
|
-
@OnFunction()
|
|
65
67
|
static startFunctionForLog(state: CustomState, node: ts.FunctionDeclaration | ts.FunctionExpression): typeof node {
|
|
66
68
|
this.initState(state);
|
|
67
69
|
state.scope.push({ type: 'function', name: node.name?.text ?? 'unknown' });
|
|
68
70
|
return node;
|
|
69
71
|
}
|
|
70
72
|
|
|
71
|
-
@AfterFunction()
|
|
72
73
|
static leaveFunctionForLog(state: CustomState, node: ts.FunctionDeclaration | ts.FunctionExpression): typeof node {
|
|
73
74
|
state.scope.pop();
|
|
74
75
|
return node;
|
|
75
76
|
}
|
|
76
77
|
|
|
77
|
-
@OnCall()
|
|
78
78
|
static onLogCall(state: CustomState, node: ts.CallExpression): typeof node | ts.Identifier {
|
|
79
79
|
if (!ts.isPropertyAccessExpression(node.expression)) {
|
|
80
80
|
return node;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import ts from 'typescript';
|
|
1
|
+
import type ts from 'typescript';
|
|
2
2
|
|
|
3
|
-
import { TransformerState,
|
|
3
|
+
import { type TransformerState, CoreUtil, TransformerHandler } from '@travetto/transformer';
|
|
4
4
|
|
|
5
5
|
const DebugSymbol = Symbol();
|
|
6
6
|
|
|
@@ -16,7 +16,10 @@ interface DebugState {
|
|
|
16
16
|
*/
|
|
17
17
|
export class DebugEntryTransformer {
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
static {
|
|
20
|
+
TransformerHandler(this, this.debugOnEntry, 'before', 'method', ['DebugBreak']);
|
|
21
|
+
}
|
|
22
|
+
|
|
20
23
|
static debugOnEntry(state: TransformerState & DebugState, node: ts.MethodDeclaration): ts.MethodDeclaration {
|
|
21
24
|
if (!state[DebugSymbol]) {
|
|
22
25
|
const imp = state.importFile('@travetto/runtime/src/debug.ts').identifier;
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { TransformerHandler, type TransformerState } from '@travetto/transformer';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Dynamic Import Transformer
|
|
7
7
|
*/
|
|
8
8
|
export class DynamicImportTransformer {
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
static {
|
|
11
|
+
TransformerHandler(this, this.onCall, 'before', 'call');
|
|
12
|
+
}
|
|
13
|
+
|
|
11
14
|
static onCall(state: TransformerState, node: ts.CallExpression): typeof node | ts.Identifier {
|
|
12
15
|
if (
|
|
13
16
|
ts.isCallExpression(node) &&
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
2
|
|
|
3
|
-
import { TransformerState,
|
|
3
|
+
import { type TransformerState, CoreUtil, TransformerHandler } from '@travetto/transformer';
|
|
4
4
|
|
|
5
5
|
import type { FunctionMetadataTag } from '../src/function.ts';
|
|
6
6
|
import { MetadataRegistrationUtil } from './transformer/metadata.ts';
|
|
@@ -18,10 +18,16 @@ interface MetadataInfo {
|
|
|
18
18
|
*/
|
|
19
19
|
export class RegisterTransformer {
|
|
20
20
|
|
|
21
|
+
static {
|
|
22
|
+
TransformerHandler(this, this.collectClassMetadata, 'before', 'class');
|
|
23
|
+
TransformerHandler(this, this.collectMethodMetadata, 'before', 'method');
|
|
24
|
+
TransformerHandler(this, this.registerClassMetadata, 'after', 'class');
|
|
25
|
+
TransformerHandler(this, this.registerFunctionMetadata, 'before', 'function');
|
|
26
|
+
}
|
|
27
|
+
|
|
21
28
|
/**
|
|
22
29
|
* Hash each class
|
|
23
30
|
*/
|
|
24
|
-
@OnClass()
|
|
25
31
|
static collectClassMetadata(state: TransformerState & MetadataInfo, node: ts.ClassDeclaration): ts.ClassDeclaration {
|
|
26
32
|
if (!MetadataRegistrationUtil.isValid(state)) {
|
|
27
33
|
return node; // Exclude self
|
|
@@ -35,7 +41,6 @@ export class RegisterTransformer {
|
|
|
35
41
|
/**
|
|
36
42
|
* Hash each method
|
|
37
43
|
*/
|
|
38
|
-
@OnMethod()
|
|
39
44
|
static collectMethodMetadata(state: TransformerState & MetadataInfo, node: ts.MethodDeclaration): ts.MethodDeclaration {
|
|
40
45
|
if (state[ClassSymbol] && ts.isIdentifier(node.name) && !CoreUtil.isAbstract(node) && ts.isClassDeclaration(node.parent)) {
|
|
41
46
|
state[MethodsSymbol]![node.name.escapedText.toString()] = MetadataRegistrationUtil.tag(state, node);
|
|
@@ -46,7 +51,6 @@ export class RegisterTransformer {
|
|
|
46
51
|
/**
|
|
47
52
|
* After visiting each class, register all the collected metadata
|
|
48
53
|
*/
|
|
49
|
-
@AfterClass()
|
|
50
54
|
static registerClassMetadata(state: TransformerState & MetadataInfo, node: ts.ClassDeclaration): ts.ClassDeclaration {
|
|
51
55
|
if (!state[ClassSymbol]) {
|
|
52
56
|
return node;
|
|
@@ -60,7 +64,6 @@ export class RegisterTransformer {
|
|
|
60
64
|
/**
|
|
61
65
|
* Register proper functions
|
|
62
66
|
*/
|
|
63
|
-
@OnFunction()
|
|
64
67
|
static registerFunctionMetadata(state: TransformerState & MetadataInfo, node: ts.FunctionDeclaration | ts.FunctionExpression): typeof node {
|
|
65
68
|
if (!MetadataRegistrationUtil.isValid(state) || !ts.isFunctionDeclaration(node)) {
|
|
66
69
|
return node;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
2
|
|
|
3
|
-
import { TransformerState,
|
|
3
|
+
import { type TransformerState, TransformerHandler } from '@travetto/transformer';
|
|
4
4
|
|
|
5
5
|
const PATH_IMPORT = '@travetto/manifest/src/path.ts';
|
|
6
6
|
|
|
@@ -17,7 +17,10 @@ const isImport = (node: ts.Node): node is ts.ImportDeclaration =>
|
|
|
17
17
|
*/
|
|
18
18
|
export class PathImportTransformer {
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
static {
|
|
21
|
+
TransformerHandler(this, this.rewritePathImport, 'before', 'file');
|
|
22
|
+
}
|
|
23
|
+
|
|
21
24
|
static rewritePathImport(state: TransformerState, node: ts.SourceFile): ts.SourceFile {
|
|
22
25
|
const statement = node.statements.find(isImport);
|
|
23
26
|
if (statement) {
|