Skip to content

fix(pack): handle paths containing spaces in build and dev-server - #525

Open
HoodieYlya13 wants to merge 2 commits into
ProtonMail:mainfrom
HoodieYlya13:fix/proton-pack-paths-with-spaces
Open

fix(pack): handle paths containing spaces in build and dev-server#525
HoodieYlya13 wants to merge 2 commits into
ProtonMail:mainfrom
HoodieYlya13:fix/proton-pack-paths-with-spaces

Conversation

@HoodieYlya13

Copy link
Copy Markdown

I was setting the repo up to look at something in Mail and the dev server
wouldn't start. It turned out to have nothing to do with my change:
proton-pack can't run when the checkout path contains a space.

dev-server and build fail to spawn

commandWithLog hands a single string to execa.command(), which splits it on
whitespace to decide what to execute. The string is built from
require.resolve('webpack-cli/bin/cli.js'), an absolute path, so once the repo
lives somewhere with a space in it the executable path itself gets split:

syscall: 'spawn /Users/me/Dev/clients/2',
spawnargs: [ '-', 'Proton/WebClients/node_modules/webpack-cli/bin/cli.js', 'serve', ... ]

ENOENT, with nothing pointing at the real cause.

The cleanup step deletes the wrong directory

build cleans its output with the same helper:

await commandWithLog(`rm -rf ${outputPath}`);

Split the same way, rm receives a truncated prefix of the intended path. I
reproduced this in a scratch directory containing dev/ next to
dev proton/WebClients/applications/mail/dist:

  • dev/ was deleted
  • the dist/ it was supposed to clean was left untouched
  • exit code 0, no output, because -f suppresses the error

So it removes something unrelated and silently skips its actual job. Whether it
destroys anything depends on the truncated prefix happening to exist, which
isn't a comfortable thing to leave to chance.

validate.sh reports healthy files as empty

With the spawn issue fixed, build still failed. detectEmpty iterates an
unquoted command substitution:

for file in $(echo "$OUTPUT_FILES" | grep -E "\.$1$"); do

bash word-splits each path on spaces, [ ! -s "$file" ] is true for every
fragment, and real chunks get reported as empty:

[error] empty file: Proton/Proton-WebClients/applications/mail/dist/assets/static/6127.a83bf143.chunk.js.map

Changes

  • protonPack.js: use execa's array form for the calls containing resolved
    paths, so arguments are passed as argv and never re-parsed. getWebpackArgs
    returns an array instead of a joined string, and the resolved CLI runs through
    process.execPath so it doesn't depend on the file's exec bit.
    commandWithLog is kept for the tar call, which needs shell: true for the
    glob.
  • validate.sh: read the file list line by line instead of iterating an
    unquoted substitution. Also switched ((total++)) to total=$((total + 1)),
    since the former returns exit 1 on the first increment and the script runs
    under set -e.

Testing

From a path containing a space: yarn workspace proton-mail start serves the
app, and yarn workspace proton-mail build:web completes (1086 files in
dist, 35M bundle) where both previously failed. The rm -rf behaviour above
was checked in a scratch directory, before and after.

@mmso
mmso force-pushed the main branch 2 times, most recently from 896ff9e to 06694ac Compare August 5, 2026 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant