Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function upgradePackageDeps(stackPath: string, projectPath: string, packageJson: PackageJson) {
const templatePath = paths.tempPath(packageJson.name);
applyTemplate(stackPath, templatePath, { name: packageJson.name });
// Update package.json deps
const stackPackageJson = readPackageJson(templatePath);
if (!stackPackageJson) {
logger.error(`Cannot find or read stack's package.json under ${stackPath}`);
return;
}
const newPackageJson = mergePackageJson(packageJson, stackPackageJson);
// If modified, the reference would be different
logger.info(`Checking if package ${packageJson.name} should be upgraded...`);
if (newPackageJson !== packageJson) {
logger.info(`Package ${chalk.cyan(packageJson.name)} is being upgraded.`);
fse.writeJsonSync(path.join(projectPath, 'package.json'), newPackageJson, { spaces: 2 });
} else {
logger.info(`Package ${chalk.cyan(packageJson.name)} upgrade not needed.`);
}
}
const genOS = () => {
if (platform === "darwin") {
return "mac";
} else if (platform === "win32") {
return "win32";
} else {
// not supported in temp
logger.error("Unsupported platform!");
throw new Error("Unsupported platform!");
}
};
return new Promise((resolve, reject) => {
const os = genOS()
let downloadUrl;
if(os === "mac") {
if(!libUrl.mac){
logger.error(`no macos lib specified`)
return reject(new Error(`no macos lib specified`))
} else {
downloadUrl = libUrl.mac
}
} else {
if(!libUrl.win){
logger.error(`no windows lib specified`)
return reject(new Error(`no windows lib specified`))
} else {
downloadUrl = libUrl.win
}
}
/** start download */
const outputDir = "./tmp/";
logger.info(`Downloading ${os} Libs...\n${downloadUrl}\n`);
errorStats.errors.forEach((error: any) => {
logger.error(error);
});
reject(`Webpack failed with ${errorStats.errors.length} error(s).`);
const packageJson = readPackageJson(projectPath);
if (packageJson && packageJson.just && packageJson.just.stack) {
const stack = packageJson.just.stack;
let stackPath: string | null = null;
if (!templateInstallationPath) {
stackPath = await downloadPackage(stack);
} else {
stackPath = path.join(templateInstallationPath, stack, 'template');
}
if (stackPath) {
upgradePackageDeps(stackPath, projectPath, packageJson);
} else {
logger.error(`Cannot read or retrieve the stack package.json for ${stack}`);
}
} else if (packageJson) {
logger.info(
`Package ${chalk.cyan(packageJson.name)} does not have a "just" key. Skipping upgrade.`
);
} else {
logger.info(`package.json not found under ${chalk.cyan(projectPath)}. Skipping upgrade.`);
}
}
}).catch(err => {
logger.error("Failed: ", err);
reject(new Error(err));
});
})