Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
removedPackages: string[],
opts: {
saveType?: DependenciesField,
prefix: string,
},
): Promise {
if (opts.saveType) {
packageManifest[opts.saveType] = packageManifest[opts.saveType]
if (!packageManifest[opts.saveType]) return packageManifest
removedPackages.forEach((dependency) => {
delete packageManifest[opts.saveType as DependenciesField]![dependency]
})
} else {
DEPENDENCIES_FIELDS
.filter((depField) => packageManifest[depField])
.forEach((depField) => {
removedPackages.forEach((dependency) => {
delete packageManifest[depField]![dependency]
})
})
}
if (packageManifest.peerDependencies) {
for (const removedDependency of removedPackages) {
delete packageManifest.peerDependencies[removedDependency]
}
}
packageManifestLogger.debug({
prefix: opts.prefix,
updated: packageManifest,
function stringifyIncludedDeps (included: IncludedDependencies) {
return DEPENDENCIES_FIELDS.filter((depsField) => included[depsField]).join(', ')
}
packageSpecs.forEach((packageSpec) => {
if (packageSpec.saveType) {
const spec = packageSpec.pref || findSpec(packageSpec.alias, packageManifest as ImporterManifest)
if (spec) {
packageManifest[packageSpec.saveType] = packageManifest[packageSpec.saveType] || {}
packageManifest[packageSpec.saveType]![packageSpec.alias] = spec
DEPENDENCIES_FIELDS.filter((depField) => depField !== packageSpec.saveType).forEach((deptype) => {
if (packageManifest[deptype]) {
delete packageManifest[deptype]![packageSpec.alias]
}
})
if (packageSpec.peer === true) {
packageManifest.peerDependencies = packageManifest.peerDependencies || {}
packageManifest.peerDependencies[packageSpec.alias] = spec
}
}
} else if (packageSpec.pref) {
const usedDepType = guessDependencyType(packageSpec.alias, packageManifest as ImporterManifest) || 'dependencies'
packageManifest[usedDepType] = packageManifest[usedDepType] || {}
packageManifest[usedDepType]![packageSpec.alias] = packageSpec.pref
}
})
export function guessDependencyType (alias: string, manifest: ImporterManifest): DependenciesField | undefined {
return DEPENDENCIES_FIELDS
.find((depField) => Boolean(manifest[depField]?.[alias]))
}
!pkg.optionalDependencies?.length &&
!pkg.unsavedDependencies?.length
) return ''
let label = ''
if (pkg.name) {
label += pkg.name
if (pkg.version) {
label += `@${pkg.version}`
}
label += ' '
}
label += pkg.path
let output = (opts.depth > -1 ? LEGEND : '') + label + '\n'
const useColumns = opts.depth === 0 && opts.long === false && !opts.search
for (let dependenciesField of [...DEPENDENCIES_FIELDS.sort(), 'unsavedDependencies']) {
if (pkg[dependenciesField]?.length) {
const depsLabel = chalk.cyanBright(
dependenciesField !== 'unsavedDependencies'
? `${dependenciesField}:`
: 'not saved (you should add these dependencies to package.json if you need them):'
)
output += `\n${depsLabel}\n`
const gPkgColor = dependenciesField === 'unsavedDependencies' ? () => NOT_SAVED_DEP_CLR : getPkgColor
if (useColumns && pkg[dependenciesField].length > 10) {
output += cliColumns(pkg[dependenciesField].map(printLabel.bind(printLabel, gPkgColor))) + '\n'
continue
}
const data = await toArchyTree(gPkgColor, pkg[dependenciesField]!, {
long: opts.long,
modules: path.join(pkg.path, 'node_modules'),
})
const jsonArr = await Promise.all(pkgs.map(async (pkg) => {
const jsonObj = {
name: pkg.name,
version: pkg.version,
}
for (const dependenciesField of [...DEPENDENCIES_FIELDS.sort(), 'unsavedDependencies']) {
if (pkg[dependenciesField]?.length) {
jsonObj[dependenciesField] = await toJsonResult(pkg[dependenciesField], { long: opts.long })
}
}
return jsonObj
}))
function mergeDependencies (lockfileImporter: LockfileImporter): { [depName: string]: string } {
return R.mergeAll(
DEPENDENCIES_FIELDS.map((depType) => lockfileImporter[depType] || {}),
)
}