-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
module: restore and warn on require('.') usage with NODE_PATH #1363
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 |
@@ -169,6 +169,9 @@ Module._findPath = function(request, paths) { | |||
} | |||
|
|||
if (filename) { | |||
if (request === '.' && i > 0) { | |||
console.error(`(node) warning: require('.') resolved to ${filename}`); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -125,6 +125,11 @@ function tryExtensions(p, exts) { | |||
} | |||
|
|||
|
|||
const noopDeprecateRequireDot = util.deprecate(function() {}, | |||
`warning: require('.') did resolve outside the package directory. ` + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the use of a template string seems unnecessary here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
@@ -125,6 +125,11 @@ function tryExtensions(p, exts) { | |||
} | |||
|
|||
|
|||
const noopDeprecateRequireDot = util.deprecate(function() {}, | |||
"warning: require('.') resolved outside the package directory. " + | |||
"This functionality will be deprecated soon."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will be deprecated soon.
sounds like it already is deprecated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about "will be removed soon" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"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 <[email protected]> Reviewed-By: Rod Vagg <[email protected]>
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_PATH
by lettingrequire('.')
look up the search paths.require('.')
still works as expected whenNODE_PATH
doesn'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.