Skip to content

Commit

Permalink
pacote: get rid of legacy pacoteOpts
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Dec 10, 2018
1 parent 8a56fa3 commit 41d19e1
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 212 deletions.
6 changes: 3 additions & 3 deletions lib/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ const finished = BB.promisify(require('mississippi').finished)
const log = require('npmlog')
const npa = require('npm-package-arg')
const npm = require('./npm.js')
const npmConfig = require('./config/figgy-config.js')
const output = require('./utils/output.js')
const pacote = require('pacote')
const pacoteOpts = require('./config/pacote')
const path = require('path')
const rm = BB.promisify(require('./utils/gently-rm.js'))
const unbuild = BB.promisify(npm.commands.unbuild)
Expand Down Expand Up @@ -107,7 +107,7 @@ function add (args, where) {
log.verbose('cache add', 'spec', spec)
if (!spec) return BB.reject(new Error(usage))
log.silly('cache add', 'parsed spec', spec)
return finished(pacote.tarball.stream(spec, pacoteOpts({where})).resume())
return finished(pacote.tarball.stream(spec, npmConfig({where})).resume())
}

cache.verify = verify
Expand All @@ -131,7 +131,7 @@ function verify () {
cache.unpack = unpack
function unpack (pkg, ver, unpackTarget, dmode, fmode, uid, gid) {
return unbuild([unpackTarget], true).then(() => {
const opts = pacoteOpts({dmode, fmode, uid, gid, offline: true})
const opts = npmConfig({dmode, fmode, uid, gid, offline: true})
return pacote.extract(npa.resolve(pkg, ver), unpackTarget, opts)
})
}
35 changes: 7 additions & 28 deletions lib/ci.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,19 @@
'use strict'

const Installer = require('libcipm')
const lifecycleOpts = require('./config/lifecycle.js')
const npm = require('./npm.js')
const npmConfig = require('./config/figgy-config.js')
const npmlog = require('npmlog')
const pacoteOpts = require('./config/pacote.js')

ci.usage = 'npm ci'

ci.completion = (cb) => cb(null, [])

Installer.CipmConfig.impl(npm.config, {
get: npm.config.get,
set: npm.config.set,
toLifecycle (moreOpts) {
return lifecycleOpts(moreOpts)
},
toPacote (moreOpts) {
return pacoteOpts(moreOpts)
}
})

module.exports = ci
function ci (args, cb) {
return new Installer({
config: npm.config,
log: npmlog
})
.run()
.then(
(details) => {
npmlog.disableProgress()
console.log(`added ${details.pkgCount} packages in ${
details.runTime / 1000
}s`)
}
)
.then(() => cb(), cb)
return new Installer(npmConfig({ log: npmlog })).run().then(details => {
npmlog.disableProgress()
console.log(`added ${details.pkgCount} packages in ${
details.runTime / 1000
}s`)
}).then(() => cb(), cb)
}
1 change: 1 addition & 0 deletions lib/config/figgy-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function mkConfig (...providers) {
dirPacker: pack.packGitDep,
hashAlgorithm: 'sha1',
includeDeprecated: false,
log,
'npm-session': npmSession,
'project-scope': npm.projectScope,
refer: npm.refer,
Expand Down
142 changes: 0 additions & 142 deletions lib/config/pacote.js

This file was deleted.

12 changes: 3 additions & 9 deletions lib/fetch-package-metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ const rimraf = require('rimraf')
const validate = require('aproba')
const npa = require('npm-package-arg')
const npm = require('./npm')
const npmConfig = require('./config/figgy-config.js')
const npmlog = require('npmlog')
const limit = require('call-limit')
const tempFilename = require('./utils/temp-filename')
const pacote = require('pacote')
let pacoteOpts
const isWindows = require('./utils/is-windows.js')

function andLogAndFinish (spec, tracker, done) {
Expand Down Expand Up @@ -52,10 +52,7 @@ function fetchPackageMetadata (spec, where, opts, done) {
err.code = 'EWINDOWSPATH'
return logAndFinish(err)
}
if (!pacoteOpts) {
pacoteOpts = require('./config/pacote')
}
pacote.manifest(dep, pacoteOpts({
pacote.manifest(dep, npmConfig({
annotate: true,
fullMetadata: opts.fullMetadata,
log: tracker || npmlog,
Expand Down Expand Up @@ -85,9 +82,6 @@ function fetchPackageMetadata (spec, where, opts, done) {
module.exports.addBundled = addBundled
function addBundled (pkg, next) {
validate('OF', arguments)
if (!pacoteOpts) {
pacoteOpts = require('./config/pacote')
}
if (pkg._bundled !== undefined) return next(null, pkg)

if (!pkg.bundleDependencies && pkg._requested.type !== 'directory') return next(null, pkg)
Expand All @@ -101,7 +95,7 @@ function addBundled (pkg, next) {
}
pkg._bundled = null
const target = tempFilename('unpack')
const opts = pacoteOpts({integrity: pkg._integrity})
const opts = npmConfig({integrity: pkg._integrity})
pacote.extract(pkg._resolved || pkg._requested || npa.resolve(pkg.name, pkg.version), target, opts).then(() => {
log.silly('addBundled', 'read tarball')
readPackageTree(target, (err, tree) => {
Expand Down
42 changes: 21 additions & 21 deletions lib/install/action/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

const BB = require('bluebird')

const figgyPudding = require('figgy-pudding')
const stat = BB.promisify(require('graceful-fs').stat)
const gentlyRm = BB.promisify(require('../../utils/gently-rm.js'))
const mkdirp = BB.promisify(require('mkdirp'))
const moduleStagingPath = require('../module-staging-path.js')
const move = require('../../utils/move.js')
const npa = require('npm-package-arg')
const npm = require('../../npm.js')
const npmConfig = require('../../config/figgy-config.js')
const packageId = require('../../utils/package-id.js')
let pacoteOpts
const path = require('path')
const localWorker = require('./extract-worker.js')
const workerFarm = require('worker-farm')
Expand All @@ -19,19 +20,12 @@ const isRegistry = require('../../utils/is-registry.js')
const WORKER_PATH = require.resolve('./extract-worker.js')
let workers

// NOTE: temporarily disabled on non-OSX due to ongoing issues:
//
// * Seems to make Windows antivirus issues much more common
// * Messes with Docker (I think)
//
// There are other issues that should be fixed that affect OSX too:
//
// * Logging is messed up right now because pacote does its own thing
// * Global deduplication in pacote breaks due to multiple procs
//
// As these get fixed, we can start experimenting with re-enabling it
// at least on some platforms.
const ENABLE_WORKERS = process.platform === 'darwin'
const ExtractOpts = figgyPudding({
log: {}
}, { other () { return true } })

// Disabled for now. Re-enable someday. Just not today.
const ENABLE_WORKERS = false

extract.init = () => {
if (ENABLE_WORKERS) {
Expand All @@ -53,10 +47,7 @@ module.exports = extract
function extract (staging, pkg, log) {
log.silly('extract', packageId(pkg))
const extractTo = moduleStagingPath(staging, pkg)
if (!pacoteOpts) {
pacoteOpts = require('../../config/pacote')
}
const opts = pacoteOpts({
let opts = ExtractOpts(npmConfig()).concat({
integrity: pkg.package._integrity,
resolved: pkg.package._resolved
})
Expand All @@ -72,9 +63,18 @@ function extract (staging, pkg, log) {
args[0] = spec.raw
if (ENABLE_WORKERS && (isRegistry(spec) || spec.type === 'remote')) {
// We can't serialize these options
opts.loglevel = opts.log.level
opts.log = null
opts.dirPacker = null
opts = opts.concat({
loglevel: opts.log.level,
log: null,
dirPacker: null,
Promise: null,
_events: null,
_eventsCount: null,
list: null,
sources: null,
_maxListeners: null,
root: null
})
// workers will run things in parallel!
launcher = workers
try {
Expand Down
4 changes: 2 additions & 2 deletions lib/install/action/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
const BB = require('bluebird')

const finished = BB.promisify(require('mississippi').finished)
const npmConfig = require('../../config/figgy-config.js')
const packageId = require('../../utils/package-id.js')
const pacote = require('pacote')
const pacoteOpts = require('../../config/pacote')

module.exports = fetch
function fetch (staging, pkg, log, next) {
log.silly('fetch', packageId(pkg))
const opts = pacoteOpts({integrity: pkg.package._integrity})
const opts = npmConfig({integrity: pkg.package._integrity})
return finished(pacote.tarball.stream(pkg.package._requested, opts))
.then(() => next(), next)
}
6 changes: 3 additions & 3 deletions lib/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ const lifecycle = BB.promisify(require('./utils/lifecycle'))
const log = require('npmlog')
const move = require('move-concurrently')
const npm = require('./npm')
const npmConfig = require('./config/figgy-config.js')
const output = require('./utils/output')
const pacote = require('pacote')
const pacoteOpts = require('./config/pacote')
const path = require('path')
const PassThrough = require('stream').PassThrough
const pathIsInside = require('path-is-inside')
Expand Down Expand Up @@ -88,8 +88,8 @@ function pack_ (pkg, dir) {
}

function packFromPackage (arg, target, filename) {
const opts = pacoteOpts()
return pacote.tarball.toFile(arg, target, pacoteOpts())
const opts = npmConfig()
return pacote.tarball.toFile(arg, target, opts)
.then(() => cacache.tmp.withTmp(npm.tmp, {tmpPrefix: 'unpacking'}, (tmp) => {
const tmpTarget = path.join(tmp, filename)
return pacote.extract(arg, tmpTarget, opts)
Expand Down
Loading

0 comments on commit 41d19e1

Please sign in to comment.