@travetto/runtime 5.0.1 → 5.0.3

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
@@ -70,15 +70,15 @@ class $Runtime {
70
70
  ```
71
71
 
72
72
  ## Environment Support
73
- The functionality we support for testing and retrieving environment information for known environment variables. They can be accessed directly on the [Env](https://github.com/travetto/travetto/tree/main/module/runtime/src/env.ts#L109) object, and will return a scoped [EnvProp](https://github.com/travetto/travetto/tree/main/module/runtime/src/env.ts#L6), that is compatible with the property definition. E.g. only showing boolean related fields when the underlying flag supports `true` or `false`
73
+ The functionality we support for testing and retrieving environment information for known environment variables. They can be accessed directly on the [Env](https://github.com/travetto/travetto/tree/main/module/runtime/src/env.ts#L111) object, and will return a scoped [EnvProp](https://github.com/travetto/travetto/tree/main/module/runtime/src/env.ts#L8), that is compatible with the property definition. E.g. only showing boolean related fields when the underlying flag supports `true` or `false`
74
74
 
75
75
  **Code: Base Known Environment Flags**
76
76
  ```typescript
77
- interface TravettoEnv {
77
+ interface EnvData {
78
78
  /**
79
- * The node environment we are running in
80
- * @default development
81
- */
79
+ * The node environment we are running in
80
+ * @default development
81
+ */
82
82
  NODE_ENV: 'development' | 'production';
83
83
  /**
84
84
  * Outputs all console.debug messages, defaults to `local` in dev, and `off` in prod.
@@ -132,7 +132,7 @@ interface TravettoEnv {
132
132
  ```
133
133
 
134
134
  ### Environment Property
135
- For a given [EnvProp](https://github.com/travetto/travetto/tree/main/module/runtime/src/env.ts#L6), we support the ability to access different properties as a means to better facilitate environment variable usage.
135
+ For a given [EnvProp](https://github.com/travetto/travetto/tree/main/module/runtime/src/env.ts#L8), we support the ability to access different properties as a means to better facilitate environment variable usage.
136
136
 
137
137
  **Code: EnvProp Shape**
138
138
  ```typescript
@@ -256,7 +256,7 @@ The primary access patterns for resources, is to directly request a file, and to
256
256
 
257
257
  The [FileLoader](https://github.com/travetto/travetto/tree/main/module/runtime/src/file-loader.ts#L11) allows for accessing information about the resources, and subsequently reading the file as text/binary or to access the resource as a `Readable` stream. If a file is not found, it will throw an [AppError](https://github.com/travetto/travetto/tree/main/module/runtime/src/error.ts#L15) with a category of 'notfound'.
258
258
 
259
- The [FileLoader](https://github.com/travetto/travetto/tree/main/module/runtime/src/file-loader.ts#L11) also supports tying itself to [Env](https://github.com/travetto/travetto/tree/main/module/runtime/src/env.ts#L109)'s `TRV_RESOURCES` information on where to attempt to find a requested resource.
259
+ The [FileLoader](https://github.com/travetto/travetto/tree/main/module/runtime/src/file-loader.ts#L11) also supports tying itself to [Env](https://github.com/travetto/travetto/tree/main/module/runtime/src/env.ts#L111)'s `TRV_RESOURCES` information on where to attempt to find a requested resource.
260
260
 
261
261
  ## Common Utilities
262
262
  Common utilities used throughout the framework. Currently [Util](https://github.com/travetto/travetto/tree/main/module/runtime/src/util.ts#L17) includes:
@@ -319,7 +319,7 @@ export class TimeUtil {
319
319
  ```
320
320
 
321
321
  ## Process Execution
322
- [ExecUtil](https://github.com/travetto/travetto/tree/main/module/runtime/src/exec.ts#L42) exposes `getResult` as a means to wrap [child_process](https://nodejs.org/api/child_process.html)'s process object. This wrapper allows for a promise-based resolution of the subprocess with the ability to capture the stderr/stdout.
322
+ [ExecUtil](https://github.com/travetto/travetto/tree/main/module/runtime/src/exec.ts#L43) exposes `getResult` as a means to wrap [child_process](https://nodejs.org/api/child_process.html)'s process object. This wrapper allows for a promise-based resolution of the subprocess with the ability to capture the stderr/stdout.
323
323
 
324
324
  A simple example would be:
325
325
 
package/__index__.ts CHANGED
@@ -1,5 +1,4 @@
1
- /// <reference path="./src/trv.d.ts" />
2
- /// <reference path="./src/global.d.ts" />
1
+ import type { } from './src/global';
3
2
  export * from './src/binary';
4
3
  export * from './src/console';
5
4
  export * from './src/context';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/runtime",
3
- "version": "5.0.1",
3
+ "version": "5.0.3",
4
4
  "description": "Runtime for travetto applications.",
5
5
  "keywords": [
6
6
  "console-manager",
@@ -28,13 +28,13 @@
28
28
  "node": ">=22.0.0"
29
29
  },
30
30
  "dependencies": {
31
- "@travetto/manifest": "^5.0.1",
31
+ "@travetto/manifest": "^5.0.2",
32
32
  "@types/debug": "^4.1.12",
33
- "@types/node": "^22.5.1",
33
+ "@types/node": "^22.5.4",
34
34
  "debug": "^4.3.6"
35
35
  },
36
36
  "peerDependencies": {
37
- "@travetto/transformer": "^5.0.1"
37
+ "@travetto/transformer": "^5.0.3"
38
38
  },
39
39
  "peerDependenciesMeta": {
40
40
  "@travetto/transformer": {
package/src/context.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { existsSync } from 'node:fs';
2
+ import fs from 'node:fs/promises';
2
3
  import path from 'node:path';
3
4
 
4
5
  import { type ManifestIndex, type ManifestContext, ManifestModuleUtil } from '@travetto/manifest';
@@ -111,9 +112,24 @@ class $Runtime {
111
112
  if (existsSync(file)) {
112
113
  imp = this.#idx.getFromSource(file)?.import;
113
114
  }
115
+
114
116
  if (!imp) {
115
117
  throw new Error(`Unable to find ${imp}, not in the manifest`);
118
+ } else if (imp.endsWith('.json')) {
119
+ imp = this.#idx.getFromImport(imp)?.sourceFile ?? imp;
120
+ return fs.readFile(imp, 'utf8').then(JSON.parse);
121
+ }
122
+
123
+ if (!/[.][cm]?[tj]sx?$/.test(imp)) {
124
+ if (imp.startsWith('@')) {
125
+ if (/[/].*?[/]/.test(imp)) {
126
+ imp = `${imp}.ts`;
127
+ }
128
+ } else {
129
+ imp = `${imp}.ts`;
130
+ }
116
131
  }
132
+
117
133
  imp = ManifestModuleUtil.withOutputExtension(imp);
118
134
  return import(imp);
119
135
  }
package/src/env.ts CHANGED
@@ -3,6 +3,8 @@ import { castKey, castTo } from './types';
3
3
  const IS_TRUE = /^(true|yes|on|1)$/i;
4
4
  const IS_FALSE = /^(false|no|off|0)$/i;
5
5
 
6
+ export interface EnvData { }
7
+
6
8
  export class EnvProp<T> {
7
9
  constructor(public readonly key: string) { }
8
10
 
@@ -86,11 +88,11 @@ export class EnvProp<T> {
86
88
  }
87
89
 
88
90
  type AllType = {
89
- [K in keyof TravettoEnv]: Pick<EnvProp<TravettoEnv[K]>, 'key' | 'export' | 'val' | 'set' | 'clear' | 'isSet' |
90
- (TravettoEnv[K] extends unknown[] ? 'list' | 'add' : never) |
91
- (Extract<TravettoEnv[K], object> extends never ? never : 'object') |
92
- (Extract<TravettoEnv[K], number> extends never ? never : 'int') |
93
- (Extract<TravettoEnv[K], boolean> extends never ? never : 'bool' | 'isTrue' | 'isFalse')
91
+ [K in keyof EnvData]: Pick<EnvProp<EnvData[K]>, 'key' | 'export' | 'val' | 'set' | 'clear' | 'isSet' |
92
+ (EnvData[K] extends unknown[] ? 'list' | 'add' : never) |
93
+ (Extract<EnvData[K], object> extends never ? never : 'object') |
94
+ (Extract<EnvData[K], number> extends never ? never : 'int') |
95
+ (Extract<EnvData[K], boolean> extends never ? never : 'bool' | 'isTrue' | 'isFalse')
94
96
  >
95
97
  };
96
98
 
package/src/exec.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { ChildProcess } from 'node:child_process';
2
2
  import { Readable } from 'node:stream';
3
3
  import { createInterface } from 'node:readline/promises';
4
+
4
5
  import { castTo } from './types';
5
6
 
6
7
  const MINUTE = (1000 * 60);
package/src/trv.d.ts CHANGED
@@ -1,16 +1,13 @@
1
- import type { ManifestModuleRole } from '@travetto/manifest';
2
-
3
- import type { TimeSpan } from './time';
4
-
1
+ import { type ManifestModuleRole } from '@travetto/manifest';
2
+ import { type TimeSpan } from './time';
5
3
  type Role = Exclude<ManifestModuleRole, 'std' | 'compile'>;
6
4
 
7
-
8
- declare global {
9
- interface TravettoEnv {
5
+ declare module "@travetto/runtime" {
6
+ interface EnvData {
10
7
  /**
11
- * The node environment we are running in
12
- * @default development
13
- */
8
+ * The node environment we are running in
9
+ * @default development
10
+ */
14
11
  NODE_ENV: 'development' | 'production';
15
12
  /**
16
13
  * Outputs all console.debug messages, defaults to `local` in dev, and `off` in prod.
@@ -6,7 +6,6 @@ import {
6
6
  } from '@travetto/transformer';
7
7
 
8
8
  const CONSOLE_IMPORT = '@travetto/runtime/src/console';
9
- const MANIFEST_MOD = '@travetto/manifest';
10
9
 
11
10
  type CustomState = TransformerState & {
12
11
  scope: { type: 'method' | 'class' | 'function', name: string }[];
@@ -75,7 +74,7 @@ export class ConsoleLogTransformer {
75
74
 
76
75
  @OnCall()
77
76
  static onLogCall(state: CustomState, node: ts.CallExpression): typeof node | ts.Identifier {
78
- if (!ts.isPropertyAccessExpression(node.expression) || state.importName.startsWith(MANIFEST_MOD)) {
77
+ if (!ts.isPropertyAccessExpression(node.expression)) {
79
78
  return node;
80
79
  }
81
80
 
@@ -0,0 +1,32 @@
1
+ import ts from 'typescript';
2
+
3
+ import { LiteralUtil, OnCall, TransformerState } from '@travetto/transformer';
4
+
5
+ /**
6
+ * Dynamic Import Transformer
7
+ */
8
+ export class DynamicImportTransformer {
9
+
10
+ static #rewriteModuleSpecifier(state: TransformerState, spec: ts.LiteralExpression | ts.Expression | undefined): ts.Expression | undefined {
11
+ if (spec && ts.isStringLiteral(spec) && state.isUntypedImport(spec)) {
12
+ return LiteralUtil.fromLiteral(state.factory, `${spec.text.replace(/['"]/g, '')}.js`);
13
+ }
14
+ return spec;
15
+ }
16
+
17
+ @OnCall()
18
+ static onLogCall(state: TransformerState, node: ts.CallExpression): typeof node | ts.Identifier {
19
+ if (
20
+ ts.isCallExpression(node) &&
21
+ node.expression.kind === ts.SyntaxKind.ImportKeyword &&
22
+ node.arguments.length &&
23
+ ts.isLiteralExpression(node.arguments[0])
24
+ ) {
25
+ const lit = this.#rewriteModuleSpecifier(state, node.arguments[0])!;
26
+ if (lit !== node.arguments[0]) {
27
+ return state.factory.updateCallExpression(node, node.expression, node.typeArguments, [lit, ...node.arguments.slice(1)]);
28
+ }
29
+ }
30
+ return node;
31
+ }
32
+ }
@@ -4,7 +4,6 @@ import { TransformerState, OnFile } from '@travetto/transformer';
4
4
 
5
5
  const PATH_REGEX = /^['"](node:)?path['"]$/;
6
6
  const PATH_TARGET = '@travetto/manifest/src/path';
7
- const SKIP_SRC = /^@travetto\/manifest\/(src|support)/;
8
7
 
9
8
  /**
10
9
  * Rewriting path imports to use manifest's path
@@ -16,10 +15,6 @@ export class PathImportTransformer {
16
15
  */
17
16
  @OnFile()
18
17
  static rewritePathImport(state: TransformerState, node: ts.SourceFile): ts.SourceFile {
19
- if (SKIP_SRC.test(state.importName)) {
20
- return node;
21
- }
22
-
23
18
  const stmt = node.statements.find((x): x is ts.ImportDeclaration =>
24
19
  ts.isImportDeclaration(x) && PATH_REGEX.test(x.moduleSpecifier?.getText() ?? ''));
25
20
  if (stmt) {