@dsh-workbench/shared 1.5.2-alpha.4 → 1.5.2-alpha.5
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/dist/components/Activity.css +69 -0
- package/dist/components/Activity.d.ts +56 -0
- package/dist/components/Activity.js +47 -0
- package/dist/components/ApprovalDetail.css +3 -0
- package/dist/components/ApprovalDetail.d.ts +42 -0
- package/dist/components/ApprovalDetail.js +53 -0
- package/dist/components/ApprovalPlan.css +39 -0
- package/dist/components/ApprovalPlan.d.ts +27 -0
- package/dist/components/ApprovalPlan.js +19 -0
- package/dist/components/Card.css +19 -0
- package/dist/components/Card.d.ts +26 -0
- package/dist/components/Card.js +18 -0
- package/dist/components/CardAnchor.d.ts +21 -0
- package/dist/components/CardAnchor.js +19 -0
- package/dist/components/CardAnchor.module.css +3 -0
- package/dist/components/CardBoundary.d.ts +42 -0
- package/dist/components/CardBoundary.js +58 -0
- package/dist/components/CardBoundary.module.css +5 -0
- package/dist/components/CardHead.css +87 -0
- package/dist/components/CardHead.d.ts +30 -0
- package/dist/components/CardHead.js +27 -0
- package/dist/components/ChoiceGroup.css +182 -0
- package/dist/components/ChoiceGroup.d.ts +54 -0
- package/dist/components/ChoiceGroup.js +63 -0
- package/dist/components/ConfirmBar.css +26 -0
- package/dist/components/ConfirmBar.d.ts +36 -0
- package/dist/components/ConfirmBar.js +26 -0
- package/dist/components/EmptyIllustration.d.ts +12 -0
- package/dist/components/EmptyIllustration.js +32 -0
- package/dist/components/Field.css +20 -0
- package/dist/components/Field.d.ts +18 -0
- package/dist/components/Field.js +15 -0
- package/dist/components/Form.css +6 -0
- package/dist/components/Form.d.ts +22 -0
- package/dist/components/Form.js +60 -0
- package/dist/components/FormActions.css +13 -0
- package/dist/components/FormActions.d.ts +29 -0
- package/dist/components/FormActions.js +43 -0
- package/dist/components/FormNodes.d.ts +107 -0
- package/dist/components/FormNodes.js +165 -0
- package/dist/components/FormRows.css +107 -0
- package/dist/components/FormRows.d.ts +36 -0
- package/dist/components/FormRows.js +26 -0
- package/dist/components/FormTypes.d.ts +84 -0
- package/dist/components/FormTypes.js +1 -0
- package/dist/components/Link.css +22 -0
- package/dist/components/Link.d.ts +22 -0
- package/dist/components/Link.js +17 -0
- package/dist/components/LongTaskRow.css +171 -0
- package/dist/components/LongTaskRow.d.ts +94 -0
- package/dist/components/LongTaskRow.js +103 -0
- package/dist/components/Note.css +13 -0
- package/dist/components/Note.d.ts +20 -0
- package/dist/components/Note.js +14 -0
- package/dist/components/ResourceStates.css +114 -0
- package/dist/components/ResourceStates.d.ts +44 -0
- package/dist/components/ResourceStates.js +41 -0
- package/dist/components/Rows.css +42 -0
- package/dist/components/Rows.d.ts +28 -0
- package/dist/components/Rows.js +21 -0
- package/dist/components/SaveBar.d.ts +24 -0
- package/dist/components/SaveBar.js +25 -0
- package/dist/components/SelectField.css +182 -0
- package/dist/components/SelectField.d.ts +89 -0
- package/dist/components/SelectField.js +260 -0
- package/dist/components/SelectFieldNodes.d.ts +49 -0
- package/dist/components/SelectFieldNodes.js +43 -0
- package/dist/components/SettingsSection.css +25 -0
- package/dist/components/SettingsSection.d.ts +20 -0
- package/dist/components/SettingsSection.js +17 -0
- package/dist/components/SetupShell.d.ts +93 -0
- package/dist/components/SetupShell.js +64 -0
- package/dist/components/SetupShell.module.css +81 -0
- package/dist/components/Spinner.css +5 -0
- package/dist/components/Spinner.d.ts +15 -0
- package/dist/components/Spinner.js +13 -0
- package/dist/components/Stack.css +6 -0
- package/dist/components/Stack.d.ts +14 -0
- package/dist/components/Stack.js +10 -0
- package/dist/components/StateBlock.css +38 -0
- package/dist/components/StateBlock.d.ts +24 -0
- package/dist/components/StateBlock.js +22 -0
- package/dist/components/TextField.css +32 -0
- package/dist/components/TextField.d.ts +14 -0
- package/dist/components/TextField.js +10 -0
- package/dist/components/board-module.d.ts +307 -0
- package/dist/components/board-module.js +1 -0
- package/dist/components/card-view-validate.d.ts +5 -0
- package/dist/components/card-view-validate.js +256 -0
- package/dist/components/icons.d.ts +63 -0
- package/dist/components/icons.js +107 -0
- package/dist/components/layout/icon-command.d.ts +8 -0
- package/dist/components/layout/icon-command.js +21 -0
- package/dist/contract/capture.d.ts +16 -0
- package/dist/contract/capture.js +1 -0
- package/dist/contract/diagnostics.d.ts +34 -0
- package/dist/contract/diagnostics.js +124 -0
- package/dist/contract/protocol/unit-manager.d.ts +50 -0
- package/dist/contract/protocol/unit-manager.js +2 -0
- package/dist/host/adapter-contract.d.ts +3 -0
- package/dist/host/adapter-contract.js +95 -0
- package/dist/host/adapter-set.d.ts +27 -0
- package/dist/host/adapter-set.js +258 -0
- package/dist/host/adapter-types.d.ts +87 -0
- package/dist/host/adapter-types.js +23 -0
- package/dist/host/adapters/platform.d.ts +14 -0
- package/dist/host/adapters/platform.js +40 -0
- package/dist/host/adapters.d.ts +28 -0
- package/dist/host/adapters.js +9 -0
- package/dist/host/auth-loss.d.ts +33 -0
- package/dist/host/auth-loss.js +107 -0
- package/dist/host/board-fact.d.ts +8 -0
- package/dist/host/board-fact.js +16 -0
- package/dist/host/boot-record.d.ts +11 -0
- package/dist/host/boot-record.js +31 -0
- package/dist/host/browser.d.ts +3 -0
- package/dist/host/browser.js +3 -0
- package/dist/host/bundle-manager.d.ts +4 -0
- package/dist/host/bundle-manager.js +338 -0
- package/dist/host/changelog.d.ts +28 -0
- package/dist/host/changelog.js +201 -0
- package/dist/host/cli-error.d.ts +8 -0
- package/dist/host/cli-error.js +70 -0
- package/dist/host/cli.d.ts +4 -0
- package/dist/host/cli.js +9 -0
- package/dist/host/config-sync.d.ts +40 -0
- package/dist/host/config-sync.js +267 -0
- package/dist/host/context-ref.d.ts +13 -0
- package/dist/host/context-ref.js +41 -0
- package/dist/host/data-error.d.ts +15 -0
- package/dist/host/data-error.js +23 -0
- package/dist/host/data-plan-check.d.ts +10 -0
- package/dist/host/data-plan-check.js +315 -0
- package/dist/host/data-plan.d.ts +15 -0
- package/dist/host/data-plan.js +283 -0
- package/dist/host/data-root.d.ts +5 -0
- package/dist/host/data-root.js +23 -0
- package/dist/host/diy-debug.d.ts +80 -0
- package/dist/host/diy-debug.js +89 -0
- package/dist/host/diy-preset.d.ts +26 -0
- package/dist/host/diy-preset.js +115 -0
- package/dist/host/diy-record.d.ts +135 -0
- package/dist/host/diy-record.js +163 -0
- package/dist/host/dsh-compat.d.ts +27 -0
- package/dist/host/dsh-compat.js +75 -0
- package/dist/host/dsh-plugins.d.ts +5 -0
- package/dist/host/dsh-plugins.js +51 -0
- package/dist/host/env-policy.d.ts +82 -0
- package/dist/host/env-policy.js +181 -0
- package/dist/host/extension.d.ts +7 -0
- package/dist/host/extension.js +40 -0
- package/dist/host/facts.d.ts +31 -0
- package/dist/host/facts.js +58 -0
- package/dist/host/fs-write.d.ts +96 -0
- package/dist/host/fs-write.js +183 -0
- package/dist/host/git.d.ts +5 -0
- package/dist/host/git.js +1 -0
- package/dist/host/host-actions.d.ts +2 -0
- package/dist/host/host-actions.js +5 -0
- package/dist/host/host-kit.d.ts +37 -0
- package/dist/host/host-kit.js +27 -0
- package/dist/host/http.d.ts +47 -0
- package/dist/host/http.js +289 -0
- package/dist/host/install-failure.d.ts +50 -0
- package/dist/host/install-failure.js +184 -0
- package/dist/host/installed-module.d.ts +25 -0
- package/dist/host/installed-module.js +289 -0
- package/dist/host/installed-sources.d.ts +10 -0
- package/dist/host/installed-sources.js +63 -0
- package/dist/host/lease.d.ts +70 -0
- package/dist/host/lease.js +264 -0
- package/dist/host/lib-capabilities.d.ts +22 -0
- package/dist/host/lib-capabilities.js +37 -0
- package/dist/host/lib-install.d.ts +19 -0
- package/dist/host/lib-install.js +40 -0
- package/dist/host/lib-runners.d.ts +18 -0
- package/dist/host/lib-runners.js +46 -0
- package/dist/host/local-declaration.d.ts +7 -0
- package/dist/host/local-declaration.js +33 -0
- package/dist/host/long-task.d.ts +97 -0
- package/dist/host/long-task.js +297 -0
- package/dist/host/market-index-claim.d.ts +19 -0
- package/dist/host/market-index-claim.js +87 -0
- package/dist/host/market-index-doc.d.ts +12 -0
- package/dist/host/market-index-doc.js +1 -0
- package/dist/host/market-index-parse.d.ts +28 -0
- package/dist/host/market-index-parse.js +413 -0
- package/dist/host/market-index.d.ts +13 -0
- package/dist/host/market-index.js +105 -0
- package/dist/host/module-root.d.ts +1 -0
- package/dist/host/module-root.js +5 -0
- package/dist/host/needs.d.ts +4 -0
- package/dist/host/needs.js +2 -0
- package/dist/host/npm-registry.d.ts +10 -0
- package/dist/host/npm-registry.js +16 -0
- package/dist/host/package-content.d.ts +8 -0
- package/dist/host/package-content.js +90 -0
- package/dist/host/package-kind.d.ts +13 -0
- package/dist/host/package-kind.js +51 -0
- package/dist/host/package-route.d.ts +33 -0
- package/dist/host/package-route.js +68 -0
- package/dist/host/panel-state.d.ts +120 -0
- package/dist/host/panel-state.js +177 -0
- package/dist/host/patch-blocks.d.ts +13 -0
- package/dist/host/patch-blocks.js +52 -0
- package/dist/host/patch.d.ts +4 -0
- package/dist/host/patch.js +7 -0
- package/dist/host/paths.d.ts +12 -0
- package/dist/host/paths.js +20 -0
- package/dist/host/payload.d.ts +12 -0
- package/dist/host/payload.js +16 -0
- package/dist/host/plan-results.d.ts +5 -0
- package/dist/host/plan-results.js +71 -0
- package/dist/host/plan-run.d.ts +41 -0
- package/dist/host/plan-run.js +87 -0
- package/dist/host/platform.d.ts +14 -0
- package/dist/host/platform.js +40 -0
- package/dist/host/plugin-ledger.d.ts +32 -0
- package/dist/host/plugin-ledger.js +106 -0
- package/dist/host/plugin.d.ts +3 -0
- package/dist/host/plugin.js +38 -0
- package/dist/host/port-types.d.ts +233 -0
- package/dist/host/port-types.js +1 -0
- package/dist/host/preflight.d.ts +32 -0
- package/dist/host/preflight.js +1 -0
- package/dist/host/process-alive.d.ts +6 -0
- package/dist/host/process-alive.js +16 -0
- package/dist/host/profile-bundles.d.ts +20 -0
- package/dist/host/profile-bundles.js +48 -0
- package/dist/host/profile-create.d.ts +19 -0
- package/dist/host/profile-create.js +124 -0
- package/dist/host/profile-port.d.ts +4 -0
- package/dist/host/profile-port.js +4 -0
- package/dist/host/profile-registries.d.ts +10 -0
- package/dist/host/profile-registries.js +149 -0
- package/dist/host/provision.d.ts +32 -0
- package/dist/host/provision.js +105 -0
- package/dist/host/read-json.d.ts +1 -0
- package/dist/host/read-json.js +11 -0
- package/dist/host/recipe-rules.d.ts +5 -0
- package/dist/host/recipe-rules.js +412 -0
- package/dist/host/recipe.d.ts +14 -0
- package/dist/host/recipe.js +332 -0
- package/dist/host/registry-declaration.d.ts +21 -0
- package/dist/host/registry-declaration.js +42 -0
- package/dist/host/reinstall-record.d.ts +16 -0
- package/dist/host/reinstall-record.js +54 -0
- package/dist/host/release-age.d.ts +24 -0
- package/dist/host/release-age.js +92 -0
- package/dist/host/release-packages.generated.d.ts +1 -0
- package/dist/host/release-packages.generated.js +10 -0
- package/dist/host/release-probe.d.ts +37 -0
- package/dist/host/release-probe.js +156 -0
- package/dist/host/runtime/browser-argv.d.ts +1 -0
- package/dist/host/runtime/browser-argv.js +9 -0
- package/dist/host/runtime/front-app.d.ts +6 -0
- package/dist/host/runtime/front-app.js +70 -0
- package/dist/host/shell-render.d.ts +52 -0
- package/dist/host/shell-render.js +117 -0
- package/dist/host/shell-text.d.ts +30 -0
- package/dist/host/shell-text.js +40 -0
- package/dist/host/shell.d.ts +25 -0
- package/dist/host/shell.js +55 -0
- package/dist/host/site.d.ts +45 -0
- package/dist/host/site.js +182 -0
- package/dist/host/spec.d.ts +8 -0
- package/dist/host/spec.js +24 -0
- package/dist/host/submit-confirm.d.ts +19 -0
- package/dist/host/submit-confirm.js +45 -0
- package/dist/host/supply-index.d.ts +38 -0
- package/dist/host/supply-index.js +209 -0
- package/dist/host/supply-port.d.ts +5 -0
- package/dist/host/supply-port.js +50 -0
- package/dist/host/time.d.ts +22 -0
- package/dist/host/time.js +33 -0
- package/dist/host/tokens.d.ts +26 -0
- package/dist/host/tokens.js +154 -0
- package/dist/host/tool-approval.d.ts +86 -0
- package/dist/host/tool-approval.js +118 -0
- package/dist/host/tool-kit.d.ts +8 -0
- package/dist/host/tool-kit.js +22 -0
- package/dist/host/toolbox-port.d.ts +16 -0
- package/dist/host/toolbox-port.js +1 -0
- package/dist/host/unit-config.d.ts +34 -0
- package/dist/host/unit-config.js +28 -0
- package/dist/host/unit-data.d.ts +3 -0
- package/dist/host/unit-data.js +127 -0
- package/dist/host/unit-face.d.ts +95 -0
- package/dist/host/unit-face.js +1 -0
- package/dist/host/unit-plugin.d.ts +24 -0
- package/dist/host/unit-plugin.js +25 -0
- package/dist/host/update-journal-manifest.d.ts +19 -0
- package/dist/host/update-journal-manifest.js +134 -0
- package/dist/host/update-journal-types.d.ts +33 -0
- package/dist/host/update-journal-types.js +2 -0
- package/dist/host/update-journal.d.ts +43 -0
- package/dist/host/update-journal.js +409 -0
- package/dist/host/value-handoff.d.ts +16 -0
- package/dist/host/value-handoff.js +22 -0
- package/dist/host/version-range.d.ts +2 -0
- package/dist/host/version-range.js +13 -0
- package/dist/host/version.d.ts +4 -0
- package/dist/host/version.js +32 -0
- package/dist/host/workspace-store.d.ts +19 -0
- package/dist/host/workspace-store.js +133 -0
- package/dist/host/write-result.d.ts +1 -0
- package/dist/host/write-result.js +18 -0
- package/dist/lib/dsh-client.d.ts +1 -1
- package/package.json +51 -47
- package/src/lib/dsh-client.ts +2 -1
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { MARKET_INDEX_DIR, MARKET_INDEX_FORMAT } from '../contract/protocol/market-index.js';
|
|
3
|
+
import { marketText } from '../lib/market-index.js';
|
|
4
|
+
import { compareVersions, isValidVersion } from './version.js';
|
|
5
|
+
const NPM_NAME = /^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/;
|
|
6
|
+
const GIT_COMMIT = /^[0-9a-f]{40}$/;
|
|
7
|
+
const MAX_ICON_CHARS = 32 * 1024;
|
|
8
|
+
export function compareSemver(left, right) {
|
|
9
|
+
return compareVersions(left, right);
|
|
10
|
+
}
|
|
11
|
+
export function httpUrlProblem(url) {
|
|
12
|
+
let parsed;
|
|
13
|
+
try {
|
|
14
|
+
parsed = new URL(url);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return '不是合法 URL';
|
|
18
|
+
}
|
|
19
|
+
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:')
|
|
20
|
+
return '只收 http / https';
|
|
21
|
+
if (parsed.username !== '' || parsed.password !== '')
|
|
22
|
+
return 'URL 不能带凭据';
|
|
23
|
+
if (parsed.search !== '' || parsed.hash !== '')
|
|
24
|
+
return 'URL 不能带 query / fragment';
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
export function gitUrlOk(url) {
|
|
28
|
+
if (url === '')
|
|
29
|
+
return false;
|
|
30
|
+
if (/^[^@\s]+@[^@\s:]+:[^@\s]+$/.test(url))
|
|
31
|
+
return true;
|
|
32
|
+
let parsed;
|
|
33
|
+
try {
|
|
34
|
+
parsed = new URL(url);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
if (parsed.protocol !== 'https:' && parsed.protocol !== 'ssh:' && parsed.protocol !== 'http:')
|
|
40
|
+
return false;
|
|
41
|
+
if (parsed.password !== '')
|
|
42
|
+
return false;
|
|
43
|
+
if (parsed.username !== '' && parsed.protocol !== 'ssh:')
|
|
44
|
+
return false;
|
|
45
|
+
if (parsed.search !== '' || parsed.hash !== '')
|
|
46
|
+
return false;
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
function asRecord(value) {
|
|
50
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
51
|
+
? value
|
|
52
|
+
: undefined;
|
|
53
|
+
}
|
|
54
|
+
function asText(value) {
|
|
55
|
+
return typeof value === 'string' ? value.trim() : '';
|
|
56
|
+
}
|
|
57
|
+
function indexPathOf(value) {
|
|
58
|
+
return asText(value).replace(/\\/g, '/');
|
|
59
|
+
}
|
|
60
|
+
function asTextArray(value) {
|
|
61
|
+
return Array.isArray(value)
|
|
62
|
+
? value.flatMap((item) => (typeof item === 'string' && item.trim() !== '' ? [item.trim()] : []))
|
|
63
|
+
: [];
|
|
64
|
+
}
|
|
65
|
+
function asLocalized(value) {
|
|
66
|
+
const record = asRecord(value);
|
|
67
|
+
if (record === undefined)
|
|
68
|
+
return undefined;
|
|
69
|
+
const zh = asText(record['zh']);
|
|
70
|
+
const en = asText(record['en']);
|
|
71
|
+
return zh === '' && en === '' ? undefined : { ...(zh === '' ? {} : { zh }), ...(en === '' ? {} : { en }) };
|
|
72
|
+
}
|
|
73
|
+
function problem(kind, detail, at) {
|
|
74
|
+
return { kind, detail, ...(at === undefined ? {} : { at }) };
|
|
75
|
+
}
|
|
76
|
+
function sourceOf(raw, at) {
|
|
77
|
+
const record = asRecord(raw);
|
|
78
|
+
if (record === undefined)
|
|
79
|
+
return problem('source', 'source 必须是一个对象', at);
|
|
80
|
+
if (record['type'] === 'npm') {
|
|
81
|
+
const registry = record['registry'];
|
|
82
|
+
if (registry !== undefined && asText(registry) === '') {
|
|
83
|
+
return problem('source', 'npm source 的 registry 必须是非空字符串', at);
|
|
84
|
+
}
|
|
85
|
+
return { type: 'npm', ...(registry === undefined ? {} : { registry: asText(registry) }) };
|
|
86
|
+
}
|
|
87
|
+
if (record['type'] === 'git') {
|
|
88
|
+
const url = asText(record['url']);
|
|
89
|
+
const commit = asText(record['commit']);
|
|
90
|
+
if (url === '')
|
|
91
|
+
return problem('source', 'git source 缺 url', at);
|
|
92
|
+
if (!GIT_COMMIT.test(commit)) {
|
|
93
|
+
return problem('git-commit', `git source 的 commit 必须是 40 位小写 SHA(现在是 ${JSON.stringify(commit)})`, at);
|
|
94
|
+
}
|
|
95
|
+
const path = indexPathOf(record['path']);
|
|
96
|
+
return {
|
|
97
|
+
type: 'git',
|
|
98
|
+
url,
|
|
99
|
+
commit,
|
|
100
|
+
...(path === '' ? {} : { path }),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
return problem('source', 'source.type 只能是 npm 或 git', at);
|
|
104
|
+
}
|
|
105
|
+
function versionOf(raw, at) {
|
|
106
|
+
const record = asRecord(raw);
|
|
107
|
+
if (record === undefined)
|
|
108
|
+
return problem('version', '版本必须是一个对象', at);
|
|
109
|
+
const version = asText(record['version']);
|
|
110
|
+
if (!isValidVersion(version))
|
|
111
|
+
return problem('version', `版本号不是合法 SemVer:${JSON.stringify(version)}`, at);
|
|
112
|
+
const source = sourceOf(record['source'], `${at}.source`);
|
|
113
|
+
if ('kind' in source)
|
|
114
|
+
return source;
|
|
115
|
+
const timestamp = record['publishTimestamp'];
|
|
116
|
+
if (timestamp !== undefined && (!Number.isInteger(timestamp) || timestamp < 0)) {
|
|
117
|
+
return problem('timestamp', 'publishTimestamp 必须是 Unix 秒整数', at);
|
|
118
|
+
}
|
|
119
|
+
const engines = asRecord(record['engines']);
|
|
120
|
+
const dsh = engines === undefined ? '' : asText(engines['dsh']);
|
|
121
|
+
return {
|
|
122
|
+
version,
|
|
123
|
+
source,
|
|
124
|
+
...(timestamp === undefined ? {} : { publishTimestamp: timestamp }),
|
|
125
|
+
...(dsh === '' ? {} : { engines: { dsh } }),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function versionsOf(raw, at) {
|
|
129
|
+
if (!Array.isArray(raw) || raw.length === 0)
|
|
130
|
+
return problem('versions', 'versions 必须是非空数组', at);
|
|
131
|
+
const versions = [];
|
|
132
|
+
const seen = new Set();
|
|
133
|
+
for (const [index, item] of raw.entries()) {
|
|
134
|
+
const parsed = versionOf(item, `${at}[${String(index)}]`);
|
|
135
|
+
if ('kind' in parsed)
|
|
136
|
+
return parsed;
|
|
137
|
+
if (seen.has(parsed.version))
|
|
138
|
+
return problem('versions', `版本重复:${parsed.version}`, at);
|
|
139
|
+
seen.add(parsed.version);
|
|
140
|
+
versions.push(parsed);
|
|
141
|
+
}
|
|
142
|
+
for (let index = 1; index < versions.length; index += 1) {
|
|
143
|
+
const order = compareSemver(versions[index - 1]?.version ?? '', versions[index]?.version ?? '');
|
|
144
|
+
if (order === undefined || order < 0) {
|
|
145
|
+
return problem('version-order', 'versions 必须按 SemVer 降序', at);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return versions;
|
|
149
|
+
}
|
|
150
|
+
function iconProblem(icon) {
|
|
151
|
+
if (icon.length > MAX_ICON_CHARS)
|
|
152
|
+
return problem('icon', 'icon 超过 32 KiB');
|
|
153
|
+
if (icon.startsWith('data:image/'))
|
|
154
|
+
return icon.includes(';base64,') ? undefined : problem('icon', 'data URL 必须是 base64');
|
|
155
|
+
if (/^https?:\/\//i.test(icon))
|
|
156
|
+
return undefined;
|
|
157
|
+
return problem('icon', 'icon 只能是 base64 data URL 或 http(s) URL');
|
|
158
|
+
}
|
|
159
|
+
const MAX_OWNER_CHARS = 200;
|
|
160
|
+
const UNIT_ID = /^[a-z][a-z0-9-]*$/;
|
|
161
|
+
function ownerProblem(owner) {
|
|
162
|
+
if (/[\r\n]/u.test(owner))
|
|
163
|
+
return problem('owner', 'owner 只能是一行署名');
|
|
164
|
+
if (owner.length > MAX_OWNER_CHARS)
|
|
165
|
+
return problem('owner', 'owner 超过 200 字');
|
|
166
|
+
return undefined;
|
|
167
|
+
}
|
|
168
|
+
function metadataOf(raw) {
|
|
169
|
+
const record = asRecord(raw);
|
|
170
|
+
if (record === undefined)
|
|
171
|
+
return undefined;
|
|
172
|
+
const workbench = record['workbench'] === true;
|
|
173
|
+
const unit = asText(record['unit']);
|
|
174
|
+
const category = asText(record['category']);
|
|
175
|
+
const labels = asTextArray(record['labels']);
|
|
176
|
+
const keywords = asTextArray(record['keywords']);
|
|
177
|
+
const sortKeysRecord = asRecord(record['sortKeys']);
|
|
178
|
+
const sortKeys = sortKeysRecord === undefined
|
|
179
|
+
? undefined
|
|
180
|
+
: Object.fromEntries(Object.entries(sortKeysRecord).flatMap(([key, value]) => typeof value === 'string' || typeof value === 'number' ? [[key, value]] : []));
|
|
181
|
+
return {
|
|
182
|
+
...(workbench ? { workbench: true } : {}),
|
|
183
|
+
...(unit === '' ? {} : { unit }),
|
|
184
|
+
...(category === '' ? {} : { category }),
|
|
185
|
+
...(labels.length === 0 ? {} : { labels }),
|
|
186
|
+
...(keywords.length === 0 ? {} : { keywords }),
|
|
187
|
+
...(sortKeys === undefined || Object.keys(sortKeys).length === 0 ? {} : { sortKeys }),
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
function entryOf(raw, at) {
|
|
191
|
+
const record = asRecord(raw);
|
|
192
|
+
if (record === undefined)
|
|
193
|
+
return problem('plugin', '插件条目必须是对象', at);
|
|
194
|
+
const name = asText(record['name']);
|
|
195
|
+
if (name === '' || name.length > 214 || !NPM_NAME.test(name)) {
|
|
196
|
+
return problem('name', `不是合法 npm 包名:${JSON.stringify(name)}`, at);
|
|
197
|
+
}
|
|
198
|
+
const versions = versionsOf(record['versions'], `${at}.versions`);
|
|
199
|
+
if ('kind' in versions)
|
|
200
|
+
return versions;
|
|
201
|
+
const icon = asText(record['icon']);
|
|
202
|
+
if (icon !== '') {
|
|
203
|
+
const badIcon = iconProblem(icon);
|
|
204
|
+
if (badIcon !== undefined)
|
|
205
|
+
return badIcon;
|
|
206
|
+
}
|
|
207
|
+
const title = asLocalized(record['title']);
|
|
208
|
+
const description = asLocalized(record['description']);
|
|
209
|
+
const author = asText(record['author']);
|
|
210
|
+
const owner = asText(record['owner']);
|
|
211
|
+
if (owner !== '') {
|
|
212
|
+
const badOwner = ownerProblem(owner);
|
|
213
|
+
if (badOwner !== undefined)
|
|
214
|
+
return badOwner;
|
|
215
|
+
}
|
|
216
|
+
const homepage = asText(record['homepage']);
|
|
217
|
+
const metadata = metadataOf(record['metadata']);
|
|
218
|
+
if (metadata?.unit !== undefined && !UNIT_ID.test(metadata.unit)) {
|
|
219
|
+
return problem('unit', `metadata.unit 只能是小写字母开头的 a-z0-9-(现在是 ${JSON.stringify(metadata.unit)})`, at);
|
|
220
|
+
}
|
|
221
|
+
return {
|
|
222
|
+
name,
|
|
223
|
+
versions,
|
|
224
|
+
...(title === undefined ? {} : { title }),
|
|
225
|
+
...(description === undefined ? {} : { description }),
|
|
226
|
+
...(author === '' ? {} : { author }),
|
|
227
|
+
...(owner === '' ? {} : { owner }),
|
|
228
|
+
...(homepage === '' ? {} : { homepage }),
|
|
229
|
+
...(icon === '' ? {} : { icon }),
|
|
230
|
+
...(metadata === undefined ? {} : { metadata }),
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
export function parseMarketIndex(raw) {
|
|
234
|
+
const record = asRecord(raw);
|
|
235
|
+
if (record === undefined)
|
|
236
|
+
return { ok: false, problems: [problem('not-object', '索引必须是一个 JSON 对象')] };
|
|
237
|
+
if (record['format'] !== MARKET_INDEX_FORMAT) {
|
|
238
|
+
return {
|
|
239
|
+
ok: false,
|
|
240
|
+
problems: [problem('format', `format 必须是 ${String(MARKET_INDEX_FORMAT)}(现在是 ${JSON.stringify(record['format'])})`)],
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
const plugins = record['plugins'];
|
|
244
|
+
if (!Array.isArray(plugins))
|
|
245
|
+
return { ok: false, problems: [problem('plugins', 'plugins 必须是数组')] };
|
|
246
|
+
const entries = [];
|
|
247
|
+
const problems = [];
|
|
248
|
+
const seen = new Set();
|
|
249
|
+
for (const [index, item] of plugins.entries()) {
|
|
250
|
+
const parsed = entryOf(item, `plugins[${String(index)}]`);
|
|
251
|
+
if ('kind' in parsed) {
|
|
252
|
+
problems.push(parsed);
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
if (seen.has(parsed.name)) {
|
|
256
|
+
problems.push(problem('duplicate-name', `插件名重复:${parsed.name}`, `plugins[${String(index)}]`));
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
seen.add(parsed.name);
|
|
260
|
+
entries.push(parsed);
|
|
261
|
+
}
|
|
262
|
+
if (problems.length > 0)
|
|
263
|
+
return { ok: false, problems };
|
|
264
|
+
const title = asLocalized(record['title']);
|
|
265
|
+
const description = asLocalized(record['description']);
|
|
266
|
+
const metadata = asRecord(record['metadata']);
|
|
267
|
+
return {
|
|
268
|
+
ok: true,
|
|
269
|
+
index: {
|
|
270
|
+
format: MARKET_INDEX_FORMAT,
|
|
271
|
+
plugins: entries,
|
|
272
|
+
...(title === undefined ? {} : { title }),
|
|
273
|
+
...(description === undefined ? {} : { description }),
|
|
274
|
+
...(metadata === undefined ? {} : { metadata: metadata }),
|
|
275
|
+
},
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
export function parseMarketIndexJson(text) {
|
|
279
|
+
try {
|
|
280
|
+
return parseMarketIndex(JSON.parse(text));
|
|
281
|
+
}
|
|
282
|
+
catch (error) {
|
|
283
|
+
return {
|
|
284
|
+
ok: false,
|
|
285
|
+
problems: [problem('not-json', `JSON 解析失败:${error instanceof Error ? error.message : String(error)}`)],
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
export function sortMarketVersions(versions) {
|
|
290
|
+
return [...versions].sort((left, right) => (compareSemver(right.version, left.version) ?? 0));
|
|
291
|
+
}
|
|
292
|
+
export function upsertMarketEntry(index, entry) {
|
|
293
|
+
const found = index.plugins.findIndex((item) => item.name === entry.name);
|
|
294
|
+
if (found === -1)
|
|
295
|
+
return { ...index, plugins: [...index.plugins, entry] };
|
|
296
|
+
const current = index.plugins[found];
|
|
297
|
+
if (current === undefined)
|
|
298
|
+
return { ...index, plugins: [...index.plugins, entry] };
|
|
299
|
+
const merged = new Map();
|
|
300
|
+
for (const one of current.versions)
|
|
301
|
+
merged.set(one.version, one);
|
|
302
|
+
for (const one of entry.versions)
|
|
303
|
+
merged.set(one.version, one);
|
|
304
|
+
const owner = current.owner ?? entry.owner;
|
|
305
|
+
const plugins = [...index.plugins];
|
|
306
|
+
plugins[found] = {
|
|
307
|
+
...current,
|
|
308
|
+
...entry,
|
|
309
|
+
...(owner === undefined ? {} : { owner }),
|
|
310
|
+
versions: sortMarketVersions([...merged.values()]),
|
|
311
|
+
};
|
|
312
|
+
return { ...index, plugins };
|
|
313
|
+
}
|
|
314
|
+
export function marketEntryLabels(entry) {
|
|
315
|
+
return entry.metadata?.labels ?? [];
|
|
316
|
+
}
|
|
317
|
+
export function filterMarketIndex(index, filter) {
|
|
318
|
+
const query = (filter.query ?? '').trim().toLowerCase();
|
|
319
|
+
const category = (filter.category ?? '').trim();
|
|
320
|
+
const label = (filter.label ?? '').trim();
|
|
321
|
+
return index.plugins.filter((entry) => {
|
|
322
|
+
if (category !== '' && entry.metadata?.category !== category)
|
|
323
|
+
return false;
|
|
324
|
+
if (label !== '' && !marketEntryLabels(entry).includes(label))
|
|
325
|
+
return false;
|
|
326
|
+
if (query === '')
|
|
327
|
+
return true;
|
|
328
|
+
const haystack = [
|
|
329
|
+
entry.name,
|
|
330
|
+
marketText(entry.title, 'zh'),
|
|
331
|
+
marketText(entry.title, 'en'),
|
|
332
|
+
marketText(entry.description, 'zh'),
|
|
333
|
+
marketText(entry.description, 'en'),
|
|
334
|
+
entry.author ?? '',
|
|
335
|
+
...(entry.metadata?.keywords ?? []),
|
|
336
|
+
]
|
|
337
|
+
.join(' ')
|
|
338
|
+
.toLowerCase();
|
|
339
|
+
return haystack.includes(query);
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
export function marketSourceKey(source) {
|
|
343
|
+
const canonical = JSON.stringify([source.kind, source.url.trim(), source.ref ?? '', source.path ?? '']);
|
|
344
|
+
return createHash('sha256').update(canonical).digest('hex').slice(0, 16);
|
|
345
|
+
}
|
|
346
|
+
export function parseSourceConfig(raw) {
|
|
347
|
+
const record = asRecord(raw);
|
|
348
|
+
if (record === undefined)
|
|
349
|
+
return { ok: false, problem: problem('source', '索引源必须是对象') };
|
|
350
|
+
const id = asText(record['id']);
|
|
351
|
+
const label = asText(record['label']);
|
|
352
|
+
const kind = record['kind'];
|
|
353
|
+
const url = asText(record['url']);
|
|
354
|
+
if (id === '')
|
|
355
|
+
return { ok: false, problem: problem('source', '索引源缺 id') };
|
|
356
|
+
if (label === '')
|
|
357
|
+
return { ok: false, problem: problem('source', '索引源缺 label') };
|
|
358
|
+
if (kind !== 'http' && kind !== 'git')
|
|
359
|
+
return { ok: false, problem: problem('source', 'kind 只能是 http 或 git') };
|
|
360
|
+
if (kind === 'http') {
|
|
361
|
+
const bad = httpUrlProblem(url);
|
|
362
|
+
if (bad !== undefined)
|
|
363
|
+
return { ok: false, problem: problem('source', bad) };
|
|
364
|
+
return { ok: true, source: { id, label, kind, url } };
|
|
365
|
+
}
|
|
366
|
+
if (!gitUrlOk(url)) {
|
|
367
|
+
return { ok: false, problem: problem('source', 'git 地址不合格(只收 https / ssh / scp 形式,且不能带凭据)') };
|
|
368
|
+
}
|
|
369
|
+
const ref = asText(record['ref']);
|
|
370
|
+
const path = indexPathOf(record['path']);
|
|
371
|
+
const localPath = asText(record['localPath']);
|
|
372
|
+
const policy = record['policy'];
|
|
373
|
+
if (policy !== undefined && policy !== 'artifacts-in-repo' && policy !== 'catalog-only') {
|
|
374
|
+
return { ok: false, problem: problem('source', 'policy 只能是 artifacts-in-repo 或 catalog-only') };
|
|
375
|
+
}
|
|
376
|
+
return {
|
|
377
|
+
ok: true,
|
|
378
|
+
source: {
|
|
379
|
+
id,
|
|
380
|
+
label,
|
|
381
|
+
kind,
|
|
382
|
+
url,
|
|
383
|
+
...(ref === '' ? {} : { ref }),
|
|
384
|
+
...(path === '' ? {} : { path }),
|
|
385
|
+
...(localPath === '' ? {} : { localPath }),
|
|
386
|
+
...(policy === undefined ? {} : { policy: policy }),
|
|
387
|
+
},
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
function indexPathBase(dir) {
|
|
391
|
+
return indexPathOf(dir).replace(/^\/+|\/+$/g, '') || MARKET_INDEX_DIR;
|
|
392
|
+
}
|
|
393
|
+
export function marketEntryPath(dir, name) {
|
|
394
|
+
if (!NPM_NAME.test(name))
|
|
395
|
+
throw new Error(`不是合法包名:${JSON.stringify(name)}`);
|
|
396
|
+
return `${indexPathBase(dir)}/${name}.json`;
|
|
397
|
+
}
|
|
398
|
+
export function parseMarketEntryJson(text) {
|
|
399
|
+
let raw;
|
|
400
|
+
try {
|
|
401
|
+
raw = JSON.parse(text);
|
|
402
|
+
}
|
|
403
|
+
catch (error) {
|
|
404
|
+
return {
|
|
405
|
+
ok: false,
|
|
406
|
+
problems: [problem('not-json', `JSON 解析失败:${error instanceof Error ? error.message : String(error)}`, 'entry')],
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
const parsed = entryOf(raw, 'entry');
|
|
410
|
+
if ('kind' in parsed)
|
|
411
|
+
return { ok: false, problems: [parsed] };
|
|
412
|
+
return { ok: true, entry: parsed };
|
|
413
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { MarketIndex, MarketIndexEntry } from '../contract/protocol/market-index.js';
|
|
2
|
+
import type { MarketEntryFile, MarketIndexAssemble } from './market-index-doc.js';
|
|
3
|
+
export declare const MARKET_ENTRIES_README_LINES: readonly string[];
|
|
4
|
+
export declare const MARKET_INDEX_README_LINES: readonly string[];
|
|
5
|
+
export { marketBranchOk, marketInstallTarget, marketText } from '../lib/market-index.js';
|
|
6
|
+
export type { MarketEntryFile, MarketIndexAssemble } from './market-index-doc.js';
|
|
7
|
+
export { compareSemver, filterMarketIndex, gitUrlOk, httpUrlProblem, marketEntryLabels, marketEntryPath, marketSourceKey, parseMarketEntryJson, parseMarketIndex, parseMarketIndexJson, parseSourceConfig, sortMarketVersions, upsertMarketEntry, } from './market-index-parse.js';
|
|
8
|
+
export type { SourceConfigParse } from './market-index-parse.js';
|
|
9
|
+
export declare function assembleMarketIndex(files: readonly MarketEntryFile[]): MarketIndexAssemble;
|
|
10
|
+
export declare function marketEntryFileOf(entry: MarketIndexEntry, dir?: string): MarketEntryFile;
|
|
11
|
+
export declare function marketEntryFilesOf(index: MarketIndex, dir?: string): readonly MarketEntryFile[];
|
|
12
|
+
export declare function collectMarketEntryFiles(dir: string): readonly MarketEntryFile[];
|
|
13
|
+
export declare function marketEntryFilesOfLegacy(text: string, dir?: string): readonly MarketEntryFile[] | undefined;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { join, relative, sep } from 'node:path';
|
|
3
|
+
import { MARKET_INDEX_DIR, MARKET_INDEX_FORMAT } from '../contract/protocol/market-index.js';
|
|
4
|
+
import { entryUnitOf } from './market-index-claim.js';
|
|
5
|
+
import { marketEntryPath, parseMarketEntryJson, parseMarketIndexJson, sortMarketVersions } from './market-index-parse.js';
|
|
6
|
+
export const MARKET_ENTRIES_README_LINES = [
|
|
7
|
+
'# 索引目录',
|
|
8
|
+
'',
|
|
9
|
+
'一个包一个文件:`market/<包名>.json`,里面是这一个包的元数据与所有版本;',
|
|
10
|
+
'',
|
|
11
|
+
'产物在 `artifacts/<包名>/`(只放最新一版,老版本按条目里的 commit 取历史)。',
|
|
12
|
+
'',
|
|
13
|
+
'发布时只改自己包的文件;包与包之间不共享文件。',
|
|
14
|
+
];
|
|
15
|
+
export const MARKET_INDEX_README_LINES = [
|
|
16
|
+
'# 模块市场索引',
|
|
17
|
+
'',
|
|
18
|
+
'这个仓库给 DeepSeek Harness 工作台当模块市场索引:一个包一个文件 `market/<包名>.json`,',
|
|
19
|
+
'产物在 `artifacts/<包名>/`;老仓库的 `market.json` 会在第一次发布时自动拆开。',
|
|
20
|
+
'',
|
|
21
|
+
'## 发布模块',
|
|
22
|
+
'',
|
|
23
|
+
'在模块包里运行:',
|
|
24
|
+
'',
|
|
25
|
+
'```bash',
|
|
26
|
+
'dsh-wb-module release --index <本仓库地址> --index-policy artifacts-in-repo',
|
|
27
|
+
'```',
|
|
28
|
+
'',
|
|
29
|
+
'发布只会改自己包的那一个文件;包与包之间不会碰同一个文件。',
|
|
30
|
+
'',
|
|
31
|
+
'一个包名归第一次发布的人(条目文件里的 `owner`)。换一个署名发同名会被拒;要换人,先把这一条的 `owner` 改成新的人。',
|
|
32
|
+
'同一个市场里,一个模块 id(`metadata.unit`)只能被一个条目使用;另一个包名想用同一个 id / 产物目录也会被拒。',
|
|
33
|
+
'',
|
|
34
|
+
'## 使用这个索引',
|
|
35
|
+
'',
|
|
36
|
+
'在工作台的「模块市场 → 发现」里添加本仓库地址,即可浏览与安装。',
|
|
37
|
+
'',
|
|
38
|
+
];
|
|
39
|
+
export { marketBranchOk, marketInstallTarget, marketText } from '../lib/market-index.js';
|
|
40
|
+
export { compareSemver, filterMarketIndex, gitUrlOk, httpUrlProblem, marketEntryLabels, marketEntryPath, marketSourceKey, parseMarketEntryJson, parseMarketIndex, parseMarketIndexJson, parseSourceConfig, sortMarketVersions, upsertMarketEntry, } from './market-index-parse.js';
|
|
41
|
+
function problem(kind, detail, at) {
|
|
42
|
+
return { kind, detail, ...(at === undefined ? {} : { at }) };
|
|
43
|
+
}
|
|
44
|
+
export function assembleMarketIndex(files) {
|
|
45
|
+
const problems = [];
|
|
46
|
+
const entries = new Map();
|
|
47
|
+
const ordered = [...files].sort((left, right) => (left.path < right.path ? -1 : left.path > right.path ? 1 : 0));
|
|
48
|
+
for (const file of ordered) {
|
|
49
|
+
if (!file.path.endsWith('.json'))
|
|
50
|
+
continue;
|
|
51
|
+
const parsed = parseMarketEntryJson(file.text);
|
|
52
|
+
if (!parsed.ok) {
|
|
53
|
+
for (const one of parsed.problems)
|
|
54
|
+
problems.push({ ...one, at: file.path });
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const entry = parsed.entry;
|
|
58
|
+
if (entries.has(entry.name)) {
|
|
59
|
+
problems.push(problem('duplicate-name', `插件名重复:${entry.name}`, file.path));
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
entries.set(entry.name, { ...entry, versions: sortMarketVersions(entry.versions) });
|
|
63
|
+
}
|
|
64
|
+
if (problems.length > 0)
|
|
65
|
+
return { ok: false, problems };
|
|
66
|
+
const plugins = [...entries.values()].sort((left, right) => (left.name < right.name ? -1 : left.name > right.name ? 1 : 0));
|
|
67
|
+
return { ok: true, index: { format: MARKET_INDEX_FORMAT, plugins } };
|
|
68
|
+
}
|
|
69
|
+
export function marketEntryFileOf(entry, dir = MARKET_INDEX_DIR) {
|
|
70
|
+
return { path: marketEntryPath(dir, entry.name), text: `${JSON.stringify(entry, null, 2)}\n` };
|
|
71
|
+
}
|
|
72
|
+
export function marketEntryFilesOf(index, dir = MARKET_INDEX_DIR) {
|
|
73
|
+
return index.plugins.map((entry) => marketEntryFileOf(healedUnit(entry), dir));
|
|
74
|
+
}
|
|
75
|
+
function healedUnit(entry) {
|
|
76
|
+
if (entry.metadata?.unit !== undefined)
|
|
77
|
+
return entry;
|
|
78
|
+
const unit = entryUnitOf(entry);
|
|
79
|
+
return unit === undefined ? entry : { ...entry, metadata: { ...entry.metadata, unit } };
|
|
80
|
+
}
|
|
81
|
+
export function collectMarketEntryFiles(dir) {
|
|
82
|
+
if (!existsSync(dir))
|
|
83
|
+
return [];
|
|
84
|
+
const files = [];
|
|
85
|
+
const walk = (current) => {
|
|
86
|
+
for (const item of readdirSync(current, { withFileTypes: true })) {
|
|
87
|
+
const full = join(current, item.name);
|
|
88
|
+
if (item.isDirectory()) {
|
|
89
|
+
walk(full);
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (!item.name.endsWith('.json'))
|
|
93
|
+
continue;
|
|
94
|
+
files.push({ path: relative(dir, full).split(sep).join('/'), text: readFileSync(full, 'utf8') });
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
walk(dir);
|
|
98
|
+
return files;
|
|
99
|
+
}
|
|
100
|
+
export function marketEntryFilesOfLegacy(text, dir = MARKET_INDEX_DIR) {
|
|
101
|
+
const parsed = parseMarketIndexJson(text);
|
|
102
|
+
if (!parsed.ok)
|
|
103
|
+
return undefined;
|
|
104
|
+
return marketEntryFilesOf(parsed.index, dir);
|
|
105
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function packageRootOf(moduleUrl: string): string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function npmRegistryOf(source: {
|
|
2
|
+
readonly registryEnv?: string;
|
|
3
|
+
readonly registryDefault?: string;
|
|
4
|
+
}, env: Readonly<Record<string, string | undefined>>): {
|
|
5
|
+
readonly ok: true;
|
|
6
|
+
readonly value: string;
|
|
7
|
+
} | {
|
|
8
|
+
readonly ok: false;
|
|
9
|
+
readonly env: string;
|
|
10
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
function envValue(env, name) {
|
|
2
|
+
const value = env[name]?.trim();
|
|
3
|
+
return value === undefined || value === '' ? { ok: false } : { ok: true, value };
|
|
4
|
+
}
|
|
5
|
+
export function npmRegistryOf(source, env) {
|
|
6
|
+
const name = source.registryEnv ?? '';
|
|
7
|
+
if (name !== '') {
|
|
8
|
+
const fromEnv = envValue(env, name);
|
|
9
|
+
if (fromEnv.ok)
|
|
10
|
+
return fromEnv;
|
|
11
|
+
}
|
|
12
|
+
const fallback = source.registryDefault?.trim();
|
|
13
|
+
if (fallback === undefined || fallback === '')
|
|
14
|
+
return { ok: false, env: name };
|
|
15
|
+
return { ok: true, value: fallback };
|
|
16
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Seam } from './seam/run.js';
|
|
2
|
+
export declare function withPackageDir<T>(options: {
|
|
3
|
+
readonly seam?: Seam | undefined;
|
|
4
|
+
readonly spec: string;
|
|
5
|
+
readonly registry?: string | undefined;
|
|
6
|
+
readonly cacheDir?: string | undefined;
|
|
7
|
+
readonly scratchRoot?: string | undefined;
|
|
8
|
+
}, visit: (dir: string) => T): Promise<T | undefined>;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { productWrite } from './seam/intent.js';
|
|
5
|
+
import { INSTALL_TIMEOUT_MS } from '../config/constants.js';
|
|
6
|
+
import { parseJsonLoose } from '../lib/text.js';
|
|
7
|
+
import { quoteShellArg } from './shell-text.js';
|
|
8
|
+
import { splitNpmSpec } from './package-kind.js';
|
|
9
|
+
import { localDirOf } from './local-declaration.js';
|
|
10
|
+
function cacheFlag(cacheDir) {
|
|
11
|
+
return cacheDir === undefined ? '' : ` --cache ${quoteShellArg(cacheDir)}`;
|
|
12
|
+
}
|
|
13
|
+
function packedFileFrom(stdout, root) {
|
|
14
|
+
const parsed = parseJsonLoose(stdout);
|
|
15
|
+
if (Array.isArray(parsed)) {
|
|
16
|
+
const first = parsed[0];
|
|
17
|
+
const filename = typeof first === 'object' && first !== null ? first.filename : undefined;
|
|
18
|
+
if (typeof filename === 'string' && filename.trim() !== '') {
|
|
19
|
+
const at = path.join(root, path.basename(filename.trim()));
|
|
20
|
+
if (fs.existsSync(at))
|
|
21
|
+
return at;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
const found = fs.readdirSync(root).filter((name) => name.endsWith('.tgz'));
|
|
26
|
+
return found.length === 1 ? path.join(root, found[0] ?? '') : undefined;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function scratchDirOf(scratchRoot) {
|
|
33
|
+
const base = scratchRoot ?? os.tmpdir();
|
|
34
|
+
try {
|
|
35
|
+
if (scratchRoot !== undefined)
|
|
36
|
+
fs.mkdirSync(base, { recursive: true });
|
|
37
|
+
return fs.mkdtempSync(path.join(base, 'wb-package-'));
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export async function withPackageDir(options, visit) {
|
|
44
|
+
const local = localDirOf(options.spec);
|
|
45
|
+
if (local !== undefined)
|
|
46
|
+
return visit(local);
|
|
47
|
+
if (splitNpmSpec(options.spec) === undefined)
|
|
48
|
+
return undefined;
|
|
49
|
+
const seam = options.seam;
|
|
50
|
+
if (seam === undefined)
|
|
51
|
+
return undefined;
|
|
52
|
+
const root = scratchDirOf(options.scratchRoot);
|
|
53
|
+
if (root === undefined)
|
|
54
|
+
return undefined;
|
|
55
|
+
try {
|
|
56
|
+
const at = options.registry === undefined ? '' : ` --registry ${quoteShellArg(options.registry)}`;
|
|
57
|
+
const packed = await seam
|
|
58
|
+
.run({
|
|
59
|
+
command: `npm pack ${quoteShellArg(options.spec)} --ignore-scripts --json --pack-destination ${quoteShellArg(root)}${cacheFlag(options.cacheDir)}${at}`,
|
|
60
|
+
intent: productWrite(),
|
|
61
|
+
retry: 'safe',
|
|
62
|
+
timeoutMs: INSTALL_TIMEOUT_MS,
|
|
63
|
+
bestEffort: true,
|
|
64
|
+
})
|
|
65
|
+
.catch(() => undefined);
|
|
66
|
+
if (packed === undefined || packed.exitCode !== 0)
|
|
67
|
+
return undefined;
|
|
68
|
+
const file = packedFileFrom(packed.stdout, root);
|
|
69
|
+
if (file === undefined)
|
|
70
|
+
return undefined;
|
|
71
|
+
const unpacked = await seam
|
|
72
|
+
.run({
|
|
73
|
+
command: `tar -xzf ${quoteShellArg(file)} -C ${quoteShellArg(root)}`,
|
|
74
|
+
intent: productWrite(),
|
|
75
|
+
retry: 'safe',
|
|
76
|
+
timeoutMs: INSTALL_TIMEOUT_MS,
|
|
77
|
+
bestEffort: true,
|
|
78
|
+
})
|
|
79
|
+
.catch(() => undefined);
|
|
80
|
+
if (unpacked === undefined || unpacked.exitCode !== 0)
|
|
81
|
+
return undefined;
|
|
82
|
+
const dir = path.join(root, 'package');
|
|
83
|
+
if (!fs.existsSync(dir))
|
|
84
|
+
return undefined;
|
|
85
|
+
return visit(dir);
|
|
86
|
+
}
|
|
87
|
+
finally {
|
|
88
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
89
|
+
}
|
|
90
|
+
}
|