electron-builder (27.0.0-alpha.6) moves the payload with builder-util, which
loses two classes of entries:
- builder-util dist/fs.js:58: walk() drops every entry named .gitkeep or
.DS_Store before it consults the caller's filter (line 63).
- builder-util dist/fs.js:225-253: copyDir() creates a directory only when
it copies a file or symlink into it ("Empty directories is never
created.").
The payload goes through them at three points after preparation:
- the extraResources copy into resources/agent-payload (app-builder-lib
dist/fileMatcher.js:462 copyFiles -> copyDir, from platformPackager.js:303),
on every OS;
- the AppImage target, which copies the whole appOutDir into its squashfs
stage (dist/targets/linux/appimage/appImageUtil.js:19 and :54, copyDir);
- the MSIX/AppX targets, whose makeappx file map lists appOutDir with walk()
(dist/targets/win/winAppUtil.js:120).
A Linux arm64 AppImage built at 7b0a2cdbdf lost 6 of 130,707 payload
entries: three empty llama.cpp directories, uv-cache/builds-v0,
contributors/emails/.gitkeep and pnpm's
dist/node_modules/undici/lib/llhttp/.gitkeep. That last file is part of
pnpm's recorded tree digest, so `hermes pm doctor` in the packaged payload
reports "pnpm: realized bytes do not match recorded digest" while the
pre-packaging payload smoke passes. The Nov 10 macOS canary zip lacks the
same .gitkeep.
An extraResources filter cannot help: walk() skips the names before any
filter runs, and no filter makes copyDir create a directory. Restoring the
entries in afterPack fixes only the first copy; a build with such a restore
still shipped an AppImage without them, because the AppImage stage copies
appOutDir again with the same copyDir, and the MSIX file map walks it with
the same walk(). Rehashing digests over the copy would hide the loss.
run-electron-builder.mjs now starts the builder child with
patch-electron-builder-copy.mjs, which rewrites builder-util's fs.js in
memory through a module load hook: walk() keeps the two names, and copyDir()
creates every directory it walks. This follows
patch-electron-builder-mac-binary.mjs, never touches node_modules, and
throws if either needle is missing, so an electron-builder upgrade that
changes this code fails the build instead of silently dropping files.
App files keep excluding .gitkeep and .DS_Store: the `files` matcher
appends electron-builder's default-ignored names to its own patterns
(fileMatcher.js getDefaultIgnoredPatterns), independently of walk().
The preload goes in as a file URL because --import reads a bare Windows
path's drive letter as a URL scheme.
The test launches node with the exact flags runElectronBuilder gives the
builder child, then runs builder-util's copyDir and walk over a fixture
payload. On the base the copy lacks both .gitkeep files, the .DS_Store and
every empty directory.
45 lines
1.6 KiB
JavaScript
45 lines
1.6 KiB
JavaScript
// builder-util's walk() drops .gitkeep/.DS_Store and copyDir() never makes empty dirs; the payload needs every entry.
|
|
import path from 'node:path'
|
|
import { createRequire, registerHooks } from 'node:module'
|
|
import { pathToFileURL } from 'node:url'
|
|
|
|
const require = createRequire(import.meta.url)
|
|
const builderUtil = createRequire(require.resolve('app-builder-lib')).resolve('builder-util')
|
|
const fsUrl = pathToFileURL(path.join(path.dirname(builderUtil), 'fs.js')).href
|
|
|
|
const patches = [
|
|
[
|
|
` if (name === ".DS_Store" || name === ".gitkeep") {
|
|
return null;
|
|
}
|
|
`,
|
|
''
|
|
],
|
|
[
|
|
` consume: async (file, stat, parent) => {
|
|
if (!stat.isFile() && !stat.isSymbolicLink()) {`,
|
|
` consume: async (file, stat, parent) => {
|
|
if (stat.isDirectory()) {
|
|
await mkdir(file.replace(src, destination), { recursive: true });
|
|
return;
|
|
}
|
|
if (!stat.isFile() && !stat.isSymbolicLink()) {`
|
|
]
|
|
]
|
|
|
|
// Transform builder-util in memory only; an upstream shape change must fail the build, not drop files again.
|
|
registerHooks({
|
|
load(url, context, nextLoad) {
|
|
const loaded = nextLoad(url, context)
|
|
if (url !== fsUrl) return loaded
|
|
let source = loaded.source.toString()
|
|
for (const [needle, replacement] of patches) {
|
|
if (!source.includes(needle)) {
|
|
throw new Error('builder-util copy shape changed; revalidate patch-electron-builder-copy.mjs')
|
|
}
|
|
source = source.replace(needle, replacement)
|
|
}
|
|
return { ...loaded, source }
|
|
}
|
|
})
|