Repository navigation
feat(nodeenv): add --isolate-npm to keep npm config inside the environment - #396
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #154
Summary
Adds
--isolate-npm(and theisolate_npmkey in~/.nodeenvrc): when set, the generatedbin/activate,bin/activate.fishand the node shim exportnpm_config_cache,npm_config_userconfigandnpm_config_init_modulepointing inside the environment ($NODE_VIRTUAL_ENV/.npm,.npmrc,.npm-init.js), anddeactivate_noderestores the previous values.Today only
prefixis redirected, so npm'scache,userconfigandinit-modulestill live under$HOME. When$HOMEis missing or read-only (the reporter's case,HOME=/nonexistent),npm installinside an activated environment fails withENOENT ... mkdir '/nonexistent'.userconfigby default would silently drop private registries and auth tokens from~/.npmrc; redirectingcacheby default would stop the cache being shared across environments.$prefix/etc/npmrc: npm reads the user config before the global one, so auserconfigline in globalconfig is displayed bynpm config ls -lbut never used (checked on npm 11). One mechanism for all three keeps it in line with howprefixis handled.npm_config_*variables are set; npm matches env keys case-insensitively, so the uppercase duplicate thatprefixcarries is not repeated.prefix:activate,activate.fish,shim(andbin/nodefor--node=system). The Windows scripts do not configure npm today and are left as they are; on win32 the flag logs a warning (not for--list) and is otherwise ignored.if set -q NODE_VIRTUAL_ENV, so thedeactivate_node nondestructivepass at the top ofactivate.fishdoes not erase pre-existingnpm_config_*values before they are saved.Changes
nodeenv.py:Config.isolate_npm,--isolate-npmargument,NPM_ISOLATE/NPM_UNISOLATEsnippet dicts next toDISABLE_PROMPT/ENABLE_PROMPT,__NPM_ISOLATE__/__NPM_UNISOLATE__placeholders inACTIVATE_SH,ACTIVATE_FISHandSHIM, their replacement ininstall_activate(), win32 warning inmain().tests/test_install_activate.py: default-off check; sh test that sources the generatedactivateinshand checks the values both while active and afterdeactivate_node; fish content test (guard, save, restore, cleanup lines); shim content test;--node=systemtest that runs the generatedbin/nodethrough a fake node and reads the exported values back; placeholder test now runs with and without the flag.tests/nodeenv_test.py: config default,~/.nodeenvrcloading, argparse, win32 warning, no warning on posix, no warning with--list.README.rst,CHANGES: option description, config block line, changelog entry.Checks
pytest tests -m "not integration": 228 passedflake8 --extend-ignore=E127 nodeenv.py tests setup.py: cleannodeenv --isolate-npm --prebuilt env, after. env/bin/activatethecache,userconfigandinit-moduleentries ofnpm config ls -lpoint underenv/;HOME=/nonexistent npm install is-oddsucceeds (onmasterit fails with theENOENTabove); afterdeactivate_nodethe three variables are back to their previous values.activate,activate.fishandshimwithout the flag compared againstmaster: identical ignoring blank lines.Not covered here
$NODE_VIRTUAL_ENVpath whileprefixgoes throughcygpath -w; the existingSHIMhas the same inconsistency forNPM_CONFIG_PREFIX.fishis not installed locally).deactivate_node nondestructivebehaviour inactivate.fishforNODE_PATH,NPM_CONFIG_PREFIXandnpm_config_prefixis left as is.