Skip to content

Commit

Permalink
fix: linting (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed Aug 16, 2022
1 parent 87d4b46 commit cf1c5ed
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 141 deletions.
11 changes: 8 additions & 3 deletions lib/bin.js
Expand Up @@ -18,10 +18,15 @@ const run = conf => {
case 'tarball':
if (!conf._[2] || conf._[2] === '-') {
return pacote.tarball.stream(conf._[1], stream => {
stream.pipe(conf.testStdout ||
/* istanbul ignore next */ process.stdout)
stream.pipe(
conf.testStdout ||
/* istanbul ignore next */
process.stdout
)
// make sure it resolves something falsey
return stream.promise().then(() => {})
return stream.promise().then(() => {
return false
})
}, conf)
} else {
return pacote.tarball.file(conf._[1], conf._[2], conf)
Expand Down
6 changes: 5 additions & 1 deletion lib/fetcher.js
Expand Up @@ -254,6 +254,7 @@ class FetcherBase {
cstream.on('error', err => stream.emit('error', err))
stream.pipe(cstream)

// eslint-disable-next-line promise/catch-or-return
cstream.promise().catch(() => {}).then(() => middleStream.end())
return middleStream
}
Expand All @@ -269,7 +270,10 @@ class FetcherBase {
}

// override the types getter
get types () {}
get types () {
return false
}

[_assertType] () {
if (this.types && !this.types.includes(this.spec.type)) {
throw new TypeError(`Wrong spec type (${
Expand Down
17 changes: 8 additions & 9 deletions lib/git.js
Expand Up @@ -239,7 +239,7 @@ class GitFetcher extends Fetcher {
tarballOk = tarballOk &&
h && resolved === repoUrl(h, { noCommittish: false }) && h.tarball

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

return (
const sha = await (
h ? this[_cloneHosted](ref, tmp)
: this[_cloneRepo](this.spec.fetchSpec, ref, tmp)
).then(sha => {
this.resolvedSha = sha
if (!this.resolved) {
this[_addGitSha](sha)
}
})
.then(() => handler(tmp))
)
this.resolvedSha = sha
if (!this.resolved) {
await this[_addGitSha](sha)
}
return handler(tmp)
})
}

Expand Down
1 change: 1 addition & 0 deletions lib/remote.js
Expand Up @@ -41,6 +41,7 @@ class RemoteFetcher extends Fetcher {
algorithms: [this.pickIntegrityAlgorithm()],
}

// eslint-disable-next-line promise/always-return
fetch(this.resolved, fetchOpts).then(res => {
res.body.on('error',
/* istanbul ignore next - exceedingly rare and hard to simulate */
Expand Down
2 changes: 1 addition & 1 deletion tap-snapshots/test/bin.js.test.cjs
Expand Up @@ -383,7 +383,7 @@ Object {
`

exports[`test/bin.js TAP run > expect resolving Promise 6`] = `
undefined
false
`

exports[`test/bin.js TAP running bin runs main file > helpful output 1`] = `
Expand Down
67 changes: 33 additions & 34 deletions test/fetcher.js
Expand Up @@ -92,17 +92,17 @@ t.test('snapshot the npmInstallCmd and npmInstallConfig', async t => {
t.matchSnapshot(yarn.npmCliConfig, 'yarn style cli config stuff')
})

t.test('tarball data', t =>
new FileFetcher(abbrevspec, { cache }).tarball()
.then(data => {
t.equal(data.toString('hex'), fs.readFileSync(abbrev, 'hex'), 'without integrity')
t.equal(data.integrity, abbrevMani._integrity, 'integrity calculated')
})
.then(() => new FileFetcher(abbrevspec, {
cache,
integrity: abbrevMani._integrity,
}).tarball())
.then(data => t.same(data, fs.readFileSync(abbrev), 'with integrity')))
t.test('tarball data', async t => {
const dataWithout = await new FileFetcher(abbrevspec, { cache }).tarball()
t.equal(dataWithout.toString('hex'), fs.readFileSync(abbrev, 'hex'), 'without integrity')
t.equal(dataWithout.integrity, abbrevMani._integrity, 'integrity calculated')

const dataWith = await new FileFetcher(abbrevspec, {
cache,
integrity: abbrevMani._integrity,
}).tarball()
t.same(dataWith, fs.readFileSync(abbrev), 'with integrity')
})

t.test('tarballFile', t => {
const target = resolve(me, 'tarball-file')
Expand Down Expand Up @@ -351,7 +351,7 @@ t.test('extract', t => {
})
})

t.test('extract into folder that already has a package in it', t => {
t.test('extract into folder that already has a package in it', async t => {
const dir = t.testdir({
'package.json': JSON.stringify({
name: 'weird',
Expand Down Expand Up @@ -384,28 +384,27 @@ t.test('extract into folder that already has a package in it', t => {
})
// some weird thing with links and such
// will remove weird and weird/foo bundle dep, but not weird/bar
return new FileFetcher(weirdspec, { cache }).extract(dir).then(() => {
const missing = [
'index-hardlink.js',
'index-symlink.js',
'.gitignore',
'lib/.gitignore',
'no-gitignore-here/.gitignore',
'node_modules/foo',
'node_modules/.bin/foo',
]
missing.forEach(f =>
t.throws(() => fs.statSync(dir + '/' + f), 'excluded or removed' + f))

const present = [
'no-gitignore-here/.npmignore',
'node_modules/bar/package.json',
'node_modules/bar/index.js',
'node_modules/.bin/bar',
]
present.forEach(f =>
t.ok(fs.statSync(dir + '/' + f), 'still have file at ' + f))
})
await new FileFetcher(weirdspec, { cache }).extract(dir)
const missing = [
'index-hardlink.js',
'index-symlink.js',
'.gitignore',
'lib/.gitignore',
'no-gitignore-here/.gitignore',
'node_modules/foo',
'node_modules/.bin/foo',
]
missing.forEach(f =>
t.throws(() => fs.statSync(dir + '/' + f), 'excluded or removed' + f))

const present = [
'no-gitignore-here/.npmignore',
'node_modules/bar/package.json',
'node_modules/bar/index.js',
'node_modules/.bin/bar',
]
present.forEach(f =>
t.ok(fs.statSync(dir + '/' + f), 'still have file at ' + f))
})

t.test('a non-retriable cache error', t => {
Expand Down
86 changes: 42 additions & 44 deletions test/git.js
Expand Up @@ -484,32 +484,33 @@ t.test('weird hosted that doesnt provide any fetch targets', t => {
t.end()
})

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

t.plan(domains.length)
domains.forEach(domain => t.test(domain, t => {
const runTest = nameat => t => {
const spec = npa(`${nameat}${domain}:repo/x#${REPO_HEAD}`)
const g = new GitFetcher(spec, { cache })
return g.manifest().then(m => t.match(m, {
name: 'repo',
version: '1.0.0',
description: 'just some random thing',
devDependencies: {
abbrev: abbrevSpec,
},
scripts: { prepare: 'node prepare.js', test: 'node index.js' },
files: ['index.js'],
_id: 'repo@1.0.0',
_integrity: /^sha512-/,
_resolved: `${remoteHosted}#${REPO_HEAD}`,
}))
.then(() => g.packument())
.then(p => t.match(p, {
for (const domain of domains) {
t.test(domain, async t => {
const runTest = nameat => async t => {
const spec = npa(`${nameat}${domain}:repo/x#${REPO_HEAD}`)
const g = new GitFetcher(spec, { cache })
const m = await g.manifest()
t.match(m, {
name: 'repo',
version: '1.0.0',
description: 'just some random thing',
devDependencies: {
abbrev: abbrevSpec,
},
scripts: { prepare: 'node prepare.js', test: 'node index.js' },
files: ['index.js'],
_id: 'repo@1.0.0',
_integrity: /^sha512-/,
_resolved: `${remoteHosted}#${REPO_HEAD}`,
})
const p = await g.packument()
t.match(p, {
name: 'repo',
'dist-tags': { latest: '1.0.0' },
versions: {
Expand All @@ -528,18 +529,16 @@ t.test('extract from tarball from hosted git service', t => {
dist: {},
},
},
}))
.then(() => g.extract(me + '/hosted'))
.then(result => {
t.throws(() => fs.statSync(me + '/hosted/prepare.js'))
fs.statSync(me + '/hosted/index.js')
})
}
await g.extract(me + '/hosted')
t.throws(() => fs.statSync(me + '/hosted/prepare.js'))
fs.statSync(me + '/hosted/index.js')
}

t.plan(2)
t.test('with repo@ on the spec', runTest('repo@'))
t.test('without repo@on the spec', runTest(''))
}))
t.test('with repo@ on the spec', runTest('repo@'))
t.test('without repo@on the spec', runTest(''))
})
}
})

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

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

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

t.end()
})
Expand Down
4 changes: 4 additions & 0 deletions test/index.js
Expand Up @@ -18,14 +18,18 @@ t.cleanSnapshot = str => str
.split(process.cwd()).join('${CWD}')
.replace(/\\/g, '/')

// Putting all these tests inside a `t.test` suite broke the tests. They either
// didn't run or failed w/ no message. Ignoring promise/catch-or-return for now.
t.resolveMatchSnapshot(pacote.resolve(abbrevspec), 'resolve')
t.resolveMatchSnapshot(pacote.extract(abbrevspec, me + '/extract'), 'extract')
t.resolveMatchSnapshot(pacote.manifest(abbrevspec), 'manifest')
t.resolveMatchSnapshot(pacote.packument(abbrevspec), 'packument')
t.resolveMatch(pacote.tarball(abbrevspec), fs.readFileSync(abbrev), 'tarball')
// eslint-disable-next-line promise/catch-or-return
t.resolveMatchSnapshot(pacote.tarball.file(abbrevspec, me + '/tarball.tgz'),
'tarball to file').then(() =>
t.match(fs.readFileSync(me + '/tarball.tgz'), fs.readFileSync(abbrev)))
// eslint-disable-next-line promise/catch-or-return
pacote.tarball.stream(abbrevspec, stream =>
new Promise((res, rej) => {
stream.on('end', res)
Expand Down
30 changes: 14 additions & 16 deletions test/registry.js
Expand Up @@ -135,18 +135,17 @@ t.test('provide matching integrity, totes ok, includes signature', async t => {
// eslint-disable-next-line max-len
integrity: 'sha512-5ZYe1LgwHIaag0p9loMwsf5N/wJ4XAuHVNhSO+qulQOXWnyJVuco6IZjo+5u4ZLF/GimdHJcX+QK892ONfOCqQ==',
})
return f.manifest().then(mani => {
t.match(mani, {
// eslint-disable-next-line max-len
_integrity: 'sha512-5ZYe1LgwHIaag0p9loMwsf5N/wJ4XAuHVNhSO+qulQOXWnyJVuco6IZjo+5u4ZLF/GimdHJcX+QK892ONfOCqQ==',
_signatures: [
{
keyid: 'SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA',
// eslint-disable-next-line max-len
sig: 'MEQCIHXwKYe70+xcDOvFhM1etZQFUKEwz9VarppUbp5/Ie1+AiAM7aZcT1a2JR0oF/XwjNb13YEHwiagnDapLgYbklRvtA==',
},
],
})
const mani = await f.manifest()
t.match(mani, {
// eslint-disable-next-line max-len
_integrity: 'sha512-5ZYe1LgwHIaag0p9loMwsf5N/wJ4XAuHVNhSO+qulQOXWnyJVuco6IZjo+5u4ZLF/GimdHJcX+QK892ONfOCqQ==',
_signatures: [
{
keyid: 'SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA',
// eslint-disable-next-line max-len
sig: 'MEQCIHXwKYe70+xcDOvFhM1etZQFUKEwz9VarppUbp5/Ie1+AiAM7aZcT1a2JR0oF/XwjNb13YEHwiagnDapLgYbklRvtA==',
},
],
})
})

Expand All @@ -166,10 +165,9 @@ t.test('verifySignatures valid signature', async t => {
pemkey: '-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE1Olb3zMAFFxXKHiIkQO5cJ3Yhl5i6UPp+IhuteBJbuHcA5UogKo0EWtlWwW6KSaKoTNEYL7JlCQiVnkhBktUgg==\n-----END PUBLIC KEY-----',
}],
})
return f.manifest().then(mani => {
t.ok(mani._signatures)
t.ok(mani._integrity)
})
const mani = await f.manifest()
t.ok(mani._signatures)
t.ok(mani._integrity)
})

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

0 comments on commit cf1c5ed

Please sign in to comment.