@dsh-workbench/shared 1.1.6 → 1.1.8

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.
Files changed (37) hide show
  1. package/dist/contract/needs.d.ts +3 -0
  2. package/dist/contract/needs.js +17 -0
  3. package/dist/contract/protocol/market-index.d.ts +1 -0
  4. package/dist/host/lib-runners.d.ts +20 -0
  5. package/dist/host/lib-runners.js +46 -0
  6. package/dist/host/market-index-claim.d.ts +0 -1
  7. package/dist/host/market-index-claim.js +0 -3
  8. package/dist/host/market-index-doc.d.ts +1 -45
  9. package/dist/host/market-index-parse.d.ts +9 -4
  10. package/dist/host/market-index-parse.js +17 -92
  11. package/dist/host/market-index.d.ts +5 -6
  12. package/dist/host/market-index.js +29 -87
  13. package/dist/host/opencli-runner.d.ts +25 -0
  14. package/dist/host/opencli-runner.js +50 -0
  15. package/dist/host.d.ts +2 -0
  16. package/dist/host.js +2 -0
  17. package/dist/i18n/en.js +3 -1
  18. package/dist/i18n/index.d.ts +4 -2
  19. package/dist/i18n/zh.d.ts +3 -1
  20. package/dist/i18n/zh.js +3 -1
  21. package/package.json +1 -1
  22. package/src/contract/__tests__/needs.test.ts +8 -0
  23. package/src/contract/needs.ts +15 -0
  24. package/src/contract/protocol/market-index.ts +1 -0
  25. package/src/host/__tests__/lib-runners.test.ts +82 -0
  26. package/src/host/__tests__/market-index-assemble.test.ts +26 -0
  27. package/src/host/__tests__/market-index.test.ts +41 -51
  28. package/src/host/__tests__/opencli-runner.test.ts +120 -0
  29. package/src/host/lib-runners.ts +70 -0
  30. package/src/host/market-index-claim.ts +0 -4
  31. package/src/host/market-index-doc.ts +1 -53
  32. package/src/host/market-index-parse.ts +21 -85
  33. package/src/host/market-index.ts +33 -127
  34. package/src/host/opencli-runner.ts +76 -0
  35. package/src/host.ts +2 -0
  36. package/src/i18n/en.ts +3 -1
  37. package/src/i18n/zh.ts +3 -1
@@ -0,0 +1,76 @@
1
+ import type { DataError, DataRequest, DataResult } from '../contract/data.js';
2
+
3
+ /**
4
+ * 一条 opencli 命令的执行器:同一形状的 `execFile('opencli', args)`,结果只留 stdout。
5
+ */
6
+ export type OpencliRunner = (
7
+ args: readonly string[],
8
+ ) => Promise<{ readonly stdout: string }>;
9
+
10
+ /**
11
+ * 读缝(`DataReader.read`)的形状;模块直接把自己的 `data.read` 传进来即可。
12
+ */
13
+ export type OpencliRead = (
14
+ request: DataRequest,
15
+ ) => Promise<DataResult<unknown>>;
16
+
17
+ export interface OpencliRunnerOptions {
18
+ readonly timeoutMs?: number;
19
+ }
20
+
21
+ const AUTH_REQUIRED_EXIT_CODE = 77;
22
+
23
+ function textOf(value: unknown): string {
24
+ return typeof value === 'string' ? value : '';
25
+ }
26
+
27
+ function failedOf(args: readonly string[], error: DataError | undefined): Error {
28
+ const head = `Command failed: opencli ${args.join(' ')}`;
29
+ const auth = error?.pageCode === 'auth-required';
30
+ const helpUrl = textOf(error?.helpUrl);
31
+ const detail = textOf(error?.detail);
32
+ const hint = textOf(error?.hint);
33
+ const failed = new Error(
34
+ [
35
+ head,
36
+ ...(auth
37
+ ? ['code: AUTH_REQUIRED', `message: ${textOf(error?.message)}`]
38
+ : [textOf(error?.message) || 'opencli 这条命令没跑通']),
39
+ ...(detail === '' ? [] : [detail]),
40
+ ...(hint === '' ? [] : [hint]),
41
+ ...(auth && helpUrl !== ''
42
+ ? [`help: Please open Chrome or Chromium and log in to ${helpUrl}`]
43
+ : []),
44
+ ].join('\n'),
45
+ );
46
+ if (auth) (failed as Error & { code?: number }).code = AUTH_REQUIRED_EXIT_CODE;
47
+ return failed;
48
+ }
49
+
50
+ /**
51
+ * 把读缝包成一条 opencli 命令的执行器:给还按 `execFile('opencli', args)` 收结果的编排库用,
52
+ * 让它们跑在面板用的那份 opencli 上(同一套插件、同一份登录态)。
53
+ *
54
+ * 失败按 opencli 自己的约定还原:未登录是 `code: AUTH_REQUIRED` + 退出码 77,编排库的
55
+ * 「等登录再重试」才接得上;其它失败保留 `Command failed: opencli …` 那句外壳。
56
+ * @param read 模块手里的读缝(`data.read`)。
57
+ * @param options `timeoutMs` 透传给读缝;不传就用读缝自己的默认值。
58
+ * @returns 执行器;直接交给编排库的 `setOpencliRunner`。
59
+ */
60
+ export function opencliRunnerOf(
61
+ read: OpencliRead,
62
+ options: OpencliRunnerOptions = {},
63
+ ): OpencliRunner {
64
+ return async (args) => {
65
+ const result = await read({
66
+ kind: 'command',
67
+ adapter: 'opencli',
68
+ argv: [...args],
69
+ ...(options.timeoutMs === undefined
70
+ ? {}
71
+ : { timeoutMs: options.timeoutMs }),
72
+ });
73
+ if (result.ok) return { stdout: JSON.stringify(result.data) };
74
+ throw failedOf(args, result.error);
75
+ };
76
+ }
package/src/host.ts CHANGED
@@ -34,6 +34,8 @@ export * from './host/tokens.js';
34
34
  export * from './host/tool-approval.js';
35
35
  export * from './host/tool-kit.js';
36
36
  export * from './host/unit-face.js';
37
+ export * from './host/opencli-runner.js';
38
+ export * from './host/lib-runners.js';
37
39
  export * from './host/value-handoff.js';
38
40
  export * from './host/workspace-store.js';
39
41
  export * from './host/write-result.js';
package/src/i18n/en.ts CHANGED
@@ -383,7 +383,7 @@ export const en: Record<keyof WorkbenchMessages, string> = {
383
383
  'panels.discover.missingIndex': 'This repository has no {path} yet.',
384
384
  'panels.discover.initTitle': 'Initialize this repository as a module market index?',
385
385
  'panels.discover.initCta': 'Initialize market index',
386
- 'panels.discover.initWhat': 'It will write the index directory market/ and README.md on {branch}, commit once, and push. Modules you publish from this workbench will commit their build files under artifacts/<package-name>/<version>/ and their entry under market/<package-name>/<version>.json. The repository stays owned by its owner.',
386
+ 'panels.discover.initWhat': 'It will write the index directory market/ and README.md on {branch}, commit once, and push. Modules you publish from this workbench will commit their build files under artifacts/<package-name>/ and their entry in market/<package-name>.json. The repository stays owned by its owner.',
387
387
  'panels.discover.initBranch': 'Branch',
388
388
  'panels.discover.initBranchHint': 'The index and build files go to this branch; an empty repository gets it created.',
389
389
  'panels.discover.initBranchBad': 'Use only letters, digits, dots, underscores, slashes, or dashes in a branch name.',
@@ -722,6 +722,8 @@ export const en: Record<keyof WorkbenchMessages, string> = {
722
722
  'approval.publish.version': 'Version',
723
723
  'approval.publish.author': 'Author',
724
724
  'approval.publish.authorMissing': 'unsigned',
725
+ 'approval.publish.labels': 'Labels',
726
+ 'approval.publish.labelsMissing': 'none yet (1–2 picked on publish)',
725
727
  'approval.publish.owner': 'Owner',
726
728
  'approval.publish.ownerUnowned': 'originally unattributed',
727
729
  'approval.publish.ownerTaken': 'Owned by {owner}',
package/src/i18n/zh.ts CHANGED
@@ -380,7 +380,7 @@ export const zh = {
380
380
  'panels.discover.missingIndex': '仓库里还没有索引文件 {path}',
381
381
  'panels.discover.initTitle': '把这个仓库初始化成模块市场索引?',
382
382
  'panels.discover.initCta': '初始化成市场索引',
383
- 'panels.discover.initWhat': '会在 {branch} 分支写索引目录 market/ 与 README.md,提交一次并推上去;之后从这个工作台发布的模块会把打包好的文件提交到 artifacts/<包名>/<版本>/,条目写到 market/<包名>/<版本>.json。仓库的写权限归它的所有者。',
383
+ 'panels.discover.initWhat': '会在 {branch} 分支写索引目录 market/ 与 README.md,提交一次并推上去;之后从这个工作台发布的模块会把打包好的文件提交到 artifacts/<包名>/,条目写到 market/<包名>.json。仓库的写权限归它的所有者。',
384
384
  'panels.discover.initBranch': '分支',
385
385
  'panels.discover.initBranchHint': '索引和打包文件都发到这个分支;空仓库会新建它。',
386
386
  'panels.discover.initBranchBad': '分支名只能用字母、数字、点、下划线、斜杠或短横线',
@@ -717,6 +717,8 @@ export const zh = {
717
717
  'approval.publish.version': '版本',
718
718
  'approval.publish.author': '作者',
719
719
  'approval.publish.authorMissing': '未署名',
720
+ 'approval.publish.labels': '标签',
721
+ 'approval.publish.labelsMissing': '还没有(发布到市场时补 1–2 个)',
720
722
  'approval.publish.owner': '认领人',
721
723
  'approval.publish.ownerUnowned': '原来没署名',
722
724
  'approval.publish.ownerTaken': '已有主人:{owner}',