Skip to content

The agent that grows with you

fix(desktop-build): `npm run builder -- --win --x64` can stage its per-target native deps

Teknium91e27b6c095e
diff --git a/apps/desktop/scripts/run-electron-builder.test.mjs b/apps/desktop/scripts/run-electron-builder.test.mjs
index c20dbc8e342..2fec7d86d8f 100644
--- a/apps/desktop/scripts/run-electron-builder.test.mjs
+++ b/apps/desktop/scripts/run-electron-builder.test.mjs
@@ -7,6 +7,7 @@ import fs from 'node:fs'
import os from 'node:os'
import { publishPackagingInputs } from './prepared-packaging.mjs'
import { recordNativeInputs } from './prepared-native-deps.mjs'
+import { productOutput } from '../../../scripts/build/frontend-common.mjs'
test('validate-only admits real prepared inputs without launching tools and rejects unsafe arguments', async () => {
const source = path.resolve(import.meta.dirname, '../../..')
@@ -51,6 +52,13 @@ test('source multiarch prepares isolated native and packaging inputs before each
}
assert.equal(calls.length, 6)
assert.notEqual(calls[0][calls[0].indexOf('--out') + 1], calls[3][calls[3].indexOf('--out') + 1])
+ // Each per-target native dir is one stage-native-deps.mjs may publish: its product guard admits
+ // only generated homes in the tree (an arch flag on a source build failed there before staging).
+ const source = path.resolve(import.meta.dirname, '../../..')
+ for (const call of calls.filter(args => args[0].endsWith('stage-native-deps.mjs'))) {
+ const out = call[call.indexOf('--out') + 1]
+ assert.doesNotThrow(() => productOutput(source, out, ['node_modules', 'apps/desktop/node_modules', 'apps/desktop/src', 'apps/desktop/electron']), out)
+ }
calls.length = 0
assert.equal(runElectronBuilder(['--dir'], { spawn }), 0)
assert.equal(calls.filter(args => args[0].endsWith('prepare-packaging-tools.mjs')).length, 1)
diff --git a/scripts/build/frontend-common.mjs b/scripts/build/frontend-common.mjs
index 213223c4b45..344962c97e5 100644
--- a/scripts/build/frontend-common.mjs
+++ b/scripts/build/frontend-common.mjs
@@ -33,8 +33,14 @@ const productMarker = '.hermes-product'
const productOwner = 'hermes-frontend-product-v1\n'
const developerOutputs = ['ui-tui/dist', 'hermes_cli/web_dist', 'apps/desktop/dist', 'apps/desktop/build/native-deps']
+// `npm run builder -- --<platform> --<arch>` stages one native tree per target
+// (apps/desktop/scripts/run-electron-builder.mjs): build/native-deps-<platform>-<arch>.
+const nativeTargetOutput = /^apps[\\/]desktop[\\/]build[\\/]native-deps-(darwin|linux|win32)-(x64|arm64)$/
+
function developerOutput(source, out) {
- return source && developerOutputs.some(name => path.resolve(out) === path.join(path.resolve(source), name))
+ if (!source) return false
+ const relative = path.relative(path.resolve(source), path.resolve(out))
+ return developerOutputs.some(name => relative === path.join(name)) || nativeTargetOutput.test(relative)
}
// A destination name alone does not confer ownership of its existing contents.
diff --git a/tests-js/product-builders.test.mjs b/tests-js/product-builders.test.mjs
index 1f5a7ef2b1f..253b96370c5 100644
--- a/tests-js/product-builders.test.mjs
+++ b/tests-js/product-builders.test.mjs
@@ -51,10 +51,12 @@ test('product outputs exclude the source tree except supported generated destina
const base = fixture()
const source = path.join(base, 'source')
mkdirSync(source)
- for (const name of ['new-source-file', 'pm/generated', 'hermes_cli/web_dist-copy', 'apps/desktop/dist-copy', 'apps/desktop/build/native-deps-copy', 'hermes_cli/web_dist/assets']) {
+ for (const name of ['new-source-file', 'pm/generated', 'hermes_cli/web_dist-copy', 'apps/desktop/dist-copy', 'apps/desktop/build/native-deps-copy', 'hermes_cli/web_dist/assets',
+ 'apps/desktop/build/native-deps-win32-x64/nested', 'apps/desktop/build/native-deps-freebsd-x64', 'apps/desktop/build/native-deps-win32-ia32']) {
expect(() => productOutput(source, path.join(source, name), inputs), name).toThrow(/output/i)
}
- for (const name of ['hermes_cli/web_dist', 'apps/desktop/dist', 'apps/desktop/build/native-deps', 'apps/desktop/build/products/tui', 'apps/desktop/build/products/web', '.build/web', '.build/termux/tui']) {
+ for (const name of ['hermes_cli/web_dist', 'apps/desktop/dist', 'apps/desktop/build/native-deps', 'apps/desktop/build/native-deps-win32-x64',
+ 'apps/desktop/build/native-deps-darwin-arm64', 'apps/desktop/build/products/tui', 'apps/desktop/build/products/web', '.build/web', '.build/termux/tui']) {
const out = path.join(source, name)
expect(productOutput(source, out, inputs).out).toBe(out)
expect(existsSync(out)).toBe(false)