Skip to content

The open source AI video agent: turns any coding agent into a video agent, with an editor to change anything it makes.

Desktop installer: pin the app's own dependencies that others pin older (#275)

riverisbuilding27fc721c8f2a
diff --git a/apps/desktop/scripts/locked-versions.mjs b/apps/desktop/scripts/locked-versions.mjs
index d762bbb..cd6e48a 100644
--- a/apps/desktop/scripts/locked-versions.mjs
+++ b/apps/desktop/scripts/locked-versions.mjs
@@ -13,8 +13,9 @@ const SEMVER = /^\d+\.\d+\.\d+(?:-[\w.]+)?$/;
/**
* npm `overrides` from `pnpm list --prod --depth Infinity --json` of the package (its first entry). A package locked at
* one version is pinned to it; one locked at several is pinned under each package that depends on it. The package's
- * own dependencies are not pinned themselves: they are exact in its package.json already, and npm refuses an override
- * of one.
+ * own dependencies are exact in its package.json already; one that another package depends on too is pinned to that
+ * (`$name`, the only override npm takes for one), as pnpm's own overrides lift a version a dependency pins (undici,
+ * pinned at 8.10.2 by pi-coding-agent).
* @param {{ dependencies?: Record<string, any> }} tree
*/
export function lockedOverrides(tree) {
@@ -22,12 +23,14 @@ export function lockedOverrides(tree) {
const versions = new Map();
/** @type {Array<[string, string, string]>} parent, child, child's version */
const edges = [];
+ /** names some package depends on, not only the package itself */
+ const nested = new Set();
const walk = (deps, parent) => {
for (const [name, dep] of Object.entries(deps ?? {})) {
if (SEMVER.test(dep?.version ?? '')) {
if (!versions.has(name)) versions.set(name, new Set());
versions.get(name).add(dep.version);
- if (parent) edges.push([parent, name, dep.version]);
+ if (parent) { edges.push([parent, name, dep.version]); nested.add(name); }
}
walk(dep?.dependencies, name);
}
@@ -37,12 +40,15 @@ export function lockedOverrides(tree) {
/** @type {Record<string, string | Record<string, string>>} */
const overrides = {};
- for (const [name, set] of versions) if (set.size === 1 && !direct.has(name)) overrides[name] = [...set][0];
+ for (const [name, set] of versions) {
+ if (set.size !== 1) continue;
+ if (!direct.has(name)) overrides[name] = [...set][0];
+ else if (nested.has(name)) overrides[name] = `$${name}`;
+ }
for (const [parent, child, version] of edges) {
if (versions.get(child).size === 1) continue;
- const parents = versions.get(parent);
let entry = overrides[parent];
- if (typeof entry !== 'object') entry = overrides[parent] = parents.size === 1 && !direct.has(parent) ? { '.': [...parents][0] } : {};
+ if (typeof entry !== 'object') entry = overrides[parent] = typeof entry === 'string' ? { '.': entry } : {};
/* the same parent name wanting two versions of it (two versions of the parent): left to npm */
if (entry[child] && entry[child] !== version) entry[child] = null;
else if (entry[child] !== null) entry[child] = version;
diff --git a/apps/desktop/scripts/locked-versions.test.mjs b/apps/desktop/scripts/locked-versions.test.mjs
index 74f59a7..a7ba8e2 100644
--- a/apps/desktop/scripts/locked-versions.test.mjs
+++ b/apps/desktop/scripts/locked-versions.test.mjs
@@ -11,9 +11,11 @@ const tree = {
'@earendil-works/pi-coding-agent': { version: '1.1.0', dependencies: {
'@earendil-works/pi-codemode': { version: '1.1.0' },
diff: { version: '8.0.4' },
+ undici: { version: '8.12.2' },
} },
'@agentclientprotocol/codex-acp': { version: '1.13.1', dependencies: { diff: { version: '9.0.0' } } },
diff: { version: '9.0.0' },
+ undici: { version: '8.12.2' },
openfilm: { version: 'link:../../packages/openfilm', dependencies: { 'playwright-core': { version: '1.50.0' } } },
},
};
@@ -22,6 +24,8 @@ test("the installer's npm install is pinned to the lockfile's versions", () => {
assert.deepEqual(lockedOverrides(tree), {
'@earendil-works/pi-codemode': '1.1.0',
'playwright-core': '1.50.0',
+ /* the package's own, which another depends on too (pinned there at an older version): that one everywhere */
+ undici: '$undici',
/* two versions of diff: each under what depends on it; the package's own (exact) is not overridden */
'@earendil-works/pi-coding-agent': { diff: '8.0.4' },
'@agentclientprotocol/codex-acp': { diff: '9.0.0' },