fix: resolve Paseo CLI via npm prefix fallback in Sprites and use bash -c for exec
- Add RESOLVE_PASEO_BIN_SNIPPET to locate paseo via npm prefix -g and symlink into ~/.local/bin for subsequent calls - Switch Sprite exec from bash -lc to bash -c so PATH_PREAMBLE exports and node version shims apply to already-sourced shells - Surface npm prefix and install log tail when binary still missing - Add justfile with plugin install/reload/logs recipes
This commit is contained in:
1 parent
36d88ef168
commit
2ded63183b
2 files changed
+61
-7
No files matched your search
@@ -0,0 +1,31 @@
|
|||||||
|
plugin_id := "fly-sprites-workers"
|
||||||
|
plugin_dir := justfile_directory()
|
||||||
|
|
||||||
|
default:
|
||||||
|
@just --list
|
||||||
|
|
||||||
|
# Install dependencies, typecheck, and install or reload the plugin in Paseo
|
||||||
|
install:
|
||||||
|
npm install
|
||||||
|
npm run typecheck
|
||||||
|
@if paseo plugin ls {{plugin_id}} >/dev/null 2>&1; then \
|
||||||
|
paseo plugin reload {{plugin_id}} || paseo plugin enable {{plugin_id}}; \
|
||||||
|
else \
|
||||||
|
paseo plugin install "{{plugin_dir}}"; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Typecheck TypeScript sources
|
||||||
|
typecheck:
|
||||||
|
npm run typecheck
|
||||||
|
|
||||||
|
# Reload the plugin in Paseo
|
||||||
|
reload:
|
||||||
|
paseo plugin reload {{plugin_id}}
|
||||||
|
|
||||||
|
# Show recent plugin logs from Paseo
|
||||||
|
logs:
|
||||||
|
paseo plugin logs {{plugin_id}}
|
||||||
|
|
||||||
|
# Remove the plugin from Paseo
|
||||||
|
uninstall:
|
||||||
|
paseo plugin remove {{plugin_id}}
|
||||||
+30
-7
@@ -15,11 +15,24 @@ const PREFERRED_PROVIDERS = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
const PATH_PREAMBLE = [
|
const PATH_PREAMBLE = [
|
||||||
'export PATH="$HOME/.npm-global/bin:$HOME/.local/bin:/usr/local/bin:$PATH"',
|
'export PATH="$HOME/.npm-global/bin:$HOME/.local/bin:/.sprite/bin:/usr/local/bin:$PATH"',
|
||||||
'for d in "$HOME"/.nvm/versions/node/*/bin "$HOME/.volta/bin" "$HOME/.local/share/mise/shims"; do [ -d "$d" ] && PATH="$d:$PATH"; done',
|
'for d in /.sprite/languages/node/nvm/versions/node/*/bin "$HOME"/.nvm/versions/node/*/bin "$HOME/.volta/bin" "$HOME/.local/share/mise/shims"; do [ -d "$d" ] && PATH="$d:$PATH"; done',
|
||||||
"export PATH",
|
"export PATH",
|
||||||
].join("; ");
|
].join("; ");
|
||||||
|
|
||||||
|
const RESOLVE_PASEO_BIN_SNIPPET = [
|
||||||
|
'PASEO_BIN="$(command -v paseo 2>/dev/null || true)"',
|
||||||
|
'if [ -z "$PASEO_BIN" ] && command -v npm >/dev/null 2>&1; then',
|
||||||
|
' _npm_prefix="$(npm prefix -g 2>/dev/null || true)"',
|
||||||
|
' if [ -n "$_npm_prefix" ] && [ -x "$_npm_prefix/bin/paseo" ]; then',
|
||||||
|
' PASEO_BIN="$_npm_prefix/bin/paseo"',
|
||||||
|
" fi",
|
||||||
|
"fi",
|
||||||
|
'if [ -n "$PASEO_BIN" ] && [ ! -e "$HOME/.local/bin/paseo" ]; then',
|
||||||
|
' mkdir -p "$HOME/.local/bin" && ln -sf "$PASEO_BIN" "$HOME/.local/bin/paseo" 2>/dev/null || true',
|
||||||
|
"fi",
|
||||||
|
].join("\n");
|
||||||
|
|
||||||
export function spriteHostSourceKey(spriteName: string): string {
|
export function spriteHostSourceKey(spriteName: string): string {
|
||||||
return `fly-sprite:${spriteName}`;
|
return `fly-sprite:${spriteName}`;
|
||||||
}
|
}
|
||||||
@@ -85,7 +98,6 @@ function parseJsonObjectFromOutput(raw: string): Record<string, unknown> | null
|
|||||||
const end = raw.lastIndexOf("}");
|
const end = raw.lastIndexOf("}");
|
||||||
if (end === -1) return null;
|
if (end === -1) return null;
|
||||||
|
|
||||||
// Prefer JSON objects starting at the beginning of a line (avoids matching `{...}` inside log lines).
|
|
||||||
const candidateStarts: number[] = [];
|
const candidateStarts: number[] = [];
|
||||||
let idx = raw.indexOf("{");
|
let idx = raw.indexOf("{");
|
||||||
while (idx !== -1 && idx < end) {
|
while (idx !== -1 && idx < end) {
|
||||||
@@ -136,7 +148,7 @@ async function execSpriteBash(
|
|||||||
): Promise<{ exitCode: number; stdout: string; stderr: string }> {
|
): Promise<{ exitCode: number; stdout: string; stderr: string }> {
|
||||||
const fullScript = `${PATH_PREAMBLE}\n${script}`;
|
const fullScript = `${PATH_PREAMBLE}\n${script}`;
|
||||||
try {
|
try {
|
||||||
const res = await sprite.execFile("bash", ["-lc", fullScript], {
|
const res = await sprite.execFile("bash", ["-c", fullScript], {
|
||||||
timeout: options?.timeoutMs ?? 60_000,
|
timeout: options?.timeoutMs ?? 60_000,
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
@@ -162,7 +174,11 @@ async function ensurePaseoCliInSprite(
|
|||||||
onProgress?: (phase: string) => void,
|
onProgress?: (phase: string) => void,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
onProgress?.("Checking Paseo CLI in Sprite…");
|
onProgress?.("Checking Paseo CLI in Sprite…");
|
||||||
const check = await execSpriteBash(sprite, "command -v paseo || true", { timeoutMs: 25_000 });
|
const check = await execSpriteBash(
|
||||||
|
sprite,
|
||||||
|
`${RESOLVE_PASEO_BIN_SNIPPET}\n[ -n "$PASEO_BIN" ] && printf '%s\\n' "$PASEO_BIN" || true`,
|
||||||
|
{ timeoutMs: 25_000 },
|
||||||
|
);
|
||||||
const existingBin = findAbsolutePathLine(check.stdout);
|
const existingBin = findAbsolutePathLine(check.stdout);
|
||||||
if (existingBin) return existingBin;
|
if (existingBin) return existingBin;
|
||||||
|
|
||||||
@@ -176,7 +192,14 @@ async function ensurePaseoCliInSprite(
|
|||||||
' npm config set prefix "$HOME/.npm-global"',
|
' npm config set prefix "$HOME/.npm-global"',
|
||||||
' npm install -g --no-audit --no-fund @getpaseo/cli >>/tmp/paseo-install.log 2>&1 || { cat /tmp/paseo-install.log >&2; exit 1; }',
|
' npm install -g --no-audit --no-fund @getpaseo/cli >>/tmp/paseo-install.log 2>&1 || { cat /tmp/paseo-install.log >&2; exit 1; }',
|
||||||
"fi",
|
"fi",
|
||||||
"command -v paseo",
|
"hash -r 2>/dev/null || true",
|
||||||
|
RESOLVE_PASEO_BIN_SNIPPET,
|
||||||
|
'if [ -z "$PASEO_BIN" ]; then',
|
||||||
|
' echo "paseo binary not found after npm install (npm prefix -g: $(npm prefix -g 2>/dev/null || echo unknown))" >&2',
|
||||||
|
' tail -n 30 /tmp/paseo-install.log >&2 || true',
|
||||||
|
" exit 1",
|
||||||
|
"fi",
|
||||||
|
'printf "%s\\n" "$PASEO_BIN"',
|
||||||
].join("\n"),
|
].join("\n"),
|
||||||
{ timeoutMs: 180_000 },
|
{ timeoutMs: 180_000 },
|
||||||
);
|
);
|
||||||
@@ -265,7 +288,7 @@ async function ensureSpriteDaemonRunning(
|
|||||||
"paseo",
|
"paseo",
|
||||||
{
|
{
|
||||||
cmd: "bash",
|
cmd: "bash",
|
||||||
args: ["-lc", serviceCmd],
|
args: ["-c", serviceCmd],
|
||||||
httpPort: 6767,
|
httpPort: 6767,
|
||||||
},
|
},
|
||||||
"3s",
|
"3s",
|
||||||
|
|||||||
Reference in new issue
Block a user