diff options
author | James M Snell <jasnell@gmail.com> | 2016-05-02 16:31:20 -0700 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2016-05-13 11:43:47 -0700 |
commit | 5d38d543cdd25962fadc49a997798d156a41e4c7 (patch) | |
tree | 04b538b19025ddaf9017cbce4aa35fb004e6a145 /test/parallel/test-module-symlinked-peer-modules.js | |
parent | f52b2f116bf510e2af8750061ac6f8a0c9caa653 (diff) | |
download | android-node-v8-5d38d543cdd25962fadc49a997798d156a41e4c7.tar.gz android-node-v8-5d38d543cdd25962fadc49a997798d156a41e4c7.tar.bz2 android-node-v8-5d38d543cdd25962fadc49a997798d156a41e4c7.zip |
src,module: add --preserve-symlinks command line flag
Add the `--preserve-symlinks` flag. This makes the changes added
in #5950 conditional. By default the old behavior is used. With
the flag set, symlinks are preserved, switching to the new
behavior. This should be considered to be a temporary solution
until we figure out how to solve the symlinked peer dependency
problem in a more general way that does not break everything
else.
Additional test cases are included.
PR-URL: https://github.com/nodejs/node/pull/6537
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'test/parallel/test-module-symlinked-peer-modules.js')
-rw-r--r-- | test/parallel/test-module-symlinked-peer-modules.js | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/test/parallel/test-module-symlinked-peer-modules.js b/test/parallel/test-module-symlinked-peer-modules.js new file mode 100644 index 0000000000..83aca75ed1 --- /dev/null +++ b/test/parallel/test-module-symlinked-peer-modules.js @@ -0,0 +1,65 @@ +// Flags: --preserve-symlinks +'use strict'; +// Refs: https://github.com/nodejs/node/pull/5950 + +// This test verifies that symlinked modules are able to find their peer +// dependencies when using the --preserve-symlinks command line flag. + +// This test passes in v6.2+ with --preserve-symlinks on and in v6.0/v6.1. +// This test will fail in Node.js v4 and v5 and should not be backported. + +const common = require('../common'); +const fs = require('fs'); +const path = require('path'); +const assert = require('assert'); + +common.refreshTmpDir(); + +const tmpDir = common.tmpDir; + +// Creates the following structure +// {tmpDir} +// ├── app +// │ ├── index.js +// │ └── node_modules +// │ ├── moduleA -> {tmpDir}/moduleA +// │ └── moduleB +// │ ├── index.js +// │ └── package.json +// └── moduleA +// ├── index.js +// └── package.json + +const moduleA = path.join(tmpDir, 'moduleA'); +const app = path.join(tmpDir, 'app'); +const moduleB = path.join(app, 'node_modules', 'moduleB'); +const moduleA_link = path.join(app, 'node_modules', 'moduleA'); +fs.mkdirSync(moduleA); +fs.mkdirSync(app); +fs.mkdirSync(path.join(app, 'node_modules')); +fs.mkdirSync(moduleB); + +// Attempt to make the symlink. If this fails due to lack of sufficient +// permissions, the test will bail out and be skipped. +try { + fs.symlinkSync(moduleA, moduleA_link); +} catch (err) { + if (err.code !== 'EPERM') throw err; + common.skip('insufficient privileges for symlinks'); + return; +} + +fs.writeFileSync(path.join(moduleA, 'package.json'), + JSON.stringify({name: 'moduleA', main: 'index.js'}), 'utf8'); +fs.writeFileSync(path.join(moduleA, 'index.js'), + 'module.exports = require(\'moduleB\');', 'utf8'); +fs.writeFileSync(path.join(app, 'index.js'), + '\'use strict\'; require(\'moduleA\');', 'utf8'); +fs.writeFileSync(path.join(moduleB, 'package.json'), + JSON.stringify({name: 'moduleB', main: 'index.js'}), 'utf8'); +fs.writeFileSync(path.join(moduleB, 'index.js'), + 'module.exports = 1;', 'utf8'); + +assert.doesNotThrow(() => { + require(path.join(app, 'index')); +}); |