dsh-crate 0.0.0-stage → 0.5.0
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/LICENSE +27 -0
- package/README.md +288 -2
- package/README.zh.md +263 -0
- package/UPDATE-API-V1.md +207 -0
- package/assets/logo.svg +37 -0
- package/client/client.js +18964 -0
- package/cordis.patch.yml +4 -0
- package/lib/accelerate.js +194 -0
- package/lib/agents.js +67 -0
- package/lib/backup.js +688 -0
- package/lib/body-progress.js +173 -0
- package/lib/catalog-local-match.js +160 -0
- package/lib/catalog-npm.js +180 -0
- package/lib/changelog.js +462 -0
- package/lib/channels.js +64 -0
- package/lib/check.js +1557 -0
- package/lib/compatibility.js +243 -0
- package/lib/crate-catalog.js +179 -0
- package/lib/diagnostics.js +49 -0
- package/lib/discovery-compatibility.js +447 -0
- package/lib/drain-journal.js +164 -0
- package/lib/drain.js +1043 -0
- package/lib/dsh-cli.js +1373 -0
- package/lib/dsh-install.js +259 -0
- package/lib/entry-identity.js +85 -0
- package/lib/gist.js +369 -0
- package/lib/groups.js +108 -0
- package/lib/home-paths.js +29 -0
- package/lib/host-recovery.js +187 -0
- package/lib/hot.js +871 -0
- package/lib/http.js +252 -0
- package/lib/index.js +394 -0
- package/lib/install.js +1147 -0
- package/lib/lifecycle.js +37 -0
- package/lib/log-redaction.js +24 -0
- package/lib/log.js +204 -0
- package/lib/ndjson.js +154 -0
- package/lib/net.js +174 -0
- package/lib/official-desktop.js +619 -0
- package/lib/order.js +284 -0
- package/lib/patch.js +943 -0
- package/lib/pending-rows.js +142 -0
- package/lib/pending-updates.js +346 -0
- package/lib/pnpm-compat.js +972 -0
- package/lib/presets.js +282 -0
- package/lib/probe-context.js +20 -0
- package/lib/proc-text.js +69 -0
- package/lib/profile.js +1978 -0
- package/lib/recovery.js +1059 -0
- package/lib/region-probe.js +93 -0
- package/lib/regions.js +283 -0
- package/lib/registry.js +308 -0
- package/lib/release-candidates.js +115 -0
- package/lib/release-updates.js +70 -0
- package/lib/restart.js +688 -0
- package/lib/routes.js +7960 -0
- package/lib/settings.js +164 -0
- package/lib/shelfry-catalog.js +179 -0
- package/lib/snapshot.js +506 -0
- package/lib/source-migration.js +164 -0
- package/lib/sources.js +1005 -0
- package/lib/state.js +38 -0
- package/lib/store.js +163 -0
- package/lib/themes.js +350 -0
- package/lib/trial.js +125 -0
- package/lib/types/accelerate.d.ts +85 -0
- package/lib/types/agents.d.ts +52 -0
- package/lib/types/backup.d.ts +171 -0
- package/lib/types/body-progress.d.ts +94 -0
- package/lib/types/catalog-local-match.d.ts +39 -0
- package/lib/types/catalog-npm.d.ts +77 -0
- package/lib/types/changelog.d.ts +131 -0
- package/lib/types/channels.d.ts +56 -0
- package/lib/types/check.d.ts +353 -0
- package/lib/types/compatibility.d.ts +83 -0
- package/lib/types/crate-catalog.d.ts +48 -0
- package/lib/types/diagnostics.d.ts +29 -0
- package/lib/types/discovery-compatibility.d.ts +145 -0
- package/lib/types/drain-journal.d.ts +25 -0
- package/lib/types/drain.d.ts +306 -0
- package/lib/types/dsh-cli.d.ts +481 -0
- package/lib/types/dsh-install.d.ts +106 -0
- package/lib/types/entry-identity.d.ts +68 -0
- package/lib/types/gist.d.ts +79 -0
- package/lib/types/groups.d.ts +34 -0
- package/lib/types/home-paths.d.ts +13 -0
- package/lib/types/host-recovery.d.ts +95 -0
- package/lib/types/hot.d.ts +405 -0
- package/lib/types/http.d.ts +114 -0
- package/lib/types/index.d.ts +52 -0
- package/lib/types/install.d.ts +463 -0
- package/lib/types/lifecycle.d.ts +14 -0
- package/lib/types/log-redaction.d.ts +2 -0
- package/lib/types/log.d.ts +43 -0
- package/lib/types/ndjson.d.ts +52 -0
- package/lib/types/net.d.ts +94 -0
- package/lib/types/official-desktop.d.ts +59 -0
- package/lib/types/order.d.ts +100 -0
- package/lib/types/patch.d.ts +218 -0
- package/lib/types/pending-rows.d.ts +81 -0
- package/lib/types/pending-updates.d.ts +161 -0
- package/lib/types/pnpm-compat.d.ts +102 -0
- package/lib/types/presets.d.ts +94 -0
- package/lib/types/probe-context.d.ts +14 -0
- package/lib/types/proc-text.d.ts +29 -0
- package/lib/types/profile.d.ts +551 -0
- package/lib/types/recovery.d.ts +342 -0
- package/lib/types/region-probe.d.ts +50 -0
- package/lib/types/regions.d.ts +134 -0
- package/lib/types/registry.d.ts +160 -0
- package/lib/types/release-candidates.d.ts +42 -0
- package/lib/types/release-updates.d.ts +15 -0
- package/lib/types/restart.d.ts +279 -0
- package/lib/types/routes.d.ts +130 -0
- package/lib/types/settings.d.ts +112 -0
- package/lib/types/shelfry-catalog.d.ts +48 -0
- package/lib/types/snapshot.d.ts +93 -0
- package/lib/types/source-migration.d.ts +100 -0
- package/lib/types/sources.d.ts +391 -0
- package/lib/types/state.d.ts +20 -0
- package/lib/types/store.d.ts +47 -0
- package/lib/types/themes.d.ts +46 -0
- package/lib/types/trial.d.ts +61 -0
- package/lib/types/update-api-v1.d.ts +83 -0
- package/lib/types/updates.d.ts +273 -0
- package/lib/types/verify.d.ts +277 -0
- package/lib/update-api-v1.js +273 -0
- package/lib/updates.js +981 -0
- package/lib/verify.js +904 -0
- package/locale/en.json +5 -0
- package/locale/zh.json +6 -0
- package/package.json +113 -4
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolving a GitHub install through a region's proxy without proxying the
|
|
3
|
+
* tarball pnpm records.
|
|
4
|
+
*
|
|
5
|
+
* pnpm does not fetch `github:owner/repo` with `git clone`; it resolves the
|
|
6
|
+
* shortcut and downloads a tarball from codeload.github.com. That rules out
|
|
7
|
+
* the usual `git config insteadOf` trick — there is no git command to
|
|
8
|
+
* redirect.
|
|
9
|
+
*
|
|
10
|
+
* Prefix-proxying that tarball used to save substantial time, but pnpm 11's
|
|
11
|
+
* fail-closed lockfile checks changed the safety boundary. A URL shaped like
|
|
12
|
+
* `https://proxy/https://codeload.github.com/.../<commit>` no longer has the
|
|
13
|
+
* codeload hostname, so pnpm treats it as an ordinary remote tarball and
|
|
14
|
+
* requires an integrity hash that its GitHub resolver does not write. The
|
|
15
|
+
* result is ERR_PNPM_MISSING_TARBALL_INTEGRITY on the install itself (#385).
|
|
16
|
+
* Disabling that check or minting a checksum from whatever the proxy served
|
|
17
|
+
* would weaken pnpm's supply-chain protection, so neither is acceptable.
|
|
18
|
+
*
|
|
19
|
+
* The safe middle ground is to resolve HEAD through the regional proxy, then
|
|
20
|
+
* hand pnpm a commit-pinned `github:owner/repo#<sha>` target. The ref lookup
|
|
21
|
+
* still avoids a slow or unreachable GitHub metadata request; pnpm itself
|
|
22
|
+
* fetches the canonical codeload URL, records it as `gitHosted: true`, and
|
|
23
|
+
* keeps its integrity policy intact.
|
|
24
|
+
*
|
|
25
|
+
* - **The commit has to be pinned.** The profile reads each plugin's
|
|
26
|
+
* installed commit back out of the lockfile by matching a codeload URL
|
|
27
|
+
* ending in a 40-character SHA (src/profile.ts). A `HEAD` tarball installs
|
|
28
|
+
* perfectly and then reports no version forever. So this resolves the SHA
|
|
29
|
+
* first, and a rewrite that cannot get one does not happen.
|
|
30
|
+
* - **Build-script approval has to keep matching.** `gitAllowBuildsKey`
|
|
31
|
+
* (src/sources.ts) derives its stable key from the repo, and the pinned
|
|
32
|
+
* GitHub form preserves that identity.
|
|
33
|
+
*
|
|
34
|
+
* Catalog subpath entries are left alone: `#path:` identifies a different
|
|
35
|
+
* package inside the repo, so the acceleration step never rewrites that
|
|
36
|
+
* fragment. Collection roots discovered after install preserve the resolved
|
|
37
|
+
* commit and add their subpath as pnpm's second `&path:` selector.
|
|
38
|
+
*
|
|
39
|
+
* Every SHA-lookup failure falls back to the original target. Acceleration
|
|
40
|
+
* is an optimisation, and an optimisation that can fail an install is a bug.
|
|
41
|
+
*/
|
|
42
|
+
import { type Region } from './regions.ts';
|
|
43
|
+
/**
|
|
44
|
+
* The commit `HEAD` points at, from git's own ref advertisement.
|
|
45
|
+
*
|
|
46
|
+
* This is the endpoint `git clone` reads before it fetches anything, and it
|
|
47
|
+
* is the right one here for two measured reasons. It is not the REST API, so
|
|
48
|
+
* it does not consume the 60-requests-per-hour unauthenticated quota that a
|
|
49
|
+
* user installing a handful of plugins could plausibly exhaust. And it
|
|
50
|
+
* survives the proxy: over five consecutive tries from an unproxied mainland
|
|
51
|
+
* connection it answered 200 in ~1.2s every time, while the REST API through
|
|
52
|
+
* the same proxy returned 200, 200, then 403 — a proxy that rate-limits the
|
|
53
|
+
* API path would silently drop every install back to the slow route.
|
|
54
|
+
*
|
|
55
|
+
* The response is git's pkt-line format, whose first ref line carries
|
|
56
|
+
* `<sha> HEAD\0<capabilities>`. Read with a pattern rather than a parser:
|
|
57
|
+
* one 40-character hex string followed by `HEAD` is unambiguous in this
|
|
58
|
+
* payload, and a length-prefix reader would be more code to get wrong.
|
|
59
|
+
*
|
|
60
|
+
* The same advertisement lists every branch and tag, which is what `ref`
|
|
61
|
+
* uses. A plugin installed from `github:owner/repo#publish` is not asking
|
|
62
|
+
* about the default branch at all, and answering with it made the market
|
|
63
|
+
* report an update forever (#446) — the two SHAs simply never match. Both
|
|
64
|
+
* namespaces are searched because pnpm accepts a tag there too, branches
|
|
65
|
+
* first since that is what the reports are about.
|
|
66
|
+
* @param ref - branch or tag to resolve, or undefined for the default branch.
|
|
67
|
+
*/
|
|
68
|
+
export declare function headCommit(repo: string, proxy: string | null, signal?: AbortSignal, ref?: string): Promise<string | null>;
|
|
69
|
+
/**
|
|
70
|
+
* The current `HEAD` commit for a repo, on whichever route the region uses.
|
|
71
|
+
*
|
|
72
|
+
* Wraps the timeout so callers outside the install path — the build-script
|
|
73
|
+
* approval below, which needs a commit-pinned key — do not each reinvent it.
|
|
74
|
+
*/
|
|
75
|
+
export declare function resolveHeadCommit(repo: string, region: Region, env?: NodeJS.ProcessEnv, ref?: string): Promise<string | null>;
|
|
76
|
+
/**
|
|
77
|
+
* The install target to actually hand pnpm, given the region in force.
|
|
78
|
+
*
|
|
79
|
+
* @param target - what `installTargetFor` produced.
|
|
80
|
+
* @param region - the download region.
|
|
81
|
+
* @param env - environment, for the proxy override.
|
|
82
|
+
* @returns a commit-pinned GitHub shortcut when one route resolves HEAD,
|
|
83
|
+
* otherwise `target` unchanged.
|
|
84
|
+
*/
|
|
85
|
+
export declare function acceleratedTarget(target: string, region: Region, env?: NodeJS.ProcessEnv): Promise<string>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional host-provided agent inventory: lets the market refuse plugin
|
|
3
|
+
* mutations while a live agent is mid-turn. Mutating `node_modules` under a
|
|
4
|
+
* running agent replaces files the running plugin modules may still read or
|
|
5
|
+
* lazily import — the update "succeeds" while old code and new files mix.
|
|
6
|
+
*/
|
|
7
|
+
export interface RunningAgentLike {
|
|
8
|
+
id?: unknown;
|
|
9
|
+
status?: unknown;
|
|
10
|
+
}
|
|
11
|
+
export interface AgentsServiceLike {
|
|
12
|
+
list(): RunningAgentLike[];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The part of the host's public Agent contract drain mode needs.
|
|
16
|
+
*
|
|
17
|
+
* Both members are optional here on purpose: the market supports hosts that
|
|
18
|
+
* predate them, and the coordinator must decide per request whether it can
|
|
19
|
+
* take the safety barrier rather than assuming the service implies it.
|
|
20
|
+
*/
|
|
21
|
+
export interface AgentHandlesLike extends RunningAgentLike {
|
|
22
|
+
whenIdle?: unknown;
|
|
23
|
+
runMaintenance?: unknown;
|
|
24
|
+
}
|
|
25
|
+
/** A live Agent whose public maintenance boundary is usable. */
|
|
26
|
+
export interface DrainableAgent {
|
|
27
|
+
id: string;
|
|
28
|
+
status: unknown;
|
|
29
|
+
whenIdle(): Promise<void>;
|
|
30
|
+
runMaintenance<T>(task: (signal: AbortSignal) => Promise<T>): Promise<T>;
|
|
31
|
+
}
|
|
32
|
+
/** The id the market reports for an agent, or null when it has none. */
|
|
33
|
+
export declare function agentIdOf(agent: RunningAgentLike | null | undefined): string | null;
|
|
34
|
+
/**
|
|
35
|
+
* Normalize one live Agent handle, or null when this host cannot put it under
|
|
36
|
+
* a maintenance hold.
|
|
37
|
+
*
|
|
38
|
+
* The methods are read structurally and called through the handle so a host
|
|
39
|
+
* implementation that relies on `this` keeps working. A missing `id` is also
|
|
40
|
+
* incompatible: the coordinator tracks holds by id, and two anonymous agents
|
|
41
|
+
* would collapse into one entry.
|
|
42
|
+
*/
|
|
43
|
+
export declare function drainableAgent(agent: unknown): DrainableAgent | null;
|
|
44
|
+
export type AgentsLookup = () => AgentsServiceLike | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Ids of the host's currently running agents, or [] when the host has no
|
|
47
|
+
* agents service. Only a positive `status === 'running'` blocks an update —
|
|
48
|
+
* unknown statuses are treated as not running, so a future agent
|
|
49
|
+
* implementation with different wording fails open (the market stays
|
|
50
|
+
* usable) instead of wedging the plugin page.
|
|
51
|
+
*/
|
|
52
|
+
export declare function runningAgentIds(agents: AgentsServiceLike | undefined): string[];
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Portable profile backups: configuration only, never installed packages.
|
|
3
|
+
*
|
|
4
|
+
* The profile directory is plain user data — aside from package.json it can
|
|
5
|
+
* hold API keys (config.toml), tokens, or the WebDAV password when stored
|
|
6
|
+
* server-side. Backups therefore behave like `dsh export` and carry the same
|
|
7
|
+
* credential-warning disclaimer in the UI (review #63).
|
|
8
|
+
*/
|
|
9
|
+
export declare const BACKUP_FORMAT = "dsh-profile-backup";
|
|
10
|
+
export declare const MAX_BACKUP_BYTES: number;
|
|
11
|
+
/** File names that routinely contain credentials (backup exports).
|
|
12
|
+
* Values are never masked in place — the export is one-to-one for
|
|
13
|
+
* faithful restores — but presence is surfaced by the UI warning. */
|
|
14
|
+
export declare const SECRET_FILE_HINTS: RegExp;
|
|
15
|
+
/** Count of exported files whose names look like they carry credentials. */
|
|
16
|
+
export declare function secretFileCount(profile: string, explicitDir?: string): number;
|
|
17
|
+
export type BackupFile = {
|
|
18
|
+
path: 'package.json';
|
|
19
|
+
json: Record<string, unknown>;
|
|
20
|
+
} | {
|
|
21
|
+
path: string;
|
|
22
|
+
lines: string[];
|
|
23
|
+
};
|
|
24
|
+
export interface ProfileBackup {
|
|
25
|
+
format: typeof BACKUP_FORMAT;
|
|
26
|
+
version: 0.2;
|
|
27
|
+
createdAt: string;
|
|
28
|
+
profile: string;
|
|
29
|
+
files: BackupFile[];
|
|
30
|
+
}
|
|
31
|
+
/** Serialize every profile file except dependencies, lock state, and market cache. */
|
|
32
|
+
export interface BackupOptions {
|
|
33
|
+
/** Partial export: only these plugins (dependency names) are kept. */
|
|
34
|
+
includeDeps?: string[];
|
|
35
|
+
/**
|
|
36
|
+
* With includeDeps, also carry the profile's other configuration files.
|
|
37
|
+
* Config files are profile-scoped and cannot be attributed to individual
|
|
38
|
+
* plugins, so this is all-or-nothing — the UI warns about secrets before
|
|
39
|
+
* enabling it (the backup itself is one-to-one, never masked).
|
|
40
|
+
*/
|
|
41
|
+
includeConfig?: boolean;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Serialize every profile file except dependencies, lock state, and market
|
|
45
|
+
* cache — or, with {@link BackupOptions.includeDeps}, only the manifest with
|
|
46
|
+
* the selected plugins (plus, optionally, the other config files).
|
|
47
|
+
*/
|
|
48
|
+
export declare function createProfileBackup(profile: string, explicitDir?: string, opts?: BackupOptions): ProfileBackup;
|
|
49
|
+
export declare function validatedBackup(value: unknown): ProfileBackup;
|
|
50
|
+
/** Atomically overwrite backed-up files and return a rollback for install failure. */
|
|
51
|
+
export declare function restoreProfileBackup(profile: string, value: unknown, explicitDir?: string): {
|
|
52
|
+
files: number;
|
|
53
|
+
rollback(): void;
|
|
54
|
+
};
|
|
55
|
+
interface PublicAddress {
|
|
56
|
+
address: string;
|
|
57
|
+
family: 4 | 6;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Ancestor collection URLs of a WebDAV file, outermost first.
|
|
61
|
+
* `https://dav.example/a/b/x.json` → [`https://dav.example/a/`, `https://dav.example/a/b/`].
|
|
62
|
+
* The server root itself is never included — it always exists, and some
|
|
63
|
+
* providers reject MKCOL on it.
|
|
64
|
+
*/
|
|
65
|
+
export declare function webdavParentCollections(url: string): string[];
|
|
66
|
+
/**
|
|
67
|
+
* Upload the backup, creating missing parent collections first (#102).
|
|
68
|
+
*
|
|
69
|
+
* WebDAV servers do not create intermediate collections implicitly, so a PUT
|
|
70
|
+
* into a folder that does not exist yet fails — Jianguoyun answers 404, which
|
|
71
|
+
* read as "sync is broken" rather than "make the folder first". MKCOL on an
|
|
72
|
+
* existing collection answers 405, which is success for our purposes; any
|
|
73
|
+
* other failure is left to the PUT to report, since some providers restrict
|
|
74
|
+
* MKCOL while still accepting the upload.
|
|
75
|
+
*/
|
|
76
|
+
export declare function uploadWebdav(url: string, username: string, password: string, backup: ProfileBackup): Promise<void>;
|
|
77
|
+
/** Refuse non-global IPv4 targets, including metadata and carrier NAT ranges. */
|
|
78
|
+
export declare function isPublicIpv4(ip: string): boolean;
|
|
79
|
+
/** Only public internet target hostnames are reachable for WebDAV. */
|
|
80
|
+
export declare function isPublicHostname(hostname: string): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Whether a WebDAV hostname may be fetched: public https targets only.
|
|
83
|
+
* Exported for tests.
|
|
84
|
+
*/
|
|
85
|
+
export declare function isPublicTarget(hostname: string): boolean;
|
|
86
|
+
/** Only global-unicast IPv6 is usable for a server-side WebDAV connection. */
|
|
87
|
+
export declare function isPublicIpv6(ip: string): boolean;
|
|
88
|
+
/** Resolve once, reject every unsafe answer, and return the address to pin. */
|
|
89
|
+
export declare function resolvePublicAddress(hostname: string): Promise<PublicAddress>;
|
|
90
|
+
/**
|
|
91
|
+
* Why a WebDAV target was refused, when the answer is not "the URL is wrong"
|
|
92
|
+
* (#999).
|
|
93
|
+
*
|
|
94
|
+
* The gate used to answer `invalid WebDAV URL` for every branch — a non-https
|
|
95
|
+
* scheme, embedded credentials, a `.local` name, an empty DNS answer and a
|
|
96
|
+
* private resolution all read the same. That made one very common setup
|
|
97
|
+
* undebuggable: a proxy client in fake-ip mode (Clash/Mihomo, the default for
|
|
98
|
+
* most Chinese setups) answers `198.18.x.x` for every proxied hostname, so
|
|
99
|
+
* every WebDAV target was refused with a message pointing at the URL.
|
|
100
|
+
*/
|
|
101
|
+
export type WebdavUrlErrorCode = 'webdav_bad_url' | 'webdav_unresolvable' | 'webdav_private_resolution';
|
|
102
|
+
export declare class WebdavUrlError extends Error {
|
|
103
|
+
readonly code: WebdavUrlErrorCode;
|
|
104
|
+
readonly address?: string | undefined;
|
|
105
|
+
constructor(code: WebdavUrlErrorCode, message: string, address?: string | undefined);
|
|
106
|
+
}
|
|
107
|
+
export declare function downloadWebdav(url: string, username: string, password: string): Promise<unknown>;
|
|
108
|
+
export interface PluginSelection {
|
|
109
|
+
deps: Record<string, string>;
|
|
110
|
+
bundles: string[];
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* The selected plugins' dependency specs and bundle entries from a backup's
|
|
114
|
+
* manifest. Only string specs survive — everything else in the manifest is
|
|
115
|
+
* untrusted and ignored (partial restore touches nothing but these).
|
|
116
|
+
*/
|
|
117
|
+
export declare function extractPluginSelection(backup: ProfileBackup, includeDeps: string[]): PluginSelection;
|
|
118
|
+
/**
|
|
119
|
+
* Merge a backup's manifest into the profile's current manifest so a restore
|
|
120
|
+
* never deletes plugins the target machine already has: current deps stay,
|
|
121
|
+
* backup specs win on name conflicts; bundle lists are unioned. When
|
|
122
|
+
* `selection` is given, only the selected plugins are merged in.
|
|
123
|
+
*/
|
|
124
|
+
/**
|
|
125
|
+
* Dependencies whose spec points at an absolute local path — `link:/Users/…`
|
|
126
|
+
* or `file:/home/…` (#205 by @Rudyy898).
|
|
127
|
+
*
|
|
128
|
+
* These are perfectly valid on the machine that wrote them and meaningless
|
|
129
|
+
* anywhere else, so a backup carrying one restores a manifest that `pnpm
|
|
130
|
+
* install` cannot satisfy: the path does not exist on the new machine and
|
|
131
|
+
* the whole restore fails on it.
|
|
132
|
+
*
|
|
133
|
+
* Reported, NOT rewritten. Turning `link:/Users/me/dev/plugin` into
|
|
134
|
+
* something portable means deciding where those files should live and
|
|
135
|
+
* whether to carry them at all, which is a design question and not
|
|
136
|
+
* something a restore should answer on the user's behalf. Naming them lets
|
|
137
|
+
* the operator decide before the install runs — which is the part that was
|
|
138
|
+
* missing.
|
|
139
|
+
*
|
|
140
|
+
* Relative `file:./vendor/x` specs are left alone: they resolve against the
|
|
141
|
+
* profile directory, which the restore recreates, so they travel fine.
|
|
142
|
+
*/
|
|
143
|
+
export declare function unportableDeps(dependencies: unknown): Array<{
|
|
144
|
+
name: string;
|
|
145
|
+
spec: string;
|
|
146
|
+
}>;
|
|
147
|
+
export declare function mergeRestoreManifest(backupManifest: Record<string, unknown>, current: Record<string, unknown>, selection?: PluginSelection): Record<string, unknown>;
|
|
148
|
+
/**
|
|
149
|
+
* Dependencies a restore must leave at the spec the target already has — the
|
|
150
|
+
* market itself, while it is the package running the restore.
|
|
151
|
+
*
|
|
152
|
+
* A restore applies the backup's manifest through `pnpm install`, which
|
|
153
|
+
* rewrites whatever that manifest pins. When the backup was written by a
|
|
154
|
+
* different market version, that install replaces THIS package's files under
|
|
155
|
+
* the live module: the mixed state the update route refuses (#608), made
|
|
156
|
+
* worse here because the code answering the restore request is the code being
|
|
157
|
+
* swapped out. The running spec therefore wins, and the backup's spec is
|
|
158
|
+
* returned so the caller can report it — the update flow can apply it later,
|
|
159
|
+
* with its restart and rollback machinery.
|
|
160
|
+
*
|
|
161
|
+
* Only string specs take part: anything else is not a pin this can compare.
|
|
162
|
+
*/
|
|
163
|
+
export declare function pinRunningDeps(merged: Record<string, unknown>, current: Record<string, unknown>, names: ReadonlySet<string>): {
|
|
164
|
+
dependencies: Record<string, unknown>;
|
|
165
|
+
pinned: Array<{
|
|
166
|
+
name: string;
|
|
167
|
+
from: string;
|
|
168
|
+
to: string;
|
|
169
|
+
}>;
|
|
170
|
+
};
|
|
171
|
+
export {};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading a response body under a stall watchdog instead of a total budget.
|
|
3
|
+
*
|
|
4
|
+
* Lives on its own because two downloads need exactly this rule and they are
|
|
5
|
+
* not the same file: the catalog served from its origin (#750/#766) and the
|
|
6
|
+
* catalog carried by a published package (#1049). The npm source had kept a
|
|
7
|
+
* fixed 20s ceiling, which is fine for a metadata answer and wrong for a
|
|
8
|
+
* multi-megabyte tarball: at 3.2 MB it needs 158 KB/s sustained, and a China
|
|
9
|
+
* mirror jittering to 17–40 KB/s cannot make that, so both attempts died at
|
|
10
|
+
* the ceiling while the link was still delivering bytes.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* How long to wait for the response to START answering.
|
|
14
|
+
*
|
|
15
|
+
* Headers arrive in one burst or not at all, so a fixed budget still fits
|
|
16
|
+
* them. It fits nothing else: the body of a catalog download keeps trickling
|
|
17
|
+
* long after any honest total budget, and a total timer cuts off a download
|
|
18
|
+
* that was still moving — measured: killed at 15s on both attempts, 89.9s
|
|
19
|
+
* end-to-end when allowed to run.
|
|
20
|
+
*/
|
|
21
|
+
export declare const HEADERS_TIMEOUT_MS = 15000;
|
|
22
|
+
/**
|
|
23
|
+
* How long the body may stay SILENT before we give up on it.
|
|
24
|
+
*
|
|
25
|
+
* Deliberately not a total budget. As long as bytes keep arriving, however
|
|
26
|
+
* slowly, the read continues; the watchdog only fires on a download that has
|
|
27
|
+
* actually stopped, which is the one failure a slow link cannot fake.
|
|
28
|
+
*/
|
|
29
|
+
export declare const BODY_STALL_TIMEOUT_MS = 15000;
|
|
30
|
+
/**
|
|
31
|
+
* How long the whole body may take, however much progress it keeps making.
|
|
32
|
+
*
|
|
33
|
+
* The stall watchdog can only act on a pause, so a mirror that sends one
|
|
34
|
+
* byte inside every 15s window would hold the read open forever. 10 minutes
|
|
35
|
+
* is ~7x the slowest measured full download (89.9s); a body still going
|
|
36
|
+
* after that is broken, not slow, and the byte count in the message says
|
|
37
|
+
* which of the two it was.
|
|
38
|
+
*/
|
|
39
|
+
export declare const BODY_TOTAL_CEILING_MS = 600000;
|
|
40
|
+
/**
|
|
41
|
+
* The most body bytes to accept before declaring the response not a catalog.
|
|
42
|
+
*
|
|
43
|
+
* The catalog passed 5 MB in September 2026 (9.5 MB unpacked by October);
|
|
44
|
+
* 256 MB is decades of headroom — and still a hard bound on memory, because
|
|
45
|
+
* the whole body is buffered before parsing and a mirror streaming garbage
|
|
46
|
+
* at line speed would otherwise grow that buffer until the process dies.
|
|
47
|
+
* backup.ts and gist.ts cap their downloads for the same reason.
|
|
48
|
+
*/
|
|
49
|
+
export declare const MAX_BODY_BYTES: number;
|
|
50
|
+
/**
|
|
51
|
+
* Read a body under a stall watchdog instead of a total budget.
|
|
52
|
+
*
|
|
53
|
+
* One timer for the whole fetch was the mistake both before and after #188:
|
|
54
|
+
* at 4s it hid slowness behind a stale snapshot, at 15s it kills downloads
|
|
55
|
+
* that are still moving. On a lossy proxied link the catalog body trickles
|
|
56
|
+
* for far longer than 15s while never once going silent — measured 89.9s
|
|
57
|
+
* end-to-end for a body the 15s cutoff had declared dead twice. This reader
|
|
58
|
+
* lets a moving body run as long as it keeps moving, in either direction's
|
|
59
|
+
* sense of "slow", and ends one that goes quiet for `stallMs` with a message
|
|
60
|
+
* that says what actually happened and how much had arrived.
|
|
61
|
+
*
|
|
62
|
+
* The rejection comes from here, not from an abort: undici's abort message
|
|
63
|
+
* ("This operation was aborted") cannot tell a user anything actionable, and
|
|
64
|
+
* a bug report containing this string will contain the byte count too.
|
|
65
|
+
*
|
|
66
|
+
* Two backstops keep "still moving" from meaning "forever", because the
|
|
67
|
+
* watchdog can only see pauses: a total ceiling for a body that trickles
|
|
68
|
+
* without ever pausing, and a size cap for one that outruns any catalog.
|
|
69
|
+
*
|
|
70
|
+
* @param res - the response whose body to read.
|
|
71
|
+
* @param stallMs - silence that ends the read, in milliseconds.
|
|
72
|
+
* @param what - the download, for the rejection message ("the catalog").
|
|
73
|
+
*/
|
|
74
|
+
export declare function readBodyWhileProgressing(res: Response, stallMs: number, what?: string): Promise<Uint8Array>;
|
|
75
|
+
/**
|
|
76
|
+
* Fetch with a headers-only deadline, then hand the body to the watchdog.
|
|
77
|
+
*
|
|
78
|
+
* Two clocks, because they measure different things: how long the origin
|
|
79
|
+
* takes to start answering, and how long it keeps answering. The abort signal
|
|
80
|
+
* covers only the first — once headers are in, the watchdog owns the read,
|
|
81
|
+
* which is what lets a slow-but-moving tarball finish.
|
|
82
|
+
*
|
|
83
|
+
* @param fetchImpl - the project's fetch (proxy-aware), injected for tests.
|
|
84
|
+
* @param url - what to fetch.
|
|
85
|
+
* @param what - the download, for messages.
|
|
86
|
+
* @param init - extra request options.
|
|
87
|
+
* @returns the body bytes.
|
|
88
|
+
*/
|
|
89
|
+
export declare function fetchBodyWhileProgressing(fetchImpl: (url: string, init?: {
|
|
90
|
+
signal?: AbortSignal;
|
|
91
|
+
headers?: Record<string, string>;
|
|
92
|
+
}) => Promise<Response>, url: string, what: string, init?: {
|
|
93
|
+
headers?: Record<string, string>;
|
|
94
|
+
}): Promise<Uint8Array>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Catalog matching for locally linked / file: installs. Shared by the host
|
|
3
|
+
* restore route and the Market client so both refuse the same wrong guesses.
|
|
4
|
+
*/
|
|
5
|
+
export declare function findCatalogEntryForLocal<T extends {
|
|
6
|
+
name: string;
|
|
7
|
+
npm?: string | null;
|
|
8
|
+
url: string;
|
|
9
|
+
}>(plugins: readonly T[], name: string, identities?: readonly string[], hints?: readonly string[]): T | null;
|
|
10
|
+
export type CatalogRestoreReason = 'no-catalog' | 'repo-mismatch';
|
|
11
|
+
/**
|
|
12
|
+
* Why a local restore was blocked, when findCatalogEntryForLocal returned
|
|
13
|
+
* null — and, when it matched, whether anything but the NAME agreed.
|
|
14
|
+
*
|
|
15
|
+
* `verified` is the difference between "put this back where it came from"
|
|
16
|
+
* and "install the catalog's plugin that happens to share this name". A
|
|
17
|
+
* local checkout with no declared repo — no git remote, no `repository`
|
|
18
|
+
* field — gives the market nothing to match on, so a unique same-named
|
|
19
|
+
* catalog entry is a guess. Usually a good one (#429: the local copy IS a
|
|
20
|
+
* tweaked copy of that entry). Not always: @liuwenji007 reported a fork of
|
|
21
|
+
* their own `dsh-humanizer` restored to a different author's plugin of the
|
|
22
|
+
* same name (#485), which is someone else's code arriving under a button
|
|
23
|
+
* labelled "restore".
|
|
24
|
+
*
|
|
25
|
+
* The match is kept, because refusing it would break the ordinary case, and
|
|
26
|
+
* the caller is told not to present it as a certainty.
|
|
27
|
+
*/
|
|
28
|
+
export declare function resolveCatalogRestore<T extends {
|
|
29
|
+
name: string;
|
|
30
|
+
npm?: string | null;
|
|
31
|
+
url: string;
|
|
32
|
+
}>(plugins: readonly T[], name: string, identities?: readonly string[], hints?: readonly string[]): {
|
|
33
|
+
ok: true;
|
|
34
|
+
entry: T;
|
|
35
|
+
verified: boolean;
|
|
36
|
+
} | {
|
|
37
|
+
ok: false;
|
|
38
|
+
reason: CatalogRestoreReason;
|
|
39
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading the plugin catalog out of a published npm package.
|
|
3
|
+
*
|
|
4
|
+
* The catalog's own host is the thing being worked around. `plugins.json` is
|
|
5
|
+
* served from GitHub Pages, and the public GitHub proxies that make GitHub
|
|
6
|
+
* usable from mainland China refuse any hostname that is not github.com's
|
|
7
|
+
* own — measured: the project domain comes back 403. So the file cannot be
|
|
8
|
+
* carried through the same route as everything else while it lives there.
|
|
9
|
+
*
|
|
10
|
+
* Published to npm it can be. Every China npm mirror already carries it, it
|
|
11
|
+
* is the same infrastructure the plugins themselves arrive on, and it needs
|
|
12
|
+
* no service that did not already have to work. It also gains a version
|
|
13
|
+
* number, which the origin never had: a catalog build that ships bad data
|
|
14
|
+
* can be rolled back instead of only being fixed forwards.
|
|
15
|
+
*
|
|
16
|
+
* Mirrors rewrite `dist.tarball` to point at themselves, so following that
|
|
17
|
+
* field is what keeps the download on the mirror rather than bouncing back
|
|
18
|
+
* to the origin registry — verified against the Tencent mirror, which serves
|
|
19
|
+
* its own host in that field.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* `dist.tarball` as an absolute URL.
|
|
23
|
+
*
|
|
24
|
+
* A registry behind a path prefix — Nexus, Verdaccio, a reverse proxy — may
|
|
25
|
+
* answer that field as a relative path (`/dsh-plugin-catalog/-/…`). pnpm
|
|
26
|
+
* resolves it against the registry; passing it straight to `fetch` threw
|
|
27
|
+
* "Failed to parse URL" instead, the npm source dropped out of the list, and
|
|
28
|
+
* the market read the catalog from somewhere else without saying so (#1117).
|
|
29
|
+
*
|
|
30
|
+
* Relative resolution follows the URL rules: a value starting with `/` is
|
|
31
|
+
* root-relative and a bare path is relative to the registry's own directory,
|
|
32
|
+
* which is where the registry serves it from. Nothing is rewritten when the
|
|
33
|
+
* field is already absolute.
|
|
34
|
+
*/
|
|
35
|
+
export declare function absoluteTarballUrl(tarball: string, registry: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* One file's bytes from a gzipped tar, or null when it is not in there.
|
|
38
|
+
*
|
|
39
|
+
* @param gz - the gzipped tarball.
|
|
40
|
+
* @param wanted - the exact entry name, npm-style (`package/plugins.json`).
|
|
41
|
+
*/
|
|
42
|
+
export declare function fileFromTarball(gz: Buffer, wanted: string): Buffer | null;
|
|
43
|
+
/**
|
|
44
|
+
* The catalog carried by a published package, and the version it came from.
|
|
45
|
+
*
|
|
46
|
+
* The version doubles as the cache validator — a better one than an ETag,
|
|
47
|
+
* because it is meaningful to a human reading a log and it is the thing a
|
|
48
|
+
* rollback would change.
|
|
49
|
+
*
|
|
50
|
+
* @param registry - registry base, no trailing slash.
|
|
51
|
+
* @param pkg - package name.
|
|
52
|
+
* @param known - a version already held, to skip re-downloading.
|
|
53
|
+
* @returns the parsed JSON and its version, or `{ version, data: null }` when
|
|
54
|
+
* the published version is the one already held.
|
|
55
|
+
* @throws when the package, the tarball or the file inside it cannot be read.
|
|
56
|
+
*/
|
|
57
|
+
export declare function catalogFromPackage(registry: string, pkg: string, known?: string,
|
|
58
|
+
/** The entry to extract; the catalog package carries `plugins.json`, companions theirs. */
|
|
59
|
+
file?: string): Promise<{
|
|
60
|
+
version: string;
|
|
61
|
+
data: unknown | null;
|
|
62
|
+
}>;
|
|
63
|
+
/**
|
|
64
|
+
* One file out of a package's newest tarball, or null when it cannot be read
|
|
65
|
+
* (#1012).
|
|
66
|
+
*
|
|
67
|
+
* The install route asks a package what it declares before it installs it: a
|
|
68
|
+
* rename can only be detected from the rows the artifact carries, not from
|
|
69
|
+
* the name it was published under. A failed read is not a verdict — the
|
|
70
|
+
* caller treats null as "not declared", because a registry hiccup must never
|
|
71
|
+
* become a refusal to install.
|
|
72
|
+
*
|
|
73
|
+
* @param registry - registry base, no trailing slash.
|
|
74
|
+
* @param pkg - package name.
|
|
75
|
+
* @param file - exact entry name inside the tarball (`package/cordis.patch.yml`).
|
|
76
|
+
*/
|
|
77
|
+
export declare function packageFileFromRegistry(registry: string, pkg: string, file: string): Promise<Buffer | null>;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Update notes: what changed between an installed version and HEAD.
|
|
3
|
+
*
|
|
4
|
+
* Every byte of GitHub data comes from the catalog side's daily probe,
|
|
5
|
+
* published as the `dsh-plugin-updates` package (origin fallback
|
|
6
|
+
* `updates.json` beside `plugins.json`). The market asks GitHub for nothing:
|
|
7
|
+
* anonymous REST quota is shared per egress IP and already unreliable behind
|
|
8
|
+
* common proxies, and this data is wanted by thousands of markets but
|
|
9
|
+
* produced perfectly well once a day by one probe.
|
|
10
|
+
*
|
|
11
|
+
* What the catalog cannot know is where each user's installed version sits,
|
|
12
|
+
* so slicing the commit tail at that boundary happens here: the same sha the
|
|
13
|
+
* update check resolved (`current`) marks where "new" begins. A tail that
|
|
14
|
+
* does not contain it means the range is wider than the tail — those are
|
|
15
|
+
* labelled recent commits rather than pretending to be an exact interval.
|
|
16
|
+
* npm installs with neither notes nor commits fall back to npm publish times,
|
|
17
|
+
* and a plugin nothing answers for gets a neutral "no notes" — absence of
|
|
18
|
+
* release notes is the ordinary condition of small plugins, not a defect.
|
|
19
|
+
* A plugin installed from any other source the notes hold nothing for gets
|
|
20
|
+
* `source` instead: its history is where it came from, and the market says
|
|
21
|
+
* it has none on hand rather than that the plugin publishes none (#819).
|
|
22
|
+
*/
|
|
23
|
+
export interface ReleaseNotes {
|
|
24
|
+
tag: string | null;
|
|
25
|
+
name: string | null;
|
|
26
|
+
publishedAt: string | null;
|
|
27
|
+
url: string | null;
|
|
28
|
+
body: string;
|
|
29
|
+
}
|
|
30
|
+
export interface CommitNote {
|
|
31
|
+
sha: string;
|
|
32
|
+
message: string;
|
|
33
|
+
date: string | null;
|
|
34
|
+
}
|
|
35
|
+
interface UpdatesEntry {
|
|
36
|
+
release?: ReleaseNotes | null;
|
|
37
|
+
commits?: CommitNote[];
|
|
38
|
+
}
|
|
39
|
+
interface UpdatesPayload {
|
|
40
|
+
count?: number;
|
|
41
|
+
updates?: Record<string, UpdatesEntry>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The update-notes payload from whichever route the region serves.
|
|
45
|
+
*
|
|
46
|
+
* Same source order as the catalog itself — the npm package first where one
|
|
47
|
+
* exists (its mirror reach is the reason the package exists), then the
|
|
48
|
+
* origin. Version-keyed like the catalog too: an unchanged payload costs one
|
|
49
|
+
* packument read per TTL, not a tarball.
|
|
50
|
+
*/
|
|
51
|
+
export declare function loadUpdateNotes(force?: boolean): Promise<UpdatesPayload>;
|
|
52
|
+
/** Drop the cached payload (nothing currently invalidates it mid-process). */
|
|
53
|
+
export declare function invalidateUpdateNotes(): void;
|
|
54
|
+
/**
|
|
55
|
+
* Slice the commit tail at the installed sha.
|
|
56
|
+
*
|
|
57
|
+
* @returns the commits newer than `installed`, and whether the boundary was
|
|
58
|
+
* actually found — `found === false` means the range is wider than the tail
|
|
59
|
+
* (or history diverged), so callers must label the result "recent" rather
|
|
60
|
+
* than exact.
|
|
61
|
+
*/
|
|
62
|
+
export declare function sliceCommitsAt(items: CommitNote[], installed: string | null): {
|
|
63
|
+
items: CommitNote[];
|
|
64
|
+
found: boolean;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* The version a release tag names, when it names one.
|
|
68
|
+
*
|
|
69
|
+
* Tags come as `v1.2.3`, `1.2.3`, `@scope/pkg@1.2.3` or `pkg-v1.2.3`; the
|
|
70
|
+
* FIRST semver-shaped run is the version in all of them. A tag that names no
|
|
71
|
+
* version (`nightly`) returns null, and callers must treat "unknown" as "do
|
|
72
|
+
* not judge" rather than "older".
|
|
73
|
+
*/
|
|
74
|
+
export declare function releaseVersionOf(tag: string | null): string | null;
|
|
75
|
+
/** The repo url key an entry's update notes live under, or null. */
|
|
76
|
+
export declare function repoKeyOf(spec: string): string | null;
|
|
77
|
+
/**
|
|
78
|
+
* The web page of the repository a git spec installs from, or null.
|
|
79
|
+
*
|
|
80
|
+
* What the dialog can point at when the market cannot read a source's notes
|
|
81
|
+
* itself. The owner/repo casing is kept: not every host matches paths
|
|
82
|
+
* case-insensitively the way GitHub does.
|
|
83
|
+
*/
|
|
84
|
+
export declare function sourceWebUrl(spec: string): string | null;
|
|
85
|
+
/**
|
|
86
|
+
* Look an entry up by its catalog url.
|
|
87
|
+
*
|
|
88
|
+
* The catalog keys entries by the url as listed (author's casing preserved);
|
|
89
|
+
* the market resolves repos to lowercase (as every other consumer of
|
|
90
|
+
* `repoOfTarget` sees them). Match case-insensitively so the two sides never
|
|
91
|
+
* disagree over a capital letter.
|
|
92
|
+
*/
|
|
93
|
+
export declare function entryForRepo(payload: UpdatesPayload, key: string): UpdatesEntry | undefined;
|
|
94
|
+
export declare function npmPublishTimes(name: string): Promise<{
|
|
95
|
+
version: string;
|
|
96
|
+
date: string;
|
|
97
|
+
}[]>;
|
|
98
|
+
/** Everything the dialog renders for one plugin, already resolved. */
|
|
99
|
+
export interface UpdateNotes {
|
|
100
|
+
kind: 'release' | 'commits' | 'npm' | 'source' | 'none';
|
|
101
|
+
/** Present for `release`: the author's own notes for the latest release. */
|
|
102
|
+
release?: ReleaseNotes;
|
|
103
|
+
/** Present for `commits`: the tail, sliced when the boundary was found. */
|
|
104
|
+
commits?: {
|
|
105
|
+
items: CommitNote[];
|
|
106
|
+
found: boolean;
|
|
107
|
+
};
|
|
108
|
+
/** Present for `npm`: recent versions with their publish dates. */
|
|
109
|
+
npmTimes?: {
|
|
110
|
+
version: string;
|
|
111
|
+
date: string;
|
|
112
|
+
}[];
|
|
113
|
+
/** Present for `source`: the repository page to read changes on, or null. */
|
|
114
|
+
sourceUrl?: string | null;
|
|
115
|
+
/**
|
|
116
|
+
* Present for `source`: `missing` when the notes loaded without this
|
|
117
|
+
* plugin, `unavailable` when they could not be loaded at all — a passing
|
|
118
|
+
* failure, not a fact about the plugin — and `unreadable` when the source is
|
|
119
|
+
* one the market can never read, so waiting will not help (#819).
|
|
120
|
+
*/
|
|
121
|
+
reason?: 'missing' | 'unavailable' | 'unreadable';
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Resolve the notes for one installed plugin, or `{ kind: 'none' }`.
|
|
125
|
+
*
|
|
126
|
+
* Never throws: every failure along the way degrades to the next tier, the
|
|
127
|
+
* same contract the issue promised — a dialog that cannot load its data shows
|
|
128
|
+
* a neutral statement, not an error.
|
|
129
|
+
*/
|
|
130
|
+
export declare function updateNotesFor(profile: string, explicitDir: string | undefined, name: string): Promise<UpdateNotes>;
|
|
131
|
+
export {};
|