@travetto/runtime 7.0.0-rc.3 → 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
@@ -37,8 +37,10 @@ class $Runtime {
37
37
  constructor(idx: ManifestIndex, resourceOverrides?: Record<string, string>);
38
38
  /** Get env name, with support for the default env */
39
39
  get env(): string | undefined;
40
- /** Are we in development mode */
40
+ /** Are we in production mode */
41
41
  get production(): boolean;
42
+ /** Get environment type mode */
43
+ get envType(): 'production' | 'development' | 'test';
42
44
  /** Get debug value */
43
45
  get debug(): false | string;
44
46
  /** Manifest main */
@@ -49,6 +51,8 @@ class $Runtime {
49
51
  get monoRoot(): boolean;
50
52
  /** Main source path */
51
53
  get mainSourcePath(): string;
54
+ /** Get trv entrypoint */
55
+ get trvEntryPoint(): string;
52
56
  /** Produce a workspace relative path */
53
57
  workspaceRelative(...parts: string[]): string;
54
58
  /** Strip off the workspace path from a file */
@@ -60,11 +64,11 @@ class $Runtime {
60
64
  /** Resolve resource paths */
61
65
  resourcePaths(paths: string[] = []): string[];
62
66
  /** Get source for function */
63
- getSourceFile(fn: Function): string;
67
+ getSourceFile(handle: Function): string;
64
68
  /** Get import for function */
65
- getImport(fn: Function): string;
69
+ getImport(handle: Function): string;
66
70
  /** Import from a given path */
67
- async importFrom<T = unknown>(imp?: string): Promise<T>;
71
+ async importFrom<T = unknown>(location?: string): Promise<T>;
68
72
  }
69
73
  ```
70
74
 
@@ -208,14 +212,10 @@ export function work() {
208
212
 
209
213
  **Code: Sample After Transpilation**
210
214
  ```javascript
211
- "use strict";
212
- Object.defineProperty(exports, "__esModule", { value: true });
213
- exports.work = work;
214
- const tslib_1 = require("tslib");
215
- const Δfunction = tslib_1.__importStar(require("@travetto/runtime/src/function.js"));
216
- 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";
217
217
  var mod_1 = ["@travetto/runtime", "doc/transpile.ts"];
218
- function work() {
218
+ export function work() {
219
219
  Δconsole.log({ level: "debug", import: mod_1, line: 2, scope: "work", args: ['Start Work'] });
220
220
  try {
221
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",
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} */
@@ -32,11 +31,20 @@ class $Runtime {
32
31
  return Env.TRV_ENV.value || (!this.production ? this.#idx.manifest.workspace.defaultEnv : undefined);
33
32
  }
34
33
 
35
- /** Are we in development mode */
34
+ /** Are we in production mode */
36
35
  get production(): boolean {
37
36
  return process.env.NODE_ENV === 'production';
38
37
  }
39
38
 
39
+ /** Get environment type mode */
40
+ get envType(): 'production' | 'development' | 'test' {
41
+ switch (process.env.NODE_ENV) {
42
+ case 'production': return 'production';
43
+ case 'test': return 'test';
44
+ default: return 'development';
45
+ }
46
+ }
47
+
40
48
  /** Get debug value */
41
49
  get debug(): false | string {
42
50
  const value = Env.DEBUG.value ?? '';
@@ -63,6 +71,11 @@ class $Runtime {
63
71
  return this.#idx.mainModule.sourcePath;
64
72
  }
65
73
 
74
+ /** Get trv entrypoint */
75
+ get trvEntryPoint(): string {
76
+ return this.workspaceRelative('node_modules', '.bin', 'trv');
77
+ }
78
+
66
79
  /** Produce a workspace relative path */
67
80
  workspaceRelative(...parts: string[]): string {
68
81
  return path.resolve(this.workspace.path, ...parts);
@@ -94,49 +107,41 @@ class $Runtime {
94
107
  }
95
108
 
96
109
  /** Get source for function */
97
- getSourceFile(fn: Function): string {
98
- return this.#idx.getFromImport(this.getImport(fn))?.sourceFile!;
110
+ getSourceFile(handle: Function): string {
111
+ return this.#idx.getFromImport(this.getImport(handle))?.sourceFile!;
99
112
  }
100
113
 
101
114
  /** Get import for function */
102
- getImport(fn: Function): string {
103
- return describeFunction(fn).import;
115
+ getImport(handle: Function): string {
116
+ return describeFunction(handle).import;
104
117
  }
105
118
 
106
119
  /** Import from a given path */
107
- async importFrom<T = unknown>(imp?: string): Promise<T> {
108
- 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!);
109
122
  if (await fs.stat(file).catch(() => false)) {
110
- imp = this.#idx.getFromSource(file)?.import;
123
+ location = this.#idx.getFromSource(file)?.import;
111
124
  }
112
125
 
113
- if (!imp) {
114
- throw new Error(`Unable to find ${imp}, not in the manifest`);
115
- } else if (imp.endsWith('.json')) {
116
- imp = this.#idx.getFromImport(imp)?.sourceFile ?? imp;
117
- 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>);
118
131
  }
119
132
 
120
- if (!ManifestModuleUtil.SOURCE_EXT_REGEX.test(imp)) {
121
- if (imp.startsWith('@')) {
122
- if (/[/].*?[/]/.test(imp)) {
123
- imp = `${imp}.ts`;
133
+ if (!ManifestModuleUtil.SOURCE_EXT_REGEX.test(location)) {
134
+ if (location.startsWith('@')) {
135
+ if (/[/].*?[/]/.test(location)) {
136
+ location = `${location}.ts`;
124
137
  }
125
138
  } else {
126
- imp = `${imp}.ts`;
139
+ location = `${location}.ts`;
127
140
  }
128
141
  }
129
142
 
130
- imp = ManifestModuleUtil.withOutputExtension(imp);
131
- const imported = await import(imp);
132
- if (imported?.default?.default) {
133
- // Unpack default.default, typescript does this in a way that requires recreating the whole object
134
- const def = imported?.default?.default;
135
- return Object.defineProperties(castTo({}), {
136
- ...Object.getOwnPropertyDescriptors(imported),
137
- default: { get: () => def, configurable: false }
138
- });
139
- }
143
+ location = ManifestModuleUtil.withOutputExtension(location);
144
+ const imported = await import(location);
140
145
  return imported;
141
146
  }
142
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
package/src/watch.ts CHANGED
@@ -3,7 +3,6 @@ import { ManifestModuleUtil, type ChangeEventType, type ManifestModuleFileType }
3
3
  import { RuntimeIndex } from './manifest-index.ts';
4
4
  import { ShutdownManager } from './shutdown.ts';
5
5
  import { Util } from './util.ts';
6
- import { AppError } from './error.ts';
7
6
 
8
7
  type WatchEvent = { file: string, action: ChangeEventType, output: string, module: string, import: string, time: number };
9
8
 
@@ -49,7 +48,7 @@ export async function* watchCompiler(config?: WatchCompilerOptions): AsyncIterab
49
48
  await client.waitForState(['compile-end', 'watch-start'], undefined, controller.signal);
50
49
 
51
50
  if (!await client.isWatching()) { // If we get here, without a watch
52
- throw new AppError('Compiler is not running');
51
+ await Util.nonBlockingTimeout(maxWindow / (maxIterations * 2));
53
52
  } else {
54
53
  if (iterations.length) {
55
54
  config?.onRestart?.();
@@ -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 {