Skip to content

The agent that grows with you

fix(desktop): reuse running Node for renderer syntax checks

funky-xamarinc7d193a127e5
diff --git a/apps/desktop/scripts/assert-dist-built.mjs b/apps/desktop/scripts/assert-dist-built.mjs
index 925263b333e..3a74fea13b5 100644
--- a/apps/desktop/scripts/assert-dist-built.mjs
+++ b/apps/desktop/scripts/assert-dist-built.mjs
@@ -111,8 +111,7 @@ function verifyChunksParse(assetsDir) {
return { ok: true }
}
- const nodeBin = process.env.NODE ||
- (process.execPath && process.execPath.endsWith("node") ? process.execPath : "node")
+ const nodeBin = process.env.NODE || process.execPath || "node"
const checker = join(import.meta.dirname, "check-chunks-parse.mjs")
const probe = spawnSync(nodeBin, ["--experimental-vm-modules", checker, assetsDir], {
encoding: "utf8",
diff --git a/tests-js/renderer-syntax-node.test.mjs b/tests-js/renderer-syntax-node.test.mjs
new file mode 100644
index 00000000000..802f4317ea1
--- /dev/null
+++ b/tests-js/renderer-syntax-node.test.mjs
@@ -0,0 +1,33 @@
+import { execFileSync } from 'node:child_process'
+import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
+import { tmpdir } from 'node:os'
+import { join } from 'node:path'
+import { expect, test } from 'vitest'
+
+const checker = new URL('../apps/desktop/scripts/assert-dist-built.mjs', import.meta.url).href
+
+test('renderer syntax checks use the running Node without PATH and preserve explicit NODE', () => {
+ const root = mkdtempSync(join(tmpdir(), 'renderer check with spaces-'))
+ const asset = join(root, 'assets', 'index-fixture.js')
+ mkdirSync(join(root, 'assets'))
+ writeFileSync(join(root, 'index.html'), '<!doctype html>')
+ const env = Object.fromEntries(Object.entries(process.env)
+ .filter(([key]) => !['PATH', 'NODE'].includes(key.toUpperCase())))
+ const check = (node) => JSON.parse(execFileSync(process.execPath, [
+ '--input-type=module', '-e',
+ `import { checkDistBuilt } from ${JSON.stringify(checker)}; console.log(JSON.stringify(checkDistBuilt(process.argv[1])))`,
+ root,
+ ], { cwd: root, env: { ...env, PATH: '', ...(node ? { NODE: node } : {}) }, encoding: 'utf8' }))
+ try {
+ // Parsing must not evaluate the renderer, even when its code would throw.
+ writeFileSync(asset, 'export const value = 1; throw new Error("do not execute")')
+ expect(check()).toEqual({ ok: true })
+ expect(check(process.execPath)).toEqual({ ok: true })
+ writeFileSync(asset, 'export const = ;')
+ expect(check()).toMatchObject({ ok: false, error: expect.stringContaining('not valid ES module syntax') })
+ const missingNode = join(root, 'missing-node')
+ expect(check(missingNode)).toMatchObject({ ok: false, error: expect.stringContaining('could not run node') })
+ } finally {
+ rmSync(root, { recursive: true, force: true })
+ }
+})