Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGar <gar+gh@danger.computer>2021-08-26 16:49:52 +0300
committerGar <gar+gh@danger.computer>2021-08-26 16:52:27 +0300
commit145f70cc1b78dee4ffa53f557fa72d0948696839 (patch)
tree144b91ba46eb74aad377226e4bb143313986ed4a
parent957fa604035992285572f63c38545eea86bbb1ff (diff)
read-package-json@4.0.1
* fix: Add gitHead in subdirectories too * fix(man): don't resolve paths to man files
-rw-r--r--node_modules/read-package-json/package.json16
-rw-r--r--node_modules/read-package-json/read-json.js198
-rw-r--r--package-lock.json14
-rw-r--r--package.json2
-rw-r--r--tap-snapshots/test/lib/publish.js.test.cjs9
5 files changed, 168 insertions, 71 deletions
diff --git a/node_modules/read-package-json/package.json b/node_modules/read-package-json/package.json
index 6589be806..5ca535cfd 100644
--- a/node_modules/read-package-json/package.json
+++ b/node_modules/read-package-json/package.json
@@ -1,6 +1,6 @@
{
"name": "read-package-json",
- "version": "4.0.0",
+ "version": "4.0.1",
"author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
"description": "The thing npm uses to read package.json files with semantics and defaults and validation",
"repository": {
@@ -11,9 +11,13 @@
"scripts": {
"prerelease": "npm t",
"postrelease": "npm publish && git push --follow-tags",
- "pretest": "standard",
"release": "standard-version -s",
- "test": "tap --nyc-arg=--all --coverage test/*.js"
+ "test": "tap --nyc-arg=--all --coverage test/*.js --branches 68 --functions 83 --lines 76 --statements 77",
+ "npmclilint": "npmcli-lint",
+ "lint": "npm run npmclilint -- --ignore-pattern test/fixtures \"*.*js\" \"test/**/*.*js\"",
+ "lintfix": "npm run lint -- --fix",
+ "posttest": "npm run lint --",
+ "postsnap": "npm run lintfix --"
},
"dependencies": {
"glob": "^7.1.1",
@@ -22,9 +26,9 @@
"npm-normalize-package-bin": "^1.0.0"
},
"devDependencies": {
- "standard": "^11.0.0",
- "standard-version": "^4.3.0",
- "tap": "^11.1.2"
+ "@npmcli/lint": "^1.0.2",
+ "standard-version": "^9.3.1",
+ "tap": "^15.0.9"
},
"license": "ISC",
"files": [
diff --git a/node_modules/read-package-json/read-json.js b/node_modules/read-package-json/read-json.js
index 4226e77c0..04d22e3af 100644
--- a/node_modules/read-package-json/read-json.js
+++ b/node_modules/read-package-json/read-json.js
@@ -20,7 +20,7 @@ readJson.extraSet = [
readme,
mans,
bins,
- githead
+ githead,
]
var typoWarned = {}
@@ -36,7 +36,9 @@ function readJson (file, log_, strict_, cb_) {
}
}
- if (!log) log = function () {}
+ if (!log) {
+ log = function () {}
+ }
cb = arguments[arguments.length - 1]
readJson_(file, log, strict, cb)
@@ -52,7 +54,9 @@ function stripBOM (content) {
// Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
// because the buffer-to-string conversion in `fs.readFileSync()`
// translates it to FEFF, the UTF-16 BOM.
- if (content.charCodeAt(0) === 0xFEFF) content = content.slice(1)
+ if (content.charCodeAt(0) === 0xFEFF) {
+ content = content.slice(1)
+ }
return content
}
@@ -87,9 +91,13 @@ function parseJson (file, er, d, log, strict, cb) {
}
})
}
- if (er) return cb(er)
+ if (er) {
+ return cb(er)
+ }
- if (cache[d]) return cb(null, jsonClone(cache[d]))
+ if (cache[d]) {
+ return cb(null, jsonClone(cache[d]))
+ }
var data
@@ -102,7 +110,9 @@ function parseJson (file, er, d, log, strict, cb) {
}
} catch (er) {
data = parseIndex(d)
- if (!data) return cb(parseError(er, file))
+ if (!data) {
+ return cb(parseError(er, file))
+ }
}
extrasCached(file, d, data, log, strict, cb)
@@ -118,16 +128,24 @@ function extrasCached (file, d, data, log, strict, cb) {
}
function indexjs (file, er, log, strict, cb) {
- if (path.basename(file) === 'index.js') return cb(er)
+ if (path.basename(file) === 'index.js') {
+ return cb(er)
+ }
var index = path.resolve(path.dirname(file), 'index.js')
fs.readFile(index, 'utf8', function (er2, d) {
- if (er2) return cb(er)
+ if (er2) {
+ return cb(er)
+ }
- if (cache[d]) return cb(null, cache[d])
+ if (cache[d]) {
+ return cb(null, cache[d])
+ }
var data = parseIndex(d)
- if (!data) return cb(er)
+ if (!data) {
+ return cb(er)
+ }
extrasCached(file, d, data, log, strict, cb)
})
@@ -144,7 +162,9 @@ function extras (file, data, log_, strict_, cb_) {
}
}
- if (!log) log = function () {}
+ if (!log) {
+ log = function () {}
+ }
cb = arguments[i]
var set = readJson.extraSet
@@ -155,15 +175,23 @@ function extras (file, data, log_, strict_, cb_) {
})
function then (er) {
- if (errState) return
- if (er) return cb(errState = er)
- if (--n > 0) return
+ if (errState) {
+ return
+ }
+ if (er) {
+ return cb(errState = er)
+ }
+ if (--n > 0) {
+ return
+ }
final(file, data, log, strict, cb)
}
}
function scriptpath (file, data, cb) {
- if (!data.scripts) return cb(null, data)
+ if (!data.scripts) {
+ return cb(null, data)
+ }
var k = Object.keys(data.scripts)
k.forEach(scriptpath_, data.scripts)
cb(null, data)
@@ -172,7 +200,9 @@ function scriptpath (file, data, cb) {
function scriptpath_ (key) {
var s = this[key]
// This is never allowed, and only causes problems
- if (typeof s !== 'string') return delete this[key]
+ if (typeof s !== 'string') {
+ return delete this[key]
+ }
var spre = /^(\.[/\\])?node_modules[/\\].bin[\\/]/
if (s.match(spre)) {
@@ -183,17 +213,25 @@ function scriptpath_ (key) {
function gypfile (file, data, cb) {
var dir = path.dirname(file)
var s = data.scripts || {}
- if (s.install || s.preinstall) return cb(null, data)
+ if (s.install || s.preinstall) {
+ return cb(null, data)
+ }
glob('*.gyp', { cwd: dir }, function (er, files) {
- if (er) return cb(er)
- if (data.gypfile === false) return cb(null, data)
+ if (er) {
+ return cb(er)
+ }
+ if (data.gypfile === false) {
+ return cb(null, data)
+ }
gypfile_(file, data, files, cb)
})
}
function gypfile_ (file, data, files, cb) {
- if (!files.length) return cb(null, data)
+ if (!files.length) {
+ return cb(null, data)
+ }
var s = data.scripts || {}
s.install = 'node-gyp rebuild'
data.scripts = s
@@ -204,15 +242,21 @@ function gypfile_ (file, data, files, cb) {
function serverjs (file, data, cb) {
var dir = path.dirname(file)
var s = data.scripts || {}
- if (s.start) return cb(null, data)
+ if (s.start) {
+ return cb(null, data)
+ }
glob('server.js', { cwd: dir }, function (er, files) {
- if (er) return cb(er)
+ if (er) {
+ return cb(er)
+ }
serverjs_(file, data, files, cb)
})
}
function serverjs_ (file, data, files, cb) {
- if (!files.length) return cb(null, data)
+ if (!files.length) {
+ return cb(null, data)
+ }
var s = data.scripts || {}
s.start = 'node server.js'
data.scripts = s
@@ -220,11 +264,15 @@ function serverjs_ (file, data, files, cb) {
}
function authors (file, data, cb) {
- if (data.contributors) return cb(null, data)
+ if (data.contributors) {
+ return cb(null, data)
+ }
var af = path.resolve(path.dirname(file), 'AUTHORS')
fs.readFile(af, 'utf8', function (er, ad) {
// ignore error. just checking it.
- if (er) return cb(null, data)
+ if (er) {
+ return cb(null, data)
+ }
authors_(file, data, ad, cb)
})
}
@@ -240,16 +288,22 @@ function authors_ (file, data, ad, cb) {
}
function readme (file, data, cb) {
- if (data.readme) return cb(null, data)
+ if (data.readme) {
+ return cb(null, data)
+ }
var dir = path.dirname(file)
var globOpts = { cwd: dir, nocase: true, mark: true }
glob('{README,README.*}', globOpts, function (er, files) {
- if (er) return cb(er)
+ if (er) {
+ return cb(er)
+ }
// don't accept directories.
files = files.filter(function (file) {
return !file.match(/\/$/)
})
- if (!files.length) return cb()
+ if (!files.length) {
+ return cb()
+ }
var fn = preferMarkdownReadme(files)
var rm = path.resolve(dir, fn)
readme_(file, data, rm, cb)
@@ -275,7 +329,9 @@ function readme_ (file, data, rm, cb) {
var rmfn = path.basename(rm)
fs.readFile(rm, 'utf8', function (er, rm) {
// maybe not readable, or something.
- if (er) return cb()
+ if (er) {
+ return cb()
+ }
data.readme = rm
data.readmeFilename = rmfn
return cb(er, data)
@@ -284,31 +340,32 @@ function readme_ (file, data, rm, cb) {
function mans (file, data, cb) {
var m = data.directories && data.directories.man
- if (data.man || !m) return cb(null, data)
+ if (data.man || !m) {
+ return cb(null, data)
+ }
m = path.resolve(path.dirname(file), m)
glob('**/*.[0-9]', { cwd: m }, function (er, mans) {
- if (er) return cb(er)
- mans_(file, data, mans, cb)
- })
-}
-
-function mans_ (file, data, mans, cb) {
- var m = data.directories && data.directories.man
- data.man = mans.map(function (mf) {
- return path.resolve(path.dirname(file), m, mf)
+ if (er) {
+ return cb(er)
+ }
+ data.man = mans
+ return cb(null, data)
})
- return cb(null, data)
}
function bins (file, data, cb) {
data = normalizePackageBin(data)
var m = data.directories && data.directories.bin
- if (data.bin || !m) return cb(null, data)
+ if (data.bin || !m) {
+ return cb(null, data)
+ }
m = path.resolve(path.dirname(file), m)
glob('**', { cwd: m }, function (er, bins) {
- if (er) return cb(er)
+ if (er) {
+ return cb(er)
+ }
bins_(file, data, bins, cb)
})
}
@@ -330,11 +387,14 @@ function bundleDependencies (file, data, cb) {
var bdd = 'bundledDependencies'
// normalize key name
if (data[bdd] !== undefined) {
- if (data[bd] === undefined) data[bd] = data[bdd]
+ if (data[bd] === undefined) {
+ data[bd] = data[bdd]
+ }
delete data[bdd]
}
- if (data[bd] === false) delete data[bd]
- else if (data[bd] === true) {
+ if (data[bd] === false) {
+ delete data[bd]
+ } else if (data[bd] === true) {
data[bd] = Object.keys(data.dependencies || {})
} else if (data[bd] !== undefined && !Array.isArray(data[bd])) {
delete data[bd]
@@ -343,16 +403,24 @@ function bundleDependencies (file, data, cb) {
}
function githead (file, data, cb) {
- if (data.gitHead) return cb(null, data)
+ if (data.gitHead) {
+ return cb(null, data)
+ }
var dir = path.dirname(file)
var head = path.resolve(dir, '.git/HEAD')
fs.readFile(head, 'utf8', function (er, head) {
- if (er) return cb(null, data)
- githead_(file, data, dir, head, cb)
+ if (er) {
+ var parent = path.dirname(dir)
+ if (parent === dir) {
+ return cb(null, data)
+ }
+ return githead(dir, data, cb)
+ }
+ githead_(data, dir, head, cb)
})
}
-function githead_ (file, data, dir, head, cb) {
+function githead_ (data, dir, head, cb) {
if (!head.match(/^ref: /)) {
data.gitHead = head.trim()
return cb(null, data)
@@ -388,16 +456,24 @@ function githead_ (file, data, dir, head, cb) {
* normalize-package-data if it had access to the file path.
*/
function checkBinReferences_ (file, data, warn, cb) {
- if (!(data.bin instanceof Object)) return cb()
+ if (!(data.bin instanceof Object)) {
+ return cb()
+ }
var keys = Object.keys(data.bin)
var keysLeft = keys.length
- if (!keysLeft) return cb()
+ if (!keysLeft) {
+ return cb()
+ }
function handleExists (relName, result) {
keysLeft--
- if (!result) warn('No bin file found at ' + relName)
- if (!keysLeft) cb()
+ if (!result) {
+ warn('No bin file found at ' + relName)
+ }
+ if (!keysLeft) {
+ cb()
+ }
}
keys.forEach(function (key) {
@@ -421,8 +497,12 @@ function final (file, data, log, strict, cb) {
var pId = makePackageId(data)
function warn (msg) {
- if (typoWarned[pId]) return
- if (log) log('package.json', pId, msg)
+ if (typoWarned[pId]) {
+ return
+ }
+ if (log) {
+ log('package.json', pId, msg)
+ }
}
try {
@@ -451,11 +531,15 @@ function cleanString (str) {
function parseIndex (data) {
data = data.split(/^\/\*\*package(?:\s|$)/m)
- if (data.length < 2) return null
+ if (data.length < 2) {
+ return null
+ }
data = data[1]
data = data.split(/\*\*\/$/m)
- if (data.length < 2) return null
+ if (data.length < 2) {
+ return null
+ }
data = data[0]
data = data.replace(/^\s*\*/mg, '')
diff --git a/package-lock.json b/package-lock.json
index bc4087f38..475f8e080 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -138,7 +138,7 @@
"parse-conflict-json": "^1.1.1",
"qrcode-terminal": "^0.12.0",
"read": "~1.0.7",
- "read-package-json": "^4.0.0",
+ "read-package-json": "^4.0.1",
"read-package-json-fast": "^2.0.3",
"readdir-scoped-modules": "^1.1.0",
"rimraf": "^3.0.2",
@@ -6450,9 +6450,9 @@
"inBundle": true
},
"node_modules/read-package-json": {
- "version": "4.0.0",
- "resolved": "https://registry.npmjs.org/read-package-json/-/read-package-json-4.0.0.tgz",
- "integrity": "sha512-EBQiek1udd0JKvUzaViAWHYVQRuQZ0IP0LWUOqVCJaZIX92ZO86dOpvsTOO3esRIQGgl7JhFBaGqW41VI57KvQ==",
+ "version": "4.0.1",
+ "resolved": "https://registry.npmjs.org/read-package-json/-/read-package-json-4.0.1.tgz",
+ "integrity": "sha512-czqCcYfkEl6sIFJVOND/5/Goseu7cVw1rcDUATq6ED0jLGjMm9/HOPmFmEZMvRu9yl272YERaMUcOlvcNU9InQ==",
"inBundle": true,
"dependencies": {
"glob": "^7.1.1",
@@ -15222,9 +15222,9 @@
"integrity": "sha512-HJpV9bQpkl6KwjxlJcBoqu9Ba0PQg8TqSNIOrulGt54a0uup0HtevreFHzYzkm0lpnleRdNBzXznKrgxglEHQw=="
},
"read-package-json": {
- "version": "4.0.0",
- "resolved": "https://registry.npmjs.org/read-package-json/-/read-package-json-4.0.0.tgz",
- "integrity": "sha512-EBQiek1udd0JKvUzaViAWHYVQRuQZ0IP0LWUOqVCJaZIX92ZO86dOpvsTOO3esRIQGgl7JhFBaGqW41VI57KvQ==",
+ "version": "4.0.1",
+ "resolved": "https://registry.npmjs.org/read-package-json/-/read-package-json-4.0.1.tgz",
+ "integrity": "sha512-czqCcYfkEl6sIFJVOND/5/Goseu7cVw1rcDUATq6ED0jLGjMm9/HOPmFmEZMvRu9yl272YERaMUcOlvcNU9InQ==",
"requires": {
"glob": "^7.1.1",
"json-parse-even-better-errors": "^2.3.0",
diff --git a/package.json b/package.json
index 52a6fc957..34eb55108 100644
--- a/package.json
+++ b/package.json
@@ -108,7 +108,7 @@
"parse-conflict-json": "^1.1.1",
"qrcode-terminal": "^0.12.0",
"read": "~1.0.7",
- "read-package-json": "^4.0.0",
+ "read-package-json": "^4.0.1",
"read-package-json-fast": "^2.0.3",
"readdir-scoped-modules": "^1.1.0",
"rimraf": "^3.0.2",
diff --git a/tap-snapshots/test/lib/publish.js.test.cjs b/tap-snapshots/test/lib/publish.js.test.cjs
index 7a7502e02..2c26efacd 100644
--- a/tap-snapshots/test/lib/publish.js.test.cjs
+++ b/tap-snapshots/test/lib/publish.js.test.cjs
@@ -15,6 +15,7 @@ exports[`test/lib/publish.js TAP private workspaces colorless > should publish a
Array [
Object {
"_id": "@npmcli/b@1.0.0",
+ "gitHead": "718c3e56033b930c016b1f2022597e8af4af0f79",
"name": "@npmcli/b",
"readme": "ERROR: No README data found!",
"version": "1.0.0",
@@ -32,6 +33,7 @@ exports[`test/lib/publish.js TAP private workspaces with color > should publish
Array [
Object {
"_id": "@npmcli/b@1.0.0",
+ "gitHead": "718c3e56033b930c016b1f2022597e8af4af0f79",
"name": "@npmcli/b",
"readme": "ERROR: No README data found!",
"version": "1.0.0",
@@ -70,6 +72,7 @@ exports[`test/lib/publish.js TAP workspaces all workspaces > should publish all
Array [
Object {
"_id": "workspace-a@1.2.3-a",
+ "gitHead": "718c3e56033b930c016b1f2022597e8af4af0f79",
"name": "workspace-a",
"readme": "ERROR: No README data found!",
"repository": Object {
@@ -83,6 +86,7 @@ Array [
"bugs": Object {
"url": "https://github.com/npm/workspace-b/issues",
},
+ "gitHead": "718c3e56033b930c016b1f2022597e8af4af0f79",
"homepage": "https://github.com/npm/workspace-b#readme",
"name": "workspace-b",
"readme": "ERROR: No README data found!",
@@ -94,6 +98,7 @@ Array [
},
Object {
"_id": "workspace-n@1.2.3-n",
+ "gitHead": "718c3e56033b930c016b1f2022597e8af4af0f79",
"name": "workspace-n",
"readme": "ERROR: No README data found!",
"version": "1.2.3-n",
@@ -123,6 +128,7 @@ exports[`test/lib/publish.js TAP workspaces json > should publish all workspaces
Array [
Object {
"_id": "workspace-a@1.2.3-a",
+ "gitHead": "718c3e56033b930c016b1f2022597e8af4af0f79",
"name": "workspace-a",
"readme": "ERROR: No README data found!",
"repository": Object {
@@ -136,6 +142,7 @@ Array [
"bugs": Object {
"url": "https://github.com/npm/workspace-b/issues",
},
+ "gitHead": "718c3e56033b930c016b1f2022597e8af4af0f79",
"homepage": "https://github.com/npm/workspace-b#readme",
"name": "workspace-b",
"readme": "ERROR: No README data found!",
@@ -147,6 +154,7 @@ Array [
},
Object {
"_id": "workspace-n@1.2.3-n",
+ "gitHead": "718c3e56033b930c016b1f2022597e8af4af0f79",
"name": "workspace-n",
"readme": "ERROR: No README data found!",
"version": "1.2.3-n",
@@ -164,6 +172,7 @@ exports[`test/lib/publish.js TAP workspaces one workspace > should publish given
Array [
Object {
"_id": "workspace-a@1.2.3-a",
+ "gitHead": "718c3e56033b930c016b1f2022597e8af4af0f79",
"name": "workspace-a",
"readme": "ERROR: No README data found!",
"repository": Object {