@travetto/runtime 7.0.0-rc.4 → 7.0.0-rc.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 +8 -10
- package/package.json +4 -3
- package/src/context.ts +24 -28
- package/src/exec.ts +2 -10
- package/support/transformer.console-log.ts +0 -1
package/README.md
CHANGED
|
@@ -51,6 +51,8 @@ class $Runtime {
|
|
|
51
51
|
get monoRoot(): boolean;
|
|
52
52
|
/** Main source path */
|
|
53
53
|
get mainSourcePath(): string;
|
|
54
|
+
/** Get trv entrypoint */
|
|
55
|
+
get trvEntryPoint(): string;
|
|
54
56
|
/** Produce a workspace relative path */
|
|
55
57
|
workspaceRelative(...parts: string[]): string;
|
|
56
58
|
/** Strip off the workspace path from a file */
|
|
@@ -62,11 +64,11 @@ class $Runtime {
|
|
|
62
64
|
/** Resolve resource paths */
|
|
63
65
|
resourcePaths(paths: string[] = []): string[];
|
|
64
66
|
/** Get source for function */
|
|
65
|
-
getSourceFile(
|
|
67
|
+
getSourceFile(handle: Function): string;
|
|
66
68
|
/** Get import for function */
|
|
67
|
-
getImport(
|
|
69
|
+
getImport(handle: Function): string;
|
|
68
70
|
/** Import from a given path */
|
|
69
|
-
async importFrom<T = unknown>(
|
|
71
|
+
async importFrom<T = unknown>(location?: string): Promise<T>;
|
|
70
72
|
}
|
|
71
73
|
```
|
|
72
74
|
|
|
@@ -210,14 +212,10 @@ export function work() {
|
|
|
210
212
|
|
|
211
213
|
**Code: Sample After Transpilation**
|
|
212
214
|
```javascript
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
exports.work = work;
|
|
216
|
-
const tslib_1 = require("tslib");
|
|
217
|
-
const Δfunction = tslib_1.__importStar(require("@travetto/runtime/src/function.js"));
|
|
218
|
-
const Δconsole = tslib_1.__importStar(require("@travetto/runtime/src/console.js"));
|
|
215
|
+
import * as Δfunction from "@travetto/runtime/src/function.js";
|
|
216
|
+
import * as Δconsole from "@travetto/runtime/src/console.js";
|
|
219
217
|
var mod_1 = ["@travetto/runtime", "doc/transpile.ts"];
|
|
220
|
-
function work() {
|
|
218
|
+
export function work() {
|
|
221
219
|
Δconsole.log({ level: "debug", import: mod_1, line: 2, scope: "work", args: ['Start Work'] });
|
|
222
220
|
try {
|
|
223
221
|
1 / 0;
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/runtime",
|
|
3
|
-
"version": "7.0.0-rc.
|
|
3
|
+
"version": "7.0.0-rc.5",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"description": "Runtime for travetto applications.",
|
|
5
6
|
"keywords": [
|
|
6
7
|
"console-manager",
|
|
@@ -25,12 +26,12 @@
|
|
|
25
26
|
"directory": "module/runtime"
|
|
26
27
|
},
|
|
27
28
|
"dependencies": {
|
|
28
|
-
"@travetto/manifest": "^7.0.0-rc.
|
|
29
|
+
"@travetto/manifest": "^7.0.0-rc.3",
|
|
29
30
|
"@types/debug": "^4.1.12",
|
|
30
31
|
"debug": "^4.4.3"
|
|
31
32
|
},
|
|
32
33
|
"peerDependencies": {
|
|
33
|
-
"@travetto/transformer": "^7.0.0-rc.
|
|
34
|
+
"@travetto/transformer": "^7.0.0-rc.4"
|
|
34
35
|
},
|
|
35
36
|
"peerDependenciesMeta": {
|
|
36
37
|
"@travetto/transformer": {
|
package/src/context.ts
CHANGED
|
@@ -6,7 +6,6 @@ import { type ManifestIndex, type ManifestContext, ManifestModuleUtil } from '@t
|
|
|
6
6
|
import { Env } from './env.ts';
|
|
7
7
|
import { RuntimeIndex } from './manifest-index.ts';
|
|
8
8
|
import { describeFunction } from './function.ts';
|
|
9
|
-
import { castTo } from './types.ts';
|
|
10
9
|
import { JSONUtil } from './json.ts';
|
|
11
10
|
|
|
12
11
|
/** Constrained version of {@type ManifestContext} */
|
|
@@ -72,6 +71,11 @@ class $Runtime {
|
|
|
72
71
|
return this.#idx.mainModule.sourcePath;
|
|
73
72
|
}
|
|
74
73
|
|
|
74
|
+
/** Get trv entrypoint */
|
|
75
|
+
get trvEntryPoint(): string {
|
|
76
|
+
return this.workspaceRelative('node_modules', '.bin', 'trv');
|
|
77
|
+
}
|
|
78
|
+
|
|
75
79
|
/** Produce a workspace relative path */
|
|
76
80
|
workspaceRelative(...parts: string[]): string {
|
|
77
81
|
return path.resolve(this.workspace.path, ...parts);
|
|
@@ -103,49 +107,41 @@ class $Runtime {
|
|
|
103
107
|
}
|
|
104
108
|
|
|
105
109
|
/** Get source for function */
|
|
106
|
-
getSourceFile(
|
|
107
|
-
return this.#idx.getFromImport(this.getImport(
|
|
110
|
+
getSourceFile(handle: Function): string {
|
|
111
|
+
return this.#idx.getFromImport(this.getImport(handle))?.sourceFile!;
|
|
108
112
|
}
|
|
109
113
|
|
|
110
114
|
/** Get import for function */
|
|
111
|
-
getImport(
|
|
112
|
-
return describeFunction(
|
|
115
|
+
getImport(handle: Function): string {
|
|
116
|
+
return describeFunction(handle).import;
|
|
113
117
|
}
|
|
114
118
|
|
|
115
119
|
/** Import from a given path */
|
|
116
|
-
async importFrom<T = unknown>(
|
|
117
|
-
const file = path.resolve(this.#idx.mainModule.sourcePath,
|
|
120
|
+
async importFrom<T = unknown>(location?: string): Promise<T> {
|
|
121
|
+
const file = path.resolve(this.#idx.mainModule.sourcePath, location!);
|
|
118
122
|
if (await fs.stat(file).catch(() => false)) {
|
|
119
|
-
|
|
123
|
+
location = this.#idx.getFromSource(file)?.import;
|
|
120
124
|
}
|
|
121
125
|
|
|
122
|
-
if (!
|
|
123
|
-
throw new Error(`Unable to find ${
|
|
124
|
-
} else if (
|
|
125
|
-
|
|
126
|
-
return fs.readFile(
|
|
126
|
+
if (!location) {
|
|
127
|
+
throw new Error(`Unable to find ${location}, not in the manifest`);
|
|
128
|
+
} else if (location.endsWith('.json')) {
|
|
129
|
+
location = this.#idx.getFromImport(location)?.sourceFile ?? location;
|
|
130
|
+
return fs.readFile(location, 'utf8').then(JSONUtil.parseSafe<T>);
|
|
127
131
|
}
|
|
128
132
|
|
|
129
|
-
if (!ManifestModuleUtil.SOURCE_EXT_REGEX.test(
|
|
130
|
-
if (
|
|
131
|
-
if (/[/].*?[/]/.test(
|
|
132
|
-
|
|
133
|
+
if (!ManifestModuleUtil.SOURCE_EXT_REGEX.test(location)) {
|
|
134
|
+
if (location.startsWith('@')) {
|
|
135
|
+
if (/[/].*?[/]/.test(location)) {
|
|
136
|
+
location = `${location}.ts`;
|
|
133
137
|
}
|
|
134
138
|
} else {
|
|
135
|
-
|
|
139
|
+
location = `${location}.ts`;
|
|
136
140
|
}
|
|
137
141
|
}
|
|
138
142
|
|
|
139
|
-
|
|
140
|
-
const imported = await import(
|
|
141
|
-
if (imported?.default?.default) {
|
|
142
|
-
// Unpack default.default, typescript does this in a way that requires recreating the whole object
|
|
143
|
-
const def = imported?.default?.default;
|
|
144
|
-
return Object.defineProperties(castTo({}), {
|
|
145
|
-
...Object.getOwnPropertyDescriptors(imported),
|
|
146
|
-
default: { get: () => def, configurable: false }
|
|
147
|
-
});
|
|
148
|
-
}
|
|
143
|
+
location = ManifestModuleUtil.withOutputExtension(location);
|
|
144
|
+
const imported = await import(location);
|
|
149
145
|
return imported;
|
|
150
146
|
}
|
|
151
147
|
}
|
package/src/exec.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type ChildProcess
|
|
1
|
+
import { type ChildProcess } from 'node:child_process';
|
|
2
2
|
import type { Readable } from 'node:stream';
|
|
3
3
|
import { createInterface } from 'node:readline/promises';
|
|
4
4
|
|
|
5
|
-
import { castTo
|
|
5
|
+
import { castTo } from './types.ts';
|
|
6
6
|
|
|
7
7
|
const ResultSymbol = Symbol();
|
|
8
8
|
|
|
@@ -39,14 +39,6 @@ type ExecutionBaseResult = Omit<ExecutionResult, 'stdout' | 'stderr'>;
|
|
|
39
39
|
*/
|
|
40
40
|
export class ExecUtil {
|
|
41
41
|
|
|
42
|
-
/**
|
|
43
|
-
* Spawn wrapper that ensures performant invocation of trv commands
|
|
44
|
-
*/
|
|
45
|
-
static spawnTrv(cmd: string, args: string[], options: SpawnOptions): ChildProcess {
|
|
46
|
-
const entry = (globalThis as Any).__entry_point__ ?? process.argv.at(1);
|
|
47
|
-
return spawn(process.argv0, [entry, cmd, ...args], options);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
42
|
/**
|
|
51
43
|
* Take a child process, and some additional options, and produce a promise that
|
|
52
44
|
* represents the entire execution. On successful completion the promise will resolve, and
|