@dsh-workbench/adapter-runtime 0.0.0-stage → 1.0.0-beta.1

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.
@@ -0,0 +1,46 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { homedir } from 'node:os';
3
+ import { join, normalize } from 'node:path';
4
+ import { pathToFileURL } from 'node:url';
5
+ import { libInstallCommand, WorkbenchDataError } from '@dsh-workbench/shared/host';
6
+ function rootsOf(env) {
7
+ const home = env['DSH_HOME'] ?? join(homedir(), '.dsh');
8
+ return [
9
+ join(home, 'workbench', 'opencli', 'libs', 'node_modules'),
10
+ join(home, 'workbench', 'opencli', 'toolchain', 'node_modules'),
11
+ ];
12
+ }
13
+ function entryProblem(entry) {
14
+ if (entry.trim() === '')
15
+ return '入口是空串';
16
+ if (entry.startsWith('/') || /^[A-Za-z]:[\\/]/u.test(entry))
17
+ return '入口不能是绝对路径';
18
+ if (normalize(entry).split(/[\\/]/u).includes('..'))
19
+ return '入口不能跳出 lib 目录';
20
+ return null;
21
+ }
22
+ export function createLibReader(options = {}) {
23
+ const env = options.env ?? process.env;
24
+ const roots = options.roots ?? rootsOf(env);
25
+ return {
26
+ async load(need, entry) {
27
+ const problem = entryProblem(entry);
28
+ if (problem !== null) {
29
+ throw new WorkbenchDataError('lib-path-invalid', `${need.name}: ${problem}`, {
30
+ hint: '入口写相对路径,比如 src/utils.js',
31
+ });
32
+ }
33
+ for (const root of roots) {
34
+ const file = join(root, need.name, entry);
35
+ if (!existsSync(file))
36
+ continue;
37
+ return (await import(pathToFileURL(file).href));
38
+ }
39
+ const source = need.sources?.find((one) => one.kind === 'npm');
40
+ const hint = source === undefined
41
+ ? `装它:${need.name}${need.version === undefined ? '' : `@${need.version}`}`
42
+ : `装它:${libInstallCommand({ need, source, ...(need.version === undefined ? {} : { version: need.version }) })}`;
43
+ throw new WorkbenchDataError('lib-missing', `没有找到 ${need.name} 的 ${entry}`, { hint });
44
+ },
45
+ };
46
+ }
package/package.json CHANGED
@@ -1,6 +1,35 @@
1
1
  {
2
2
  "name": "@dsh-workbench/adapter-runtime",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.0-beta.1",
4
+ "description": "Opencli, browser and data runtime adapters.",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.ts",
9
+ "default": "./dist/index.js"
10
+ }
11
+ },
12
+ "files": [
13
+ "dist",
14
+ "channel"
15
+ ],
16
+ "dependencies": {
17
+ "@dsh-workbench/shared": "1.0.0-beta.1"
18
+ },
19
+ "devDependencies": {
20
+ "@types/node": "^24.19.0",
21
+ "@vitest/coverage-v8": "^5.0.2",
22
+ "vitest": "^5.0.2"
23
+ },
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "license": "MIT",
28
+ "scripts": {
29
+ "build": "tsc -p tsconfig.json",
30
+ "test": "vitest run --testTimeout=20000",
31
+ "coverage": "vitest run --coverage --coverage.reporter=text-summary --testTimeout=20000",
32
+ "arch": "arch-guard",
33
+ "check:runtimes": "node ../../scripts/check-adapter-package.mjs --runtime"
34
+ }
6
35
  }