Files
wekan/tests/fixtures
Lauri Ojansivu 35cf025f07 Run the Windows single EXE from the archive instead of unpacking it
The EXE unpacked its whole bundle - 39,035 files, 685 MB - beside itself on
first run. It does not any more. It unpacks only what cannot be virtual, and
the server reads the rest out of the EXE in its own process.

What cannot be virtual, and why: node.exe and ferretdb.exe are separate
processes, so Windows needs a real path to start one; .node addons are loaded
with LoadLibrary, same reason; main.js is the entry Node resolves before any
hook could see it; start-wekan.bat is read by cmd.exe; and wekan-vfs.cjs is
read by node --require before anything is mounted. main.js also chdir()s into
programs/server, and a working directory is a kernel concept no hook can
answer, so that one directory is created for real. That is about thirty files
out of 39,035. releases/append-windows-payload.mjs --manifest computes the
list from the archive and writes it as a C header the launcher includes, so a
bundle that gains an addon or a database tool cannot silently lose it.

The mount itself is releases/single-exe/wekan-vfs.cjs. It needs two
mechanisms, because Node needs both:

  - module.registerHooks() for require(). Node's CJS loader resolves through
    internal C++ bindings, so patching fs cannot make require see a virtual
    file, and Module._stat is captured as a module-local inside
    Module._findPath, so replacing it does nothing either. Resolution is
    therefore reimplemented here - and checked against Node's own answer for
    every package in a real bundle: 1407 package directories and 1865 bare
    specifiers, all matching.
  - fs patching for everything that is not a module. Meteor's boot.js reads
    program.json and every server package with fs.readFileSync and runs them
    through vm.runInThisContext, and webapp serves the client files with
    fs.createReadStream.

And one thing below both: Meteor's runtime.js hands reify a resolver that
calls Module._resolveFilename directly. registerHooks sits above that call and
never sees it, so that layer is patched too.

Two traps, both hit while building this. A .node addon must be resolved with
NO format declared: saying "commonjs" for one makes Node compile the binary as
JavaScript and die with "SyntaxError: Invalid or unexpected token" on its own
header - the 11.48 crash reproduced from the other side. And a directory that
exists both really and in the archive has to merge both listings, or
wekan-app/programs/server would list the two unpacked files and hide the
entire server.

Verified end to end on a real bundle rather than by reading: with 23 real
files on disk and 38,931 served from the ZIP, WeKan boots, connects to
FerretDB and answers 200 on /sign-in and on its 6.9 MB client bundle. The
release smoke test now also counts what reached the disk, so a change that
quietly went back to unpacking everything fails the job instead of passing it.

Thanks to xet7 !
2026-09-04 16:16:15 +03:00
..