From b1d5e8d243822301c51cfdeffa6db2621e599d2e Mon Sep 17 00:00:00 2001 From: isaacs Date: Wed, 24 Jul 2019 01:31:43 -0700 Subject: [PATCH 1/3] doc: fix typo in changelog --- CHANGELOG.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a77c898d984aa..7cf53e92f553a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,10 +28,6 @@ Unix systems. * [`235e5d6df`](https://github.com/npm/cli/commit/235e5d6df6f427585ec58425f1f3339d08f39d8a) ensure correct owner on cached all-packages metadata ([@isaacs](https://github.com/isaacs)) -* [`fa6acd2ea`](https://github.com/npm/cli/commit/fa6acd2ea035bf26c04d7885b534d03d5b77e7ba) - [npm.community#8450](https://npm.community/t/npm-audit-fails-with-child-requires-fails-because-requires-must-be-an-object/8540) - audit: report server error on failure - ([@isaacs](https://github.com/isaacs)) * [`e2d377bb6`](https://github.com/npm/cli/commit/e2d377bb6419d8a3c1d80a73dba46062b4dad336) [npm.community#8540](https://npm.community/t/npm-audit-fails-with-child-requires-fails-because-requires-must-be-an-object/8540) audit: report server error on failure From d3bb77914347b40834d2406d452f85d885f2e48b Mon Sep 17 00:00:00 2001 From: isaacs Date: Fri, 26 Jul 2019 11:46:14 -0700 Subject: [PATCH 2/3] install: don't crash if registry is unset --- lib/install/inflate-shrinkwrap.js | 2 +- test/tap/install-without-registry-config.js | 35 +++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 test/tap/install-without-registry-config.js diff --git a/lib/install/inflate-shrinkwrap.js b/lib/install/inflate-shrinkwrap.js index 395cc11191309..5da9418bbdb7a 100644 --- a/lib/install/inflate-shrinkwrap.js +++ b/lib/install/inflate-shrinkwrap.js @@ -74,7 +74,7 @@ function quotemeta (str) { } function tarballToVersion (name, tb) { - const registry = quotemeta(npm.config.get('registry')) + const registry = quotemeta(npm.config.get('registry') || '') .replace(/https?:/, 'https?:') .replace(/([^/])$/, '$1/') let matchRegTarball diff --git a/test/tap/install-without-registry-config.js b/test/tap/install-without-registry-config.js new file mode 100644 index 0000000000000..852bd777ced5a --- /dev/null +++ b/test/tap/install-without-registry-config.js @@ -0,0 +1,35 @@ +const t = require('tap') +const { pkg, npm } = require('../common-tap.js') +const { writeFileSync, statSync, readFileSync } = require('fs') +const mkdirp = require('mkdirp') +const proj = pkg + '/project' +const dep = pkg + '/dep' +mkdirp.sync(proj) +mkdirp.sync(dep) +writeFileSync(dep + '/package.json', JSON.stringify({ + name: 'dependency', + version: '1.2.3' +})) +writeFileSync(proj + '/package.json', JSON.stringify({ + name: 'project', + version: '4.2.0' +})) + +const runTest = t => npm([ + 'install', + '../dep', + '--no-registry' +], { cwd: proj }).then(([code, out, err]) => { + t.equal(code, 0) + t.match(out, /^\+ dependency@1\.2\.3\n.* 1 package in [0-9.]+m?s\n$/) + t.equal(err, '') + const data = readFileSync(proj + '/node_modules/dependency/package.json', 'utf8') + t.same(JSON.parse(data), { + name: 'dependency', + version: '1.2.3' + }, 'dep got installed') + t.ok(statSync(proj + '/package-lock.json').isFile(), 'package-lock exists') +}) + +t.test('install without a registry, no package lock', t => runTest(t)) +t.test('install without a registry, with package lock', t => runTest(t)) From bdf7cd9ae87ce300c80dedb0bf576b2b4a6e07d8 Mon Sep 17 00:00:00 2001 From: isaacs Date: Fri, 26 Jul 2019 11:46:26 -0700 Subject: [PATCH 3/3] doctor: don't crash if registry is unset --- lib/doctor.js | 2 +- test/tap/doctor.js | 48 +++++++++++++++++++++++++++++++++++----------- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/lib/doctor.js b/lib/doctor.js index 95ede1bc87242..96094e6346d05 100644 --- a/lib/doctor.js +++ b/lib/doctor.js @@ -87,7 +87,7 @@ function makePretty (p) { const cacheStatus = p[8] ? `verified ${p[8].verifiedContent} tarballs` : 'notOk' const npmV = npm.version const nodeV = process.version.replace('v', '') - const registry = npm.config.get('registry') + const registry = npm.config.get('registry') || '' const list = [ ['npm ping', ping], ['npm -v', 'v' + npmV], diff --git a/test/tap/doctor.js b/test/tap/doctor.js index 7b07e0f39b7d8..9285518c2e10e 100644 --- a/test/tap/doctor.js +++ b/test/tap/doctor.js @@ -5,9 +5,8 @@ const http = require('http') const mr = require('npm-registry-mock') const npm = require('../../lib/npm.js') const path = require('path') -const rimraf = require('rimraf') const Tacks = require('tacks') -const test = require('tap').test +const t = require('tap') const which = require('which') const Dir = Tacks.Dir @@ -44,12 +43,23 @@ const npmResponse = { } } -test('setup', (t) => { +let nodeServer + +t.teardown(() => { + if (server) { + server.close() + } + if (nodeServer) { + nodeServer.close() + } +}) + +t.test('setup', (t) => { const port = common.port + 1 - http.createServer(function (q, s) { + nodeServer = http.createServer(function (q, s) { s.end(JSON.stringify([{lts: true, version: '0.0.0'}])) - this.close() - }).listen(port, () => { + }) + nodeServer.listen(port, () => { node_url = 'http://localhost:' + port mr({port: common.port}, (err, s) => { t.ifError(err, 'registry mocked successfully') @@ -78,7 +88,7 @@ test('setup', (t) => { }) }) -test('npm doctor', function (t) { +t.test('npm doctor', function (t) { npm.commands.doctor({'node-url': node_url}, true, function (e, list) { t.ifError(e, 'npm loaded successfully') t.same(list.length, 9, 'list should have 9 prop') @@ -93,13 +103,29 @@ test('npm doctor', function (t) { which('git', function (e, resolvedPath) { t.ifError(e, 'git command is installed') t.same(list[4][1], resolvedPath, 'which git') - server.close() t.done() }) }) }) -test('cleanup', (t) => { - rimraf.sync(ROOT) - t.done() +t.test('npm doctor works without registry', function (t) { + npm.config.set('registry', false) + npm.commands.doctor({'node-url': node_url}, true, function (e, list) { + t.ifError(e, 'npm loaded successfully') + t.same(list.length, 9, 'list should have 9 prop') + t.same(list[0][1], 'OK', 'npm ping') + t.same(list[1][1], 'v' + npm.version, 'npm -v') + t.same(list[2][1], process.version, 'node -v') + t.same(list[3][1], '', 'no registry, but no crash') + t.same(list[5][1], 'ok', 'Perms check on cached files') + t.same(list[6][1], 'ok', 'Perms check on global node_modules') + t.same(list[7][1], 'ok', 'Perms check on local node_modules') + t.match(list[8][1], /^verified \d+ tarballs?$/, 'Cache verified') + which('git', function (e, resolvedPath) { + t.ifError(e, 'git command is installed') + t.same(list[4][1], resolvedPath, 'which git') + server.close() + t.done() + }) + }) })