Skip to content

Commit

Permalink
deps: @npmcli/package-json@5.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed May 29, 2024
1 parent 4b57b95 commit e3f0fd4
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 21 deletions.
60 changes: 48 additions & 12 deletions node_modules/@npmcli/package-json/lib/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,14 @@ function normalizePackageBin (pkg, changes) {
changes?.push(`removed invalid "bin[${binKey}]"`)
continue
}
const base = path.join('/', path.basename(binKey.replace(/\\|:/g, '/'))).slice(1)
const base = path.basename(secureAndUnixifyPath(binKey))
if (!base) {
delete pkg.bin[binKey]
changes?.push(`removed invalid "bin[${binKey}]"`)
continue
}

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

if (!binTarget) {
delete pkg.bin[binKey]
Expand Down Expand Up @@ -83,6 +82,27 @@ function normalizePackageBin (pkg, changes) {
delete pkg.bin
}

function normalizePackageMan (pkg, changes) {
if (pkg.man) {
const mans = []
for (const man of (Array.isArray(pkg.man) ? pkg.man : [pkg.man])) {
if (typeof man !== 'string') {
changes?.push(`removed invalid "man [${man}]"`)
} else {
mans.push(secureAndUnixifyPath(man))
}
}

if (!mans.length) {
changes?.push('empty "man" was removed')
} else {
pkg.man = mans
return pkg
}
}
delete pkg.man
}

function isCorrectlyEncodedName (spec) {
return !spec.match(/[/@\s+%:]/) &&
spec === encodeURIComponent(spec)
Expand All @@ -103,6 +123,19 @@ function isValidScopedPackageName (spec) {
rest[1] === encodeURIComponent(rest[1])
}

function unixifyPath (ref) {
return ref.replace(/\\|:/g, '/')
}

function securePath (ref) {
const secured = path.join('.', path.join('/', unixifyPath(ref)))
return secured.startsWith('.') ? '' : secured
}

function secureAndUnixifyPath (ref) {
return unixifyPath(securePath(ref))
}

// We don't want the `changes` array in here by default because this is a hot
// path for parsing packuments during install. So the calling method passes it
// in if it wants to track changes.
Expand Down Expand Up @@ -251,7 +284,7 @@ const normalize = async (pkg, { strict, steps, root, changes, allowLegacyCase })

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

// expand directories.man
if (steps.includes('mans') && !data.man && data.directories?.man) {
const manDir = data.directories.man
const cwd = path.resolve(pkg.path, manDir)
const files = await lazyLoadGlob()('**/*.[0-9]', { cwd })
data.man = files.map(man =>
path.relative(pkg.path, path.join(cwd, man)).split(path.sep).join('/')
)
if (steps.includes('mans')) {
if (data.directories?.man && !data.man) {
const manDir = secureAndUnixifyPath(data.directories.man)
const cwd = path.resolve(pkg.path, manDir)
const files = await lazyLoadGlob()('**/*.[0-9]', { cwd })
data.man = files.map(man =>
path.relative(pkg.path, path.join(cwd, man)).split(path.sep).join('/')
)
}
normalizePackageMan(data, changes)
}

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

// expand "directories.bin"
if (steps.includes('binDir') && data.directories?.bin && !data.bin) {
const binsDir = path.resolve(pkg.path, path.join('.', path.join('/', data.directories.bin)))
const binsDir = path.resolve(pkg.path, securePath(data.directories.bin))
const bins = await lazyLoadGlob()('**', { cwd: binsDir })
data.bin = bins.reduce((acc, binFile) => {
if (binFile && !binFile.startsWith('.')) {
Expand Down
8 changes: 4 additions & 4 deletions node_modules/@npmcli/package-json/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@npmcli/package-json",
"version": "5.1.0",
"version": "5.1.1",
"description": "Programmatic API to update package.json",
"main": "lib/index.js",
"files": [
Expand All @@ -25,7 +25,7 @@
"license": "ISC",
"devDependencies": {
"@npmcli/eslint-config": "^4.0.0",
"@npmcli/template-oss": "4.21.4",
"@npmcli/template-oss": "4.22.0",
"read-package-json": "^7.0.0",
"read-package-json-fast": "^3.0.2",
"tap": "^16.0.1"
Expand All @@ -41,14 +41,14 @@
},
"repository": {
"type": "git",
"url": "https://github.com/npm/package-json.git"
"url": "git+https://github.com/npm/package-json.git"
},
"engines": {
"node": "^16.14.0 || >=18.0.0"
},
"templateOSS": {
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
"version": "4.21.4",
"version": "4.22.0",
"publish": "true"
},
"tap": {
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"@npmcli/config": "^8.3.2",
"@npmcli/fs": "^3.1.1",
"@npmcli/map-workspaces": "^3.0.6",
"@npmcli/package-json": "^5.1.0",
"@npmcli/package-json": "^5.1.1",
"@npmcli/promise-spawn": "^7.0.2",
"@npmcli/redact": "^2.0.0",
"@npmcli/run-script": "^8.1.0",
Expand Down Expand Up @@ -1716,9 +1716,9 @@
}
},
"node_modules/@npmcli/package-json": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/@npmcli/package-json/-/package-json-5.1.0.tgz",
"integrity": "sha512-1aL4TuVrLS9sf8quCLerU3H9J4vtCtgu8VauYozrmEyU57i/EdKleCnsQ7vpnABIH6c9mnTxcH5sFkO3BlV8wQ==",
"version": "5.1.1",
"resolved": "https://registry.npmjs.org/@npmcli/package-json/-/package-json-5.1.1.tgz",
"integrity": "sha512-uTq5j/UqUzbOaOxVy+osfOhpqOiLfUZ0Ut33UbcyyAPJbZcJsf4Mrsyb8r58FoIFlofw0iOFsuCA/oDK14VDJQ==",
"inBundle": true,
"license": "ISC",
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"@npmcli/config": "^8.3.2",
"@npmcli/fs": "^3.1.1",
"@npmcli/map-workspaces": "^3.0.6",
"@npmcli/package-json": "^5.1.0",
"@npmcli/package-json": "^5.1.1",
"@npmcli/promise-spawn": "^7.0.2",
"@npmcli/redact": "^2.0.0",
"@npmcli/run-script": "^8.1.0",
Expand Down

0 comments on commit e3f0fd4

Please # to comment.