Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function renamePkgDirIfNecessary(destPkg) {
if (destPkg.isRoot) {
return Promise.resolve(destPkg);
}
const pkgJson = readJsonSync(destPkg.dir.join('package.json').asNative);
const outputDirPath = path.dirname(destPkg.dir.asNative);
if (pkgJson.name !== destPkg.name || pkgJson.version !== destPkg.version) {
const newDirPath = path.join(
outputDirPath,
getPackageTargetDir(pkgJson.name, pkgJson.version)
);
rimraf.sync(newDirPath);
return fs
.move(destPkg.dir.asNative, newDirPath)
.then(() => new PkgDesc(pkgJson.name, pkgJson.version, newDirPath));
}
return Promise.resolve(destPkg);
}
deps.forEach(dep => {
let dirPrefix;
if (dep.indexOf('/') != -1) {
dirPrefix = `${getPackageTargetDir(dep)}@`;
} else {
dirPrefix = `${dep}@`;
}
if (!pkgJson.dependencies[dep]) {
const nodeModulesDir = path.resolve(path.join(pkg.dir, '..'));
for (let dir of fs.readdirSync(nodeModulesDir)) {
if (dir.startsWith(dirPrefix)) {
const depPkgJson = readJsonSync(
path.join(nodeModulesDir, dir, 'package.json')
);
pkgJson.dependencies[dep] = depPkgJson.version;
log.info(
export function renamePkgDirIfPkgJsonChanged(pkg) {
const pkgJson = readJsonSync(path.join(pkg.dir, 'package.json'));
const outputDir = path.dirname(pkg.dir);
if (pkgJson.name !== pkg.name || pkgJson.version !== pkg.version) {
const newDir = path.join(
outputDir,
getPackageTargetDir(pkgJson.name, pkgJson.version)
);
return fs
.move(pkg.dir, newDir)
.then(
() =>
new PkgDesc(
pkgJson.name,
pkgJson.version,
newDir,
pkg.isRoot
)
);
}
return Promise.resolve(pkg);
export function getDestDir(pkg) {
return pkg.isRoot
? project.dir.join(project.buildDir).asNative
: project.buildDir.join(
'node_modules',
getPackageTargetDir(pkg.name, pkg.version)
).asNative;
}