mirror of
https://github.com/sotashimozono/obsidian-remote-ssh.git
synced 2026-07-22 17:10:32 +00:00
Dogfooding beta.13: the static-daemon fix shipped, but users still ran the old dynamically-linked binary — the cache was keyed by ARCH only (cacheHit = existsSync), so a plugin upgrade never re-downloaded the daemon. And locateDaemonBinary returned any staged binary at the dev filename, so a prior *download* masqueraded as a dev build and skipped the refresh entirely. Now (single cached file, no per-version pileup): - DaemonDownloader validates the cache by SHA against the release manifest, not mere existence: reuse iff the cached bytes still match the expected sha, else re-download (atomic overwrite = old dropped). A daemon that didn't change across a bump is NOT re-downloaded; a changed/stale one is. - ensureDaemonBinary fast-paths on `settings.daemonBinaryVersion === version` (cached file present) -> no GitHub round-trip, works offline; on mismatch it runs the sha re-check and records the new version after provisioning. - locateDaemonBinary now requires a `.dev-daemon` marker (written by dev-install) to treat a staged binary as a genuine dev build; an unmarked download is re-validated instead of trusted. This is what makes an existing store/BRAT user's stale binary auto-replace seamlessly (no manual delete). Implements the deferred #406 "re-verify cached binary sha before reuse". tsc/lint/vitest green (1188). Ships as beta.14. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
83 lines
3.3 KiB
JavaScript
83 lines
3.3 KiB
JavaScript
#!/usr/bin/env node
|
|
/*
|
|
* dev-install — copy build artifacts (main.js, manifest.json, styles.css)
|
|
* into the dev vault's plugins folder.
|
|
*
|
|
* Usage:
|
|
* node scripts/dev-install.mjs
|
|
* node scripts/dev-install.mjs <vault-root>
|
|
*
|
|
* The default vault root is read from the `REMOTE_SSH_DEV_VAULT` env var
|
|
* or falls back to `../../dev-vault` relative to this script (i.e. a
|
|
* sibling of the repo root, since the plugin lives under
|
|
* `<repo>/plugin/`). Set the env var in your shell rc to point at
|
|
* whatever vault you actually use for development.
|
|
*/
|
|
|
|
import * as fs from 'node:fs';
|
|
import * as path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
const pluginRoot = path.resolve(__dirname, '..'); // <repo>/plugin
|
|
const repoRoot = path.resolve(pluginRoot, '..'); // <repo>
|
|
|
|
const vaultRoot = process.argv[2]
|
|
?? process.env.REMOTE_SSH_DEV_VAULT
|
|
?? path.resolve(repoRoot, '..', 'dev-vault');
|
|
|
|
const manifestPath = path.join(pluginRoot, 'manifest.json');
|
|
if (!fs.existsSync(manifestPath)) {
|
|
console.error(`manifest.json not found at ${manifestPath}`);
|
|
process.exit(1);
|
|
}
|
|
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
|
|
|
|
const targetDir = path.join(vaultRoot, '.obsidian', 'plugins', manifest.id);
|
|
if (!fs.existsSync(path.join(vaultRoot, '.obsidian'))) {
|
|
console.error(`Vault root does not look like an Obsidian vault: ${vaultRoot}`);
|
|
console.error(`(no .obsidian directory found)`);
|
|
process.exit(1);
|
|
}
|
|
|
|
fs.mkdirSync(targetDir, { recursive: true });
|
|
|
|
const files = ['main.js', 'manifest.json', 'styles.css'];
|
|
for (const f of files) {
|
|
const src = path.join(pluginRoot, f);
|
|
if (!fs.existsSync(src)) {
|
|
console.error(`missing build artifact: ${src} (run npm run build first)`);
|
|
process.exit(1);
|
|
}
|
|
const dst = path.join(targetDir, f);
|
|
fs.copyFileSync(src, dst);
|
|
console.log(`copied ${f} -> ${dst}`);
|
|
}
|
|
|
|
// Stage the obsidian-remote-server binaries (if any) so the plugin
|
|
// can ship one to the remote at connect time. Built by
|
|
// `npm run build:server`; missing means "no auto-deploy this run",
|
|
// not an error.
|
|
const serverBinDir = path.join(pluginRoot, 'server-bin');
|
|
if (fs.existsSync(serverBinDir)) {
|
|
const binTarget = path.join(targetDir, 'server-bin');
|
|
fs.mkdirSync(binTarget, { recursive: true });
|
|
for (const f of fs.readdirSync(serverBinDir)) {
|
|
const src = path.join(serverBinDir, f);
|
|
if (!fs.statSync(src).isFile()) continue;
|
|
const dst = path.join(binTarget, f);
|
|
fs.copyFileSync(src, dst);
|
|
console.log(`copied server-bin/${f} -> ${dst}`);
|
|
}
|
|
// Mark this as a DEV-staged daemon so the plugin trusts it over a
|
|
// downloaded binary. locateDaemonBinary requires this marker; without it a
|
|
// downloaded binary at the same filename would be re-validated (sha) and
|
|
// replaced on a version bump instead of being treated as a dev build.
|
|
fs.writeFileSync(path.join(binTarget, '.dev-daemon'), '');
|
|
console.log('wrote server-bin/.dev-daemon marker');
|
|
} else {
|
|
console.log('server-bin/ not present — skipping daemon staging (run `npm run build:server` to build it)');
|
|
}
|
|
|
|
console.log(`\nplugin '${manifest.id}' v${manifest.version} installed to ${targetDir}`);
|
|
console.log('Reload the plugin in Obsidian (Settings → Community plugins → toggle off/on).');
|