Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions pgpm/cli/src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { checkForUpdates } from '@inquirerer/utils';
import { CLIOptions, Inquirerer, ParsedArgs, cliExitWithError, extractFirst, getPackageJson } from 'inquirerer';
import { teardownPgPools } from 'pg-cache';
import semver from 'semver';

import add from './commands/add';
import adminUsers from './commands/admin-users';
Expand Down Expand Up @@ -116,8 +117,11 @@ export const commands = async (argv: Partial<ParsedArgs>, prompter: Inquirerer,
pkgVersion: pkg.version,
toolName: 'pgpm',
});
if (updateResult.hasUpdate && updateResult.message) {
console.warn(updateResult.message);
if (updateResult.latestVersion
&& semver.valid(updateResult.latestVersion)
&& semver.valid(pkg.version)
&& semver.gt(updateResult.latestVersion, pkg.version)) {
console.warn(`Update available: ${pkg.version} -> ${updateResult.latestVersion}`);
console.warn('Run pgpm update to upgrade.');
}
} catch {
Expand Down
9 changes: 9 additions & 0 deletions pgpm/cli/src/commands/update.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Logger } from '@pgpmjs/logger';
import { CLIOptions, Inquirerer, cliExitWithError, getPackageJson } from 'inquirerer';
import { appstash } from 'appstash';
import { spawn } from 'child_process';
import * as fs from 'fs';
import * as path from 'path';
import { fetchLatestVersion } from '../utils/npm-version';

const log = new Logger('update');
Expand Down Expand Up @@ -65,6 +68,12 @@ export default async (

try {
await runNpmInstall(pkgName, registry);

try {
const cacheFile = path.join(appstash('pgpm').cache, 'update-check.json');
if (fs.existsSync(cacheFile)) fs.unlinkSync(cacheFile);
} catch {}

const latest = await fetchLatestVersion(pkgName);
if (latest) {
log.success(`Successfully updated ${pkgName} to version ${latest}.`);
Expand Down