@zhin.js/runtime 1.0.3 → 1.0.4
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/lib/package-resolver.js +31 -2
- package/package.json +12 -12
package/lib/package-resolver.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { access, readFile, readdir, realpath } from 'node:fs/promises';
|
|
2
|
-
import { dirname, join, resolve } from 'node:path';
|
|
2
|
+
import { dirname, extname, join, relative, resolve } from 'node:path';
|
|
3
3
|
import { parsePackageJson } from './manifest.js';
|
|
4
4
|
export class PackageResolutionError extends Error {
|
|
5
5
|
request;
|
|
@@ -93,7 +93,17 @@ export class NodePackageResolver {
|
|
|
93
93
|
return cached;
|
|
94
94
|
const file = join(normalized, 'package.json');
|
|
95
95
|
const content = await readFile(file, 'utf8');
|
|
96
|
-
const
|
|
96
|
+
const parsedPackageJson = parsePackageJson(JSON.parse(content), file);
|
|
97
|
+
const entry = await resolveRuntimeEntry(normalized, parsedPackageJson.zhin.entry, source);
|
|
98
|
+
const packageJson = entry === parsedPackageJson.zhin.entry
|
|
99
|
+
? parsedPackageJson
|
|
100
|
+
: Object.freeze({
|
|
101
|
+
...parsedPackageJson,
|
|
102
|
+
zhin: Object.freeze({
|
|
103
|
+
...parsedPackageJson.zhin,
|
|
104
|
+
entry,
|
|
105
|
+
}),
|
|
106
|
+
});
|
|
97
107
|
const result = Object.freeze({
|
|
98
108
|
name: packageJson.name,
|
|
99
109
|
root: normalized,
|
|
@@ -104,6 +114,25 @@ export class NodePackageResolver {
|
|
|
104
114
|
return result;
|
|
105
115
|
}
|
|
106
116
|
}
|
|
117
|
+
async function resolveRuntimeEntry(packageRoot, declaredEntry, source) {
|
|
118
|
+
const declared = resolve(packageRoot, declaredEntry);
|
|
119
|
+
const extension = extname(declared);
|
|
120
|
+
const base = declared.slice(0, -extension.length);
|
|
121
|
+
const sourceCandidates = extension === '.js'
|
|
122
|
+
? [`${base}.ts`, `${base}.tsx`]
|
|
123
|
+
: [declared];
|
|
124
|
+
const javascriptCandidates = extension === '.ts' || extension === '.tsx'
|
|
125
|
+
? [`${base}.js`, join(packageRoot, 'lib', `${base.slice(packageRoot.length + 1)}.js`)]
|
|
126
|
+
: [declared];
|
|
127
|
+
const candidates = source === 'node_modules'
|
|
128
|
+
? [...javascriptCandidates, ...sourceCandidates]
|
|
129
|
+
: [...sourceCandidates, ...javascriptCandidates];
|
|
130
|
+
for (const candidate of new Set(candidates)) {
|
|
131
|
+
if (await exists(candidate))
|
|
132
|
+
return `./${relative(packageRoot, candidate).replaceAll('\\', '/')}`;
|
|
133
|
+
}
|
|
134
|
+
return declaredEntry;
|
|
135
|
+
}
|
|
107
136
|
function declaredDependency(request, pkg) {
|
|
108
137
|
const specification = (pkg.dependencies?.[request]
|
|
109
138
|
?? pkg.optionalDependencies?.[request]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/runtime",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Static Plugin graph, generation transaction and HMR Root runtime for Zhin.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -18,22 +18,22 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"ajv": "8.18.0",
|
|
20
20
|
"semver": "7.8.5",
|
|
21
|
-
"@zhin.js/feature-kit": "1.0.
|
|
21
|
+
"@zhin.js/feature-kit": "1.0.4",
|
|
22
22
|
"@zhin.js/plugin-runtime": "1.1.1"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/node": "^26.1.0",
|
|
26
26
|
"typescript": "^6.0.3",
|
|
27
|
-
"@zhin.js/adapter": "1.1.
|
|
28
|
-
"@zhin.js/agent-feature": "1.0.
|
|
29
|
-
"@zhin.js/command": "1.0.
|
|
30
|
-
"@zhin.js/component": "1.0.
|
|
31
|
-
"@zhin.js/layout": "1.0.
|
|
32
|
-
"@zhin.js/mcp-feature": "1.0.
|
|
33
|
-
"@zhin.js/middleware": "1.0.
|
|
34
|
-
"@zhin.js/page": "1.0.
|
|
35
|
-
"@zhin.js/skill": "1.0.
|
|
36
|
-
"@zhin.js/tool": "1.0.
|
|
27
|
+
"@zhin.js/adapter": "1.1.2",
|
|
28
|
+
"@zhin.js/agent-feature": "1.0.4",
|
|
29
|
+
"@zhin.js/command": "1.0.4",
|
|
30
|
+
"@zhin.js/component": "1.0.4",
|
|
31
|
+
"@zhin.js/layout": "1.0.4",
|
|
32
|
+
"@zhin.js/mcp-feature": "1.0.4",
|
|
33
|
+
"@zhin.js/middleware": "1.0.4",
|
|
34
|
+
"@zhin.js/page": "1.0.4",
|
|
35
|
+
"@zhin.js/skill": "1.0.4",
|
|
36
|
+
"@zhin.js/tool": "1.0.4"
|
|
37
37
|
},
|
|
38
38
|
"repository": {
|
|
39
39
|
"type": "git",
|