Skip to content

feat(nodeenv): install local packages from a requirements file - #407

Merged
ekalinin merged 1 commit into
masterfrom
feat/local-requirements
Sep 20, 2026
Merged

ekalinin merged 1 commit into
masterfrom
feat/local-requirements

Conversation

@ekalinin

Copy link
Copy Markdown
Owner

Closes #206.

Problem

-r/--requirements took a single value: no action='append', no nargs. Repeating the flag silently kept the last file, with no error and no merge:

-r global-req.txt -r local-req.txt  ->  requirements = 'local-req.txt'

And install_packages() always installed globally (npm install -g), with no option anywhere in --help asking for a local install. The gap is visible from the other side too: freeze -l was added for #71 and is documented in the README, so nodeenv could produce a list of locally installed packages but not install one. The file it printed, fed back through -r, installed globally.

Change

  • -r/--requirements may be given more than once; files are read in the order given.
  • New --local-requirements, also repeatable, installs the packages of a file without -g, into node_modules of the directory nodeenv was invoked from. That is the directory freeze -l was run from, and the one node resolves from when the project runs.
  • Global packages are installed first, then the local ones.
$ cd myproject
$ nodeenv --requirements=global-req.txt --local-requirements=local-req.txt env
myproject/
├── env/
│   └── lib/node_modules/   <- from -r
└── node_modules/           <- from --local-requirements

-r file behaves exactly as before, and requirements is not a Config attribute, so ~/.nodeenvrc, tox.ini and setup.cfg are unaffected. The --update path needed no change: it calls install_packages() directly, which now handles both lists.

The npm < 1.0.0 branch (npm install + npm activate) is left alone - it has no -g to drop, so a local file is still installed the old way there. Noted in CHANGES.

Tests

install_packages() had no test at all. Four new ones cover the repeated -r, the new flag, and the generated npm commands (-g present for global files in file order, absent for local ones, locals last).

Verified on a real environment as well: nodeenv --node=system -r glob.txt --local-requirements loc.txt env puts left-pad in env/lib/node_modules and mime in ./node_modules; freeze and freeze -l in that environment then print the two lists back.

-r could only be given once and always installed globally, so the list
that `freeze -l` writes had no way back in. -r now accepts repeated use,
and --local-requirements installs the packages of a file into
"node_modules" of the current directory. Global packages go first.

npm < 1.0.0 has no -g at all, so a local file is still installed the old
way there.

#206
@ekalinin
ekalinin merged commit dcaa7f5 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.

Global AND local modules at initial setup

1 participant