@zhin.js/runtime 1.0.0
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/LICENSE +21 -0
- package/README.md +39 -0
- package/lib/compatibility.d.ts +10 -0
- package/lib/compatibility.js +45 -0
- package/lib/config-composer.d.ts +27 -0
- package/lib/config-composer.js +212 -0
- package/lib/config-document.d.ts +19 -0
- package/lib/config-document.js +6 -0
- package/lib/config-patch-planner.d.ts +25 -0
- package/lib/config-patch-planner.js +126 -0
- package/lib/environment-store.d.ts +56 -0
- package/lib/environment-store.js +300 -0
- package/lib/environment.d.ts +8 -0
- package/lib/environment.js +13 -0
- package/lib/feature-projector.d.ts +15 -0
- package/lib/feature-projector.js +57 -0
- package/lib/generation-assets.d.ts +9 -0
- package/lib/generation-assets.js +67 -0
- package/lib/hmr-coordinator.d.ts +23 -0
- package/lib/hmr-coordinator.js +110 -0
- package/lib/index.d.ts +21 -0
- package/lib/index.js +21 -0
- package/lib/invalidation-planner.d.ts +29 -0
- package/lib/invalidation-planner.js +106 -0
- package/lib/isolation.d.ts +28 -0
- package/lib/isolation.js +1 -0
- package/lib/manifest.d.ts +45 -0
- package/lib/manifest.js +195 -0
- package/lib/module-runtime.d.ts +17 -0
- package/lib/module-runtime.js +7 -0
- package/lib/native-development-runtime.d.ts +22 -0
- package/lib/native-development-runtime.js +190 -0
- package/lib/node-discovery-host.d.ts +10 -0
- package/lib/node-discovery-host.js +37 -0
- package/lib/package-resolver.d.ts +23 -0
- package/lib/package-resolver.js +121 -0
- package/lib/plugin-scope-assembler.d.ts +38 -0
- package/lib/plugin-scope-assembler.js +167 -0
- package/lib/process-restart.d.ts +15 -0
- package/lib/process-restart.js +29 -0
- package/lib/project-graph.d.ts +30 -0
- package/lib/project-graph.js +129 -0
- package/lib/restart-boundary.d.ts +6 -0
- package/lib/restart-boundary.js +68 -0
- package/lib/root-runtime.d.ts +37 -0
- package/lib/root-runtime.js +432 -0
- package/lib/runtime-generation.d.ts +18 -0
- package/lib/runtime-generation.js +1 -0
- package/lib/slot-generation-preparer.d.ts +9 -0
- package/lib/slot-generation-preparer.js +76 -0
- package/lib/source-ownership.d.ts +19 -0
- package/lib/source-ownership.js +105 -0
- package/lib/subtree-generation-preparer.d.ts +24 -0
- package/lib/subtree-generation-preparer.js +152 -0
- package/lib/topology-generation-preparer.d.ts +22 -0
- package/lib/topology-generation-preparer.js +249 -0
- package/lib/topology-transaction.d.ts +26 -0
- package/lib/topology-transaction.js +142 -0
- package/lib/typescript-specifier-remap.d.ts +23 -0
- package/lib/typescript-specifier-remap.js +92 -0
- package/package.json +57 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { access } from 'node:fs/promises';
|
|
2
|
+
import { register } from 'node:module';
|
|
3
|
+
import { sep } from 'node:path';
|
|
4
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
5
|
+
/**
|
|
6
|
+
* ESM resolve hook: when a relative/absolute `.js` specifier fails and a
|
|
7
|
+
* sibling `.ts` / `.tsx` exists, rewrite to that source file.
|
|
8
|
+
*
|
|
9
|
+
* Needed for Plugin Runtime on Node 22.6–22.17 with `--experimental-strip-types`:
|
|
10
|
+
* TypeScript authoring uses `.js` import suffixes, but strip-types does not
|
|
11
|
+
* remap missing `.js` → `.ts` the way `tsc`/tsx do.
|
|
12
|
+
*/
|
|
13
|
+
export async function resolve(specifier, context, nextResolve) {
|
|
14
|
+
try {
|
|
15
|
+
return await nextResolve(specifier, context);
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
if (!shouldTryTypeScript(specifier, error))
|
|
19
|
+
throw error;
|
|
20
|
+
const candidate = await firstExistingTypeScript(specifier, context.parentURL);
|
|
21
|
+
if (!candidate)
|
|
22
|
+
throw error;
|
|
23
|
+
return nextResolve(candidate, context);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
let registered = false;
|
|
27
|
+
/** Register once for the current process (safe to call from CLI / RootHost). */
|
|
28
|
+
export function ensureTypeScriptSpecifierRemap() {
|
|
29
|
+
if (registered)
|
|
30
|
+
return;
|
|
31
|
+
registered = true;
|
|
32
|
+
register(import.meta.url);
|
|
33
|
+
}
|
|
34
|
+
function shouldTryTypeScript(specifier, error) {
|
|
35
|
+
if (!(error instanceof Error) || !('code' in error) || error.code !== 'ERR_MODULE_NOT_FOUND') {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
if (specifier.startsWith('node:') || specifier.startsWith('data:'))
|
|
39
|
+
return false;
|
|
40
|
+
return /\.[cm]?js$/u.test(specifier) || specifier.endsWith('.jsx');
|
|
41
|
+
}
|
|
42
|
+
async function firstExistingTypeScript(specifier, parentURL) {
|
|
43
|
+
const resolvedJs = resolveAgainstParent(specifier, parentURL);
|
|
44
|
+
if (!resolvedJs)
|
|
45
|
+
return undefined;
|
|
46
|
+
// Prefer compiled lib/ over strip-types (.ts): many packages use syntax that
|
|
47
|
+
// Node strip-only mode rejects (parameter properties, enums, etc.).
|
|
48
|
+
const libCandidate = compiledLibPath(resolvedJs);
|
|
49
|
+
if (libCandidate && await exists(libCandidate)) {
|
|
50
|
+
return pathToFileURL(libCandidate).href;
|
|
51
|
+
}
|
|
52
|
+
const bases = [
|
|
53
|
+
resolvedJs.replace(/\.jsx$/u, ''),
|
|
54
|
+
resolvedJs.replace(/\.[cm]?js$/u, ''),
|
|
55
|
+
];
|
|
56
|
+
for (const base of bases) {
|
|
57
|
+
for (const ext of ['.ts', '.tsx', '.mts', '.cts']) {
|
|
58
|
+
const candidate = `${base}${ext}`;
|
|
59
|
+
if (await exists(candidate))
|
|
60
|
+
return pathToFileURL(candidate).href;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
function compiledLibPath(sourceJsPath) {
|
|
66
|
+
const marker = `${sep}src${sep}`;
|
|
67
|
+
const index = sourceJsPath.lastIndexOf(marker);
|
|
68
|
+
if (index < 0)
|
|
69
|
+
return undefined;
|
|
70
|
+
return `${sourceJsPath.slice(0, index)}${sep}lib${sep}${sourceJsPath.slice(index + marker.length)}`;
|
|
71
|
+
}
|
|
72
|
+
function resolveAgainstParent(specifier, parentURL) {
|
|
73
|
+
try {
|
|
74
|
+
if (specifier.startsWith('file:'))
|
|
75
|
+
return fileURLToPath(specifier);
|
|
76
|
+
if (!parentURL)
|
|
77
|
+
return undefined;
|
|
78
|
+
return fileURLToPath(new URL(specifier, parentURL));
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async function exists(path) {
|
|
85
|
+
try {
|
|
86
|
+
await access(path);
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zhin.js/runtime",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Static Plugin graph, generation transaction and HMR Root runtime for Zhin.js",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./lib/index.js",
|
|
7
|
+
"types": "./lib/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./lib/index.d.ts",
|
|
11
|
+
"development": "./src/index.ts",
|
|
12
|
+
"import": "./lib/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"lib"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"ajv": "8.18.0",
|
|
20
|
+
"semver": "7.8.5",
|
|
21
|
+
"@zhin.js/feature-kit": "1.0.0",
|
|
22
|
+
"@zhin.js/plugin-runtime": "1.0.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/node": "^26.1.0",
|
|
26
|
+
"typescript": "^6.0.3",
|
|
27
|
+
"@zhin.js/adapter": "1.0.0",
|
|
28
|
+
"@zhin.js/agent-feature": "1.0.0",
|
|
29
|
+
"@zhin.js/component": "1.0.0",
|
|
30
|
+
"@zhin.js/page": "1.0.0",
|
|
31
|
+
"@zhin.js/layout": "1.0.0",
|
|
32
|
+
"@zhin.js/mcp-feature": "1.0.0",
|
|
33
|
+
"@zhin.js/command": "1.0.0",
|
|
34
|
+
"@zhin.js/middleware": "1.0.0",
|
|
35
|
+
"@zhin.js/tool": "1.0.0",
|
|
36
|
+
"@zhin.js/skill": "1.0.0"
|
|
37
|
+
},
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "git+https://github.com/zhinjs/zhin.git",
|
|
41
|
+
"directory": "packages/im/runtime"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public",
|
|
45
|
+
"registry": "https://registry.npmjs.org"
|
|
46
|
+
},
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
49
|
+
},
|
|
50
|
+
"license": "MIT",
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "tsc",
|
|
53
|
+
"clean": "rimraf lib",
|
|
54
|
+
"test": "vitest run --root ../../.. packages/im/runtime/tests",
|
|
55
|
+
"check:size": "node ../../../scripts/check-plugin-runtime-install-size.mjs @zhin.js/runtime"
|
|
56
|
+
}
|
|
57
|
+
}
|