Skip to content

The agent that grows with you

perf(desktop): skip restaging native inputs whose receipt still matches

kshitijk4poor97260490e1d6
diff --git a/apps/desktop/scripts/build.mjs b/apps/desktop/scripts/build.mjs
index 3c635c080fe..fd1ecacb7e0 100644
--- a/apps/desktop/scripts/build.mjs
+++ b/apps/desktop/scripts/build.mjs
@@ -4,6 +4,7 @@ import { cpSync } from 'node:fs'
import { join, resolve } from 'node:path'
import { parseArgs } from 'node:util'
import { isMain, repoRoot } from '../../../scripts/build/frontend-common.mjs'
+import { readNativeInputs } from './prepared-native-deps.mjs'
export function buildSourceDesktop({ source = repoRoot, icons, run = execFileSync } = {}) {
source = resolve(source)
@@ -22,9 +23,21 @@ export function buildSourceDesktop({ source = repoRoot, icons, run = execFileSyn
}
// locales/_keys.desktop.json is a committed artifact (i18n-keys.test.mjs pins it to en.ts);
// the build must not write into the checkout — a dirty tree breaks `hermes update`.
- step('apps/desktop/scripts/stage-native-deps.mjs')
+ // The native inputs carry their own receipt (inputs identity + tree digest): restaging the
+ // same sources recompiles two universal helpers for identical bytes on every update.
+ const nativeDeps = join(app, 'build/native-deps')
+ if (!nativeCurrent({ source, nativeDeps })) step('apps/desktop/scripts/stage-native-deps.mjs')
step('scripts/build/desktop.mjs', ['--source', source, '--icons', icons,
- '--stamp', join(app, 'build/install-stamp.json'), '--native-deps', join(app, 'build/native-deps'), '--out', join(app, 'dist')])
+ '--stamp', join(app, 'build/install-stamp.json'), '--native-deps', nativeDeps, '--out', join(app, 'dist')])
+}
+
+function nativeCurrent(inputs) {
+ try {
+ readNativeInputs(inputs)
+ return true
+ } catch {
+ return false
+ }
}
if (isMain(import.meta.url)) {
diff --git a/tests-js/desktop-builder.test.mjs b/tests-js/desktop-builder.test.mjs
index c14cccfc1ea..81f3f690036 100644
--- a/tests-js/desktop-builder.test.mjs
+++ b/tests-js/desktop-builder.test.mjs
@@ -23,6 +23,28 @@ test('desktop development composition reuses prepared icon pixels instead of pro
expect(compile[compile.indexOf('--icons') + 1]).toBe(input.icons)
})
afterEach(() => { for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true }) })
+
+test('desktop development composition restages native inputs only when their receipt is stale', async () => {
+ const { buildSourceDesktop } = await import('../apps/desktop/scripts/build.mjs')
+ const { recordNativeInputs } = await import('../apps/desktop/scripts/prepared-native-deps.mjs')
+ const input = fixture()
+ put(join(input.source, 'package-lock.json'), '{}')
+ const nativeDeps = join(input.source, 'apps/desktop/build/native-deps')
+ cpSync(input.nativeDeps, nativeDeps, { recursive: true })
+ const staged = () => {
+ const commands = []
+ buildSourceDesktop({ source: input.source, run: (command, args) => commands.push([command, ...args]) })
+ return commands.some(command => command.some(arg => /stage-native-deps\.mjs$/.test(arg)))
+ }
+ expect(staged()).toBe(true) // no receipt
+ recordNativeInputs({ source: input.source, out: nativeDeps, platform: process.platform, arch: process.arch })
+ expect(staged()).toBe(false)
+ put(join(nativeDeps, 'native/helper-fixture'), 'tampered')
+ expect(staged()).toBe(true) // the tree no longer matches its digest
+ recordNativeInputs({ source: input.source, out: nativeDeps, platform: process.platform, arch: process.arch })
+ put(join(input.source, 'package-lock.json'), '{"lockfileVersion":3}')
+ expect(staged()).toBe(true) // a dependency pin moved
+})
function put(path, text) { mkdirSync(dirname(path), { recursive: true }); writeFileSync(path, text) }
function fixture() {
const root = mkdtempSync(join(tmpdir(), 'desktop build with spaces-'))