@dsh-workbench/shared 1.5.2-alpha.0 → 1.5.2-alpha.2

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 (322) hide show
  1. package/dist/contract/protocol/bundle-install.d.ts +7 -1
  2. package/dist/contract/protocol/bundle-install.js +1 -0
  3. package/dist/host/runtime/dsh-compat.js +20 -6
  4. package/dist/i18n/en.js +2 -0
  5. package/dist/i18n/index.d.ts +3 -1
  6. package/dist/i18n/zh.d.ts +2 -0
  7. package/dist/i18n/zh.js +2 -0
  8. package/dist/lib/dsh-client.d.ts +1 -1
  9. package/package.json +47 -51
  10. package/src/contract/protocol/bundle-install.ts +9 -1
  11. package/src/host/runtime/__tests__/dsh-compat.test.ts +23 -0
  12. package/src/host/runtime/dsh-compat.ts +18 -5
  13. package/src/i18n/en.ts +2 -0
  14. package/src/i18n/zh.ts +2 -0
  15. package/src/lib/dsh-client.ts +1 -2
  16. package/dist/components/Activity.css +0 -69
  17. package/dist/components/Activity.d.ts +0 -56
  18. package/dist/components/Activity.js +0 -47
  19. package/dist/components/ApprovalDetail.css +0 -3
  20. package/dist/components/ApprovalDetail.d.ts +0 -42
  21. package/dist/components/ApprovalDetail.js +0 -53
  22. package/dist/components/ApprovalPlan.css +0 -39
  23. package/dist/components/ApprovalPlan.d.ts +0 -27
  24. package/dist/components/ApprovalPlan.js +0 -19
  25. package/dist/components/Card.css +0 -19
  26. package/dist/components/Card.d.ts +0 -26
  27. package/dist/components/Card.js +0 -18
  28. package/dist/components/CardAnchor.d.ts +0 -21
  29. package/dist/components/CardAnchor.js +0 -19
  30. package/dist/components/CardAnchor.module.css +0 -3
  31. package/dist/components/CardBoundary.d.ts +0 -42
  32. package/dist/components/CardBoundary.js +0 -58
  33. package/dist/components/CardBoundary.module.css +0 -5
  34. package/dist/components/CardHead.css +0 -87
  35. package/dist/components/CardHead.d.ts +0 -30
  36. package/dist/components/CardHead.js +0 -27
  37. package/dist/components/ChoiceGroup.css +0 -182
  38. package/dist/components/ChoiceGroup.d.ts +0 -54
  39. package/dist/components/ChoiceGroup.js +0 -63
  40. package/dist/components/ConfirmBar.css +0 -26
  41. package/dist/components/ConfirmBar.d.ts +0 -36
  42. package/dist/components/ConfirmBar.js +0 -26
  43. package/dist/components/EmptyIllustration.d.ts +0 -12
  44. package/dist/components/EmptyIllustration.js +0 -32
  45. package/dist/components/Field.css +0 -20
  46. package/dist/components/Field.d.ts +0 -18
  47. package/dist/components/Field.js +0 -15
  48. package/dist/components/Form.css +0 -6
  49. package/dist/components/Form.d.ts +0 -22
  50. package/dist/components/Form.js +0 -60
  51. package/dist/components/FormActions.css +0 -13
  52. package/dist/components/FormActions.d.ts +0 -29
  53. package/dist/components/FormActions.js +0 -43
  54. package/dist/components/FormNodes.d.ts +0 -107
  55. package/dist/components/FormNodes.js +0 -165
  56. package/dist/components/FormRows.css +0 -107
  57. package/dist/components/FormRows.d.ts +0 -36
  58. package/dist/components/FormRows.js +0 -26
  59. package/dist/components/FormTypes.d.ts +0 -84
  60. package/dist/components/FormTypes.js +0 -1
  61. package/dist/components/Link.css +0 -22
  62. package/dist/components/Link.d.ts +0 -22
  63. package/dist/components/Link.js +0 -17
  64. package/dist/components/LongTaskRow.css +0 -171
  65. package/dist/components/LongTaskRow.d.ts +0 -94
  66. package/dist/components/LongTaskRow.js +0 -103
  67. package/dist/components/Note.css +0 -13
  68. package/dist/components/Note.d.ts +0 -20
  69. package/dist/components/Note.js +0 -14
  70. package/dist/components/ResourceStates.css +0 -114
  71. package/dist/components/ResourceStates.d.ts +0 -44
  72. package/dist/components/ResourceStates.js +0 -41
  73. package/dist/components/Rows.css +0 -42
  74. package/dist/components/Rows.d.ts +0 -28
  75. package/dist/components/Rows.js +0 -21
  76. package/dist/components/SaveBar.d.ts +0 -24
  77. package/dist/components/SaveBar.js +0 -25
  78. package/dist/components/SelectField.css +0 -182
  79. package/dist/components/SelectField.d.ts +0 -89
  80. package/dist/components/SelectField.js +0 -260
  81. package/dist/components/SelectFieldNodes.d.ts +0 -49
  82. package/dist/components/SelectFieldNodes.js +0 -43
  83. package/dist/components/SettingsSection.css +0 -25
  84. package/dist/components/SettingsSection.d.ts +0 -20
  85. package/dist/components/SettingsSection.js +0 -17
  86. package/dist/components/SetupShell.d.ts +0 -93
  87. package/dist/components/SetupShell.js +0 -64
  88. package/dist/components/SetupShell.module.css +0 -81
  89. package/dist/components/Spinner.css +0 -5
  90. package/dist/components/Spinner.d.ts +0 -15
  91. package/dist/components/Spinner.js +0 -13
  92. package/dist/components/Stack.css +0 -6
  93. package/dist/components/Stack.d.ts +0 -14
  94. package/dist/components/Stack.js +0 -10
  95. package/dist/components/StateBlock.css +0 -38
  96. package/dist/components/StateBlock.d.ts +0 -24
  97. package/dist/components/StateBlock.js +0 -22
  98. package/dist/components/TextField.css +0 -32
  99. package/dist/components/TextField.d.ts +0 -14
  100. package/dist/components/TextField.js +0 -10
  101. package/dist/components/board-module.d.ts +0 -307
  102. package/dist/components/board-module.js +0 -1
  103. package/dist/components/card-view-validate.d.ts +0 -5
  104. package/dist/components/card-view-validate.js +0 -256
  105. package/dist/components/icons.d.ts +0 -63
  106. package/dist/components/icons.js +0 -107
  107. package/dist/components/layout/icon-command.d.ts +0 -8
  108. package/dist/components/layout/icon-command.js +0 -21
  109. package/dist/contract/capture.d.ts +0 -16
  110. package/dist/contract/capture.js +0 -1
  111. package/dist/contract/diagnostics.d.ts +0 -34
  112. package/dist/contract/diagnostics.js +0 -124
  113. package/dist/contract/protocol/unit-manager.d.ts +0 -50
  114. package/dist/contract/protocol/unit-manager.js +0 -2
  115. package/dist/host/adapter-contract.d.ts +0 -3
  116. package/dist/host/adapter-contract.js +0 -95
  117. package/dist/host/adapter-set.d.ts +0 -27
  118. package/dist/host/adapter-set.js +0 -258
  119. package/dist/host/adapter-types.d.ts +0 -87
  120. package/dist/host/adapter-types.js +0 -23
  121. package/dist/host/adapters/platform.d.ts +0 -14
  122. package/dist/host/adapters/platform.js +0 -40
  123. package/dist/host/adapters.d.ts +0 -28
  124. package/dist/host/adapters.js +0 -9
  125. package/dist/host/auth-loss.d.ts +0 -33
  126. package/dist/host/auth-loss.js +0 -107
  127. package/dist/host/board-fact.d.ts +0 -8
  128. package/dist/host/board-fact.js +0 -16
  129. package/dist/host/boot-record.d.ts +0 -11
  130. package/dist/host/boot-record.js +0 -31
  131. package/dist/host/browser.d.ts +0 -3
  132. package/dist/host/browser.js +0 -3
  133. package/dist/host/bundle-manager.d.ts +0 -4
  134. package/dist/host/bundle-manager.js +0 -338
  135. package/dist/host/changelog.d.ts +0 -28
  136. package/dist/host/changelog.js +0 -201
  137. package/dist/host/cli-error.d.ts +0 -8
  138. package/dist/host/cli-error.js +0 -70
  139. package/dist/host/cli.d.ts +0 -4
  140. package/dist/host/cli.js +0 -9
  141. package/dist/host/config-sync.d.ts +0 -40
  142. package/dist/host/config-sync.js +0 -267
  143. package/dist/host/context-ref.d.ts +0 -13
  144. package/dist/host/context-ref.js +0 -41
  145. package/dist/host/data-error.d.ts +0 -15
  146. package/dist/host/data-error.js +0 -23
  147. package/dist/host/data-plan-check.d.ts +0 -10
  148. package/dist/host/data-plan-check.js +0 -315
  149. package/dist/host/data-plan.d.ts +0 -15
  150. package/dist/host/data-plan.js +0 -283
  151. package/dist/host/data-root.d.ts +0 -5
  152. package/dist/host/data-root.js +0 -23
  153. package/dist/host/diy-debug.d.ts +0 -80
  154. package/dist/host/diy-debug.js +0 -89
  155. package/dist/host/diy-preset.d.ts +0 -26
  156. package/dist/host/diy-preset.js +0 -115
  157. package/dist/host/diy-record.d.ts +0 -135
  158. package/dist/host/diy-record.js +0 -163
  159. package/dist/host/dsh-compat.d.ts +0 -27
  160. package/dist/host/dsh-compat.js +0 -75
  161. package/dist/host/dsh-plugins.d.ts +0 -5
  162. package/dist/host/dsh-plugins.js +0 -51
  163. package/dist/host/env-policy.d.ts +0 -82
  164. package/dist/host/env-policy.js +0 -181
  165. package/dist/host/extension.d.ts +0 -7
  166. package/dist/host/extension.js +0 -40
  167. package/dist/host/facts.d.ts +0 -31
  168. package/dist/host/facts.js +0 -58
  169. package/dist/host/fs-write.d.ts +0 -96
  170. package/dist/host/fs-write.js +0 -183
  171. package/dist/host/git.d.ts +0 -5
  172. package/dist/host/git.js +0 -1
  173. package/dist/host/host-actions.d.ts +0 -2
  174. package/dist/host/host-actions.js +0 -5
  175. package/dist/host/host-kit.d.ts +0 -37
  176. package/dist/host/host-kit.js +0 -27
  177. package/dist/host/http.d.ts +0 -47
  178. package/dist/host/http.js +0 -289
  179. package/dist/host/install-failure.d.ts +0 -50
  180. package/dist/host/install-failure.js +0 -184
  181. package/dist/host/installed-module.d.ts +0 -25
  182. package/dist/host/installed-module.js +0 -289
  183. package/dist/host/installed-sources.d.ts +0 -10
  184. package/dist/host/installed-sources.js +0 -63
  185. package/dist/host/lease.d.ts +0 -70
  186. package/dist/host/lease.js +0 -264
  187. package/dist/host/lib-capabilities.d.ts +0 -22
  188. package/dist/host/lib-capabilities.js +0 -37
  189. package/dist/host/lib-install.d.ts +0 -19
  190. package/dist/host/lib-install.js +0 -40
  191. package/dist/host/lib-runners.d.ts +0 -18
  192. package/dist/host/lib-runners.js +0 -46
  193. package/dist/host/local-declaration.d.ts +0 -7
  194. package/dist/host/local-declaration.js +0 -33
  195. package/dist/host/long-task.d.ts +0 -97
  196. package/dist/host/long-task.js +0 -297
  197. package/dist/host/market-index-claim.d.ts +0 -19
  198. package/dist/host/market-index-claim.js +0 -87
  199. package/dist/host/market-index-doc.d.ts +0 -12
  200. package/dist/host/market-index-doc.js +0 -1
  201. package/dist/host/market-index-parse.d.ts +0 -28
  202. package/dist/host/market-index-parse.js +0 -413
  203. package/dist/host/market-index.d.ts +0 -13
  204. package/dist/host/market-index.js +0 -105
  205. package/dist/host/module-root.d.ts +0 -1
  206. package/dist/host/module-root.js +0 -5
  207. package/dist/host/needs.d.ts +0 -4
  208. package/dist/host/needs.js +0 -2
  209. package/dist/host/npm-registry.d.ts +0 -10
  210. package/dist/host/npm-registry.js +0 -16
  211. package/dist/host/package-content.d.ts +0 -8
  212. package/dist/host/package-content.js +0 -90
  213. package/dist/host/package-kind.d.ts +0 -13
  214. package/dist/host/package-kind.js +0 -51
  215. package/dist/host/package-route.d.ts +0 -33
  216. package/dist/host/package-route.js +0 -68
  217. package/dist/host/panel-state.d.ts +0 -120
  218. package/dist/host/panel-state.js +0 -177
  219. package/dist/host/patch-blocks.d.ts +0 -13
  220. package/dist/host/patch-blocks.js +0 -52
  221. package/dist/host/patch.d.ts +0 -4
  222. package/dist/host/patch.js +0 -7
  223. package/dist/host/paths.d.ts +0 -12
  224. package/dist/host/paths.js +0 -20
  225. package/dist/host/payload.d.ts +0 -12
  226. package/dist/host/payload.js +0 -16
  227. package/dist/host/plan-results.d.ts +0 -5
  228. package/dist/host/plan-results.js +0 -71
  229. package/dist/host/plan-run.d.ts +0 -41
  230. package/dist/host/plan-run.js +0 -87
  231. package/dist/host/platform.d.ts +0 -14
  232. package/dist/host/platform.js +0 -40
  233. package/dist/host/plugin-ledger.d.ts +0 -32
  234. package/dist/host/plugin-ledger.js +0 -106
  235. package/dist/host/plugin.d.ts +0 -3
  236. package/dist/host/plugin.js +0 -38
  237. package/dist/host/port-types.d.ts +0 -233
  238. package/dist/host/port-types.js +0 -1
  239. package/dist/host/preflight.d.ts +0 -32
  240. package/dist/host/preflight.js +0 -1
  241. package/dist/host/process-alive.d.ts +0 -6
  242. package/dist/host/process-alive.js +0 -16
  243. package/dist/host/profile-bundles.d.ts +0 -20
  244. package/dist/host/profile-bundles.js +0 -48
  245. package/dist/host/profile-create.d.ts +0 -19
  246. package/dist/host/profile-create.js +0 -124
  247. package/dist/host/profile-port.d.ts +0 -4
  248. package/dist/host/profile-port.js +0 -4
  249. package/dist/host/profile-registries.d.ts +0 -10
  250. package/dist/host/profile-registries.js +0 -149
  251. package/dist/host/provision.d.ts +0 -32
  252. package/dist/host/provision.js +0 -105
  253. package/dist/host/read-json.d.ts +0 -1
  254. package/dist/host/read-json.js +0 -11
  255. package/dist/host/recipe-rules.d.ts +0 -5
  256. package/dist/host/recipe-rules.js +0 -412
  257. package/dist/host/recipe.d.ts +0 -14
  258. package/dist/host/recipe.js +0 -332
  259. package/dist/host/registry-declaration.d.ts +0 -21
  260. package/dist/host/registry-declaration.js +0 -42
  261. package/dist/host/reinstall-record.d.ts +0 -16
  262. package/dist/host/reinstall-record.js +0 -54
  263. package/dist/host/release-age.d.ts +0 -24
  264. package/dist/host/release-age.js +0 -92
  265. package/dist/host/release-packages.generated.d.ts +0 -1
  266. package/dist/host/release-packages.generated.js +0 -10
  267. package/dist/host/release-probe.d.ts +0 -37
  268. package/dist/host/release-probe.js +0 -156
  269. package/dist/host/runtime/browser-argv.d.ts +0 -1
  270. package/dist/host/runtime/browser-argv.js +0 -9
  271. package/dist/host/runtime/front-app.d.ts +0 -6
  272. package/dist/host/runtime/front-app.js +0 -70
  273. package/dist/host/shell-render.d.ts +0 -52
  274. package/dist/host/shell-render.js +0 -117
  275. package/dist/host/shell-text.d.ts +0 -30
  276. package/dist/host/shell-text.js +0 -40
  277. package/dist/host/shell.d.ts +0 -25
  278. package/dist/host/shell.js +0 -55
  279. package/dist/host/site.d.ts +0 -45
  280. package/dist/host/site.js +0 -182
  281. package/dist/host/spec.d.ts +0 -8
  282. package/dist/host/spec.js +0 -24
  283. package/dist/host/submit-confirm.d.ts +0 -19
  284. package/dist/host/submit-confirm.js +0 -45
  285. package/dist/host/supply-index.d.ts +0 -38
  286. package/dist/host/supply-index.js +0 -209
  287. package/dist/host/supply-port.d.ts +0 -5
  288. package/dist/host/supply-port.js +0 -50
  289. package/dist/host/time.d.ts +0 -22
  290. package/dist/host/time.js +0 -33
  291. package/dist/host/tokens.d.ts +0 -26
  292. package/dist/host/tokens.js +0 -154
  293. package/dist/host/tool-approval.d.ts +0 -86
  294. package/dist/host/tool-approval.js +0 -118
  295. package/dist/host/tool-kit.d.ts +0 -8
  296. package/dist/host/tool-kit.js +0 -22
  297. package/dist/host/toolbox-port.d.ts +0 -16
  298. package/dist/host/toolbox-port.js +0 -1
  299. package/dist/host/unit-config.d.ts +0 -34
  300. package/dist/host/unit-config.js +0 -28
  301. package/dist/host/unit-data.d.ts +0 -3
  302. package/dist/host/unit-data.js +0 -127
  303. package/dist/host/unit-face.d.ts +0 -95
  304. package/dist/host/unit-face.js +0 -1
  305. package/dist/host/unit-plugin.d.ts +0 -24
  306. package/dist/host/unit-plugin.js +0 -25
  307. package/dist/host/update-journal-manifest.d.ts +0 -19
  308. package/dist/host/update-journal-manifest.js +0 -134
  309. package/dist/host/update-journal-types.d.ts +0 -33
  310. package/dist/host/update-journal-types.js +0 -2
  311. package/dist/host/update-journal.d.ts +0 -43
  312. package/dist/host/update-journal.js +0 -409
  313. package/dist/host/value-handoff.d.ts +0 -16
  314. package/dist/host/value-handoff.js +0 -22
  315. package/dist/host/version-range.d.ts +0 -2
  316. package/dist/host/version-range.js +0 -13
  317. package/dist/host/version.d.ts +0 -4
  318. package/dist/host/version.js +0 -32
  319. package/dist/host/workspace-store.d.ts +0 -19
  320. package/dist/host/workspace-store.js +0 -133
  321. package/dist/host/write-result.d.ts +0 -1
  322. package/dist/host/write-result.js +0 -18
@@ -1,184 +0,0 @@
1
- import { accessSync, constants, statSync } from 'node:fs';
2
- import { dirname } from 'node:path';
3
- const TARGET_FLAGS = ['--prefix', '--cache', '--dir', '--store-dir'];
4
- const PACKAGE_MANAGER = /^(?:pnpm|npm)(?:\.c?m?js|\.cmd|\.exe)?$/;
5
- const INSTALL_VERB = /^(?:add|install|i)$/;
6
- const LAUNCHER_TOKENS = 2;
7
- const NPM_PATH = /^npm (?:error|ERR!) path (.+)$/m;
8
- export function commandTokens(command) {
9
- const tokens = [];
10
- const token = /'([^']*)'|"([^"]*)"|(\S+)/g;
11
- for (let match = token.exec(command); match !== null; match = token.exec(command)) {
12
- tokens.push(match[1] ?? match[2] ?? match[3] ?? '');
13
- }
14
- return tokens;
15
- }
16
- export function installVerbAt(command) {
17
- const tokens = commandTokens(command);
18
- const limit = Math.min(tokens.length - 1, LAUNCHER_TOKENS + 1);
19
- for (let index = 0; index < limit; index += 1) {
20
- if (!PACKAGE_MANAGER.test(binNameOf(tokens[index] ?? '')))
21
- continue;
22
- return INSTALL_VERB.test((tokens[index + 1] ?? '').toLowerCase()) ? index + 1 : undefined;
23
- }
24
- return undefined;
25
- }
26
- function binNameOf(token) {
27
- const at = Math.max(token.lastIndexOf('/'), token.lastIndexOf('\\'));
28
- return (at >= 0 ? token.slice(at + 1) : token).toLowerCase();
29
- }
30
- export function installTargets(command) {
31
- const tokens = commandTokens(command);
32
- const targets = [];
33
- for (let index = 0; index < tokens.length - 1; index += 1) {
34
- if (TARGET_FLAGS.includes(tokens[index] ?? ''))
35
- targets.push(tokens[index + 1] ?? '');
36
- }
37
- return targets.filter((target) => target !== '');
38
- }
39
- export function failurePathIn(output) {
40
- const path = NPM_PATH.exec(output)?.[1]?.trim();
41
- return path === undefined || path === '' ? undefined : path;
42
- }
43
- export function nearestDir(path) {
44
- let at = path;
45
- for (;;) {
46
- const here = () => {
47
- try {
48
- return statSync(at).isDirectory();
49
- }
50
- catch {
51
- return false;
52
- }
53
- };
54
- if (here())
55
- return at;
56
- const up = dirname(at);
57
- if (up === at)
58
- return undefined;
59
- at = up;
60
- }
61
- }
62
- export function writeStateOf(dir, access = accessSync) {
63
- try {
64
- access(dir, constants.W_OK);
65
- return 'ok';
66
- }
67
- catch (error) {
68
- const code = error.code;
69
- return code === 'EACCES' || code === 'EPERM' ? 'denied' : 'unknown';
70
- }
71
- }
72
- export function dirFacts(dir) {
73
- try {
74
- const stats = statSync(dir);
75
- return {
76
- mode: (stats.mode & 0o777).toString(8),
77
- owner: { uid: stats.uid, gid: stats.gid },
78
- writable: writeStateOf(dir) === 'ok',
79
- };
80
- }
81
- catch {
82
- return undefined;
83
- }
84
- }
85
- export function currentUser() {
86
- return { uid: process.getuid?.() ?? -1, gid: process.getgid?.() ?? -1 };
87
- }
88
- export function classifyInstallFailure(output) {
89
- const text = output.toLowerCase();
90
- if (/enospc|no space left/.test(text))
91
- return 'disk-full';
92
- if (/eacces|eperm|permission denied|operation not permitted|access is denied/.test(text))
93
- return 'permission';
94
- return 'unknown';
95
- }
96
- export function installFailureOf(facts) {
97
- const kind = facts.kind ?? classifyInstallFailure(facts.output);
98
- const path = facts.path;
99
- const base = {
100
- command: facts.command,
101
- exitCode: facts.exitCode,
102
- output: facts.output,
103
- ...(path === undefined ? {} : { path }),
104
- ...(facts.mode === undefined ? {} : { mode: facts.mode }),
105
- ...(facts.owner === undefined ? {} : { owner: facts.owner }),
106
- current: facts.current,
107
- };
108
- if (kind === 'disk-full') {
109
- return { ...base, kind, fix: path === undefined ? { kind: 'handoff' } : { kind: 'space', path } };
110
- }
111
- if (kind === 'permission' && path !== undefined) {
112
- const owner = facts.owner;
113
- if (owner !== undefined && owner.uid !== facts.current.uid && facts.current.uid >= 0) {
114
- return { ...base, kind, fix: { kind: 'chown', path, uid: facts.current.uid, gid: facts.current.gid } };
115
- }
116
- if (facts.writable === false) {
117
- return { ...base, kind, fix: { kind: 'chmod', path } };
118
- }
119
- if (facts.writable === true) {
120
- return { ...base, kind: 'sandbox', fix: { kind: 'handoff' } };
121
- }
122
- }
123
- return { ...base, kind, fix: { kind: 'handoff' } };
124
- }
125
- export function diagnoseInstallFailure(input) {
126
- const current = currentUser();
127
- const candidates = [
128
- failurePathIn(input.output),
129
- ...installTargets(input.command),
130
- input.fallback,
131
- ].filter((path) => path !== undefined && path !== '');
132
- for (const candidate of candidates) {
133
- const dir = nearestDir(candidate);
134
- if (dir === undefined)
135
- continue;
136
- const facts = dirFacts(dir);
137
- if (facts === undefined)
138
- continue;
139
- return installFailureOf({
140
- command: input.command,
141
- exitCode: input.exitCode,
142
- output: input.output,
143
- path: dir,
144
- mode: facts.mode,
145
- owner: facts.owner,
146
- writable: facts.writable,
147
- current,
148
- });
149
- }
150
- return installFailureOf({
151
- command: input.command,
152
- exitCode: input.exitCode,
153
- output: input.output,
154
- current,
155
- });
156
- }
157
- export function installWriteProblem(input) {
158
- if (installVerbAt(input.command) === undefined)
159
- return undefined;
160
- const current = currentUser();
161
- const candidates = [...installTargets(input.command), input.fallback].filter((path) => path !== undefined && path !== '');
162
- for (const candidate of candidates) {
163
- const dir = nearestDir(candidate);
164
- if (dir === undefined)
165
- continue;
166
- if (writeStateOf(dir) !== 'denied')
167
- continue;
168
- const facts = dirFacts(dir);
169
- if (facts === undefined)
170
- continue;
171
- return installFailureOf({
172
- command: input.command,
173
- exitCode: null,
174
- output: '',
175
- kind: 'permission',
176
- path: dir,
177
- mode: facts.mode,
178
- owner: facts.owner,
179
- writable: facts.writable,
180
- current,
181
- });
182
- }
183
- return undefined;
184
- }
@@ -1,25 +0,0 @@
1
- import type { DshHostContext } from '../api/dsh.js';
2
- import type { InstalledModule, ProfileModule, ProfilePackage } from './adapter-types.js';
3
- export interface UnitDeclarationSource {
4
- readonly pkg: string;
5
- readonly declaration: unknown;
6
- }
7
- export declare function profileDirOf(ctx: DshHostContext): string | null;
8
- export declare function profileManifestOf(profileDir: string | null): Readonly<Record<string, unknown>> | undefined;
9
- export declare function declaresPackage(profileDir: string | null, pkg: string): boolean;
10
- export declare function profileModules(profileDir: string | null): readonly ProfileModule[];
11
- export declare function createDeclarationLookup(profileDir: string | null): (unit: string) => UnitDeclarationSource | undefined;
12
- export declare function moduleDeclarationOf(profileDir: string | null, pkg: string): unknown;
13
- export interface DeclarationGap {
14
- readonly pkg: string;
15
- readonly problems: readonly string[];
16
- }
17
- export declare function declarationGaps(profileDir: string | null): readonly DeclarationGap[] | undefined;
18
- export declare function declaredPluginCommands(profileDir: string | null): ReadonlyMap<string, ReadonlySet<string>>;
19
- export declare function readInstalledModule(profileDir: string | null, pkg: string): InstalledModule;
20
- export declare function isPackedArtifactSpec(spec: string): boolean;
21
- export declare function isLocalDependencySpec(spec: string): boolean;
22
- export declare function isManagedLinkSpec(spec: string, versionsDir: string, baseDir: string): boolean;
23
- export declare function isRegistryDependencySpec(spec: string): boolean;
24
- export declare function readProfilePackage(profileDir: string | null, pkg: string): ProfilePackage | undefined;
25
- export declare function packageVersionAt(packageRoot: string): string | undefined;
@@ -1,289 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import { declarationProblemsOf, readDeclaration } from '../contract/unit-declaration.js';
4
- import { packageSourceOf } from './installed-sources.js';
5
- import { scopeOf } from './adapter-types.js';
6
- import { workbenchRoot } from './data-root.js';
7
- import { isPackageName } from './spec.js';
8
- function asRecord(value) {
9
- return typeof value === 'object' && value !== null ? value : undefined;
10
- }
11
- function asText(value) {
12
- return typeof value === 'string' ? value : '';
13
- }
14
- export function profileDirOf(ctx) {
15
- const profile = ctx.get('profileContext');
16
- const dir = typeof profile?.dir === 'string' ? profile.dir.trim() : '';
17
- return dir === '' ? null : dir;
18
- }
19
- function stringsOf(value) {
20
- return Array.isArray(value) ? value.filter((item) => typeof item === 'string') : [];
21
- }
22
- export function profileManifestOf(profileDir) {
23
- if (profileDir === null)
24
- return undefined;
25
- try {
26
- return asRecord(JSON.parse(fs.readFileSync(path.join(profileDir, 'package.json'), 'utf8')));
27
- }
28
- catch {
29
- return undefined;
30
- }
31
- }
32
- export function declaresPackage(profileDir, pkg) {
33
- const manifest = profileManifestOf(profileDir);
34
- if (manifest === undefined)
35
- return false;
36
- if (typeof asRecord(manifest.dependencies)?.[pkg] === 'string')
37
- return true;
38
- const bundles = asRecord(asRecord(manifest.dsh)?.profile)?.bundles;
39
- return Array.isArray(bundles) && bundles.includes(pkg);
40
- }
41
- export function profileModules(profileDir) {
42
- const record = profileManifestOf(profileDir);
43
- if (record === undefined)
44
- return [];
45
- const bundles = stringsOf(asRecord(asRecord(record.dsh)?.profile)?.bundles);
46
- const dependencies = asRecord(record.dependencies) ?? {};
47
- const names = bundles.length > 0 ? bundles : Object.keys(dependencies);
48
- const found = [];
49
- for (const pkg of names) {
50
- const read = readInstalledModule(profileDir, pkg);
51
- if (read.kind === 'module') {
52
- const spec = asText(dependencies[read.pkg]);
53
- found.push({
54
- pkg: read.pkg,
55
- unit: read.unit,
56
- version: read.version,
57
- ...(read.registry === undefined ? {} : { registry: read.registry }),
58
- local: isLocalCopySpec(profileDir, spec),
59
- fromRegistry: isRegistryDependencySpec(spec),
60
- });
61
- }
62
- }
63
- return found;
64
- }
65
- export function createDeclarationLookup(profileDir) {
66
- let roster;
67
- const scan = () => new Map(profileModules(profileDir).map((row) => [row.unit, row.pkg]));
68
- return (unit) => {
69
- roster ??= scan();
70
- let pkg = roster.get(unit);
71
- if (pkg === undefined) {
72
- roster = scan();
73
- pkg = roster.get(unit);
74
- }
75
- return pkg === undefined ? undefined : { pkg, declaration: moduleDeclarationOf(profileDir, pkg) };
76
- };
77
- }
78
- function registryFromLockfile(profileDir, pkg) {
79
- let text;
80
- try {
81
- text = fs.readFileSync(path.join(profileDir, 'pnpm-lock.yaml'), 'utf8');
82
- }
83
- catch {
84
- return undefined;
85
- }
86
- const at = text.indexOf(` ${pkg}@`);
87
- const quoted = at === -1 ? text.indexOf(` '${pkg}@`) : at;
88
- if (quoted === -1)
89
- return undefined;
90
- const headerEnd = text.indexOf('\n', quoted);
91
- const end = headerEnd === -1 ? -1 : text.indexOf('\n ', headerEnd + 1);
92
- const block = text.slice(quoted, end === -1 ? quoted + 900 : end);
93
- const match = /tarball:\s*([^\s,}]+)/.exec(block);
94
- const tarball = match?.[1];
95
- if (tarball === undefined || !tarball.startsWith('http'))
96
- return undefined;
97
- const cut = tarball.lastIndexOf(`/${pkg}/`);
98
- if (cut <= 'https://'.length)
99
- return undefined;
100
- return tarball.slice(0, cut);
101
- }
102
- function unquoted(value) {
103
- const quote = value.charAt(0);
104
- if (value.length >= 2 && (quote === '"' || quote === "'") && value.endsWith(quote)) {
105
- return value.slice(1, -1).trim();
106
- }
107
- return value;
108
- }
109
- function registryFromNpmrc(profileDir, pkg) {
110
- let text;
111
- try {
112
- text = fs.readFileSync(path.join(profileDir, '.npmrc'), 'utf8');
113
- }
114
- catch {
115
- return undefined;
116
- }
117
- const scope = scopeOf(pkg);
118
- let fallback;
119
- for (const line of text.split('\n')) {
120
- const trimmed = line.trim();
121
- if (trimmed === '' || trimmed.startsWith('#') || trimmed.startsWith(';'))
122
- continue;
123
- const separator = trimmed.indexOf('=');
124
- if (separator <= 0)
125
- continue;
126
- const key = trimmed.slice(0, separator).trim();
127
- const value = unquoted(trimmed.slice(separator + 1).trim());
128
- if (value === '')
129
- continue;
130
- if (scope !== null && key === `${scope}:registry`)
131
- return value;
132
- if (key === 'registry')
133
- fallback = value;
134
- }
135
- return fallback;
136
- }
137
- function registryOf(profileDir, pkg, manifest) {
138
- const declared = asText(asRecord(manifest.publishConfig)?.registry);
139
- if (declared !== '')
140
- return declared;
141
- const recorded = packageSourceOf(profileDir, pkg);
142
- if (recorded !== undefined)
143
- return recorded.registry;
144
- const locked = registryFromLockfile(profileDir, pkg);
145
- return locked === undefined ? registryFromNpmrc(profileDir, pkg) : locked;
146
- }
147
- export function moduleDeclarationOf(profileDir, pkg) {
148
- if (profileDir === null || !isPackageName(pkg))
149
- return undefined;
150
- try {
151
- const text = fs.readFileSync(path.join(profileDir, 'node_modules', pkg, 'package.json'), 'utf8');
152
- return asRecord(asRecord(asRecord(JSON.parse(text))?.dsh)?.workbench);
153
- }
154
- catch {
155
- return undefined;
156
- }
157
- }
158
- export function declarationGaps(profileDir) {
159
- if (profileManifestOf(profileDir) === undefined)
160
- return undefined;
161
- const gaps = [];
162
- for (const module of profileModules(profileDir)) {
163
- const problems = declarationProblemsOf(module.pkg, moduleDeclarationOf(profileDir, module.pkg));
164
- if (problems.length > 0)
165
- gaps.push({ pkg: module.pkg, problems });
166
- }
167
- return gaps;
168
- }
169
- export function declaredPluginCommands(profileDir) {
170
- const declared = new Map();
171
- for (const module of profileModules(profileDir)) {
172
- const read = readDeclaration(module.pkg, moduleDeclarationOf(profileDir, module.pkg));
173
- for (const need of read.manifest?.needs ?? []) {
174
- if (need.kind !== 'extension')
175
- continue;
176
- const name = need.name.trim();
177
- if (name === '')
178
- continue;
179
- const commands = declared.get(name) ?? new Set();
180
- for (const command of need.commands ?? [])
181
- commands.add(command);
182
- declared.set(name, commands);
183
- }
184
- }
185
- return declared;
186
- }
187
- export function readInstalledModule(profileDir, pkg) {
188
- if (profileDir === null || !isPackageName(pkg))
189
- return { kind: 'unknown', pkg };
190
- let manifest;
191
- try {
192
- manifest = JSON.parse(fs.readFileSync(path.join(profileDir, 'node_modules', pkg, 'package.json'), 'utf8'));
193
- }
194
- catch {
195
- return { kind: 'unknown', pkg };
196
- }
197
- const record = asRecord(manifest);
198
- if (record === undefined)
199
- return { kind: 'unknown', pkg };
200
- const declared = asRecord(asRecord(record.dsh)?.workbench);
201
- const unit = declared === undefined ? '' : asText(declared.unit);
202
- if (unit === '')
203
- return { kind: 'not-module', pkg };
204
- const registry = registryOf(profileDir, pkg, record);
205
- return {
206
- kind: 'module',
207
- pkg,
208
- unit,
209
- version: asText(record.version),
210
- ...(registry === undefined ? {} : { registry }),
211
- };
212
- }
213
- const PACKED_ARTIFACT = /\.(?:tgz|tar\.gz|tar)$/i;
214
- export function isPackedArtifactSpec(spec) {
215
- const trimmed = spec.trim();
216
- const pkgPath = trimmed.startsWith('file:') ? trimmed.slice('file:'.length) : trimmed;
217
- return PACKED_ARTIFACT.test(pkgPath);
218
- }
219
- export function isLocalDependencySpec(spec) {
220
- const trimmed = spec.trim();
221
- if (isPackedArtifactSpec(trimmed))
222
- return false;
223
- return (trimmed.startsWith('link:') ||
224
- trimmed.startsWith('file:') ||
225
- trimmed.startsWith('./') ||
226
- trimmed.startsWith('../') ||
227
- trimmed.startsWith('/'));
228
- }
229
- const LINK_SPEC_PREFIX = 'link:';
230
- export function isManagedLinkSpec(spec, versionsDir, baseDir) {
231
- const trimmed = spec.trim();
232
- if (!trimmed.startsWith(LINK_SPEC_PREFIX))
233
- return false;
234
- const target = path.resolve(baseDir, trimmed.slice(LINK_SPEC_PREFIX.length));
235
- const root = path.resolve(versionsDir);
236
- return target === root || target.startsWith(`${root}${path.sep}`);
237
- }
238
- function isLocalCopySpec(profileDir, spec) {
239
- const local = isLocalDependencySpec(spec);
240
- if (!local || profileDir === null)
241
- return local;
242
- return !isManagedLinkSpec(spec, path.join(workbenchRoot(), 'versions'), profileDir);
243
- }
244
- const NON_REGISTRY_SPEC = /^(?:git\+|git:|github:|gitlab:|bitbucket:|https?:|ssh:|workspace:)/i;
245
- export function isRegistryDependencySpec(spec) {
246
- const trimmed = spec.trim();
247
- if (trimmed === '')
248
- return true;
249
- if (isLocalDependencySpec(trimmed) || isPackedArtifactSpec(trimmed))
250
- return false;
251
- return !NON_REGISTRY_SPEC.test(trimmed);
252
- }
253
- export function readProfilePackage(profileDir, pkg) {
254
- if (profileDir === null || !isPackageName(pkg))
255
- return undefined;
256
- let manifest;
257
- try {
258
- manifest = JSON.parse(fs.readFileSync(path.join(profileDir, 'node_modules', pkg, 'package.json'), 'utf8'));
259
- }
260
- catch {
261
- return undefined;
262
- }
263
- const record = asRecord(manifest);
264
- if (record === undefined)
265
- return undefined;
266
- const version = asText(record.version);
267
- if (version === '')
268
- return undefined;
269
- const registry = registryOf(profileDir, pkg, record);
270
- const dependencies = asRecord(profileManifestOf(profileDir)?.dependencies) ?? {};
271
- const local = isLocalCopySpec(profileDir, asText(dependencies[pkg]));
272
- return {
273
- pkg,
274
- version,
275
- ...(registry === undefined ? {} : { registry }),
276
- ...(local ? { local: true } : {}),
277
- };
278
- }
279
- export function packageVersionAt(packageRoot) {
280
- let manifest;
281
- try {
282
- manifest = JSON.parse(fs.readFileSync(path.join(packageRoot, 'package.json'), 'utf8'));
283
- }
284
- catch {
285
- return undefined;
286
- }
287
- const version = asText(asRecord(manifest)?.version);
288
- return version === '' ? undefined : version;
289
- }
@@ -1,10 +0,0 @@
1
- export interface InstalledSource {
2
- readonly version: string;
3
- readonly registry: string;
4
- }
5
- export type InstalledSourceMap = Readonly<Record<string, InstalledSource>>;
6
- export declare function installedSourcesFile(profileDir: string): string;
7
- export declare function readInstalledSources(profileDir: string | null): InstalledSourceMap;
8
- export declare function packageSourceOf(profileDir: string | null, pkg: string): InstalledSource | undefined;
9
- export declare function rememberPackageSource(profileDir: string, pkg: string, source: InstalledSource): void;
10
- export declare function forgetPackageSource(profileDir: string, pkg: string): void;
@@ -1,63 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import { writeTextFile } from './fs-write.js';
4
- const FILE_NAME = '.dsh-workbench-sources.json';
5
- const FILE_VERSION = 1;
6
- function asRecord(value) {
7
- return typeof value === 'object' && value !== null ? value : undefined;
8
- }
9
- function asText(value) {
10
- return typeof value === 'string' ? value.trim() : '';
11
- }
12
- export function installedSourcesFile(profileDir) {
13
- return path.join(profileDir, FILE_NAME);
14
- }
15
- export function readInstalledSources(profileDir) {
16
- if (profileDir === null)
17
- return {};
18
- let parsed;
19
- try {
20
- parsed = JSON.parse(fs.readFileSync(installedSourcesFile(profileDir), 'utf8'));
21
- }
22
- catch {
23
- return {};
24
- }
25
- const packages = asRecord(asRecord(parsed)?.packages);
26
- if (packages === undefined)
27
- return {};
28
- const found = {};
29
- for (const [pkg, value] of Object.entries(packages)) {
30
- const record = asRecord(value);
31
- if (record === undefined)
32
- continue;
33
- const version = asText(record.version);
34
- const registry = asText(record.registry);
35
- if (pkg === '' || version === '' || registry === '')
36
- continue;
37
- found[pkg] = { version, registry };
38
- }
39
- return found;
40
- }
41
- export function packageSourceOf(profileDir, pkg) {
42
- return readInstalledSources(profileDir)[pkg];
43
- }
44
- function writeInstalledSources(profileDir, sources) {
45
- writeTextFile(installedSourcesFile(profileDir), `${JSON.stringify({ version: FILE_VERSION, packages: sources }, null, 2)}\n`, {
46
- mode: 0o600,
47
- });
48
- }
49
- export function rememberPackageSource(profileDir, pkg, source) {
50
- const trimmed = pkg.trim();
51
- if (trimmed === '' || source.version.trim() === '' || source.registry.trim() === '')
52
- return;
53
- const all = { ...readInstalledSources(profileDir) };
54
- all[trimmed] = { version: source.version.trim(), registry: source.registry.trim() };
55
- writeInstalledSources(profileDir, all);
56
- }
57
- export function forgetPackageSource(profileDir, pkg) {
58
- const all = { ...readInstalledSources(profileDir) };
59
- if (all[pkg] === undefined)
60
- return;
61
- delete all[pkg];
62
- writeInstalledSources(profileDir, all);
63
- }
@@ -1,70 +0,0 @@
1
- export interface HostLeaseInput {
2
- readonly profileDir: string;
3
- readonly profile: string;
4
- readonly version?: string | undefined;
5
- readonly pid?: number | undefined;
6
- readonly startedAt?: string | undefined;
7
- readonly token?: string | undefined;
8
- }
9
- export interface HostLeaseRecord {
10
- readonly pid: number;
11
- readonly startedAt: string;
12
- readonly token: string;
13
- readonly profile: string;
14
- readonly version?: string | undefined;
15
- readonly file: string;
16
- }
17
- export interface HostLeaseHandle {
18
- readonly record: HostLeaseRecord;
19
- release(): void;
20
- }
21
- export interface UpdateLeaseInput {
22
- readonly root: string;
23
- readonly pid?: number | undefined;
24
- readonly startedAt?: string | undefined;
25
- readonly token?: string | undefined;
26
- readonly kind?: UpdateLeaseKind | undefined;
27
- }
28
- export type UpdateLeaseKind = 'update' | 'reinstall';
29
- export interface UpdateLeaseRecord {
30
- readonly pid: number;
31
- readonly startedAt: string;
32
- readonly token: string;
33
- readonly file: string;
34
- readonly kind?: UpdateLeaseKind | undefined;
35
- }
36
- export interface UpdateLeaseHandle {
37
- readonly record: UpdateLeaseRecord;
38
- release(): void;
39
- rewrite(pid: number): boolean;
40
- }
41
- export declare const UPDATE_LEASE_LAUNCH_MS = 120000;
42
- /** 有 pid 的更新租约最长认账时间:超过它基本可以断定 pid 被复活进程复用了。 */
43
- export declare const UPDATE_LEASE_MAX_MS: number;
44
- export declare function randomLeaseToken(): string;
45
- export declare function hostLeaseDir(profileDir: string): string;
46
- export declare function hostLeaseFile(profileDir: string, pid: number, token: string): string;
47
- export declare function hostLeaseFiles(profileDir: string): readonly string[];
48
- export declare function readHostLease(file: string): HostLeaseRecord | undefined;
49
- export declare function acquireHostLease(input: HostLeaseInput): HostLeaseHandle;
50
- export declare function releaseHostLease(input: {
51
- readonly file: string;
52
- readonly pid: number;
53
- readonly token: string;
54
- }): boolean;
55
- export declare function activeHostLeases(profileDir: string): readonly HostLeaseRecord[];
56
- export declare function updateLeaseFile(root: string): string;
57
- export declare function readUpdateLease(root: string): UpdateLeaseRecord | undefined;
58
- export declare function updateLeaseActive(root: string, at?: number): boolean;
59
- export declare function acquireUpdateLease(input: UpdateLeaseInput): UpdateLeaseHandle | undefined;
60
- export declare function rewriteUpdateLease(input: {
61
- readonly root: string;
62
- readonly token: string;
63
- readonly pid: number;
64
- readonly startedAt?: string | undefined;
65
- }): boolean;
66
- export declare function releaseUpdateLease(input: {
67
- readonly root: string;
68
- readonly token: string;
69
- readonly pid?: number | undefined;
70
- }): boolean;