-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
module: resolve _-prefixed dependencies to real path
Since #5950, `require('some-symlink')` no longer resolves the module to its real path, but instead uses the path of the symlink itself as a cache key. This change allows users to resolve dependencies to their real path when required using the _-prefix. Example using old mechanism (pre v6.0.0): --- node_modules/_real-module -> ../real-module real-modules/index.js require('./real_module') === require('real_module') Example using new mechanism (post v6.0.0): --- node_modules/real-module -> ../real-module real-modules/index.js require('./real_module') !== require('real_module') As discussed in #3402
- Loading branch information
1 parent
3cdb506
commit 6564aae
Showing
5 changed files
with
83 additions
and
39 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
exports.internalRequire = require; |
1 change: 1 addition & 0 deletions
1
test/fixtures/module-require-real-path/node_modules/real-module/index.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
exports.dirname = __dirname; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
|
||
const realModuleSymlinkPath = path.join(common.fixturesDir, | ||
'/module-require-real-path/node_modules/_real-module'); | ||
|
||
const localRealModulePath = path.join(common.fixturesDir, | ||
'/module-require-real-path/real-module'); | ||
|
||
// module-require-real-path exports its require function. That way we can test | ||
// how modules get resolved **from** its. | ||
const _require = require( | ||
path.join(common.fixturesDir, '/module-require-real-path') | ||
).internalRequire; | ||
|
||
process.on('exit', function() { | ||
fs.unlinkSync(realModuleSymlinkPath); | ||
}); | ||
|
||
fs.symlinkSync('../real-module', realModuleSymlinkPath); | ||
|
||
assert.equal(_require('./real-module'), _require('real-module')); | ||
assert.equal(_require('real-module').dirname, localRealModulePath); | ||
|
||
// When required directly with the _-prefix, resolve to path of symlink. | ||
assert.notEqual(_require('./real-module'), _require('_real-module')); | ||
assert.equal(_require('_real-module').dirname, realModuleSymlinkPath); |