@travetto/runtime 5.0.0-rc.5 → 5.0.0-rc.7
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 +5 -2
- package/package.json +3 -3
- package/src/context.ts +16 -2
- package/src/function.ts +5 -3
- package/src/util.ts +11 -3
package/README.md
CHANGED
|
@@ -34,6 +34,7 @@ While running any code within the framework, there are common patterns/goals for
|
|
|
34
34
|
```typescript
|
|
35
35
|
class $Runtime {
|
|
36
36
|
constructor(idx: ManifestIndex, resourceOverrides?: Record<string, string>);
|
|
37
|
+
get #moduleAliases(): Record<string, string>;
|
|
37
38
|
/** Get env name, with support for the default env */
|
|
38
39
|
get envName(): string | undefined;
|
|
39
40
|
/** Are we in development mode */
|
|
@@ -64,6 +65,8 @@ class $Runtime {
|
|
|
64
65
|
getSourceFile(fn: Function): string;
|
|
65
66
|
/** Get import for function */
|
|
66
67
|
getImport(fn: Function): string;
|
|
68
|
+
/** Import from a given path */
|
|
69
|
+
importFrom<T = unknown>(imp?: string): Promise<T>;
|
|
67
70
|
}
|
|
68
71
|
```
|
|
69
72
|
|
|
@@ -212,7 +215,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
212
215
|
exports.work = work;
|
|
213
216
|
const tslib_1 = require("tslib");
|
|
214
217
|
const ᚕ_c = tslib_1.__importStar(require("@travetto/runtime/src/console.js"));
|
|
215
|
-
var ᚕm = ["@travetto/runtime", "doc/transpile"];
|
|
218
|
+
var ᚕm = ["@travetto/runtime", "doc/transpile.ts"];
|
|
216
219
|
function work() {
|
|
217
220
|
ᚕ_c.log({ level: "debug", import: ᚕm, line: 2, scope: "work", args: ['Start Work'] });
|
|
218
221
|
try {
|
|
@@ -255,7 +258,7 @@ The [FileLoader](https://github.com/travetto/travetto/tree/main/module/runtime/s
|
|
|
255
258
|
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#L108)'s `TRV_RESOURCES` information on where to attempt to find a requested resource.
|
|
256
259
|
|
|
257
260
|
## Common Utilities
|
|
258
|
-
Common utilities used throughout the framework. Currently [Util](https://github.com/travetto/travetto/tree/main/module/runtime/src/util.ts#
|
|
261
|
+
Common utilities used throughout the framework. Currently [Util](https://github.com/travetto/travetto/tree/main/module/runtime/src/util.ts#L18) includes:
|
|
259
262
|
* `uuid(len: number)` generates a simple uuid for use within the application.
|
|
260
263
|
* `allowDenyMatcher(rules[])` builds a matching function that leverages the rules as an allow/deny list, where order of the rules matters. Negative rules are prefixed by '!'.
|
|
261
264
|
* `hash(text: string, size?: number)` produces a full sha512 hash.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/runtime",
|
|
3
|
-
"version": "5.0.0-rc.
|
|
3
|
+
"version": "5.0.0-rc.7",
|
|
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.0-rc.
|
|
31
|
+
"@travetto/manifest": "^5.0.0-rc.4",
|
|
32
32
|
"@types/debug": "^4.1.12",
|
|
33
33
|
"@types/node": "^22.1.0",
|
|
34
34
|
"debug": "^4.3.5"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@travetto/transformer": "^5.0.0-rc.
|
|
37
|
+
"@travetto/transformer": "^5.0.0-rc.5"
|
|
38
38
|
},
|
|
39
39
|
"peerDependenciesMeta": {
|
|
40
40
|
"@travetto/transformer": {
|
package/src/context.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
1
2
|
import path from 'node:path';
|
|
2
3
|
|
|
3
|
-
import type
|
|
4
|
+
import { type ManifestIndex, type ManifestContext, ManifestModuleUtil } from '@travetto/manifest';
|
|
4
5
|
|
|
5
6
|
import { Env } from './env';
|
|
6
7
|
import { RuntimeIndex } from './manifest-index';
|
|
@@ -91,7 +92,7 @@ class $Runtime {
|
|
|
91
92
|
|
|
92
93
|
/** Resolve resource paths */
|
|
93
94
|
resourcePaths(paths: string[] = []): string[] {
|
|
94
|
-
return [...paths, ...Env.TRV_RESOURCES.list ?? [], '@#resources', '@@#resources'].map(v => this.modulePath(v));
|
|
95
|
+
return [...new Set([...paths, ...Env.TRV_RESOURCES.list ?? [], '@#resources', '@@#resources'].map(v => this.modulePath(v)))];
|
|
95
96
|
}
|
|
96
97
|
|
|
97
98
|
/** Get source for function */
|
|
@@ -103,6 +104,19 @@ class $Runtime {
|
|
|
103
104
|
getImport(fn: Function): string {
|
|
104
105
|
return describeFunction(fn).import;
|
|
105
106
|
}
|
|
107
|
+
|
|
108
|
+
/** Import from a given path */
|
|
109
|
+
importFrom<T = unknown>(imp?: string): Promise<T> {
|
|
110
|
+
const file = path.resolve(this.#idx.mainModule.sourcePath, imp!);
|
|
111
|
+
if (existsSync(file)) {
|
|
112
|
+
imp = this.#idx.getFromSource(file)?.import;
|
|
113
|
+
}
|
|
114
|
+
if (!imp) {
|
|
115
|
+
throw new Error(`Unable to find ${imp}, not in the manifest`);
|
|
116
|
+
}
|
|
117
|
+
imp = ManifestModuleUtil.withOutputExtension(imp);
|
|
118
|
+
return import(imp);
|
|
119
|
+
}
|
|
106
120
|
}
|
|
107
121
|
|
|
108
122
|
export const Runtime = new $Runtime(RuntimeIndex, Env.TRV_RESOURCE_OVERRIDES.object);
|
package/src/function.ts
CHANGED
|
@@ -29,11 +29,13 @@ export function registerFunction(
|
|
|
29
29
|
fn: Function, [pkg, pth]: [string, string], tag: FunctionMetadataTag,
|
|
30
30
|
methods?: Record<string, FunctionMetadataTag>, abstract?: boolean, synthetic?: boolean
|
|
31
31
|
): void {
|
|
32
|
-
const
|
|
33
|
-
|
|
32
|
+
const modulePath = pth.replace(/[.][cm]?[tj]sx?$/, '');
|
|
33
|
+
|
|
34
|
+
const metadata: FunctionMetadata = {
|
|
35
|
+
id: (fn.name ? `${pkg}:${modulePath}○${fn.name}` : `${pkg}:${modulePath}`),
|
|
34
36
|
import: `${pkg}/${pth}`,
|
|
35
37
|
module: pkg,
|
|
36
|
-
modulePath
|
|
38
|
+
modulePath,
|
|
37
39
|
...tag, methods, abstract, synthetic, class: abstract !== undefined
|
|
38
40
|
};
|
|
39
41
|
pending.add(fn);
|
package/src/util.ts
CHANGED
|
@@ -2,6 +2,7 @@ import crypto from 'node:crypto';
|
|
|
2
2
|
import timers from 'node:timers/promises';
|
|
3
3
|
import fs from 'node:fs/promises';
|
|
4
4
|
import path from 'node:path';
|
|
5
|
+
import os from 'node:os';
|
|
5
6
|
|
|
6
7
|
type PromiseWithResolvers<T> = {
|
|
7
8
|
resolve: (v: T) => void;
|
|
@@ -74,10 +75,17 @@ export class Util {
|
|
|
74
75
|
/**
|
|
75
76
|
* Write file and copy over when ready
|
|
76
77
|
*/
|
|
77
|
-
static async bufferedFileWrite(file: string, content: string): Promise<void> {
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
static async bufferedFileWrite(file: string, content: string, checkHash = false): Promise<void> {
|
|
79
|
+
if (checkHash) {
|
|
80
|
+
const current = await fs.readFile(file, 'utf8').catch(() => '');
|
|
81
|
+
if (Util.hash(current) === Util.hash(content)) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const temp = path.resolve(os.tmpdir(), `${process.hrtime()[1]}.${path.basename(file)}`);
|
|
80
87
|
await fs.writeFile(temp, content, 'utf8');
|
|
88
|
+
await fs.mkdir(path.dirname(file), { recursive: true });
|
|
81
89
|
await fs.rename(temp, file);
|
|
82
90
|
}
|
|
83
91
|
|