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 intonodejs:v1.xfrom
Conversation
|
Deprecation warning + note to remove this quirk in 2.0 maybe? |
|
I mean, if Looking at the code, this suggestion might be too complex though. :( |
|
Looking into adding a warning. Few more notes:
|
|
One more blocking issue I've noticed: It seems the suitable |
Is |
|
Note that process.cwd() can fail with ENOENT if the working directory has been unlinked. |
|
Edit: I think I have an idea how to solve it. Hold on. |
97b60c4 to
712e75c
Compare
|
Updated with a better way of obtaining PWD, which is also resilient to Not sure the fallback to Also added a warning if |
|
Will look into changing that |
lib/module.js
Outdated
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:
var noopDeprecateRequireDotFile = 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.
|
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
9a2e885
Compare
lib/module.js
Outdated
There 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"
|
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 |
|
Agreed. I first thought doing a test wasn't easily possible because |
|
Nits fixed and test added, please have a final look. |
lib/module.js
Outdated
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"
|
@Fishrock123 fixed the message. Adding |
|
Feel free to merge this at will. |
|
@Fishrock123 LGTY? |
|
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: #1363
Fixes: #1356
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Rod Vagg <rod@vagg.org>
|
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.