Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (localConfig instanceof NowError && !(localConfig instanceof ERRORS.CantFindConfig)) {
output.error(`Failed to load local config file: ${localConfig.message}`);
return 1;
}
// the second argument to the command can be a path
// (as in: `now path/`) or a subcommand / provider
// (as in: `now ls`)
const targetOrSubcommand = argv._[2];
let update = null;
try {
if (targetOrSubcommand !== 'update') {
update = await checkForUpdate(pkg, {
interval: ms('1d'),
distTag: pkg.version.includes('canary') ? 'canary' : 'latest'
});
}
} catch (err) {
console.error(
error(`Checking for updates failed${isDebugging ? ':' : ''}`)
);
if (isDebugging) {
console.error(err);
}
}
if (update && isTTY) {
console.log(
!(localConfig instanceof ERRORS.CantFindConfig)
) {
output.error(`Failed to load local config file: ${localConfig.message}`);
return 1;
}
// the second argument to the command can be a path
// (as in: `now path/`) or a subcommand / provider
// (as in: `now ls`)
const targetOrSubcommand = argv._[2];
let update = null;
try {
if (targetOrSubcommand !== 'update') {
update = await checkForUpdate(pkg, {
interval: ms('1d'),
distTag: pkg.version.includes('canary') ? 'canary' : 'latest',
});
}
} catch (err) {
console.error(
error(`Checking for updates failed${isDebugging ? ':' : ''}`)
);
if (isDebugging) {
console.error(err);
}
}
if (update && isTTY) {
console.log(
console.error(error(`Failed to read package.json while checking for update`))
return
}
try {
// 1.0.1 -> latest
// 1.0.1-beta.1 -> beta
const validDistTags = ['latest', 'beta']
let distTag = 'latest'
const versionParts = prerelease(pkg.version) || []
if (versionParts) {
if (validDistTags.includes(versionParts[0])) distTag = versionParts[0]
}
const update = await checkForUpdate(pkg, {
interval: ms('1d'),
distTag,
})
if (update) {
printUpdateMessage(pkg.version, distTag, update)
}
} catch (err) {
console.error(error(`Checking for updates failed`))
console.error(err)
}
}
export default async function shouldUpdate() {
const packageJson = () => require('../package.json');
const update = checkForUpdate(packageJson()).catch(() => null);
try {
const res = await update;
if (res && res.latest) {
const isYarn = shouldUseYarn();
const _packageJson = packageJson();
console.log();
console.log(chalk.yellow.bold(`A new version of \`${_packageJson.name}\` is available`));
console.log(
'You can update by running: ' +
chalk.cyan(
isYarn ? `yarn global add ${_packageJson.name}` : `npm i -g ${_packageJson.name}`
)
);
console.log();