Skip to content

Commit e3f0fd4

Browse files
committed
deps: @npmcli/package-json@5.1.1
1 parent 4b57b95 commit e3f0fd4

File tree

4 files changed

+57
-21
lines changed

4 files changed

+57
-21
lines changed

node_modules/@npmcli/package-json/lib/normalize.js

+48-12
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,14 @@ function normalizePackageBin (pkg, changes) {
4646
changes?.push(`removed invalid "bin[${binKey}]"`)
4747
continue
4848
}
49-
const base = path.join('/', path.basename(binKey.replace(/\\|:/g, '/'))).slice(1)
49+
const base = path.basename(secureAndUnixifyPath(binKey))
5050
if (!base) {
5151
delete pkg.bin[binKey]
5252
changes?.push(`removed invalid "bin[${binKey}]"`)
5353
continue
5454
}
5555

56-
const binTarget = path.join('/', pkg.bin[binKey].replace(/\\/g, '/'))
57-
.replace(/\\/g, '/').slice(1)
56+
const binTarget = secureAndUnixifyPath(pkg.bin[binKey])
5857

5958
if (!binTarget) {
6059
delete pkg.bin[binKey]
@@ -83,6 +82,27 @@ function normalizePackageBin (pkg, changes) {
8382
delete pkg.bin
8483
}
8584

85+
function normalizePackageMan (pkg, changes) {
86+
if (pkg.man) {
87+
const mans = []
88+
for (const man of (Array.isArray(pkg.man) ? pkg.man : [pkg.man])) {
89+
if (typeof man !== 'string') {
90+
changes?.push(`removed invalid "man [${man}]"`)
91+
} else {
92+
mans.push(secureAndUnixifyPath(man))
93+
}
94+
}
95+
96+
if (!mans.length) {
97+
changes?.push('empty "man" was removed')
98+
} else {
99+
pkg.man = mans
100+
return pkg
101+
}
102+
}
103+
delete pkg.man
104+
}
105+
86106
function isCorrectlyEncodedName (spec) {
87107
return !spec.match(/[/@\s+%:]/) &&
88108
spec === encodeURIComponent(spec)
@@ -103,6 +123,19 @@ function isValidScopedPackageName (spec) {
103123
rest[1] === encodeURIComponent(rest[1])
104124
}
105125

126+
function unixifyPath (ref) {
127+
return ref.replace(/\\|:/g, '/')
128+
}
129+
130+
function securePath (ref) {
131+
const secured = path.join('.', path.join('/', unixifyPath(ref)))
132+
return secured.startsWith('.') ? '' : secured
133+
}
134+
135+
function secureAndUnixifyPath (ref) {
136+
return unixifyPath(securePath(ref))
137+
}
138+
106139
// We don't want the `changes` array in here by default because this is a hot
107140
// path for parsing packuments during install. So the calling method passes it
108141
// in if it wants to track changes.
@@ -251,7 +284,7 @@ const normalize = async (pkg, { strict, steps, root, changes, allowLegacyCase })
251284

252285
// strip "node_modules/.bin" from scripts entries
253286
// remove invalid scripts entries (non-strings)
254-
if (steps.includes('scripts') || steps.includes('scriptpath')) {
287+
if ((steps.includes('scripts') || steps.includes('scriptpath')) && data.scripts !== undefined) {
255288
const spre = /^(\.[/\\])?node_modules[/\\].bin[\\/]/
256289
if (typeof data.scripts === 'object') {
257290
for (const name in data.scripts) {
@@ -325,13 +358,16 @@ const normalize = async (pkg, { strict, steps, root, changes, allowLegacyCase })
325358
}
326359

327360
// expand directories.man
328-
if (steps.includes('mans') && !data.man && data.directories?.man) {
329-
const manDir = data.directories.man
330-
const cwd = path.resolve(pkg.path, manDir)
331-
const files = await lazyLoadGlob()('**/*.[0-9]', { cwd })
332-
data.man = files.map(man =>
333-
path.relative(pkg.path, path.join(cwd, man)).split(path.sep).join('/')
334-
)
361+
if (steps.includes('mans')) {
362+
if (data.directories?.man && !data.man) {
363+
const manDir = secureAndUnixifyPath(data.directories.man)
364+
const cwd = path.resolve(pkg.path, manDir)
365+
const files = await lazyLoadGlob()('**/*.[0-9]', { cwd })
366+
data.man = files.map(man =>
367+
path.relative(pkg.path, path.join(cwd, man)).split(path.sep).join('/')
368+
)
369+
}
370+
normalizePackageMan(data, changes)
335371
}
336372

337373
if (steps.includes('bin') || steps.includes('binDir') || steps.includes('binRefs')) {
@@ -340,7 +376,7 @@ const normalize = async (pkg, { strict, steps, root, changes, allowLegacyCase })
340376

341377
// expand "directories.bin"
342378
if (steps.includes('binDir') && data.directories?.bin && !data.bin) {
343-
const binsDir = path.resolve(pkg.path, path.join('.', path.join('/', data.directories.bin)))
379+
const binsDir = path.resolve(pkg.path, securePath(data.directories.bin))
344380
const bins = await lazyLoadGlob()('**', { cwd: binsDir })
345381
data.bin = bins.reduce((acc, binFile) => {
346382
if (binFile && !binFile.startsWith('.')) {

node_modules/@npmcli/package-json/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@npmcli/package-json",
3-
"version": "5.1.0",
3+
"version": "5.1.1",
44
"description": "Programmatic API to update package.json",
55
"main": "lib/index.js",
66
"files": [
@@ -25,7 +25,7 @@
2525
"license": "ISC",
2626
"devDependencies": {
2727
"@npmcli/eslint-config": "^4.0.0",
28-
"@npmcli/template-oss": "4.21.4",
28+
"@npmcli/template-oss": "4.22.0",
2929
"read-package-json": "^7.0.0",
3030
"read-package-json-fast": "^3.0.2",
3131
"tap": "^16.0.1"
@@ -41,14 +41,14 @@
4141
},
4242
"repository": {
4343
"type": "git",
44-
"url": "https://github.com/npm/package-json.git"
44+
"url": "git+https://github.com/npm/package-json.git"
4545
},
4646
"engines": {
4747
"node": "^16.14.0 || >=18.0.0"
4848
},
4949
"templateOSS": {
5050
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
51-
"version": "4.21.4",
51+
"version": "4.22.0",
5252
"publish": "true"
5353
},
5454
"tap": {

package-lock.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
"@npmcli/config": "^8.3.2",
9292
"@npmcli/fs": "^3.1.1",
9393
"@npmcli/map-workspaces": "^3.0.6",
94-
"@npmcli/package-json": "^5.1.0",
94+
"@npmcli/package-json": "^5.1.1",
9595
"@npmcli/promise-spawn": "^7.0.2",
9696
"@npmcli/redact": "^2.0.0",
9797
"@npmcli/run-script": "^8.1.0",
@@ -1716,9 +1716,9 @@
17161716
}
17171717
},
17181718
"node_modules/@npmcli/package-json": {
1719-
"version": "5.1.0",
1720-
"resolved": "https://registry.npmjs.org/@npmcli/package-json/-/package-json-5.1.0.tgz",
1721-
"integrity": "sha512-1aL4TuVrLS9sf8quCLerU3H9J4vtCtgu8VauYozrmEyU57i/EdKleCnsQ7vpnABIH6c9mnTxcH5sFkO3BlV8wQ==",
1719+
"version": "5.1.1",
1720+
"resolved": "https://registry.npmjs.org/@npmcli/package-json/-/package-json-5.1.1.tgz",
1721+
"integrity": "sha512-uTq5j/UqUzbOaOxVy+osfOhpqOiLfUZ0Ut33UbcyyAPJbZcJsf4Mrsyb8r58FoIFlofw0iOFsuCA/oDK14VDJQ==",
17221722
"inBundle": true,
17231723
"license": "ISC",
17241724
"dependencies": {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"@npmcli/config": "^8.3.2",
5757
"@npmcli/fs": "^3.1.1",
5858
"@npmcli/map-workspaces": "^3.0.6",
59-
"@npmcli/package-json": "^5.1.0",
59+
"@npmcli/package-json": "^5.1.1",
6060
"@npmcli/promise-spawn": "^7.0.2",
6161
"@npmcli/redact": "^2.0.0",
6262
"@npmcli/run-script": "^8.1.0",

0 commit comments

Comments
 (0)