mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 07:50:13 +00:00
fix(cli): only name a shadowing install whose manager can move it (#7499)
A project-local node_modules/.bin/hyperframes can shadow plain npx hyperframes, but npm install -g never updates it. Classify the shadowing copy like the running one: global installs keep their manager's command, project-local installs get the project's own manager (from its lockfile), and unknown layouts stay quiet. The command pins the release the npx copy is running.
This commit is contained in:
@@ -303,10 +303,45 @@ describe("shadowingInstall: the older global install a plain `npx hyperframes` r
|
||||
const { shadowingInstall } = await import("./installerDetection.js");
|
||||
expect(shadowingInstall("0.9.29")).toEqual({
|
||||
version: "0.9.8",
|
||||
updateCommand: "npm install -g hyperframes@latest",
|
||||
updateCommand: "npm install -g hyperframes@0.9.29",
|
||||
});
|
||||
});
|
||||
|
||||
/** Swaps the global install for a package at `pkgDir` (relative to the layout root) on PATH. */
|
||||
function onPathInstead(root: string, pkgDir: string): string {
|
||||
const pkg = join(root, pkgDir);
|
||||
mkdirSync(join(pkg, "bin"), { recursive: true });
|
||||
writeFileSync(
|
||||
join(pkg, "package.json"),
|
||||
JSON.stringify({ name: "hyperframes", version: "0.9.8" }),
|
||||
);
|
||||
writeFileSync(join(pkg, "bin/hyperframes.mjs"), "");
|
||||
const bin = join(root, "other-bin");
|
||||
mkdirSync(bin, { recursive: true });
|
||||
symlinkSync(join(pkg, "bin/hyperframes.mjs"), join(bin, "hyperframes"));
|
||||
const [npxBin] = (process.env["PATH"] ?? "").split(delimiter);
|
||||
process.env["PATH"] = [npxBin, bin].join(delimiter);
|
||||
return pkg;
|
||||
}
|
||||
|
||||
it("moves an older project-local install with the project's own manager", async () => {
|
||||
const root = layout(null);
|
||||
onPathInstead(root, "app/node_modules/hyperframes");
|
||||
writeFileSync(join(root, "app/bun.lock"), "");
|
||||
const { shadowingInstall } = await import("./installerDetection.js");
|
||||
expect(shadowingInstall("0.9.29")).toEqual({
|
||||
version: "0.9.8",
|
||||
updateCommand: "bun add hyperframes@0.9.29",
|
||||
});
|
||||
});
|
||||
|
||||
it("stays quiet when no manager is known to move the older install", async () => {
|
||||
const root = layout(null);
|
||||
onPathInstead(root, "opt/hyperframes");
|
||||
const { shadowingInstall } = await import("./installerDetection.js");
|
||||
expect(shadowingInstall("0.9.29")).toBeNull();
|
||||
});
|
||||
|
||||
it("stays quiet when the global install is not older, or there is none", async () => {
|
||||
const { shadowingInstall } = await import("./installerDetection.js");
|
||||
layout("0.9.29");
|
||||
|
||||
@@ -235,7 +235,11 @@ export function runningInstall(): RunningInstall {
|
||||
const path = resolveEntry();
|
||||
// plugin-cli.mjs runs a pinned `npx hyperframes@<version>` and marks the child with this.
|
||||
if (process.env["HYPERFRAMES_PLUGIN_VERSION"]) return { channel: "plugin", path };
|
||||
const installer = detectInstaller();
|
||||
return installAt(path);
|
||||
}
|
||||
|
||||
function installAt(path: string | null): RunningInstall {
|
||||
const installer = detectInstaller(path);
|
||||
if (installer.kind !== "skip") return { channel: installer.kind, path };
|
||||
if (!path) return { channel: "unknown", path };
|
||||
if (isWorkspaceLink(path)) return { channel: "workspace", path };
|
||||
@@ -306,6 +310,8 @@ function packageVersionAbove(entry: string): string | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
const UPDATABLE_CHANNELS = new Set<InstallChannel>(["npm", "pnpm", "bun", "brew", "project"]);
|
||||
|
||||
export interface ShadowingInstall {
|
||||
version: string;
|
||||
/** What moves that install to the latest release. */
|
||||
@@ -338,8 +344,9 @@ function isOlder(version: string, than: string): boolean {
|
||||
}
|
||||
|
||||
/**
|
||||
* The older global install a plain `npx hyperframes` runs instead of this npx copy: the first
|
||||
* `hyperframes` on PATH outside the npx cache, when it is older than `current`. Agents never update
|
||||
* The older install a plain `npx hyperframes` runs instead of this npx copy: the first
|
||||
* `hyperframes` on PATH outside the npx cache, when it is older than `current` and its manager
|
||||
* (global or the project's) can move it. Agents never update
|
||||
* it (no notice, no auto-install unattended), so it only moves when the person runs this command.
|
||||
* ponytail: POSIX shims only; Windows `.cmd` shims are not looked up.
|
||||
*/
|
||||
@@ -348,7 +355,7 @@ export function shadowingInstall(current: string): ShadowingInstall | null {
|
||||
const global = firstGlobalOnPath(resolveEntry());
|
||||
const version = global ? packageVersionAbove(global) : null;
|
||||
if (!global || !version || !isOlder(version, current)) return null;
|
||||
const updateCommand =
|
||||
detectInstaller(global).installCommand("latest") ?? "npm install -g hyperframes@latest";
|
||||
return { version, updateCommand };
|
||||
const install = installAt(global);
|
||||
if (!UPDATABLE_CHANNELS.has(install.channel)) return null;
|
||||
return { version, updateCommand: updateCommandFor(install, current) };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user