fix(repository-plugin): require published prepare dependency
This commit is contained in:
26 files changed
+319
-243
No files matched your search
@@ -3,10 +3,9 @@
|
||||
* @module
|
||||
*/
|
||||
|
||||
import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { readFile } from 'node:fs/promises'
|
||||
import { join, resolve } from 'node:path'
|
||||
import { fileURLToPath, pathToFileURL } from 'node:url'
|
||||
import { pathToFileURL } from 'node:url'
|
||||
import type { Context, Fiber, FiberState, Plugin } from 'cordis'
|
||||
import type { RepositoryCache } from '@cordisjs/plugin-loader/repository'
|
||||
import { resolveDshHome } from '@deepseek-ai/dsh-paths'
|
||||
@@ -24,56 +23,6 @@ const FIBER_ACTIVE = 2 as FiberState.ACTIVE
|
||||
/** Directory under the Harness home containing immutable repository generations. */
|
||||
export const DEFAULT_REPOSITORY_CACHE_DIRECTORY = 'repository-plugins'
|
||||
|
||||
/** Temporary host command supplied to repository package lifecycle scripts. */
|
||||
export interface RepositoryPrepareCommand {
|
||||
/** Absolute directory to prepend to the isolated install's executable search path. */
|
||||
directory: string
|
||||
/** Remove the temporary command directory. */
|
||||
dispose(): Promise<void>
|
||||
}
|
||||
|
||||
function shellQuote(value: string): string {
|
||||
return `'${value.replaceAll("'", "'\\''")}'`
|
||||
}
|
||||
|
||||
function batchQuote(value: string): string {
|
||||
return `"${value.replaceAll('%', '%%')}"`
|
||||
}
|
||||
|
||||
/**
|
||||
* Materialize the DSH-owned prepare executable used only while pnpm packs Git source.
|
||||
* @returns a command directory and its idempotent cleanup operation.
|
||||
*/
|
||||
export async function createRepositoryPrepareCommand(): Promise<RepositoryPrepareCommand> {
|
||||
const directory = await mkdtemp(join(tmpdir(), 'dsh-repository-plugin-bin-'))
|
||||
const target = fileURLToPath(new URL('../lib/bin.js', import.meta.url))
|
||||
try {
|
||||
await Promise.all([
|
||||
writeFile(join(directory, REPOSITORY_PLUGIN_PREPARE_COMMAND), [
|
||||
'#!/bin/sh',
|
||||
`exec ${shellQuote(process.execPath)} ${shellQuote(target)} "$@"`,
|
||||
'',
|
||||
].join('\n'), { mode: 0o700 }),
|
||||
writeFile(join(directory, `${REPOSITORY_PLUGIN_PREPARE_COMMAND}.cmd`), [
|
||||
'@echo off',
|
||||
`${batchQuote(process.execPath)} ${batchQuote(target)} %*`,
|
||||
'',
|
||||
].join('\r\n'), { mode: 0o700 }),
|
||||
])
|
||||
} catch (cause) {
|
||||
/* v8 ignore next -- requires a host filesystem failure after mkdtemp; cleanup semantics are the contract under test. */
|
||||
await rm(directory, { recursive: true, force: true })
|
||||
/* v8 ignore next -- preserves that unstageable host failure after best-effort cleanup. */
|
||||
throw cause
|
||||
}
|
||||
return {
|
||||
directory,
|
||||
async dispose() {
|
||||
await rm(directory, { recursive: true, force: true })
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// The ref segment excludes `#` so `github:o/r#a#b` fails here — at the config
|
||||
// parser, with the syntax the error message promises — instead of inside the
|
||||
// cache's pnpm install ('misconfiguration fails loud at the earliest
|
||||
|
||||
Reference in New Issue
Block a user