Skip to content

Commit 7dbef6f

Browse files
reggiwraithgar
authored andcommitted
deps: pacote@20.0.0
1 parent e19bff0 commit 7dbef6f

File tree

27 files changed

+1911
-48
lines changed

27 files changed

+1911
-48
lines changed

mock-registry/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"json-stringify-safe": "^5.0.1",
5353
"nock": "^13.3.3",
5454
"npm-package-arg": "^12.0.0",
55-
"pacote": "^19.0.0",
55+
"pacote": "^20.0.0",
5656
"tap": "^16.3.8"
5757
}
5858
}

node_modules/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
!/@npmcli/installed-package-contents
2323
!/@npmcli/map-workspaces
2424
!/@npmcli/metavuln-calculator
25+
!/@npmcli/metavuln-calculator/node_modules/
26+
/@npmcli/metavuln-calculator/node_modules/*
27+
!/@npmcli/metavuln-calculator/node_modules/pacote
2528
!/@npmcli/name-from-folder
2629
!/@npmcli/node-gyp
2730
!/@npmcli/package-json
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) Isaac Z. Schlueter, Kat Marchán, npm, Inc., and Contributors
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 AUTHOR DISCLAIMS ALL WARRANTIES
10+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
15+
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
#!/usr/bin/env node
2+
3+
const run = conf => {
4+
const pacote = require('../')
5+
switch (conf._[0]) {
6+
case 'resolve':
7+
case 'manifest':
8+
case 'packument':
9+
if (conf._[0] === 'resolve' && conf.long) {
10+
return pacote.manifest(conf._[1], conf).then(mani => ({
11+
resolved: mani._resolved,
12+
integrity: mani._integrity,
13+
from: mani._from,
14+
}))
15+
}
16+
return pacote[conf._[0]](conf._[1], conf)
17+
18+
case 'tarball':
19+
if (!conf._[2] || conf._[2] === '-') {
20+
return pacote.tarball.stream(conf._[1], stream => {
21+
stream.pipe(
22+
conf.testStdout ||
23+
/* istanbul ignore next */
24+
process.stdout
25+
)
26+
// make sure it resolves something falsey
27+
return stream.promise().then(() => {
28+
return false
29+
})
30+
}, conf)
31+
} else {
32+
return pacote.tarball.file(conf._[1], conf._[2], conf)
33+
}
34+
35+
case 'extract':
36+
return pacote.extract(conf._[1], conf._[2], conf)
37+
38+
default: /* istanbul ignore next */ {
39+
throw new Error(`bad command: ${conf._[0]}`)
40+
}
41+
}
42+
}
43+
44+
const version = require('../package.json').version
45+
const usage = () =>
46+
`Pacote - The JavaScript Package Handler, v${version}
47+
48+
Usage:
49+
50+
pacote resolve <spec>
51+
Resolve a specifier and output the fully resolved target
52+
Returns integrity and from if '--long' flag is set.
53+
54+
pacote manifest <spec>
55+
Fetch a manifest and print to stdout
56+
57+
pacote packument <spec>
58+
Fetch a full packument and print to stdout
59+
60+
pacote tarball <spec> [<filename>]
61+
Fetch a package tarball and save to <filename>
62+
If <filename> is missing or '-', the tarball will be streamed to stdout.
63+
64+
pacote extract <spec> <folder>
65+
Extract a package to the destination folder.
66+
67+
Configuration values all match the names of configs passed to npm, or
68+
options passed to Pacote. Additional flags for this executable:
69+
70+
--long Print an object from 'resolve', including integrity and spec.
71+
--json Print result objects as JSON rather than node's default.
72+
(This is the default if stdout is not a TTY.)
73+
--help -h Print this helpful text.
74+
75+
For example '--cache=/path/to/folder' will use that folder as the cache.
76+
`
77+
78+
const shouldJSON = (conf, result) =>
79+
conf.json ||
80+
!process.stdout.isTTY &&
81+
conf.json === undefined &&
82+
result &&
83+
typeof result === 'object'
84+
85+
const pretty = (conf, result) =>
86+
shouldJSON(conf, result) ? JSON.stringify(result, 0, 2) : result
87+
88+
let addedLogListener = false
89+
const main = args => {
90+
const conf = parse(args)
91+
if (conf.help || conf.h) {
92+
return console.log(usage())
93+
}
94+
95+
if (!addedLogListener) {
96+
process.on('log', console.error)
97+
addedLogListener = true
98+
}
99+
100+
try {
101+
return run(conf)
102+
.then(result => result && console.log(pretty(conf, result)))
103+
.catch(er => {
104+
console.error(er)
105+
process.exit(1)
106+
})
107+
} catch (er) {
108+
console.error(er.message)
109+
console.error(usage())
110+
}
111+
}
112+
113+
const parseArg = arg => {
114+
const split = arg.slice(2).split('=')
115+
const k = split.shift()
116+
const v = split.join('=')
117+
const no = /^no-/.test(k) && !v
118+
const key = (no ? k.slice(3) : k)
119+
.replace(/^tag$/, 'defaultTag')
120+
.replace(/-([a-z])/g, (_, c) => c.toUpperCase())
121+
const value = v ? v.replace(/^~/, process.env.HOME) : !no
122+
return { key, value }
123+
}
124+
125+
const parse = args => {
126+
const conf = {
127+
_: [],
128+
cache: process.env.HOME + '/.npm/_cacache',
129+
}
130+
let dashdash = false
131+
args.forEach(arg => {
132+
if (dashdash) {
133+
conf._.push(arg)
134+
} else if (arg === '--') {
135+
dashdash = true
136+
} else if (arg === '-h') {
137+
conf.help = true
138+
} else if (/^--/.test(arg)) {
139+
const { key, value } = parseArg(arg)
140+
conf[key] = value
141+
} else {
142+
conf._.push(arg)
143+
}
144+
})
145+
return conf
146+
}
147+
148+
if (module === require.main) {
149+
main(process.argv.slice(2))
150+
} else {
151+
module.exports = {
152+
main,
153+
run,
154+
usage,
155+
parseArg,
156+
parse,
157+
}
158+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
const { resolve } = require('node:path')
2+
const packlist = require('npm-packlist')
3+
const runScript = require('@npmcli/run-script')
4+
const tar = require('tar')
5+
const { Minipass } = require('minipass')
6+
const Fetcher = require('./fetcher.js')
7+
const FileFetcher = require('./file.js')
8+
const _ = require('./util/protected.js')
9+
const tarCreateOptions = require('./util/tar-create-options.js')
10+
11+
class DirFetcher extends Fetcher {
12+
constructor (spec, opts) {
13+
super(spec, opts)
14+
// just the fully resolved filename
15+
this.resolved = this.spec.fetchSpec
16+
17+
this.tree = opts.tree || null
18+
this.Arborist = opts.Arborist || null
19+
}
20+
21+
// exposes tarCreateOptions as public API
22+
static tarCreateOptions (manifest) {
23+
return tarCreateOptions(manifest)
24+
}
25+
26+
get types () {
27+
return ['directory']
28+
}
29+
30+
#prepareDir () {
31+
return this.manifest().then(mani => {
32+
if (!mani.scripts || !mani.scripts.prepare) {
33+
return
34+
}
35+
36+
// we *only* run prepare.
37+
// pre/post-pack is run by the npm CLI for publish and pack,
38+
// but this function is *also* run when installing git deps
39+
const stdio = this.opts.foregroundScripts ? 'inherit' : 'pipe'
40+
41+
return runScript({
42+
// this || undefined is because runScript will be unhappy with the default null value
43+
scriptShell: this.opts.scriptShell || undefined,
44+
pkg: mani,
45+
event: 'prepare',
46+
path: this.resolved,
47+
stdio,
48+
env: {
49+
npm_package_resolved: this.resolved,
50+
npm_package_integrity: this.integrity,
51+
npm_package_json: resolve(this.resolved, 'package.json'),
52+
},
53+
})
54+
})
55+
}
56+
57+
[_.tarballFromResolved] () {
58+
if (!this.tree && !this.Arborist) {
59+
throw new Error('DirFetcher requires either a tree or an Arborist constructor to pack')
60+
}
61+
62+
const stream = new Minipass()
63+
stream.resolved = this.resolved
64+
stream.integrity = this.integrity
65+
66+
const { prefix, workspaces } = this.opts
67+
68+
// run the prepare script, get the list of files, and tar it up
69+
// pipe to the stream, and proxy errors the chain.
70+
this.#prepareDir()
71+
.then(async () => {
72+
if (!this.tree) {
73+
const arb = new this.Arborist({ path: this.resolved })
74+
this.tree = await arb.loadActual()
75+
}
76+
return packlist(this.tree, { path: this.resolved, prefix, workspaces })
77+
})
78+
.then(files => tar.c(tarCreateOptions(this.package), files)
79+
.on('error', er => stream.emit('error', er)).pipe(stream))
80+
.catch(er => stream.emit('error', er))
81+
return stream
82+
}
83+
84+
manifest () {
85+
if (this.package) {
86+
return Promise.resolve(this.package)
87+
}
88+
89+
return this[_.readPackageJson](this.resolved)
90+
.then(mani => this.package = {
91+
...mani,
92+
_integrity: this.integrity && String(this.integrity),
93+
_resolved: this.resolved,
94+
_from: this.from,
95+
})
96+
}
97+
98+
packument () {
99+
return FileFetcher.prototype.packument.apply(this)
100+
}
101+
}
102+
module.exports = DirFetcher

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy