-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue with sub folder local references (#86)
PR-URL: #86 Fixes: https://npm.community/t/npm-install-for-package-with-local-dependency-fails/754 Credit: @iarna Credit: @jhecking Reviewed-By: @aeschright
- Loading branch information
1 parent
7c62cde
commit d513709
Showing
5 changed files
with
77 additions
and
8 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
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,69 @@ | ||
var fs = require('graceful-fs') | ||
var path = require('path') | ||
|
||
var mkdirp = require('mkdirp') | ||
var osenv = require('osenv') | ||
var rimraf = require('rimraf') | ||
var test = require('tap').test | ||
|
||
var common = require('../common-tap.js') | ||
|
||
var pkg = path.join(__dirname, 'install-at-sub-path-locally') | ||
|
||
var EXEC_OPTS = { cwd: pkg, stdio: [0, 1, 2] } | ||
|
||
var json = { | ||
name: 'install-at-sub-path-locally-mock', | ||
version: '0.0.0' | ||
} | ||
|
||
var target = '../package@1.2.3' | ||
|
||
test('setup', function (t) { | ||
cleanup() | ||
t.end() | ||
}) | ||
|
||
test('\'npm install ../package@1.2.3\' should install local pkg from sub path', function (t) { | ||
setup() | ||
common.npm(['install', '--loglevel=silent', target], EXEC_OPTS, function (err, code) { | ||
if (err) throw err | ||
var p = path.resolve(pkg, 'node_modules/install-at-sub-path-locally-mock/package.json') | ||
t.equal(code, 0, 'npm install exited with code') | ||
t.ok(JSON.parse(fs.readFileSync(p, 'utf8'))) | ||
t.end() | ||
}) | ||
}) | ||
|
||
test('\'running npm install ../package@1.2.3\' should not break on sub path re-install', function (t) { | ||
common.npm(['install', '--loglevel=silent', target], EXEC_OPTS, function (err, code) { | ||
if (err) throw err | ||
var p = path.resolve(pkg, 'node_modules/install-at-sub-path-locally-mock/package.json') | ||
t.equal(code, 0, 'npm install exited with code') | ||
t.ok(JSON.parse(fs.readFileSync(p, 'utf8'))) | ||
t.end() | ||
}) | ||
}) | ||
|
||
test('cleanup', function (t) { | ||
cleanup() | ||
t.end() | ||
}) | ||
|
||
function cleanup () { | ||
process.chdir(osenv.tmpdir()) | ||
rimraf.sync(pkg) | ||
rimraf.sync(path.resolve(pkg, target)) | ||
} | ||
|
||
function setup () { | ||
cleanup() | ||
var root = path.resolve(pkg, target) | ||
mkdirp.sync(root) | ||
fs.writeFileSync( | ||
path.join(root, 'package.json'), | ||
JSON.stringify(json, null, 2) | ||
) | ||
mkdirp.sync(path.resolve(pkg, 'node_modules')) | ||
process.chdir(pkg) | ||
} |
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