Skip to content

Commit

Permalink
fix(standard): update to new standard rules
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Mar 8, 2018
1 parent 5f78812 commit bb52d02
Show file tree
Hide file tree
Showing 17 changed files with 267 additions and 267 deletions.
72 changes: 36 additions & 36 deletions extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,47 +24,47 @@ function extract (spec, dest, opts) {
return withTarballStream(spec, opts, stream => {
return tryExtract(spec, stream, dest, opts)
})
.then(() => {
if (!opts.resolved) {
const pjson = path.join(dest, 'package.json')
return readFileAsync(pjson, 'utf8')
.then(str => truncateAsync(pjson)
.then(() => appendFileAsync(pjson, str.replace(
/}\s*$/,
`\n,"_resolved": ${
JSON.stringify(opts.resolved || '')
}\n,"_integrity": ${
JSON.stringify(opts.integrity || '')
}\n,"_from": ${
JSON.stringify(spec.toString())
}\n}`
))))
}
})
.then(() => opts.log.silly(
'extract',
`${spec} extracted to ${dest} (${Date.now() - startTime}ms)`
))
.then(() => {
if (!opts.resolved) {
const pjson = path.join(dest, 'package.json')
return readFileAsync(pjson, 'utf8')
.then(str => truncateAsync(pjson)
.then(() => appendFileAsync(pjson, str.replace(
/}\s*$/,
`\n,"_resolved": ${
JSON.stringify(opts.resolved || '')
}\n,"_integrity": ${
JSON.stringify(opts.integrity || '')
}\n,"_from": ${
JSON.stringify(spec.toString())
}\n}`
))))
}
})
.then(() => opts.log.silly(
'extract',
`${spec} extracted to ${dest} (${Date.now() - startTime}ms)`
))
}

function tryExtract (spec, tarStream, dest, opts) {
return new BB((resolve, reject) => {
tarStream.on('error', reject)
setImmediate(resolve)
})
.then(() => rimraf(dest))
.then(() => mkdirp(dest))
.then(() => new BB((resolve, reject) => {
const xtractor = extractStream(spec, dest, opts)
tarStream.on('error', reject)
xtractor.on('error', reject)
xtractor.on('close', resolve)
tarStream.pipe(xtractor)
}))
.catch(err => {
if (err.code === 'EINTEGRITY') {
err.message = `Verification failed while extracting ${spec}:\n${err.message}`
}
throw err
})
.then(() => rimraf(dest))
.then(() => mkdirp(dest))
.then(() => new BB((resolve, reject) => {
const xtractor = extractStream(spec, dest, opts)
tarStream.on('error', reject)
xtractor.on('error', reject)
xtractor.on('close', resolve)
tarStream.pipe(xtractor)
}))
.catch(err => {
if (err.code === 'EINTEGRITY') {
err.message = `Verification failed while extracting ${spec}:\n${err.message}`
}
throw err
})
}
14 changes: 7 additions & 7 deletions lib/fetchers/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ Fetcher.impl(fetchFile, {
} else {
let integrity
const cacheWriter = !opts.cache
? BB.resolve(null)
: (pipe(
fs.createReadStream(src),
cacache.put.stream(opts.cache, `pacote:tarball:${src}`, {
integrity: opts.integrity
}).on('integrity', d => { integrity = d })
))
? BB.resolve(null)
: (pipe(
fs.createReadStream(src),
cacache.put.stream(opts.cache, `pacote:tarball:${src}`, {
integrity: opts.integrity
}).on('integrity', d => { integrity = d })
))
return cacheWriter.then(() => {
if (integrity) { stream.emit('integrity', integrity) }
return pipe(fs.createReadStream(src), stream)
Expand Down
20 changes: 10 additions & 10 deletions lib/fetchers/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,16 @@ function resolve (url, spec, name, opts) {
const isSemver = !!spec.gitRange
return git.revs(url, opts).then(remoteRefs => {
return isSemver
? pickManifest({
versions: remoteRefs.versions,
'dist-tags': remoteRefs['dist-tags'],
name: name
}, spec.gitRange, opts)
: remoteRefs
? BB.resolve(
remoteRefs.refs[spec.gitCommittish] || remoteRefs.refs[remoteRefs.shas[spec.gitCommittish]]
)
: null
? pickManifest({
versions: remoteRefs.versions,
'dist-tags': remoteRefs['dist-tags'],
name: name
}, spec.gitRange, opts)
: remoteRefs
? BB.resolve(
remoteRefs.refs[spec.gitCommittish] || remoteRefs.refs[remoteRefs.shas[spec.gitCommittish]]
)
: null
})
}

Expand Down
12 changes: 6 additions & 6 deletions lib/fetchers/registry/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ function logRequest (uri, res, startTime, opts) {

function getCacheMode (opts) {
return opts.offline
? 'only-if-cached'
: opts.preferOffline
? 'force-cache'
: opts.preferOnline
? 'no-cache'
: 'default'
? 'only-if-cached'
: opts.preferOffline
? 'force-cache'
: opts.preferOnline
? 'no-cache'
: 'default'
}

function getHeaders (uri, registry, opts) {
Expand Down
4 changes: 2 additions & 2 deletions lib/fetchers/registry/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ function manifest (spec, opts) {

function metadataUrl (registry, name) {
const normalized = registry.slice(-1) !== '/'
? registry + '/'
: registry
? registry + '/'
: registry
return url.resolve(normalized, name)
}

Expand Down
22 changes: 11 additions & 11 deletions lib/fetchers/registry/tarball.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,20 @@ function fromManifest (manifest, spec, opts) {
integrity: manifest._integrity,
algorithms: [
manifest._integrity
? ssri.parse(manifest._integrity).pickAlgorithm()
: 'sha1'
? ssri.parse(manifest._integrity).pickAlgorithm()
: 'sha1'
],
spec
}, opts))
.then(res => {
const hash = res.headers.get('x-local-cache-hash')
if (hash) {
stream.emit('integrity', decodeURIComponent(hash))
}
res.body.on('error', err => stream.emit('error', err))
res.body.pipe(stream)
})
.catch(err => stream.emit('error', err))
.then(res => {
const hash = res.headers.get('x-local-cache-hash')
if (hash) {
stream.emit('integrity', decodeURIComponent(hash))
}
res.body.on('error', err => stream.emit('error', err))
res.body.pipe(stream)
})
.catch(err => stream.emit('error', err))
return stream
}

Expand Down
12 changes: 6 additions & 6 deletions lib/finalize-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ function finalizeManifest (pkg, spec, opts) {
opts = optCheck(opts)

const cachedManifest = (opts.cache && key && !opts.preferOnline && !opts.fullMetadata)
? cacache.get.info(opts.cache, key, opts)
: BB.resolve(null)
? cacache.get.info(opts.cache, key, opts)
: BB.resolve(null)

return cachedManifest.then(cached => {
if (cached && cached.metadata.manifest) {
return new Manifest(cached.metadata.manifest)
} else {
return tarballedProps(pkg, spec, opts).then(props => {
return pkg && pkg.name
? new Manifest(pkg, props, opts.fullMetadata)
: new Manifest(props, null, opts.fullMetadata)
? new Manifest(pkg, props, opts.fullMetadata)
: new Manifest(props, null, opts.fullMetadata)
}).then(manifest => {
const cacheKey = key || finalKey(manifest, spec)
if (!opts.cache || !cacheKey) {
Expand Down Expand Up @@ -169,8 +169,8 @@ function tarballedProps (pkg, spec, opts) {
// to add to bin
if (paths && paths.length) {
const dirBin = mani
? (mani && mani.directories && mani.directories.bin)
: (pkg && pkg.directories && pkg.directories.bin)
? (mani && mani.directories && mani.directories.bin)
: (pkg && pkg.directories && pkg.directories.bin)
if (dirBin) {
extraProps.bin = {}
paths.forEach(filePath => {
Expand Down
12 changes: 6 additions & 6 deletions lib/util/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,10 @@ const REFS_HEADS = 'refs/heads/'
const HEAD = 'HEAD'
function refType (ref) {
return ref.indexOf(REFS_TAGS) !== -1
? 'tag'
: ref.indexOf(REFS_HEADS) !== -1
? 'branch'
: ref.endsWith(HEAD)
? 'head'
: 'other'
? 'tag'
: ref.indexOf(REFS_HEADS) !== -1
? 'branch'
: ref.endsWith(HEAD)
? 'head'
: 'other'
}
4 changes: 2 additions & 2 deletions lib/util/opt-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ function PacoteOptions (opts) {
this.fullMetadata = opts.fullMetadata
this.alwaysAuth = opts.alwaysAuth
this.includeDeprecated = opts.includeDeprecated == null
? true
: opts.includeDeprecated
? true
: opts.includeDeprecated

this.dirPacker = opts.dirPacker || null

Expand Down
4 changes: 2 additions & 2 deletions lib/util/pack-dir.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ function packDir (manifest, label, dir, target, opts) {
opts = optCheck(opts)

const packer = opts.dirPacker
? BB.resolve(opts.dirPacker(manifest, dir))
: mkPacker(dir)
? BB.resolve(opts.dirPacker(manifest, dir))
: mkPacker(dir)

if (!opts.cache) {
return packer.then(packer => pipe(packer, target))
Expand Down
Loading

0 comments on commit bb52d02

Please sign in to comment.