Skip to content

Commit feac87c

Browse files
committed
deps: update @npmcli/[email protected]
1 parent dd90f9e commit feac87c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+6764
-55
lines changed

DEPENDENCIES.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ graph LR;
207207
npmcli-installed-package-contents-->npm-bundled;
208208
npmcli-installed-package-contents-->npm-normalize-package-bin;
209209
npmcli-map-workspaces-->npmcli-name-from-folder["@npmcli/name-from-folder"];
210-
npmcli-map-workspaces-->read-package-json-fast;
210+
npmcli-map-workspaces-->npmcli-package-json["@npmcli/package-json"];
211211
npmcli-metavuln-calculator-->cacache;
212212
npmcli-metavuln-calculator-->json-parse-even-better-errors;
213213
npmcli-metavuln-calculator-->pacote;
@@ -655,7 +655,7 @@ graph LR;
655655
npmcli-map-workspaces-->glob;
656656
npmcli-map-workspaces-->minimatch;
657657
npmcli-map-workspaces-->npmcli-name-from-folder["@npmcli/name-from-folder"];
658-
npmcli-map-workspaces-->read-package-json-fast;
658+
npmcli-map-workspaces-->npmcli-package-json["@npmcli/package-json"];
659659
npmcli-metavuln-calculator-->cacache;
660660
npmcli-metavuln-calculator-->json-parse-even-better-errors;
661661
npmcli-metavuln-calculator-->pacote;
@@ -794,10 +794,10 @@ packages higher up the chain.
794794
- @npmcli/mock-registry, libnpmdiff, libnpmfund, libnpmpack
795795
- @npmcli/arborist
796796
- @npmcli/metavuln-calculator
797-
- pacote, libnpmversion
798-
- @npmcli/run-script, @npmcli/config, libnpmhook, libnpmorg, libnpmsearch, libnpmteam, init-package-json, npm-profile
797+
- pacote, @npmcli/config, libnpmversion
798+
- @npmcli/map-workspaces, @npmcli/run-script, libnpmhook, libnpmorg, libnpmsearch, libnpmteam, init-package-json, npm-profile
799799
- @npmcli/package-json, npm-registry-fetch
800800
- @npmcli/git, make-fetch-happen
801-
- @npmcli/installed-package-contents, @npmcli/map-workspaces, cacache, npm-pick-manifest, promzard
802-
- @npmcli/docs, @npmcli/fs, npm-bundled, read-package-json-fast, unique-filename, npm-install-checks, npm-package-arg, normalize-package-data, npm-packlist, bin-links, nopt, parse-conflict-json, @npmcli/mock-globals, read
803-
- @npmcli/eslint-config, @npmcli/template-oss, ignore-walk, semver, npm-normalize-package-bin, @npmcli/name-from-folder, json-parse-even-better-errors, fs-minipass, ssri, unique-slug, @npmcli/promise-spawn, ini, hosted-git-info, proc-log, validate-npm-package-name, @npmcli/node-gyp, @npmcli/redact, @npmcli/agent, minipass-fetch, @npmcli/query, cmd-shim, read-cmd-shim, write-file-atomic, abbrev, proggy, minify-registry-metadata, mute-stream, npm-audit-report, npm-user-validate
801+
- @npmcli/installed-package-contents, npm-pick-manifest, cacache, promzard
802+
- @npmcli/docs, @npmcli/fs, npm-bundled, npm-install-checks, npm-package-arg, normalize-package-data, unique-filename, npm-packlist, bin-links, nopt, parse-conflict-json, read-package-json-fast, @npmcli/mock-globals, read
803+
- @npmcli/eslint-config, @npmcli/template-oss, ignore-walk, semver, npm-normalize-package-bin, @npmcli/name-from-folder, @npmcli/promise-spawn, ini, hosted-git-info, proc-log, validate-npm-package-name, json-parse-even-better-errors, fs-minipass, ssri, unique-slug, @npmcli/node-gyp, @npmcli/redact, @npmcli/agent, minipass-fetch, @npmcli/query, cmd-shim, read-cmd-shim, write-file-atomic, abbrev, proggy, minify-registry-metadata, mute-stream, npm-audit-report, npm-user-validate

node_modules/.gitignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,26 @@
2020
!/@npmcli/git
2121
!/@npmcli/installed-package-contents
2222
!/@npmcli/map-workspaces
23+
!/@npmcli/map-workspaces/node_modules/
24+
/@npmcli/map-workspaces/node_modules/*
25+
!/@npmcli/map-workspaces/node_modules/@npmcli/
26+
/@npmcli/map-workspaces/node_modules/@npmcli/*
27+
!/@npmcli/map-workspaces/node_modules/@npmcli/git
28+
!/@npmcli/map-workspaces/node_modules/@npmcli/name-from-folder
29+
!/@npmcli/map-workspaces/node_modules/@npmcli/package-json
30+
!/@npmcli/map-workspaces/node_modules/@npmcli/promise-spawn
31+
!/@npmcli/map-workspaces/node_modules/hosted-git-info
32+
!/@npmcli/map-workspaces/node_modules/ini
33+
!/@npmcli/map-workspaces/node_modules/isexe
34+
!/@npmcli/map-workspaces/node_modules/json-parse-even-better-errors
35+
!/@npmcli/map-workspaces/node_modules/normalize-package-data
36+
!/@npmcli/map-workspaces/node_modules/npm-install-checks
37+
!/@npmcli/map-workspaces/node_modules/npm-normalize-package-bin
38+
!/@npmcli/map-workspaces/node_modules/npm-package-arg
39+
!/@npmcli/map-workspaces/node_modules/npm-pick-manifest
40+
!/@npmcli/map-workspaces/node_modules/proc-log
41+
!/@npmcli/map-workspaces/node_modules/validate-npm-package-name
42+
!/@npmcli/map-workspaces/node_modules/which
2343
!/@npmcli/metavuln-calculator
2444
!/@npmcli/name-from-folder
2545
!/@npmcli/node-gyp

node_modules/@npmcli/map-workspaces/lib/index.js

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const path = require('path')
22

33
const getName = require('@npmcli/name-from-folder')
44
const { minimatch } = require('minimatch')
5-
const rpj = require('read-package-json-fast')
5+
const pkgJson = require('@npmcli/package-json')
66
const { glob } = require('glob')
77

88
function appendNegatedPatterns (allPatterns) {
@@ -67,15 +67,7 @@ function getPatterns (workspaces) {
6767
}
6868

6969
function getPackageName (pkg, pathname) {
70-
const { name } = pkg
71-
return name || getName(pathname)
72-
}
73-
74-
function pkgPathmame (opts) {
75-
return (...args) => {
76-
const cwd = opts.cwd ? opts.cwd : process.cwd()
77-
return path.join.apply(null, [cwd, ...args])
78-
}
70+
return pkg.name || getName(pathname)
7971
}
8072

8173
// make sure glob pattern only matches folders
@@ -101,16 +93,19 @@ async function mapWorkspaces (opts = {}) {
10193
code: 'EMAPWORKSPACESPKG',
10294
})
10395
}
96+
if (!opts.cwd) {
97+
opts.cwd = process.cwd()
98+
}
10499

105100
const { workspaces = [] } = opts.pkg
106101
const { patterns, negatedPatterns } = getPatterns(workspaces)
107102
const results = new Map()
108-
const seen = new Map()
109103

110104
if (!patterns.length && !negatedPatterns.length) {
111105
return results
112106
}
113107

108+
const seen = new Map()
114109
const getGlobOpts = () => ({
115110
...opts,
116111
ignore: [
@@ -121,8 +116,6 @@ async function mapWorkspaces (opts = {}) {
121116
],
122117
})
123118

124-
const getPackagePathname = pkgPathmame(opts)
125-
126119
let matches = await glob(patterns.map((p) => getGlobPattern(p)), getGlobOpts())
127120
// preserves glob@8 behavior
128121
matches = matches.sort((a, b) => a.localeCompare(b, 'en'))
@@ -138,10 +131,8 @@ async function mapWorkspaces (opts = {}) {
138131

139132
for (const match of orderedMatches) {
140133
let pkg
141-
const packageJsonPathname = getPackagePathname(match, 'package.json')
142-
143134
try {
144-
pkg = await rpj(packageJsonPathname)
135+
pkg = await pkgJson.normalize(path.join(opts.cwd, match))
145136
} catch (err) {
146137
if (err.code === 'ENOENT') {
147138
continue
@@ -150,15 +141,14 @@ async function mapWorkspaces (opts = {}) {
150141
}
151142
}
152143

153-
const packagePathname = path.dirname(packageJsonPathname)
154-
const name = getPackageName(pkg, packagePathname)
144+
const name = getPackageName(pkg.content, pkg.path)
155145

156146
let seenPackagePathnames = seen.get(name)
157147
if (!seenPackagePathnames) {
158148
seenPackagePathnames = new Set()
159149
seen.set(name, seenPackagePathnames)
160150
}
161-
seenPackagePathnames.add(packagePathname)
151+
seenPackagePathnames.add(pkg.path)
162152
}
163153

164154
const errorMessageArray = ['must not have multiple workspaces with the same name']
@@ -200,6 +190,9 @@ mapWorkspaces.virtual = function (opts = {}) {
200190
code: 'EMAPWORKSPACESLOCKFILE',
201191
})
202192
}
193+
if (!opts.cwd) {
194+
opts.cwd = process.cwd()
195+
}
203196

204197
const { packages = {} } = opts.lockfile
205198
const { workspaces = [] } = packages[''] || {}
@@ -218,10 +211,9 @@ mapWorkspaces.virtual = function (opts = {}) {
218211
}
219212
}
220213

221-
const getPackagePathname = pkgPathmame(opts)
222214
for (const pattern of patterns) {
223215
for (const packageKey of minimatch.match(packageKeys, pattern)) {
224-
const packagePathname = getPackagePathname(packageKey)
216+
const packagePathname = path.join(opts.cwd, packageKey)
225217
const name = getPackageName(packages[packageKey], packagePathname)
226218
results.set(packagePathname, name)
227219
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
The ISC License
2+
3+
Copyright (c) npm, Inc.
4+
5+
Permission to use, copy, modify, and/or distribute this software for any
6+
purpose with or without fee is hereby granted, provided that the above
7+
copyright notice and this permission notice appear in all copies.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS" AND THE NPM DISCLAIMS ALL WARRANTIES WITH
10+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
11+
FITNESS. IN NO EVENT SHALL THE NPM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
12+
OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
13+
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
14+
ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
15+
SOFTWARE.
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
// The goal here is to minimize both git workload and
2+
// the number of refs we download over the network.
3+
//
4+
// Every method ends up with the checked out working dir
5+
// at the specified ref, and resolves with the git sha.
6+
7+
// Only certain whitelisted hosts get shallow cloning.
8+
// Many hosts (including GHE) don't always support it.
9+
// A failed shallow fetch takes a LOT longer than a full
10+
// fetch in most cases, so we skip it entirely.
11+
// Set opts.gitShallow = true/false to force this behavior
12+
// one way or the other.
13+
const shallowHosts = new Set([
14+
'github.com',
15+
'gist.github.com',
16+
'gitlab.com',
17+
'bitbucket.com',
18+
'bitbucket.org',
19+
])
20+
// we have to use url.parse until we add the same shim that hosted-git-info has
21+
// to handle scp:// urls
22+
const { parse } = require('url') // eslint-disable-line node/no-deprecated-api
23+
const path = require('path')
24+
25+
const getRevs = require('./revs.js')
26+
const spawn = require('./spawn.js')
27+
const { isWindows } = require('./utils.js')
28+
29+
const pickManifest = require('npm-pick-manifest')
30+
const fs = require('fs/promises')
31+
32+
module.exports = (repo, ref = 'HEAD', target = null, opts = {}) =>
33+
getRevs(repo, opts).then(revs => clone(
34+
repo,
35+
revs,
36+
ref,
37+
resolveRef(revs, ref, opts),
38+
target || defaultTarget(repo, opts.cwd),
39+
opts
40+
))
41+
42+
const maybeShallow = (repo, opts) => {
43+
if (opts.gitShallow === false || opts.gitShallow) {
44+
return opts.gitShallow
45+
}
46+
return shallowHosts.has(parse(repo).host)
47+
}
48+
49+
const defaultTarget = (repo, /* istanbul ignore next */ cwd = process.cwd()) =>
50+
path.resolve(cwd, path.basename(repo.replace(/[/\\]?\.git$/, '')))
51+
52+
const clone = (repo, revs, ref, revDoc, target, opts) => {
53+
if (!revDoc) {
54+
return unresolved(repo, ref, target, opts)
55+
}
56+
if (revDoc.sha === revs.refs.HEAD.sha) {
57+
return plain(repo, revDoc, target, opts)
58+
}
59+
if (revDoc.type === 'tag' || revDoc.type === 'branch') {
60+
return branch(repo, revDoc, target, opts)
61+
}
62+
return other(repo, revDoc, target, opts)
63+
}
64+
65+
const resolveRef = (revs, ref, opts) => {
66+
const { spec = {} } = opts
67+
ref = spec.gitCommittish || ref
68+
/* istanbul ignore next - will fail anyway, can't pull */
69+
if (!revs) {
70+
return null
71+
}
72+
if (spec.gitRange) {
73+
return pickManifest(revs, spec.gitRange, opts)
74+
}
75+
if (!ref) {
76+
return revs.refs.HEAD
77+
}
78+
if (revs.refs[ref]) {
79+
return revs.refs[ref]
80+
}
81+
if (revs.shas[ref]) {
82+
return revs.refs[revs.shas[ref][0]]
83+
}
84+
return null
85+
}
86+
87+
// pull request or some other kind of advertised ref
88+
const other = (repo, revDoc, target, opts) => {
89+
const shallow = maybeShallow(repo, opts)
90+
91+
const fetchOrigin = ['fetch', 'origin', revDoc.rawRef]
92+
.concat(shallow ? ['--depth=1'] : [])
93+
94+
const git = (args) => spawn(args, { ...opts, cwd: target })
95+
return fs.mkdir(target, { recursive: true })
96+
.then(() => git(['init']))
97+
.then(() => isWindows(opts)
98+
? git(['config', '--local', '--add', 'core.longpaths', 'true'])
99+
: null)
100+
.then(() => git(['remote', 'add', 'origin', repo]))
101+
.then(() => git(fetchOrigin))
102+
.then(() => git(['checkout', revDoc.sha]))
103+
.then(() => updateSubmodules(target, opts))
104+
.then(() => revDoc.sha)
105+
}
106+
107+
// tag or branches. use -b
108+
const branch = (repo, revDoc, target, opts) => {
109+
const args = [
110+
'clone',
111+
'-b',
112+
revDoc.ref,
113+
repo,
114+
target,
115+
'--recurse-submodules',
116+
]
117+
if (maybeShallow(repo, opts)) {
118+
args.push('--depth=1')
119+
}
120+
if (isWindows(opts)) {
121+
args.push('--config', 'core.longpaths=true')
122+
}
123+
return spawn(args, opts).then(() => revDoc.sha)
124+
}
125+
126+
// just the head. clone it
127+
const plain = (repo, revDoc, target, opts) => {
128+
const args = [
129+
'clone',
130+
repo,
131+
target,
132+
'--recurse-submodules',
133+
]
134+
if (maybeShallow(repo, opts)) {
135+
args.push('--depth=1')
136+
}
137+
if (isWindows(opts)) {
138+
args.push('--config', 'core.longpaths=true')
139+
}
140+
return spawn(args, opts).then(() => revDoc.sha)
141+
}
142+
143+
const updateSubmodules = async (target, opts) => {
144+
const hasSubmodules = await fs.stat(`${target}/.gitmodules`)
145+
.then(() => true)
146+
.catch(() => false)
147+
if (!hasSubmodules) {
148+
return null
149+
}
150+
return spawn([
151+
'submodule',
152+
'update',
153+
'-q',
154+
'--init',
155+
'--recursive',
156+
], { ...opts, cwd: target })
157+
}
158+
159+
const unresolved = (repo, ref, target, opts) => {
160+
// can't do this one shallowly, because the ref isn't advertised
161+
// but we can avoid checking out the working dir twice, at least
162+
const lp = isWindows(opts) ? ['--config', 'core.longpaths=true'] : []
163+
const cloneArgs = ['clone', '--mirror', '-q', repo, target + '/.git']
164+
const git = (args) => spawn(args, { ...opts, cwd: target })
165+
return fs.mkdir(target, { recursive: true })
166+
.then(() => git(cloneArgs.concat(lp)))
167+
.then(() => git(['init']))
168+
.then(() => git(['checkout', ref]))
169+
.then(() => updateSubmodules(target, opts))
170+
.then(() => git(['rev-parse', '--revs-only', 'HEAD']))
171+
.then(({ stdout }) => stdout.trim())
172+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
const maxRetry = 3
3+
4+
class GitError extends Error {
5+
shouldRetry () {
6+
return false
7+
}
8+
}
9+
10+
class GitConnectionError extends GitError {
11+
constructor () {
12+
super('A git connection error occurred')
13+
}
14+
15+
shouldRetry (number) {
16+
return number < maxRetry
17+
}
18+
}
19+
20+
class GitPathspecError extends GitError {
21+
constructor () {
22+
super('The git reference could not be found')
23+
}
24+
}
25+
26+
class GitUnknownError extends GitError {
27+
constructor () {
28+
super('An unknown git error occurred')
29+
}
30+
}
31+
32+
module.exports = {
33+
GitConnectionError,
34+
GitPathspecError,
35+
GitUnknownError,
36+
}

0 commit comments

Comments
 (0)