fix: retarget updater to @mosaic/mosaic (#384)
This commit was merged in pull request #384.
This commit is contained in:
@@ -7,9 +7,9 @@
|
||||
|
||||
import { execFileSync, execSync, spawnSync } from 'node:child_process';
|
||||
import { existsSync, mkdirSync, readFileSync, writeFileSync, readdirSync, rmSync } from 'node:fs';
|
||||
import { createRequire } from 'node:module';
|
||||
import { homedir } from 'node:os';
|
||||
import { join, dirname } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import type { Command } from 'commander';
|
||||
|
||||
const MOSAIC_HOME = process.env['MOSAIC_HOME'] ?? join(homedir(), '.config', 'mosaic');
|
||||
@@ -498,10 +498,14 @@ function delegateToScript(scriptPath: string, args: string[], env?: Record<strin
|
||||
* CLI version) over the deployed copy in ~/.config/mosaic/ (may be stale).
|
||||
*/
|
||||
function resolveTool(...segments: string[]): string {
|
||||
// Resolve relative to the built file: dist/commands/launch.js → ../../framework/tools/...
|
||||
const thisFile = fileURLToPath(import.meta.url);
|
||||
const bundled = join(dirname(thisFile), '..', '..', 'framework', 'tools', ...segments);
|
||||
if (existsSync(bundled)) return bundled;
|
||||
try {
|
||||
const req = createRequire(import.meta.url);
|
||||
const mosaicPkg = dirname(req.resolve('@mosaic/mosaic/package.json'));
|
||||
const bundled = join(mosaicPkg, 'framework', 'tools', ...segments);
|
||||
if (existsSync(bundled)) return bundled;
|
||||
} catch {
|
||||
// Fall through to deployed copy
|
||||
}
|
||||
return join(MOSAIC_HOME, 'tools', ...segments);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user