Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.then(() => new PkgDesc(pkgJson.name, pkgJson.version, newDirPath));
}
/**
* © 2017 Liferay, Inc.
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
import PkgDesc from 'liferay-npm-build-tools-common/lib/pkg-desc';
import project from 'liferay-npm-build-tools-common/lib/project';
import path from 'path';
import readJsonSync from 'read-json-sync';
import resolveModule from 'resolve';
import report from './report';
const pkgJson = project.pkgJson;
const rootPkg = new PkgDesc(pkgJson.name, pkgJson.version);
/**
* Get root package descriptor
* @return {PkgDesc} the root package descriptor
*/
export function getRootPkg() {
return rootPkg;
}
/**
* Recursively find the dependencies of a package and return them as PkgDesc
* objects.
* @param {object} collectedDependencies a hash of objects where key is the
* package id and values are PkgDesc objects
* @param {string} basedirPath directory where package lives in
* @param {Array} extraDependencies an array of package names to add to
export function addPackageDependencies(
collectedDependencies,
basedirPath,
extraDependencies = []
) {
const packageJson = readJsonSync(path.join(basedirPath, '/package.json'));
const pkg = new PkgDesc(
packageJson.name,
packageJson.version,
path.resolve(basedirPath) == path.resolve(project.dir.asNative)
? null
: basedirPath
);
if (collectedDependencies[pkg.id]) {
return;
}
collectedDependencies[pkg.id] = pkg;
let dependencies = packageJson.dependencies || {};
dependencies = Object.keys(dependencies);
dependencies = dependencies.concat(extraDependencies);
() =>
new PkgDesc(
pkgJson.name,
pkgJson.version,
newDir,
pkg.isRoot
)
);