@travetto/runtime 8.0.0-alpha.2 → 8.0.0-alpha.21
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 +24 -21
- package/__index__.ts +6 -5
- package/package.json +9 -6
- package/src/binary-metadata.ts +33 -19
- package/src/binary.ts +18 -10
- package/src/codec.ts +25 -7
- package/src/console.ts +20 -12
- package/src/context.ts +26 -17
- package/src/debug.ts +1 -2
- package/src/env.ts +42 -22
- package/src/error.ts +4 -15
- package/src/exec.ts +41 -27
- package/src/file-loader.ts +4 -5
- package/src/function.ts +14 -6
- package/src/global.d.ts +20 -0
- package/src/json.ts +63 -48
- package/src/manifest-index.ts +1 -1
- package/src/queue.ts +1 -2
- package/src/resources.ts +1 -1
- package/src/shutdown.ts +21 -14
- package/src/time.ts +54 -19
- package/src/trv.d.ts +1 -1
- package/src/types.ts +30 -15
- package/src/util.ts +20 -22
- package/src/watch.ts +27 -18
- package/support/patch.js +42 -0
- package/support/transformer/metadata.ts +15 -28
- package/support/transformer.concrete-type.ts +19 -21
- package/support/transformer.console-log.ts +13 -19
- package/support/transformer.debug-method.ts +13 -9
- package/support/transformer.dynamic-import.ts +1 -2
- package/support/transformer.function-metadata.ts +6 -4
- package/support/transformer.rewrite-path-import.ts +9 -12
- package/support/polyfill.js +0 -9
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { LiteralUtil, TransformerHandler, type TransformerState } from '@travetto/transformer';
|
|
4
4
|
|
|
5
5
|
const CONSOLE_IMPORT = '@travetto/runtime/src/console.ts';
|
|
6
6
|
|
|
7
7
|
type CustomState = TransformerState & {
|
|
8
|
-
scope: { type: 'method' | 'class' | 'function'
|
|
8
|
+
scope: { type: 'method' | 'class' | 'function'; name: string }[];
|
|
9
9
|
imported?: ts.Identifier;
|
|
10
10
|
};
|
|
11
11
|
|
|
@@ -21,7 +21,6 @@ const VALID_LEVELS: Record<string, string> = {
|
|
|
21
21
|
* Logging support with code-location aware messages.
|
|
22
22
|
*/
|
|
23
23
|
export class ConsoleLogTransformer {
|
|
24
|
-
|
|
25
24
|
static {
|
|
26
25
|
TransformerHandler(this, this.startClassForLog, 'before', 'class');
|
|
27
26
|
TransformerHandler(this, this.leaveClassForLog, 'after', 'class');
|
|
@@ -91,23 +90,18 @@ export class ConsoleLogTransformer {
|
|
|
91
90
|
const level = name.escapedText!;
|
|
92
91
|
|
|
93
92
|
if (VALID_LEVELS[level]) {
|
|
94
|
-
const identifier = state.imported ??= state.importFile(CONSOLE_IMPORT).identifier;
|
|
95
|
-
return state.factory.updateCallExpression(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
scope: state.scope?.map(part => part.name).join(':'),
|
|
105
|
-
args: node.arguments.slice(0)
|
|
106
|
-
}),
|
|
107
|
-
]
|
|
108
|
-
);
|
|
93
|
+
const identifier = (state.imported ??= state.importFile(CONSOLE_IMPORT).identifier);
|
|
94
|
+
return state.factory.updateCallExpression(node, state.createAccess(identifier, 'log'), node.typeArguments, [
|
|
95
|
+
LiteralUtil.fromLiteral(state.factory, {
|
|
96
|
+
level: state.factory.createStringLiteral(VALID_LEVELS[level]),
|
|
97
|
+
import: state.getModuleIdentifier(),
|
|
98
|
+
line: state.source.getLineAndCharacterOfPosition(node.getStart(state.source)).line + 1,
|
|
99
|
+
scope: state.scope?.map(part => part.name).join(':'),
|
|
100
|
+
args: node.arguments.slice(0)
|
|
101
|
+
})
|
|
102
|
+
]);
|
|
109
103
|
} else {
|
|
110
104
|
return node;
|
|
111
105
|
}
|
|
112
106
|
}
|
|
113
|
-
}
|
|
107
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type ts from 'typescript';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { CoreUtil, TransformerHandler, type TransformerState } from '@travetto/transformer';
|
|
4
4
|
|
|
5
5
|
const DebugSymbol = Symbol();
|
|
6
6
|
|
|
@@ -15,7 +15,6 @@ interface DebugState {
|
|
|
15
15
|
* Add debugger-optional statement to methods that should be debuggable
|
|
16
16
|
*/
|
|
17
17
|
export class DebugEntryTransformer {
|
|
18
|
-
|
|
19
18
|
static {
|
|
20
19
|
TransformerHandler(this, this.debugOnEntry, 'before', 'method', ['DebugBreak']);
|
|
21
20
|
}
|
|
@@ -26,7 +25,8 @@ export class DebugEntryTransformer {
|
|
|
26
25
|
state[DebugSymbol] = CoreUtil.createAccess(state.factory, imp, 'tryDebugger');
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
return state.factory.updateMethodDeclaration(
|
|
28
|
+
return state.factory.updateMethodDeclaration(
|
|
29
|
+
node,
|
|
30
30
|
node.modifiers,
|
|
31
31
|
node.asteriskToken,
|
|
32
32
|
node.name,
|
|
@@ -34,11 +34,15 @@ export class DebugEntryTransformer {
|
|
|
34
34
|
node.typeParameters,
|
|
35
35
|
node.parameters,
|
|
36
36
|
node.type,
|
|
37
|
-
node.body
|
|
38
|
-
state.factory.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
node.body
|
|
38
|
+
? state.factory.updateBlock(node.body, [
|
|
39
|
+
state.factory.createIfStatement(
|
|
40
|
+
state[DebugSymbol]!,
|
|
41
|
+
state.factory.createExpressionStatement(state.factory.createIdentifier('debugger'))
|
|
42
|
+
),
|
|
43
|
+
...node.body.statements
|
|
44
|
+
])
|
|
45
|
+
: node.body
|
|
42
46
|
);
|
|
43
47
|
}
|
|
44
|
-
}
|
|
48
|
+
}
|
|
@@ -6,7 +6,6 @@ import { TransformerHandler, type TransformerState } from '@travetto/transformer
|
|
|
6
6
|
* Dynamic Import Transformer
|
|
7
7
|
*/
|
|
8
8
|
export class DynamicImportTransformer {
|
|
9
|
-
|
|
10
9
|
static {
|
|
11
10
|
TransformerHandler(this, this.onCall, 'before', 'call');
|
|
12
11
|
}
|
|
@@ -25,4 +24,4 @@ export class DynamicImportTransformer {
|
|
|
25
24
|
}
|
|
26
25
|
return node;
|
|
27
26
|
}
|
|
28
|
-
}
|
|
27
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { CoreUtil, TransformerHandler, type TransformerState } from '@travetto/transformer';
|
|
4
4
|
|
|
5
5
|
import type { FunctionMetadataTag } from '../src/function.ts';
|
|
6
6
|
import { MetadataRegistrationUtil } from './transformer/metadata.ts';
|
|
@@ -17,7 +17,6 @@ interface MetadataInfo {
|
|
|
17
17
|
* Providing metadata for classes
|
|
18
18
|
*/
|
|
19
19
|
export class RegisterTransformer {
|
|
20
|
-
|
|
21
20
|
static {
|
|
22
21
|
TransformerHandler(this, this.collectClassMetadata, 'before', 'class');
|
|
23
22
|
TransformerHandler(this, this.collectMethodMetadata, 'before', 'method');
|
|
@@ -64,7 +63,10 @@ export class RegisterTransformer {
|
|
|
64
63
|
/**
|
|
65
64
|
* Register proper functions
|
|
66
65
|
*/
|
|
67
|
-
static registerFunctionMetadata(
|
|
66
|
+
static registerFunctionMetadata(
|
|
67
|
+
state: TransformerState & MetadataInfo,
|
|
68
|
+
node: ts.FunctionDeclaration | ts.FunctionExpression
|
|
69
|
+
): typeof node {
|
|
68
70
|
if (!MetadataRegistrationUtil.isValid(state) || !ts.isFunctionDeclaration(node)) {
|
|
69
71
|
return node;
|
|
70
72
|
}
|
|
@@ -74,4 +76,4 @@ export class RegisterTransformer {
|
|
|
74
76
|
}
|
|
75
77
|
return node;
|
|
76
78
|
}
|
|
77
|
-
}
|
|
79
|
+
}
|
|
@@ -1,22 +1,18 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
2
|
|
|
3
|
-
import { type TransformerState
|
|
3
|
+
import { TransformerHandler, type TransformerState } from '@travetto/transformer';
|
|
4
4
|
|
|
5
5
|
const PATH_IMPORT = '@travetto/manifest/src/path.ts';
|
|
6
6
|
|
|
7
7
|
const isImport = (node: ts.Node): node is ts.ImportDeclaration =>
|
|
8
|
-
ts.isImportDeclaration(node)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
node.moduleSpecifier.text === 'node:path'
|
|
12
|
-
|| node.moduleSpecifier.text === 'path'
|
|
13
|
-
);
|
|
8
|
+
ts.isImportDeclaration(node) &&
|
|
9
|
+
ts.isStringLiteral(node.moduleSpecifier) &&
|
|
10
|
+
(node.moduleSpecifier.text === 'node:path' || node.moduleSpecifier.text === 'path');
|
|
14
11
|
|
|
15
12
|
/**
|
|
16
13
|
* Rewriting path imports to use manifest's path
|
|
17
14
|
*/
|
|
18
15
|
export class PathImportTransformer {
|
|
19
|
-
|
|
20
16
|
static {
|
|
21
17
|
TransformerHandler(this, this.rewritePathImport, 'before', 'file');
|
|
22
18
|
}
|
|
@@ -31,10 +27,11 @@ export class PathImportTransformer {
|
|
|
31
27
|
state.factory.createStringLiteral(PATH_IMPORT),
|
|
32
28
|
statement.attributes
|
|
33
29
|
);
|
|
34
|
-
return state.factory.updateSourceFile(
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
return state.factory.updateSourceFile(
|
|
31
|
+
node,
|
|
32
|
+
node.statements.map(item => (item === statement ? updated : item))
|
|
33
|
+
);
|
|
37
34
|
}
|
|
38
35
|
return node;
|
|
39
36
|
}
|
|
40
|
-
}
|
|
37
|
+
}
|
package/support/polyfill.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import 'temporal-polyfill-lite/global';
|
|
2
|
-
|
|
3
|
-
Map.prototype.getOrInsert ??= function(key, value) {
|
|
4
|
-
return (this.has(key) || this.set(key, value), this.get(key));
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
Map.prototype.getOrInsertComputed ??= function(key, compute) {
|
|
8
|
-
return (this.has(key) || this.set(key, compute()), this.get(key));
|
|
9
|
-
};
|