Skip to content

feat(nodeenv): clean "src" directory by default - #404

Merged
ekalinin merged 2 commits into
masterfrom
feat/clean-src-by-default
Sep 20, 2026
Merged

ekalinin merged 2 commits into
masterfrom
feat/clean-src-by-default

Conversation

@ekalinin

Copy link
Copy Markdown
Owner

Closes #205.

Problem

A prebuilt install leaves a full copy of node under <env>/src, so an environment is twice the size it needs to be. Measured on macOS arm64 with node 26.9.0:

nodeenv --prebuilt ne1              -> 441M total, src/ = 221M
nodeenv --prebuilt --clean-src ne1c -> 221M total

Nothing reads that copy back. The "already downloaded" check looks for src/node-v<ver>, while a prebuilt archive unpacks into src/node-v<ver>-<platform>, so in the default mode the directory is not even a download cache - the tarball is downloaded again on every run.

Two smaller facts from the same path: clean_src was not a Config attribute, so it could not be set in a config file at all, and -n system created src unconditionally and left it empty.

Change

--clean-src is now the default, and --no-clean-src opts out.

Keeping src is worth it in exactly one case: with --source the directory holds the source tree that a repeated --force build reuses. That case now needs --no-clean-src, which is noted in CHANGES. A default that differs per install mode would be invisible from --help, so both modes clean by default.

--clean-src and -c keep working. pre-commit passes the flag explicitly (['-mnodeenv', '--prebuilt', '--clean-src', envdir]), and a test asserts it still parses.

clean_src also becomes a Config attribute, so it can be set in tox.ini, setup.cfg or ~/.nodeenvrc:

[nodeenv]
clean_src = False

mkdir(src_dir) stays unconditional: the empty src from -n system is now removed by the default cleanup, and it survives only under an explicit --no-clean-src, which is what that flag asks for.

Verified

command src after the run
nodeenv --prebuilt ne1 removed, 221M, node and npm work
nodeenv --prebuilt --no-clean-src ne2 kept, 441M
nodeenv -n system ne3 removed (used to be an empty directory)
clean_src = false in a config file kept
nodeenv -n system -c ne5 removed, flag still accepted

235 tests pass (233 unit plus the 2 integration smoke tests), flake8 --extend-ignore=E127 nodeenv.py tests setup.py is clean.

Out of scope

A shared download cache outside the environment, which would fix the repeated downloads that prebuilt mode does today. That also makes the dead node_src_dir check meaningful again, and both belong together in a separate change.

A prebuilt install leaves a full copy of node under <env>/src, so an
environment is twice the size it needs to be: 441M instead of 221M for
node 26.9.0.

Nothing reads that copy back. The "already downloaded" check looks for
src/node-v<ver>, while a prebuilt archive unpacks into
src/node-v<ver>-<platform>, so in the default mode the directory is not
even a download cache.

Flip --clean-src on by default and add --no-clean-src for the case that
does benefit from keeping it: with --source the directory holds the
source tree a repeated --force build reuses. --clean-src and -c keep
working, pre-commit passes the flag explicitly.

clean_src also becomes a Config attribute, so it can now be set in
tox.ini, setup.cfg or ~/.nodeenvrc.

Closes #205
@ekalinin
ekalinin force-pushed the feat/clean-src-by-default branch from c39b05d to 4cd4d9d Compare September 20, 2026 11:59
@ekalinin
ekalinin merged commit 4b20189 into master Sep 20, 2026
42 checks passed
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.

Consider defaulting --clean-src to True

1 participant