@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 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(fn: Function): string;
67
+ getSourceFile(handle: Function): string;
66
68
  /** Get import for function */
67
- getImport(fn: Function): string;
69
+ getImport(handle: Function): string;
68
70
  /** Import from a given path */
69
- async importFrom<T = unknown>(imp?: string): Promise<T>;
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
- "use strict";
214
- Object.defineProperty(exports, "__esModule", { value: true });
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.4",
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.2",
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.3"
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(fn: Function): string {
107
- return this.#idx.getFromImport(this.getImport(fn))?.sourceFile!;
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(fn: Function): string {
112
- return describeFunction(fn).import;
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>(imp?: string): Promise<T> {
117
- const file = path.resolve(this.#idx.mainModule.sourcePath, imp!);
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
- imp = this.#idx.getFromSource(file)?.import;
123
+ location = this.#idx.getFromSource(file)?.import;
120
124
  }
121
125
 
122
- if (!imp) {
123
- throw new Error(`Unable to find ${imp}, not in the manifest`);
124
- } else if (imp.endsWith('.json')) {
125
- imp = this.#idx.getFromImport(imp)?.sourceFile ?? imp;
126
- return fs.readFile(imp, 'utf8').then(JSONUtil.parseSafe<T>);
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(imp)) {
130
- if (imp.startsWith('@')) {
131
- if (/[/].*?[/]/.test(imp)) {
132
- imp = `${imp}.ts`;
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
- imp = `${imp}.ts`;
139
+ location = `${location}.ts`;
136
140
  }
137
141
  }
138
142
 
139
- imp = ManifestModuleUtil.withOutputExtension(imp);
140
- const imported = await import(imp);
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, spawn, type SpawnOptions } from 'node:child_process';
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, type Any } from './types.ts';
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
@@ -42,7 +42,6 @@ export class ConsoleLogTransformer {
42
42
  return node;
43
43
  }
44
44
 
45
-
46
45
  @OnStaticMethod()
47
46
  @OnMethod()
48
47
  static startMethodForLog(state: CustomState, node: ts.MethodDeclaration): typeof node {