@deepseek-ai/dsh-plugin-manager 0.2.2-rc.1 → 0.2.2-rc.3
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/README.i18n.yaml +4 -4
- package/README.md +6 -5
- package/README.zh.md +6 -5
- package/lib/index.js +255 -68
- package/lib/typert.host.js +84 -66
- package/lib/typert.remote-client.d.ts.map +1 -0
- package/lib/typert.remote-client.js +77 -59
- package/lib/types/build-approval.d.ts.map +1 -0
- package/lib/types/build-approval.js.map +1 -0
- package/lib/types/bundle-detail.d.ts.map +1 -0
- package/lib/types/bundle-detail.js.map +1 -0
- package/lib/types/diagnostic.d.ts.map +1 -0
- package/lib/types/diagnostic.js +1 -0
- package/lib/types/diagnostic.js.map +1 -0
- package/lib/types/failure.d.ts.map +1 -0
- package/lib/types/failure.js.map +1 -0
- package/lib/types/git-transport.d.ts.map +1 -0
- package/lib/types/git-transport.js.map +1 -0
- package/lib/types/github-connection.d.ts +16 -5
- package/lib/types/github-connection.d.ts.map +1 -0
- package/lib/types/github-connection.js +18 -8
- package/lib/types/github-connection.js.map +1 -0
- package/lib/types/index.d.ts +39 -10
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +144 -46
- package/lib/types/index.js.map +1 -0
- package/lib/types/install-failure.d.ts.map +1 -0
- package/lib/types/install-failure.js.map +1 -0
- package/lib/types/install-spec.d.ts +13 -1
- package/lib/types/install-spec.d.ts.map +1 -0
- package/lib/types/install-spec.js +41 -1
- package/lib/types/install-spec.js.map +1 -0
- package/lib/types/official-install-target.d.ts.map +1 -0
- package/lib/types/official-install-target.js.map +1 -0
- package/lib/types/operations.d.ts +16 -4
- package/lib/types/operations.d.ts.map +1 -0
- package/lib/types/operations.js +38 -5
- package/lib/types/operations.js.map +1 -0
- package/lib/types/patch.d.ts.map +1 -0
- package/lib/types/patch.js.map +1 -0
- package/lib/types/registry.d.ts.map +1 -0
- package/lib/types/registry.js.map +1 -0
- package/lib/types/run-tree.d.ts.map +1 -0
- package/lib/types/run-tree.js.map +1 -0
- package/lib/types/tools.d.ts.map +1 -0
- package/lib/types/tools.js +2 -1
- package/lib/types/tools.js.map +1 -0
- package/lib/types/types.d.ts +31 -5
- package/lib/types/types.d.ts.map +1 -0
- package/lib/types/types.js.map +1 -0
- package/lib/types/versions.d.ts.map +1 -0
- package/lib/types/versions.js.map +1 -0
- package/package.json +39 -35
- package/src/build-approval.ts +96 -0
- package/src/bundle-detail.ts +104 -0
- package/src/diagnostic.ts +86 -0
- package/src/failure.ts +29 -0
- package/src/git-transport.ts +72 -0
- package/src/github-connection.ts +102 -0
- package/src/index.ts +1458 -0
- package/src/install-failure.ts +44 -0
- package/src/install-spec.ts +159 -0
- package/src/official-install-target.ts +58 -0
- package/src/operations.ts +695 -0
- package/src/patch.ts +78 -0
- package/src/registry.ts +98 -0
- package/src/run-tree.ts +77 -0
- package/src/tools.ts +164 -0
- package/src/types.ts +477 -0
- package/src/versions.ts +80 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/** Bounded Git repository connection checks using the installer's Git configuration and environment. */
|
|
2
|
+
import { mkdir, mkdtemp, open } from 'node:fs/promises'
|
|
3
|
+
import { join } from 'node:path'
|
|
4
|
+
import { execa } from 'execa'
|
|
5
|
+
import { scrubbedParentEnv } from '@deepseek-ai/dsh-subprocess'
|
|
6
|
+
import { classifyInstallFailure } from './install-failure.ts'
|
|
7
|
+
import { HTTP_USER_INFO, type ParsedInstallSpec } from './install-spec.ts'
|
|
8
|
+
import type { PackageResult } from './types.ts'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A failed check, with the Git command line the install dialog shows as the installation's only run.
|
|
12
|
+
* The returned result itself stays a plain {@link PackageResult}: the command line never joins the wire fields.
|
|
13
|
+
*/
|
|
14
|
+
export interface GithubConnectionFailure extends PackageResult {
|
|
15
|
+
/**
|
|
16
|
+
* The `git` command line the check ran, with the user information of an http(s) repository URL removed:
|
|
17
|
+
* `git -c credential.helper= ls-remote -- <repository> HEAD`.
|
|
18
|
+
*/
|
|
19
|
+
readonly argv: readonly string[]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Deadline, diagnostics and cancellation for one read-only Git repository check. */
|
|
23
|
+
export interface GithubConnectionOptions {
|
|
24
|
+
timeoutMs: number
|
|
25
|
+
outputBytes: number
|
|
26
|
+
signal: AbortSignal
|
|
27
|
+
/** The application-owned package manager's environment, also used by its Git children. */
|
|
28
|
+
env?: Readonly<Record<string, string>>
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Check a GitHub repository before pnpm starts, without downloading or building its package.
|
|
33
|
+
* @param spec The parsed installation address; npm packages, local paths and other hosts are not checked.
|
|
34
|
+
* @param dir The profile directory where installation runs.
|
|
35
|
+
* @param options The connection deadline, output bound and operation cancellation.
|
|
36
|
+
* @returns As {@link checkGitConnection}, or undefined for a spec that does not name a GitHub repository.
|
|
37
|
+
*/
|
|
38
|
+
export async function checkGithubConnection(
|
|
39
|
+
spec: ParsedInstallSpec, dir: string, options: GithubConnectionOptions,
|
|
40
|
+
): Promise<GithubConnectionFailure | undefined> {
|
|
41
|
+
if (spec.kind !== 'git') return undefined
|
|
42
|
+
const host = spec.host.toLowerCase().replace(/:.*$/, '')
|
|
43
|
+
if (host !== 'github.com' && !host.endsWith('.github.com')) return undefined
|
|
44
|
+
return checkGitConnection(spec, dir, options)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Check a Git repository with `git ls-remote`, without downloading or building its package. A host shorthand is read
|
|
49
|
+
* over HTTPS; any other spec over the URL it names. Git reads the profile's Git and proxy configuration without
|
|
50
|
+
* invoking credential helpers or prompting, so a repository that needs credentials fails as `unknown`, not as a
|
|
51
|
+
* connection failure. Timeout and cancellation terminate its descendants too.
|
|
52
|
+
* @param spec The parsed address of a Git repository.
|
|
53
|
+
* @param dir The profile directory where installation runs.
|
|
54
|
+
* @param options The connection deadline, output bound and operation cancellation.
|
|
55
|
+
* @returns A failed check carrying the command line it ran (without URL user information), its bounded output and its
|
|
56
|
+
* failure kind, with a complete log at logPath, or undefined for a reachable repository.
|
|
57
|
+
*/
|
|
58
|
+
export async function checkGitConnection(
|
|
59
|
+
spec: ParsedInstallSpec & { readonly kind: 'git' }, dir: string, options: GithubConnectionOptions,
|
|
60
|
+
): Promise<GithubConnectionFailure | undefined> {
|
|
61
|
+
const repository = spec.spec.replace(/#.*$/s, '')
|
|
62
|
+
.replace(/^(?:github|gitlab|bitbucket|gist):/i, `https://${spec.host}/`)
|
|
63
|
+
.replace(/^git\+/i, '')
|
|
64
|
+
const logRoot = join(dir, '.plugin-manager', 'logs')
|
|
65
|
+
await mkdir(logRoot, { recursive: true, mode: 0o700 })
|
|
66
|
+
const logDir = await mkdtemp(join(logRoot, 'github-connection-'))
|
|
67
|
+
const logPath = join(logDir, 'git.log')
|
|
68
|
+
const log = await open(logPath, 'ax+', 0o600)
|
|
69
|
+
const argv = ['git', '-c', 'credential.helper=', 'ls-remote', '--', repository, 'HEAD'] as const
|
|
70
|
+
// The executed command keeps any credentials the spec names; the recorded one drops them before it is displayed.
|
|
71
|
+
const recordedArgv = argv.map(argument => argument.replace(HTTP_USER_INFO, '$1'))
|
|
72
|
+
const [command, ...args] = argv
|
|
73
|
+
try {
|
|
74
|
+
const result = await execa(command, args, {
|
|
75
|
+
cwd: dir,
|
|
76
|
+
env: {
|
|
77
|
+
...scrubbedParentEnv(), ...options.env, LC_ALL: 'C', GIT_TERMINAL_PROMPT: '0',
|
|
78
|
+
GIT_ASKPASS: '', SSH_ASKPASS: '', SSH_ASKPASS_REQUIRE: 'never',
|
|
79
|
+
},
|
|
80
|
+
extendEnv: false,
|
|
81
|
+
stdin: 'ignore', stdout: 'ignore', stderr: { file: logPath, append: true }, buffer: false, reject: false,
|
|
82
|
+
timeout: options.timeoutMs, cancelSignal: options.signal, killDescendants: true, killSignal: 'SIGKILL',
|
|
83
|
+
})
|
|
84
|
+
if (!result.failed) return undefined
|
|
85
|
+
if (result.timedOut) await log.write(`dsh: connection to ${spec.host} timed out after ${String(options.timeoutMs)}ms\n`)
|
|
86
|
+
if ((await log.stat()).size === 0) await log.write(result.shortMessage ?? 'Git connection check failed')
|
|
87
|
+
const { size } = await log.stat()
|
|
88
|
+
const bytes = Buffer.alloc(Math.min(size, options.outputBytes))
|
|
89
|
+
await log.read(bytes, 0, bytes.length, size - bytes.length)
|
|
90
|
+
const output = bytes.toString('utf8')
|
|
91
|
+
// `PackageResult.exitCode` is a status number, so a Git the deadline stopped records the status its failure is read
|
|
92
|
+
// as. The run streamed for the same failure reports no exit code, because that process ended without one.
|
|
93
|
+
return {
|
|
94
|
+
argv: recordedArgv, exitCode: result.exitCode ?? (result.code === 'ENOENT' ? 127 : 1),
|
|
95
|
+
output, truncated: size > options.outputBytes, logPath,
|
|
96
|
+
kind: classifyInstallFailure({ log: output, timedOut: result.timedOut }),
|
|
97
|
+
...result.timedOut ? { timedOut: true } : {},
|
|
98
|
+
}
|
|
99
|
+
} finally {
|
|
100
|
+
await log.close()
|
|
101
|
+
}
|
|
102
|
+
}
|