-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
write builtin config on any global npm install
This is literally how it's always *supposed* to have been working. Yet, mysteriously, it has not been.
- Loading branch information
Showing
4 changed files
with
144 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,3 +25,5 @@ html/*.png | |
/npm-*.tgz | ||
|
||
*.pyc | ||
|
||
/test/tap/builtin-config |
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,125 @@ | ||
var fs = require("fs") | ||
|
||
if (process.argv[2] === "write-builtin") { | ||
var pid = process.argv[3] | ||
fs.writeFileSync("npmrc", "foo=bar\npid=" + pid + "\n") | ||
return | ||
} | ||
|
||
var rcdata = "foo=bar\npid=" + process.pid + "\n" | ||
var common = require("../common-tap.js") | ||
var path = require("path") | ||
var rimraf = require("rimraf") | ||
var mkdirp = require("mkdirp") | ||
var folder = path.resolve(__dirname, "builtin-config") | ||
var test = require("tap").test | ||
var npm = path.resolve(__dirname, "../..") | ||
var spawn = require("child_process").spawn | ||
var node = process.execPath | ||
|
||
test("setup", function (t) { | ||
rimraf.sync(folder) | ||
mkdirp.sync(folder + "/first") | ||
mkdirp.sync(folder + "/second") | ||
mkdirp.sync(folder + "/cache") | ||
mkdirp.sync(folder + "/tmp") | ||
|
||
t.pass("finished setup") | ||
t.end() | ||
}) | ||
|
||
|
||
test("install npm into first folder", function (t) { | ||
var args = ["install", npm, "-g", | ||
"--prefix=" + folder + "/first", | ||
"--cache=" + folder + "/cache", | ||
"--no-spin", | ||
"--loglevel=silent", | ||
"--tmp=" + folder + "/tmp"] | ||
common.npm(args, {stdio: "inherit"}, function (er, code) { | ||
if (er) throw er | ||
t.equal(code, 0) | ||
t.end() | ||
}) | ||
}) | ||
|
||
test("write npmrc file", function (t) { | ||
common.npm(["explore", "npm", "-g", | ||
"--prefix=" + folder + "/first", | ||
"--cache=" + folder + "/cache", | ||
"--tmp=" + folder + "/tmp", | ||
"--no-spin", | ||
"--", | ||
node, __filename, "write-builtin", process.pid | ||
], | ||
{"stdio": "inherit"}, | ||
function (er, code) { | ||
if (er) throw er | ||
t.equal(code, 0) | ||
t.end() | ||
}) | ||
}) | ||
|
||
test("use first npm to install second npm", function (t) { | ||
// get the root location | ||
common.npm([ "root", "-g", | ||
"--prefix=" + folder + "/first", | ||
"--cache=" + folder + "/cache", | ||
"--tmp=" + folder + "/tmp", | ||
"--no-spin" | ||
], {}, function (er, code, so) { | ||
if (er) throw er | ||
t.equal(code, 0) | ||
var root = so.trim() | ||
t.ok(fs.statSync(root).isDirectory()) | ||
|
||
var bin = path.resolve(root, "npm/bin/npm-cli.js") | ||
spawn( node | ||
, [ bin | ||
, "install", npm | ||
, "-g" | ||
, "--prefix=" + folder + "/second" | ||
, "--cache=" + folder + "/cache" | ||
, "--tmp=" + folder + "/tmp" | ||
, "--no-spin" | ||
]) | ||
.on("error", function (er) { throw er }) | ||
.on("close", function (code) { | ||
t.equal(code, 0, "code is zero") | ||
t.end() | ||
}) | ||
}) | ||
}) | ||
|
||
test("verify that the builtin config matches", function (t) { | ||
common.npm([ "root", "-g", | ||
"--prefix=" + folder + "/first", | ||
"--cache=" + folder + "/cache", | ||
"--tmp=" + folder + "/tmp" | ||
], {}, function (er, code, so) { | ||
if (er) throw er | ||
t.equal(code, 0) | ||
var firstRoot = so.trim() | ||
common.npm([ "root", "-g", | ||
"--prefix=" + folder + "/second", | ||
"--cache=" + folder + "/cache", | ||
"--tmp=" + folder + "/tmp" | ||
], {}, function (er, code, so) { | ||
if (er) throw er | ||
t.equal(code, 0) | ||
var secondRoot = so.trim() | ||
var firstRc = path.resolve(firstRoot, "npm", "npmrc") | ||
var secondRc = path.resolve(secondRoot, "npm", "npmrc") | ||
var firstData = fs.readFileSync(firstRc, "utf8") | ||
var secondData = fs.readFileSync(secondRc, "utf8") | ||
t.equal(firstData, secondData) | ||
t.end() | ||
}) | ||
}) | ||
}) | ||
|
||
|
||
test("clean", function (t) { | ||
rimraf.sync(folder) | ||
t.end() | ||
}) |