Skip to content

Commit

Permalink
deps: update npm-package-arg@12.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
reggi committed Oct 2, 2024
1 parent 591130d commit 50a7bc8
Show file tree
Hide file tree
Showing 38 changed files with 1,329 additions and 112 deletions.
2 changes: 1 addition & 1 deletion mock-registry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@npmcli/template-oss": "4.23.3",
"json-stringify-safe": "^5.0.1",
"nock": "^13.3.3",
"npm-package-arg": "^11.0.2",
"npm-package-arg": "^12.0.0",
"pacote": "^18.0.6",
"tap": "^16.3.8"
}
Expand Down
12 changes: 7 additions & 5 deletions node_modules/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@
!/@npmcli/package-json/node_modules/@npmcli/git
!/@npmcli/package-json/node_modules/isexe
!/@npmcli/package-json/node_modules/npm-normalize-package-bin
!/@npmcli/package-json/node_modules/npm-package-arg
!/@npmcli/package-json/node_modules/npm-pick-manifest
!/@npmcli/package-json/node_modules/proc-log
!/@npmcli/package-json/node_modules/validate-npm-package-name
!/@npmcli/package-json/node_modules/which
!/@npmcli/promise-spawn
!/@npmcli/promise-spawn/node_modules/
Expand Down Expand Up @@ -163,8 +161,6 @@
!/init-package-json/node_modules/
/init-package-json/node_modules/*
!/init-package-json/node_modules/mute-stream
!/init-package-json/node_modules/npm-package-arg
!/init-package-json/node_modules/proc-log
!/init-package-json/node_modules/read
!/init-package-json/node_modules/validate-npm-package-name
!/ip-address
Expand Down Expand Up @@ -237,12 +233,15 @@
!/npm-package-arg
!/npm-package-arg/node_modules/
/npm-package-arg/node_modules/*
!/npm-package-arg/node_modules/hosted-git-info
!/npm-package-arg/node_modules/proc-log
!/npm-package-arg/node_modules/validate-npm-package-name
!/npm-packlist
!/npm-pick-manifest
!/npm-pick-manifest/node_modules/
/npm-pick-manifest/node_modules/*
!/npm-pick-manifest/node_modules/hosted-git-info
!/npm-pick-manifest/node_modules/npm-install-checks
!/npm-pick-manifest/node_modules/npm-package-arg
!/npm-profile
!/npm-registry-fetch
!/npm-registry-fetch/node_modules/
Expand All @@ -253,7 +252,9 @@
!/npm-registry-fetch/node_modules/@npmcli/fs
!/npm-registry-fetch/node_modules/@npmcli/redact
!/npm-registry-fetch/node_modules/cacache
!/npm-registry-fetch/node_modules/hosted-git-info
!/npm-registry-fetch/node_modules/make-fetch-happen
!/npm-registry-fetch/node_modules/npm-package-arg
!/npm-registry-fetch/node_modules/unique-filename
!/npm-registry-fetch/node_modules/unique-slug
!/npm-user-validate
Expand All @@ -272,6 +273,7 @@
!/pacote/node_modules/hosted-git-info
!/pacote/node_modules/json-parse-even-better-errors
!/pacote/node_modules/normalize-package-data
!/pacote/node_modules/npm-package-arg
!/pacote/node_modules/unique-filename
!/pacote/node_modules/unique-slug
!/parse-conflict-json
Expand Down
16 changes: 8 additions & 8 deletions node_modules/npm-package-arg/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "npm-package-arg",
"version": "11.0.3",
"version": "12.0.0",
"description": "Parse the things that can be arguments to `npm install`",
"main": "./lib/npa.js",
"directories": {
Expand All @@ -11,14 +11,14 @@
"lib/"
],
"dependencies": {
"hosted-git-info": "^7.0.0",
"proc-log": "^4.0.0",
"hosted-git-info": "^8.0.0",
"proc-log": "^5.0.0",
"semver": "^7.3.5",
"validate-npm-package-name": "^5.0.0"
"validate-npm-package-name": "^6.0.0"
},
"devDependencies": {
"@npmcli/eslint-config": "^4.0.0",
"@npmcli/template-oss": "4.23.1",
"@npmcli/eslint-config": "^5.0.0",
"@npmcli/template-oss": "4.23.3",
"tap": "^16.0.1"
},
"scripts": {
Expand All @@ -44,7 +44,7 @@
},
"homepage": "https://github.com/npm/npm-package-arg",
"engines": {
"node": "^16.14.0 || >=18.0.0"
"node": "^18.17.0 || >=20.5.0"
},
"tap": {
"branches": 97,
Expand All @@ -55,7 +55,7 @@
},
"templateOSS": {
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
"version": "4.23.1",
"version": "4.23.3",
"publish": true
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "npm-package-arg",
"version": "12.0.0",
"version": "11.0.3",
"description": "Parse the things that can be arguments to `npm install`",
"main": "./lib/npa.js",
"directories": {
Expand All @@ -11,14 +11,14 @@
"lib/"
],
"dependencies": {
"hosted-git-info": "^8.0.0",
"proc-log": "^5.0.0",
"hosted-git-info": "^7.0.0",
"proc-log": "^4.0.0",
"semver": "^7.3.5",
"validate-npm-package-name": "^6.0.0"
"validate-npm-package-name": "^5.0.0"
},
"devDependencies": {
"@npmcli/eslint-config": "^5.0.0",
"@npmcli/template-oss": "4.23.3",
"@npmcli/eslint-config": "^4.0.0",
"@npmcli/template-oss": "4.23.1",
"tap": "^16.0.1"
},
"scripts": {
Expand All @@ -44,7 +44,7 @@
},
"homepage": "https://github.com/npm/npm-package-arg",
"engines": {
"node": "^18.17.0 || >=20.5.0"
"node": "^16.14.0 || >=18.0.0"
},
"tap": {
"branches": 97,
Expand All @@ -55,7 +55,7 @@
},
"templateOSS": {
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
"version": "4.23.3",
"version": "4.23.1",
"publish": true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright (c) 2015, Rebecca Turner

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
'use strict'

const parseUrl = require('./parse-url')

// look for github shorthand inputs, such as npm/cli
const isGitHubShorthand = (arg) => {
// it cannot contain whitespace before the first #
// it cannot start with a / because that's probably an absolute file path
// but it must include a slash since repos are username/repository
// it cannot start with a . because that's probably a relative file path
// it cannot start with an @ because that's a scoped package if it passes the other tests
// it cannot contain a : before a # because that tells us that there's a protocol
// a second / may not exist before a #
const firstHash = arg.indexOf('#')
const firstSlash = arg.indexOf('/')
const secondSlash = arg.indexOf('/', firstSlash + 1)
const firstColon = arg.indexOf(':')
const firstSpace = /\s/.exec(arg)
const firstAt = arg.indexOf('@')

const spaceOnlyAfterHash = !firstSpace || (firstHash > -1 && firstSpace.index > firstHash)
const atOnlyAfterHash = firstAt === -1 || (firstHash > -1 && firstAt > firstHash)
const colonOnlyAfterHash = firstColon === -1 || (firstHash > -1 && firstColon > firstHash)
const secondSlashOnlyAfterHash = secondSlash === -1 || (firstHash > -1 && secondSlash > firstHash)
const hasSlash = firstSlash > 0
// if a # is found, what we really want to know is that the character
// immediately before # is not a /
const doesNotEndWithSlash = firstHash > -1 ? arg[firstHash - 1] !== '/' : !arg.endsWith('/')
const doesNotStartWithDot = !arg.startsWith('.')

return spaceOnlyAfterHash && hasSlash && doesNotEndWithSlash &&
doesNotStartWithDot && atOnlyAfterHash && colonOnlyAfterHash &&
secondSlashOnlyAfterHash
}

module.exports = (giturl, opts, { gitHosts, protocols }) => {
if (!giturl) {
return
}

const correctedUrl = isGitHubShorthand(giturl) ? `github:${giturl}` : giturl
const parsed = parseUrl(correctedUrl, protocols)
if (!parsed) {
return
}

const gitHostShortcut = gitHosts.byShortcut[parsed.protocol]
const gitHostDomain = gitHosts.byDomain[parsed.hostname.startsWith('www.')
? parsed.hostname.slice(4)
: parsed.hostname]
const gitHostName = gitHostShortcut || gitHostDomain
if (!gitHostName) {
return
}

const gitHostInfo = gitHosts[gitHostShortcut || gitHostDomain]
let auth = null
if (protocols[parsed.protocol]?.auth && (parsed.username || parsed.password)) {
auth = `${parsed.username}${parsed.password ? ':' + parsed.password : ''}`
}

let committish = null
let user = null
let project = null
let defaultRepresentation = null

try {
if (gitHostShortcut) {
let pathname = parsed.pathname.startsWith('/') ? parsed.pathname.slice(1) : parsed.pathname
const firstAt = pathname.indexOf('@')
// we ignore auth for shortcuts, so just trim it out
if (firstAt > -1) {
pathname = pathname.slice(firstAt + 1)
}

const lastSlash = pathname.lastIndexOf('/')
if (lastSlash > -1) {
user = decodeURIComponent(pathname.slice(0, lastSlash))
// we want nulls only, never empty strings
if (!user) {
user = null
}
project = decodeURIComponent(pathname.slice(lastSlash + 1))
} else {
project = decodeURIComponent(pathname)
}

if (project.endsWith('.git')) {
project = project.slice(0, -4)
}

if (parsed.hash) {
committish = decodeURIComponent(parsed.hash.slice(1))
}

defaultRepresentation = 'shortcut'
} else {
if (!gitHostInfo.protocols.includes(parsed.protocol)) {
return
}

const segments = gitHostInfo.extract(parsed)
if (!segments) {
return
}

user = segments.user && decodeURIComponent(segments.user)
project = decodeURIComponent(segments.project)
committish = decodeURIComponent(segments.committish)
defaultRepresentation = protocols[parsed.protocol]?.name || parsed.protocol.slice(0, -1)
}
} catch (err) {
/* istanbul ignore else */
if (err instanceof URIError) {
return
} else {
throw err
}
}

return [gitHostName, user, auth, project, committish, defaultRepresentation, opts]
}
Loading

0 comments on commit 50a7bc8

Please sign in to comment.