Keep two more build paths out of the desktop bundle

The leak check from #765 caught two that older builds shipped:

- The embedded Python smoke test wrote .pyc files after staging, and each
  records the build checkout path. It now runs with -B.
- Webpack bakes maplibre-gl's import.meta.url into a JS chunk as a file://
  URL of the checkout. The export now swaps that root for a neutral one; the
  URL never resolves on a user's machine, so nothing changes at runtime.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
BigBodyCobainandClaude Opus 5.5 committed 2026-12-02 17:33:59 -07:00
1 parent 49fd217c27
commit 121ccd1b93
2 files changed
+36

No files matched your search

@@ -395,10 +395,14 @@ function verifyRelocatableWindowsRuntime() {
const env = { ...process.env };
delete env.PYTHONHOME;
delete env.PYTHONPATH;
// -B: the probe must not leave .pyc files behind; they record this
// machine's build path and would ship in the bundle.
env.PYTHONDONTWRITEBYTECODE = '1';
result = spawnSync(
path.join(probeDir, 'python', 'python.exe'),
[
'-I',
'-B',
'-c',
[
'import sys',
@@ -1,7 +1,9 @@
#!/usr/bin/env node
const fs = require('node:fs');
const os = require('node:os');
const path = require('node:path');
const { pathToFileURL } = require('node:url');
const { spawnSync } = require('node:child_process');
const scriptDir = __dirname;
@@ -100,10 +102,40 @@ function runExportBuild() {
}
}
// Webpack turns `import.meta.url` into a file:// URL of this machine's
// checkout (maplibre-gl's worker fallback does this). That URL never resolves
// on a user's machine, so a neutral root changes nothing at runtime and keeps
// the build path out of the shipped bundle.
function scrubBuildPaths(dir) {
const replacements = [
[pathToFileURL(repoRoot).href, 'file:///shadowbroker'],
[pathToFileURL(os.homedir()).href, 'file:///~'],
];
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
const full = path.join(dir, entry.name);
if (entry.isDirectory()) {
scrubBuildPaths(full);
continue;
}
if (!/\.(?:js|mjs|html|json|txt|map|css)$/i.test(entry.name)) {
continue;
}
const text = fs.readFileSync(full, 'utf8');
let scrubbed = text;
for (const [from, to] of replacements) {
scrubbed = scrubbed.split(from).join(to);
}
if (scrubbed !== text) {
fs.writeFileSync(full, scrubbed);
}
}
}
function syncBuildOutput() {
if (!fs.existsSync(buildOutDir)) {
throw new Error(`Desktop export did not produce ${buildOutDir}`);
}
scrubBuildPaths(buildOutDir);
fs.rmSync(liveOutDir, { recursive: true, force: true });
fs.cpSync(buildOutDir, liveOutDir, {
recursive: true,