Skip to content

Commit cf1c5ed

Browse files
authoredAug 16, 2022
fix: linting (#187)
1 parent 87d4b46 commit cf1c5ed

File tree

10 files changed

+145
-141
lines changed

10 files changed

+145
-141
lines changed
 

‎lib/bin.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,15 @@ const run = conf => {
1818
case 'tarball':
1919
if (!conf._[2] || conf._[2] === '-') {
2020
return pacote.tarball.stream(conf._[1], stream => {
21-
stream.pipe(conf.testStdout ||
22-
/* istanbul ignore next */ process.stdout)
21+
stream.pipe(
22+
conf.testStdout ||
23+
/* istanbul ignore next */
24+
process.stdout
25+
)
2326
// make sure it resolves something falsey
24-
return stream.promise().then(() => {})
27+
return stream.promise().then(() => {
28+
return false
29+
})
2530
}, conf)
2631
} else {
2732
return pacote.tarball.file(conf._[1], conf._[2], conf)

‎lib/fetcher.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ class FetcherBase {
254254
cstream.on('error', err => stream.emit('error', err))
255255
stream.pipe(cstream)
256256

257+
// eslint-disable-next-line promise/catch-or-return
257258
cstream.promise().catch(() => {}).then(() => middleStream.end())
258259
return middleStream
259260
}
@@ -269,7 +270,10 @@ class FetcherBase {
269270
}
270271

271272
// override the types getter
272-
get types () {}
273+
get types () {
274+
return false
275+
}
276+
273277
[_assertType] () {
274278
if (this.types && !this.types.includes(this.spec.type)) {
275279
throw new TypeError(`Wrong spec type (${

‎lib/git.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ class GitFetcher extends Fetcher {
239239
tarballOk = tarballOk &&
240240
h && resolved === repoUrl(h, { noCommittish: false }) && h.tarball
241241

242-
return cacache.tmp.withTmp(this.cache, o, tmp => {
242+
return cacache.tmp.withTmp(this.cache, o, async tmp => {
243243
// if we're resolved, and have a tarball url, shell out to RemoteFetcher
244244
if (tarballOk) {
245245
const nameat = this.spec.name ? `${this.spec.name}@` : ''
@@ -259,16 +259,15 @@ class GitFetcher extends Fetcher {
259259
})
260260
}
261261

262-
return (
262+
const sha = await (
263263
h ? this[_cloneHosted](ref, tmp)
264264
: this[_cloneRepo](this.spec.fetchSpec, ref, tmp)
265-
).then(sha => {
266-
this.resolvedSha = sha
267-
if (!this.resolved) {
268-
this[_addGitSha](sha)
269-
}
270-
})
271-
.then(() => handler(tmp))
265+
)
266+
this.resolvedSha = sha
267+
if (!this.resolved) {
268+
await this[_addGitSha](sha)
269+
}
270+
return handler(tmp)
272271
})
273272
}
274273

‎lib/remote.js

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class RemoteFetcher extends Fetcher {
4141
algorithms: [this.pickIntegrityAlgorithm()],
4242
}
4343

44+
// eslint-disable-next-line promise/always-return
4445
fetch(this.resolved, fetchOpts).then(res => {
4546
res.body.on('error',
4647
/* istanbul ignore next - exceedingly rare and hard to simulate */

‎tap-snapshots/test/bin.js.test.cjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ Object {
383383
`
384384

385385
exports[`test/bin.js TAP run > expect resolving Promise 6`] = `
386-
undefined
386+
false
387387
`
388388

389389
exports[`test/bin.js TAP running bin runs main file > helpful output 1`] = `

‎test/fetcher.js

+33-34
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,17 @@ t.test('snapshot the npmInstallCmd and npmInstallConfig', async t => {
9292
t.matchSnapshot(yarn.npmCliConfig, 'yarn style cli config stuff')
9393
})
9494

95-
t.test('tarball data', t =>
96-
new FileFetcher(abbrevspec, { cache }).tarball()
97-
.then(data => {
98-
t.equal(data.toString('hex'), fs.readFileSync(abbrev, 'hex'), 'without integrity')
99-
t.equal(data.integrity, abbrevMani._integrity, 'integrity calculated')
100-
})
101-
.then(() => new FileFetcher(abbrevspec, {
102-
cache,
103-
integrity: abbrevMani._integrity,
104-
}).tarball())
105-
.then(data => t.same(data, fs.readFileSync(abbrev), 'with integrity')))
95+
t.test('tarball data', async t => {
96+
const dataWithout = await new FileFetcher(abbrevspec, { cache }).tarball()
97+
t.equal(dataWithout.toString('hex'), fs.readFileSync(abbrev, 'hex'), 'without integrity')
98+
t.equal(dataWithout.integrity, abbrevMani._integrity, 'integrity calculated')
99+
100+
const dataWith = await new FileFetcher(abbrevspec, {
101+
cache,
102+
integrity: abbrevMani._integrity,
103+
}).tarball()
104+
t.same(dataWith, fs.readFileSync(abbrev), 'with integrity')
105+
})
106106

107107
t.test('tarballFile', t => {
108108
const target = resolve(me, 'tarball-file')
@@ -351,7 +351,7 @@ t.test('extract', t => {
351351
})
352352
})
353353

354-
t.test('extract into folder that already has a package in it', t => {
354+
t.test('extract into folder that already has a package in it', async t => {
355355
const dir = t.testdir({
356356
'package.json': JSON.stringify({
357357
name: 'weird',
@@ -384,28 +384,27 @@ t.test('extract into folder that already has a package in it', t => {
384384
})
385385
// some weird thing with links and such
386386
// will remove weird and weird/foo bundle dep, but not weird/bar
387-
return new FileFetcher(weirdspec, { cache }).extract(dir).then(() => {
388-
const missing = [
389-
'index-hardlink.js',
390-
'index-symlink.js',
391-
'.gitignore',
392-
'lib/.gitignore',
393-
'no-gitignore-here/.gitignore',
394-
'node_modules/foo',
395-
'node_modules/.bin/foo',
396-
]
397-
missing.forEach(f =>
398-
t.throws(() => fs.statSync(dir + '/' + f), 'excluded or removed' + f))
399-
400-
const present = [
401-
'no-gitignore-here/.npmignore',
402-
'node_modules/bar/package.json',
403-
'node_modules/bar/index.js',
404-
'node_modules/.bin/bar',
405-
]
406-
present.forEach(f =>
407-
t.ok(fs.statSync(dir + '/' + f), 'still have file at ' + f))
408-
})
387+
await new FileFetcher(weirdspec, { cache }).extract(dir)
388+
const missing = [
389+
'index-hardlink.js',
390+
'index-symlink.js',
391+
'.gitignore',
392+
'lib/.gitignore',
393+
'no-gitignore-here/.gitignore',
394+
'node_modules/foo',
395+
'node_modules/.bin/foo',
396+
]
397+
missing.forEach(f =>
398+
t.throws(() => fs.statSync(dir + '/' + f), 'excluded or removed' + f))
399+
400+
const present = [
401+
'no-gitignore-here/.npmignore',
402+
'node_modules/bar/package.json',
403+
'node_modules/bar/index.js',
404+
'node_modules/.bin/bar',
405+
]
406+
present.forEach(f =>
407+
t.ok(fs.statSync(dir + '/' + f), 'still have file at ' + f))
409408
})
410409

411410
t.test('a non-retriable cache error', t => {

‎test/git.js

+42-44
Original file line numberDiff line numberDiff line change
@@ -484,32 +484,33 @@ t.test('weird hosted that doesnt provide any fetch targets', t => {
484484
t.end()
485485
})
486486

487-
t.test('extract from tarball from hosted git service', t => {
487+
t.test('extract from tarball from hosted git service', async t => {
488488
// run in both ssh and https url types from a hosted service
489489
// both of these actually produce a git:// url so that the test
490490
// doesn't hang waiting for SSH key approval/passphrases.
491491
const domains = ['localhost', 'localhostssh']
492492

493-
t.plan(domains.length)
494-
domains.forEach(domain => t.test(domain, t => {
495-
const runTest = nameat => t => {
496-
const spec = npa(`${nameat}${domain}:repo/x#${REPO_HEAD}`)
497-
const g = new GitFetcher(spec, { cache })
498-
return g.manifest().then(m => t.match(m, {
499-
name: 'repo',
500-
version: '1.0.0',
501-
description: 'just some random thing',
502-
devDependencies: {
503-
abbrev: abbrevSpec,
504-
},
505-
scripts: { prepare: 'node prepare.js', test: 'node index.js' },
506-
files: ['index.js'],
507-
_id: 'repo@1.0.0',
508-
_integrity: /^sha512-/,
509-
_resolved: `${remoteHosted}#${REPO_HEAD}`,
510-
}))
511-
.then(() => g.packument())
512-
.then(p => t.match(p, {
493+
for (const domain of domains) {
494+
t.test(domain, async t => {
495+
const runTest = nameat => async t => {
496+
const spec = npa(`${nameat}${domain}:repo/x#${REPO_HEAD}`)
497+
const g = new GitFetcher(spec, { cache })
498+
const m = await g.manifest()
499+
t.match(m, {
500+
name: 'repo',
501+
version: '1.0.0',
502+
description: 'just some random thing',
503+
devDependencies: {
504+
abbrev: abbrevSpec,
505+
},
506+
scripts: { prepare: 'node prepare.js', test: 'node index.js' },
507+
files: ['index.js'],
508+
_id: 'repo@1.0.0',
509+
_integrity: /^sha512-/,
510+
_resolved: `${remoteHosted}#${REPO_HEAD}`,
511+
})
512+
const p = await g.packument()
513+
t.match(p, {
513514
name: 'repo',
514515
'dist-tags': { latest: '1.0.0' },
515516
versions: {
@@ -528,18 +529,16 @@ t.test('extract from tarball from hosted git service', t => {
528529
dist: {},
529530
},
530531
},
531-
}))
532-
.then(() => g.extract(me + '/hosted'))
533-
.then(result => {
534-
t.throws(() => fs.statSync(me + '/hosted/prepare.js'))
535-
fs.statSync(me + '/hosted/index.js')
536532
})
537-
}
533+
await g.extract(me + '/hosted')
534+
t.throws(() => fs.statSync(me + '/hosted/prepare.js'))
535+
fs.statSync(me + '/hosted/index.js')
536+
}
538537

539-
t.plan(2)
540-
t.test('with repo@ on the spec', runTest('repo@'))
541-
t.test('without repo@on the spec', runTest(''))
542-
}))
538+
t.test('with repo@ on the spec', runTest('repo@'))
539+
t.test('without repo@on the spec', runTest(''))
540+
})
541+
}
543542
})
544543

545544
t.test('include auth with hosted https when provided', async t => {
@@ -593,20 +592,19 @@ t.test('add git sha to hosted git shorthand', t =>
593592

594593
t.test('fetch a weird ref', t => {
595594
let head3 = ''
596-
t.test('hosted', t =>
597-
new GitFetcher('localhost:repo/x#HEAD~3', { cache }).extract(me + '/h3h')
598-
.then(result => {
599-
head3 = result.resolved.split('#').pop()
600-
t.match(result.resolved, /^git\+git:\/\/127\.0\.0\.1:[0-9]+\/repo#[a-z0-9]{40}$/,
601-
'got git url as resolved value')
602-
t.not(result.resolved, `${remoteHosted}#${REPO_HEAD}`,
603-
'git url for HEAD~3 is not the same as HEAD')
604-
}))
595+
t.test('hosted', async t => {
596+
const result = await new GitFetcher('localhost:repo/x#HEAD~3', { cache }).extract(me + '/h3h')
597+
head3 = result.resolved.split('#').pop()
598+
t.match(result.resolved, /^git\+git:\/\/127\.0\.0\.1:[0-9]+\/repo#[a-z0-9]{40}$/,
599+
'got git url as resolved value')
600+
t.not(result.resolved, `${remoteHosted}#${REPO_HEAD}`,
601+
'git url for HEAD~3 is not the same as HEAD')
602+
})
605603

606-
t.test('reglar', t =>
607-
new GitFetcher(`${remote}#HEAD~3`, { cache }).extract(me + '/h3r')
608-
.then(result => t.equal(result.resolved, `${remote}#${head3}`,
609-
'got the same HEAD~3 sha as before')))
604+
t.test('regular', async t => {
605+
const result = await new GitFetcher(`${remote}#HEAD~3`, { cache }).extract(me + '/h3r')
606+
t.equal(result.resolved, `${remote}#${head3}`, 'got the same HEAD~3 sha as before')
607+
})
610608

611609
t.end()
612610
})

‎test/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,18 @@ t.cleanSnapshot = str => str
1818
.split(process.cwd()).join('${CWD}')
1919
.replace(/\\/g, '/')
2020

21+
// Putting all these tests inside a `t.test` suite broke the tests. They either
22+
// didn't run or failed w/ no message. Ignoring promise/catch-or-return for now.
2123
t.resolveMatchSnapshot(pacote.resolve(abbrevspec), 'resolve')
2224
t.resolveMatchSnapshot(pacote.extract(abbrevspec, me + '/extract'), 'extract')
2325
t.resolveMatchSnapshot(pacote.manifest(abbrevspec), 'manifest')
2426
t.resolveMatchSnapshot(pacote.packument(abbrevspec), 'packument')
2527
t.resolveMatch(pacote.tarball(abbrevspec), fs.readFileSync(abbrev), 'tarball')
28+
// eslint-disable-next-line promise/catch-or-return
2629
t.resolveMatchSnapshot(pacote.tarball.file(abbrevspec, me + '/tarball.tgz'),
2730
'tarball to file').then(() =>
2831
t.match(fs.readFileSync(me + '/tarball.tgz'), fs.readFileSync(abbrev)))
32+
// eslint-disable-next-line promise/catch-or-return
2933
pacote.tarball.stream(abbrevspec, stream =>
3034
new Promise((res, rej) => {
3135
stream.on('end', res)

‎test/registry.js

+14-16
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,17 @@ t.test('provide matching integrity, totes ok, includes signature', async t => {
135135
// eslint-disable-next-line max-len
136136
integrity: 'sha512-5ZYe1LgwHIaag0p9loMwsf5N/wJ4XAuHVNhSO+qulQOXWnyJVuco6IZjo+5u4ZLF/GimdHJcX+QK892ONfOCqQ==',
137137
})
138-
return f.manifest().then(mani => {
139-
t.match(mani, {
140-
// eslint-disable-next-line max-len
141-
_integrity: 'sha512-5ZYe1LgwHIaag0p9loMwsf5N/wJ4XAuHVNhSO+qulQOXWnyJVuco6IZjo+5u4ZLF/GimdHJcX+QK892ONfOCqQ==',
142-
_signatures: [
143-
{
144-
keyid: 'SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA',
145-
// eslint-disable-next-line max-len
146-
sig: 'MEQCIHXwKYe70+xcDOvFhM1etZQFUKEwz9VarppUbp5/Ie1+AiAM7aZcT1a2JR0oF/XwjNb13YEHwiagnDapLgYbklRvtA==',
147-
},
148-
],
149-
})
138+
const mani = await f.manifest()
139+
t.match(mani, {
140+
// eslint-disable-next-line max-len
141+
_integrity: 'sha512-5ZYe1LgwHIaag0p9loMwsf5N/wJ4XAuHVNhSO+qulQOXWnyJVuco6IZjo+5u4ZLF/GimdHJcX+QK892ONfOCqQ==',
142+
_signatures: [
143+
{
144+
keyid: 'SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA',
145+
// eslint-disable-next-line max-len
146+
sig: 'MEQCIHXwKYe70+xcDOvFhM1etZQFUKEwz9VarppUbp5/Ie1+AiAM7aZcT1a2JR0oF/XwjNb13YEHwiagnDapLgYbklRvtA==',
147+
},
148+
],
150149
})
151150
})
152151

@@ -166,10 +165,9 @@ t.test('verifySignatures valid signature', async t => {
166165
pemkey: '-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE1Olb3zMAFFxXKHiIkQO5cJ3Yhl5i6UPp+IhuteBJbuHcA5UogKo0EWtlWwW6KSaKoTNEYL7JlCQiVnkhBktUgg==\n-----END PUBLIC KEY-----',
167166
}],
168167
})
169-
return f.manifest().then(mani => {
170-
t.ok(mani._signatures)
171-
t.ok(mani._integrity)
172-
})
168+
const mani = await f.manifest()
169+
t.ok(mani._signatures)
170+
t.ok(mani._integrity)
173171
})
174172

175173
t.test('verifySignatures expired signature', async t => {

‎test/remote.js

+29-33
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ t.test('start server', t => {
5050
})
5151
})
5252

53-
t.test('packument', t => {
53+
t.test('packument', async t => {
5454
// const url = 'https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz'
5555
const url = `https://registry.npmjs.org/abbrev.tgz`
5656
const f = new RemoteFetcher(url, {
@@ -64,38 +64,34 @@ t.test('packument', t => {
6464
npmSession: 'foobarbaz',
6565
})
6666
// run twice to pull from cache the second time
67-
return t.resolveMatchSnapshot(f.packument(), 'packument')
68-
.then(() => {
69-
const f2 = new RemoteFetcher(`abbrev@${url}`, {
70-
registry: server,
71-
pkgid: `remote:abbrev@${url}`,
72-
cache,
73-
})
74-
return t.resolveMatchSnapshot(f2.packument(), 'packument 2')
75-
})
76-
.then(() => {
77-
const version = require('../package.json').version
78-
t.equal(requestLog.length, 1, 'only one request hit the server')
79-
t.match(requestLog, [
80-
[
81-
'/abbrev.tgz',
82-
{
83-
connection: 'keep-alive',
84-
'user-agent': `pacote/${version} node/${process.version}`,
85-
'pacote-version': version,
86-
'pacote-req-type': 'tarball',
87-
'pacote-pkg-id': `remote:${server}/abbrev.tgz`,
88-
accept: '*/*',
89-
'accept-encoding': 'gzip,deflate',
90-
host: new URL(server).host,
91-
'npm-session': 'foobarbaz',
92-
'npm-scope': '@npmcli',
93-
'not-referer': 'http://example.com',
94-
},
95-
],
96-
])
97-
requestLog.length = 0
98-
})
67+
await t.resolveMatchSnapshot(f.packument(), 'packument')
68+
const f2 = new RemoteFetcher(`abbrev@${url}`, {
69+
registry: server,
70+
pkgid: `remote:abbrev@${url}`,
71+
cache,
72+
})
73+
await t.resolveMatchSnapshot(f2.packument(), 'packument 2')
74+
const version = require('../package.json').version
75+
t.equal(requestLog.length, 1, 'only one request hit the server')
76+
t.match(requestLog, [
77+
[
78+
'/abbrev.tgz',
79+
{
80+
connection: 'keep-alive',
81+
'user-agent': `pacote/${version} node/${process.version}`,
82+
'pacote-version': version,
83+
'pacote-req-type': 'tarball',
84+
'pacote-pkg-id': `remote:${server}/abbrev.tgz`,
85+
accept: '*/*',
86+
'accept-encoding': 'gzip,deflate',
87+
host: new URL(server).host,
88+
'npm-session': 'foobarbaz',
89+
'npm-scope': '@npmcli',
90+
'not-referer': 'http://example.com',
91+
},
92+
],
93+
])
94+
requestLog.length = 0
9995
})
10096

10197
t.test('bad integrity', t => {

0 commit comments

Comments
 (0)
Please sign in to comment.