Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async isLatestDatabase() {
// Read package.json database semver and database package file
const [ remotePackage, localPackage ] = await Promise.all( [
manifest( databasePackage ),
readJSON( join( DATABASE_FOLDER, 'package.json' ), 'utf-8' ),
] )
const { version: local } = localPackage
const { version: remote } = remotePackage
this.emit( 'database-version', { local, remote } )
logger.info( 'Local Database Version:', local )
logger.info( 'Remote Database Version:', remote )
return localPackage.version === remotePackage.version
}
function getManifest(depString) {
if (cache[depString]) {
// Only use it if it's not expired
if (cache[depString].ttl + MAX_TTL > Date.now()) {
return cache[depString].promise;
}
}
const promise = pacote.manifest(depString);
cache[depString] = promise;
return promise;
}
newNodeFromSpec (name, spec, parent) {
// pacote will slap integrity on its options, so we have to clone
// the object so it doesn't get mutated.
// Don't bother to load the manifest for link deps, because the target
// might be within another package that doesn't exist yet.
return spec.type === 'directory'
? Promise.resolve(new Link({ name, parent, realpath: spec.fetchSpec }))
: pacote.manifest(spec, Object.create(this.options))
.then(pkg => new Node({ name, pkg, parent }))
}
.catch((error) => {
if (error.code === 'ETARGET') {
const { latest } = error.distTags;
return pacote.manifest(`${packageName}@${latest}`, pacoteOptions);
}
if (error.code === 'E404') {
console.error(`\nError: "${packageName}@${packageVersion}" not found`);
return packageVersion !== 'latest' ? pacote.manifest(packageName, pacoteOptions)
: Promise.reject(new Error(`${packageName}@${packageVersion} not found`));
}
return Promise.reject(error);
}),
packageVersion !== 'latest' ? pacote.packument(packageName, pacoteOptions) : Promise.resolve(),
.catch((error) => {
if (error.code === 'ETARGET') {
const { latest } = error.distTags;
return pacote.manifest(`${packageName}@${latest}`, pacoteOptions);
}
if (error.code === 'E404') {
console.error(`\nError: "${packageName}@${packageVersion}" not found`);
return packageVersion !== 'latest' ? pacote.manifest(packageName, pacoteOptions)
: Promise.reject(new Error(`${packageName}@${packageVersion} not found`));
}
return Promise.reject(error);
}),
packageVersion !== 'latest' ? pacote.packument(packageName, pacoteOptions) : Promise.resolve(),
async installPackage (packSpec) {
const log = this.log
log.trace(`${this.constructor.name}.installPackage('${packSpec}')`)
const config = this.config
const cachePath = this.globalConfig.cacheFolderPath
let manifest
try {
manifest = await pacote.manifest(packSpec, { cache: cachePath })
log.trace(manifest)
} catch (err) {
log.error(err.message)
return CliExitCodes.ERROR.INPUT
}
const manifestId = new ManifestId(manifest)
log.trace(manifestId)
const globalPackagePath = path.join(
this.globalConfig.globalFolderPath, manifestId.getPath())
const packFullName = manifestId.getFullName()
log.info(`Processing ${packFullName}...`)
async collectDevDependencies (json) {
const log = this.log
log.trace(`${this.constructor.name}.collectDevDependencies()` +
` for ${json.name}`)
const cachePath = this.globalConfig.cacheFolderPath
if (json.devDependencies) {
for (const [key, value] of Object.entries(json.devDependencies)) {
const version = value.replace(/^[^0-9]+/, '')
const pack = `${key}@${version}`
let manifest
try {
log.info(`Processing package ${pack}...`)
manifest = await pacote.manifest(pack, { cache: cachePath })
} catch (err) {
log.error(err.message)
return CliExitCodes.ERROR.APPLICATION
}
if (!this.collectedDependencies[key]) {
manifest.isContributedByDevDependencies = true
this.collectedDependencies[key] = manifest
} else {
if (version !== manifest.version) {
log.error('Version mitigation not yet implemented.')
return CliExitCodes.ERROR.APPLICATION
}
}
}
}