Uh oh!
There was an error while loading. Please reload this page.
module: restore and warn on require('.') usage with NODE_PATH - #1363
module: restore and warn on require('.') usage with NODE_PATH#1363silverwind wants to merge 6 commits into
Conversation
rlidwka
commented
Apr 7, 2015
Deprecation warning + note to remove this quirk in 2.0 maybe? |
silverwind
commented
Apr 7, 2015
rlidwka
commented
Apr 7, 2015
I mean, if Looking at the code, this suggestion might be too complex though. :( |
silverwind
commented
Apr 7, 2015
Looking into adding a warning. Few more notes:
|
silverwind
commented
Apr 7, 2015
One more blocking issue I've noticed: It seems the suitable |
rlidwka
commented
Apr 7, 2015
Is |
bnoordhuis
commented
Apr 7, 2015
Note that process.cwd() can fail with ENOENT if the working directory has been unlinked. |
silverwind
commented
Apr 7, 2015
Edit: I think I have an idea how to solve it. Hold on. |
97b60c4 to
712e75cComparesilverwind
commented
Apr 7, 2015
Updated with a better way of obtaining PWD, which is also resilient to Not sure the fallback to Also added a warning if |
silverwind
commented
Apr 8, 2015
Will look into changing that |
There was a problem hiding this comment.
Any advice on how to use util.deprecate in this case? It seems util.deprecate is tuned for deprecating functions. In this case, I'd like to print a single warning if this condition is met.
There was a problem hiding this comment.
just a thought, and perhaps this is too much of a hack but:
varnoopDeprecateRequireDotFile=util.deprecate(function(){},'message here')...if(request==='.'&&i>0)noopDeprecateRequireDotFile();There was a problem hiding this comment.
I'd be fine with something like that, but in the long term, we probably need something like util.warnOnce(msg). These probably shouldn't be public methods either.
silverwind
commented
Apr 11, 2015
Updated warning with suggested usage of ['.',/* NODE_PATH entries */,'node_modules','.node_libraries']If we hit a index in that array except the first, we warn once. Note that Please review @iojs/collaborators |
ef2f039 to
9a2e885CompareThere was a problem hiding this comment.
the use of a template string seems unnecessary here
There was a problem hiding this comment.
also, "did resolve" could be just "resolved"
rvagg
commented
Apr 15, 2015
lgtm, perhaps could do with a test though? we may want to at least flag it in the tests as functionality that's being used in the wild--not having that covered is why we got into this position in the first place |
silverwind
commented
Apr 15, 2015
Agreed. I first thought doing a test wasn't easily possible because |
silverwind
commented
Apr 16, 2015
Nits fixed and test added, please have a final look. |
There was a problem hiding this comment.
will be deprecated soon.
sounds like it already is deprecated?
There was a problem hiding this comment.
How about "will be removed soon" ?
There was a problem hiding this comment.
"is deprecated" should be fine, or "is deprecated and will be removed"
silverwind
commented
Apr 16, 2015
@Fishrock123 fixed the message. Adding |
chrisdickinson
commented
Apr 16, 2015
Feel free to merge this at will. |
silverwind
commented
Apr 16, 2015
@Fishrock123 LGTY? |
Fishrock123
commented
Apr 16, 2015
yeah LGTM |
This commit restores the functionality of adding a module's path to
NODE_PATH and requiring it with require('.'). As NODE_PATH was never
intended to be used as a pointer to a module directory (but instead, to
a directory containing directories of modules), this feature is also
being deprecated in turn, to be removed at a later point in time.
PR-URL: #1363Fixes: #1356
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Rod Vagg <rod@vagg.org>silverwind
commented
Apr 16, 2015
Landed in #1363 I'll follow up with the removal commit for 2.0 shortly. |
Notable Changes: * build: Support for building io.js as a static library (Marat Abdullin) #1341 * deps: upgrade openssl to 1.0.2a (Shigeki Ohtsu) #1389 * npm: Upgrade npm to 2.8.3. (Forrest L Norvell) #1448 * src: allow multiple arguments to be passed to process.nextTick (Trevor Norris) #1077 * module: interaction of require('.') with NODE_PATH has been restored and deprecated. This functionality will be removed at a later point. (Roman Reiss) #1363
Notable Changes: * build: Support for building io.js as a static library (Marat Abdullin) #1341 * deps: upgrade openssl to 1.0.2a (Shigeki Ohtsu) #1389 * npm: Upgrade npm to 2.8.3. (Forrest L Norvell) #1448 * src: allow multiple arguments to be passed to process.nextTick (Trevor Norris) #1077 * module: the interaction of require('.') with NODE_PATH has been restored and deprecated. This functionality will be removed at a later point. (Roman Reiss) #1363
Notable Changes: * build: revert vcbuild.bat changes * changes inherited from v1.8.0: * build: Support for building io.js as a static library (Marat Abdullin) #1341 * npm: Upgrade npm to 2.8.3. (Forrest L Norvell) #1448 * deps: upgrade openssl to 1.0.2a (Shigeki Ohtsu) #1389 * src: allow multiple arguments to be passed to process.nextTick (Trevor Norris) #1077 * module: the interaction of require('.') with NODE_PATH has been restored and deprecated. This functionality will be removed at a later point. (Roman Reiss) #1363
related: #1356, #1358
require('.'), likerequire('./')did not use module search paths, which inself is probably alright, as it is unexpected that.would refer to anything outside PWD.It appears some users (#1356) were relying on unintended (and in my eyes bugged) behaviour when NODE_PATH contains a
index.js, and surprisingly,require('.')did resolve to that module (which it probably never should have done).This patch fixes the case of
require('.')+NODE_PATHby lettingrequire('.')look up the search paths.require('.')still works as expected whenNODE_PATHdoesn't contain aindex.js.If both NODE_PATH and PWD contain
index.js, PWD is preferred (as it comes first in the array of search paths), which I think is the more sane way to fix that conflict, as it doesn't encourage relying on undefined behaviour.