pgpm 2.4.0 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/commands/add.js CHANGED
@@ -33,9 +33,9 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
+ const utils_1 = require("@inquirerer/utils");
36
37
  const core_1 = require("@pgpmjs/core");
37
38
  const path = __importStar(require("path"));
38
- const argv_1 = require("../utils/argv");
39
39
  const addUsageText = `
40
40
  Add Command:
41
41
 
@@ -65,7 +65,7 @@ exports.default = async (argv, prompter, _options) => {
65
65
  process.exit(0);
66
66
  }
67
67
  const cwd = argv.cwd || process.cwd();
68
- const { first: change, newArgv } = (0, argv_1.extractFirst)(argv);
68
+ const { first: change, newArgv } = (0, utils_1.extractFirst)(argv);
69
69
  let finalChange = change;
70
70
  if (!change) {
71
71
  const answers = await prompter.prompt(newArgv, [{
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const utils_1 = require("../utils");
6
+ const utils_1 = require("@inquirerer/utils");
7
7
  const add_1 = __importDefault(require("./admin-users/add"));
8
8
  const bootstrap_1 = __importDefault(require("./admin-users/bootstrap"));
9
9
  const remove_1 = __importDefault(require("./admin-users/remove"));
package/commands/cache.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const create_gen_app_1 = require("create-gen-app");
4
- const cli_error_1 = require("../utils/cli-error");
3
+ const utils_1 = require("@inquirerer/utils");
4
+ const genomic_1 = require("genomic");
5
5
  const cacheUsageText = `
6
6
  Cache Command:
7
7
 
@@ -19,10 +19,10 @@ exports.default = async (argv, _prompter, _options) => {
19
19
  const action = argv._?.[0] || 'clean';
20
20
  if (action !== 'clean') {
21
21
  console.log(cacheUsageText);
22
- await (0, cli_error_1.cliExitWithError)(`Unknown cache action: ${action}`);
22
+ await (0, utils_1.cliExitWithError)(`Unknown cache action: ${action}`);
23
23
  }
24
24
  const toolName = argv.tool || 'pgpm';
25
- const cacheManager = new create_gen_app_1.CacheManager({ toolName });
25
+ const cacheManager = new genomic_1.CacheManager({ toolName });
26
26
  cacheManager.clearAll();
27
27
  process.stdout.write(`Cleared template cache for "${toolName}".\n`);
28
28
  return argv;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const child_process_1 = require("child_process");
4
- const utils_1 = require("../utils");
4
+ const utils_1 = require("@inquirerer/utils");
5
5
  const dockerUsageText = `
6
6
  Docker Command:
7
7
 
@@ -245,14 +245,15 @@ async function handleModuleInit(argv, prompter, ctx, wasExplicitModuleRequest =
245
245
  // Offer to create a workspace instead
246
246
  const recoveryQuestion = [
247
247
  {
248
- name: 'createWorkspace',
248
+ name: 'workspace',
249
+ alias: 'w',
249
250
  message: 'You are not inside a PGPM workspace. Would you like to create a new workspace instead?',
250
251
  type: 'confirm',
251
252
  required: true,
252
253
  },
253
254
  ];
254
- const { createWorkspace } = await prompter.prompt(argv, recoveryQuestion);
255
- if (createWorkspace) {
255
+ const { workspace } = await prompter.prompt(argv, recoveryQuestion);
256
+ if (workspace) {
256
257
  return handleWorkspaceInit(argv, prompter, {
257
258
  fromPath: 'workspace',
258
259
  templateRepo: ctx.templateRepo,
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const utils_1 = require("../utils");
6
+ const utils_1 = require("@inquirerer/utils");
7
7
  const deps_1 = __importDefault(require("./migrate/deps"));
8
8
  // Migrate subcommands
9
9
  const init_1 = __importDefault(require("./migrate/init"));
@@ -1,17 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("@inquirerer/utils");
3
4
  const core_1 = require("@pgpmjs/core");
4
5
  const env_1 = require("@pgpmjs/env");
5
6
  const logger_1 = require("@pgpmjs/logger");
6
7
  const pg_env_1 = require("pg-env");
7
- const utils_1 = require("../utils");
8
- const cli_error_1 = require("../utils/cli-error");
8
+ const utils_2 = require("../utils");
9
9
  const log = new logger_1.Logger('remove');
10
10
  exports.default = async (argv, prompter, _options) => {
11
11
  if (!argv.to) {
12
- await (0, cli_error_1.cliExitWithError)('No change specified. Usage: pgpm remove --to <change>');
12
+ await (0, utils_1.cliExitWithError)('No change specified. Usage: pgpm remove --to <change>');
13
13
  }
14
- const database = await (0, utils_1.getTargetDatabase)(argv, prompter, {
14
+ const database = await (0, utils_2.getTargetDatabase)(argv, prompter, {
15
15
  message: 'Select database'
16
16
  });
17
17
  const questions = [
@@ -3,14 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("@inquirerer/utils");
6
7
  const core_1 = require("@pgpmjs/core");
7
8
  const path_1 = __importDefault(require("path"));
8
- const cli_error_1 = require("../utils/cli-error");
9
9
  exports.default = async (argv, _prompter) => {
10
10
  const cwd = argv.cwd || process.cwd();
11
11
  const to = argv.to || (argv._ && argv._[0]);
12
12
  if (!to) {
13
- await (0, cli_error_1.cliExitWithError)('Missing new name. Use --to <name> or provide as positional argument.');
13
+ await (0, utils_1.cliExitWithError)('Missing new name. Use --to <name> or provide as positional argument.');
14
14
  }
15
15
  const dryRun = !!argv['dry-run'] || !!argv.dryRun;
16
16
  const syncPkg = !!argv['sync-pkg-name'] || !!argv.syncPkgName;
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("@inquirerer/utils");
3
4
  const core_1 = require("@pgpmjs/core");
4
5
  const env_1 = require("@pgpmjs/env");
5
6
  const logger_1 = require("@pgpmjs/logger");
6
7
  const pg_env_1 = require("pg-env");
7
- const utils_1 = require("../utils");
8
- const cli_error_1 = require("../utils/cli-error");
8
+ const utils_2 = require("../utils");
9
9
  const deployed_changes_1 = require("../utils/deployed-changes");
10
10
  const log = new logger_1.Logger('revert');
11
11
  const revertUsageText = `
@@ -35,7 +35,7 @@ exports.default = async (argv, prompter, _options) => {
35
35
  console.log(revertUsageText);
36
36
  process.exit(0);
37
37
  }
38
- const database = await (0, utils_1.getTargetDatabase)(argv, prompter, {
38
+ const database = await (0, utils_2.getTargetDatabase)(argv, prompter, {
39
39
  message: 'Select database'
40
40
  });
41
41
  const questions = [
@@ -72,7 +72,7 @@ exports.default = async (argv, prompter, _options) => {
72
72
  if (recursive && argv.to !== true) {
73
73
  packageName = await (0, deployed_changes_1.selectDeployedPackage)(database, argv, prompter, log, 'revert', cwd);
74
74
  if (!packageName) {
75
- await (0, cli_error_1.cliExitWithError)('No package found to revert');
75
+ await (0, utils_1.cliExitWithError)('No package found to revert');
76
76
  }
77
77
  }
78
78
  const pkg = new core_1.PgpmPackage(cwd);
@@ -86,7 +86,7 @@ exports.default = async (argv, prompter, _options) => {
86
86
  if (argv.to === true) {
87
87
  target = await (0, deployed_changes_1.selectDeployedChange)(database, argv, prompter, log, 'revert', cwd);
88
88
  if (!target) {
89
- await (0, cli_error_1.cliExitWithError)('No target selected, operation cancelled');
89
+ await (0, utils_1.cliExitWithError)('No target selected, operation cancelled');
90
90
  }
91
91
  }
92
92
  else if (packageName && argv.to) {
@@ -96,11 +96,11 @@ exports.default = async (argv, prompter, _options) => {
96
96
  target = packageName;
97
97
  }
98
98
  else if (argv.package && argv.to) {
99
- const resolvedPackage = (0, utils_1.resolvePackageAlias)(argv.package, cwd);
99
+ const resolvedPackage = (0, utils_2.resolvePackageAlias)(argv.package, cwd);
100
100
  target = `${resolvedPackage}:${argv.to}`;
101
101
  }
102
102
  else if (argv.package) {
103
- target = (0, utils_1.resolvePackageAlias)(argv.package, cwd);
103
+ target = (0, utils_2.resolvePackageAlias)(argv.package, cwd);
104
104
  }
105
105
  await pkg.revert(opts, target, recursive);
106
106
  log.success('Revert complete.');
package/commands/tag.js CHANGED
@@ -33,11 +33,11 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
+ const utils_1 = require("@inquirerer/utils");
36
37
  const core_1 = require("@pgpmjs/core");
37
38
  const logger_1 = require("@pgpmjs/logger");
38
39
  const types_1 = require("@pgpmjs/types");
39
40
  const path = __importStar(require("path"));
40
- const argv_1 = require("../utils/argv");
41
41
  const module_utils_1 = require("../utils/module-utils");
42
42
  const package_alias_1 = require("../utils/package-alias");
43
43
  const log = new logger_1.Logger('tag');
@@ -69,7 +69,7 @@ exports.default = async (argv, prompter, _options) => {
69
69
  console.log(tagUsageText);
70
70
  process.exit(0);
71
71
  }
72
- const { first: tagName, newArgv } = (0, argv_1.extractFirst)(argv);
72
+ const { first: tagName, newArgv } = (0, utils_1.extractFirst)(argv);
73
73
  const cwdResult = await prompter.prompt(newArgv, [
74
74
  {
75
75
  type: 'text',
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("@inquirerer/utils");
3
4
  const find_and_require_package_json_1 = require("find-and-require-package-json");
4
5
  const logger_1 = require("@pgpmjs/logger");
5
6
  const child_process_1 = require("child_process");
6
7
  const npm_version_1 = require("../utils/npm-version");
7
- const cli_error_1 = require("../utils/cli-error");
8
8
  const log = new logger_1.Logger('update');
9
9
  const updateUsageText = `
10
10
  Update Command:
@@ -63,7 +63,7 @@ exports.default = async (argv, _prompter, _options) => {
63
63
  }
64
64
  }
65
65
  catch (error) {
66
- await (0, cli_error_1.cliExitWithError)(error instanceof Error ? error.message : String(error), { package: pkgName, registry });
66
+ await (0, utils_1.cliExitWithError)(error instanceof Error ? error.message : String(error), { context: { package: pkgName, registry } });
67
67
  }
68
68
  return argv;
69
69
  };
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("@inquirerer/utils");
3
4
  const core_1 = require("@pgpmjs/core");
4
5
  const env_1 = require("@pgpmjs/env");
5
6
  const logger_1 = require("@pgpmjs/logger");
6
7
  const pg_env_1 = require("pg-env");
7
- const utils_1 = require("../utils");
8
- const cli_error_1 = require("../utils/cli-error");
8
+ const utils_2 = require("../utils");
9
9
  const deployed_changes_1 = require("../utils/deployed-changes");
10
10
  const log = new logger_1.Logger('verify');
11
11
  const verifyUsageText = `
@@ -34,7 +34,7 @@ exports.default = async (argv, prompter, _options) => {
34
34
  console.log(verifyUsageText);
35
35
  process.exit(0);
36
36
  }
37
- const database = await (0, utils_1.getTargetDatabase)(argv, prompter, {
37
+ const database = await (0, utils_2.getTargetDatabase)(argv, prompter, {
38
38
  message: 'Select database'
39
39
  });
40
40
  const questions = [
@@ -53,7 +53,7 @@ exports.default = async (argv, prompter, _options) => {
53
53
  if (recursive && argv.to !== true) {
54
54
  packageName = await (0, deployed_changes_1.selectDeployedPackage)(database, argv, prompter, log, 'verify', cwd);
55
55
  if (!packageName) {
56
- await (0, cli_error_1.cliExitWithError)('No package found to verify');
56
+ await (0, utils_1.cliExitWithError)('No package found to verify');
57
57
  }
58
58
  }
59
59
  const project = new core_1.PgpmPackage(cwd);
@@ -64,7 +64,7 @@ exports.default = async (argv, prompter, _options) => {
64
64
  if (argv.to === true) {
65
65
  target = await (0, deployed_changes_1.selectDeployedChange)(database, argv, prompter, log, 'verify', cwd);
66
66
  if (!target) {
67
- await (0, cli_error_1.cliExitWithError)('No target selected, operation cancelled');
67
+ await (0, utils_1.cliExitWithError)('No target selected, operation cancelled');
68
68
  }
69
69
  }
70
70
  else if (packageName && argv.to) {
@@ -74,11 +74,11 @@ exports.default = async (argv, prompter, _options) => {
74
74
  target = packageName;
75
75
  }
76
76
  else if (argv.package && argv.to) {
77
- const resolvedPackage = (0, utils_1.resolvePackageAlias)(argv.package, cwd);
77
+ const resolvedPackage = (0, utils_2.resolvePackageAlias)(argv.package, cwd);
78
78
  target = `${resolvedPackage}:${argv.to}`;
79
79
  }
80
80
  else if (argv.package) {
81
- target = (0, utils_1.resolvePackageAlias)(argv.package, cwd);
81
+ target = (0, utils_2.resolvePackageAlias)(argv.package, cwd);
82
82
  }
83
83
  await project.verify(opts, target, recursive);
84
84
  log.success('Verify complete.');
package/commands.js CHANGED
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.commands = exports.createPgpmCommandMap = void 0;
7
7
  const find_and_require_package_json_1 = require("find-and-require-package-json");
8
+ const utils_1 = require("@inquirerer/utils");
8
9
  const pg_cache_1 = require("pg-cache");
9
10
  const add_1 = __importDefault(require("./commands/add"));
10
11
  const admin_users_1 = __importDefault(require("./commands/admin-users"));
@@ -30,9 +31,7 @@ const revert_1 = __importDefault(require("./commands/revert"));
30
31
  const tag_1 = __importDefault(require("./commands/tag"));
31
32
  const test_packages_1 = __importDefault(require("./commands/test-packages"));
32
33
  const verify_1 = __importDefault(require("./commands/verify"));
33
- const utils_1 = require("./utils");
34
- const cli_error_1 = require("./utils/cli-error");
35
- const update_check_1 = require("./utils/update-check");
34
+ const utils_2 = require("./utils");
36
35
  const withPgTeardown = (fn, skipTeardown = false) => async (...args) => {
37
36
  try {
38
37
  await fn(...args);
@@ -81,11 +80,11 @@ const commands = async (argv, prompter, options) => {
81
80
  }
82
81
  let { first: command, newArgv } = (0, utils_1.extractFirst)(argv);
83
82
  if ((argv.help || argv.h || command === 'help') && !command) {
84
- console.log(utils_1.usageText);
83
+ console.log(utils_2.usageText);
85
84
  process.exit(0);
86
85
  }
87
86
  if (command === 'help') {
88
- console.log(utils_1.usageText);
87
+ console.log(utils_2.usageText);
89
88
  process.exit(0);
90
89
  }
91
90
  const commandMap = (0, exports.createPgpmCommandMap)(options?.skipPgTeardown);
@@ -100,14 +99,24 @@ const commands = async (argv, prompter, options) => {
100
99
  ]);
101
100
  command = answer.command;
102
101
  }
103
- try {
104
- await (0, update_check_1.checkForUpdates)({
105
- command,
106
- pkgVersion: (0, find_and_require_package_json_1.findAndRequirePackageJson)(__dirname).version
107
- });
108
- }
109
- catch {
110
- // ignore update check failures
102
+ // Run update check (skip on 'update' command to avoid redundant check)
103
+ // (checkForUpdates auto-skips in CI or when INQUIRERER_SKIP_UPDATE_CHECK / PGPM_SKIP_UPDATE_CHECK is set)
104
+ if (command !== 'update') {
105
+ try {
106
+ const pkg = (0, find_and_require_package_json_1.findAndRequirePackageJson)(__dirname);
107
+ const updateResult = await (0, utils_1.checkForUpdates)({
108
+ pkgName: pkg.name,
109
+ pkgVersion: pkg.version,
110
+ toolName: 'pgpm',
111
+ });
112
+ if (updateResult.hasUpdate && updateResult.message) {
113
+ console.warn(updateResult.message);
114
+ console.warn('Run pgpm update to upgrade.');
115
+ }
116
+ }
117
+ catch {
118
+ // ignore update check failures
119
+ }
111
120
  }
112
121
  newArgv = await prompter.prompt(newArgv, [
113
122
  {
@@ -121,8 +130,8 @@ const commands = async (argv, prompter, options) => {
121
130
  ]);
122
131
  const commandFn = commandMap[command];
123
132
  if (!commandFn) {
124
- console.log(utils_1.usageText);
125
- await (0, cli_error_1.cliExitWithError)(`Unknown command: ${command}`);
133
+ console.log(utils_2.usageText);
134
+ await (0, utils_1.cliExitWithError)(`Unknown command: ${command}`, { beforeExit: pg_cache_1.teardownPgPools });
126
135
  }
127
136
  await commandFn(newArgv, prompter, options);
128
137
  prompter.close();
@@ -1,6 +1,6 @@
1
+ import { extractFirst } from '@inquirerer/utils';
1
2
  import { PgpmPackage } from '@pgpmjs/core';
2
3
  import * as path from 'path';
3
- import { extractFirst } from '../utils/argv';
4
4
  const addUsageText = `
5
5
  Add Command:
6
6
 
@@ -1,4 +1,4 @@
1
- import { extractFirst } from '../utils';
1
+ import { extractFirst } from '@inquirerer/utils';
2
2
  import add from './admin-users/add';
3
3
  import bootstrap from './admin-users/bootstrap';
4
4
  import remove from './admin-users/remove';
@@ -1,5 +1,5 @@
1
- import { CacheManager } from 'create-gen-app';
2
- import { cliExitWithError } from '../utils/cli-error';
1
+ import { cliExitWithError } from '@inquirerer/utils';
2
+ import { CacheManager } from 'genomic';
3
3
  const cacheUsageText = `
4
4
  Cache Command:
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { spawn } from 'child_process';
2
- import { cliExitWithError, extractFirst } from '../utils';
2
+ import { cliExitWithError, extractFirst } from '@inquirerer/utils';
3
3
  const dockerUsageText = `
4
4
  Docker Command:
5
5
 
@@ -238,14 +238,15 @@ async function handleModuleInit(argv, prompter, ctx, wasExplicitModuleRequest =
238
238
  // Offer to create a workspace instead
239
239
  const recoveryQuestion = [
240
240
  {
241
- name: 'createWorkspace',
241
+ name: 'workspace',
242
+ alias: 'w',
242
243
  message: 'You are not inside a PGPM workspace. Would you like to create a new workspace instead?',
243
244
  type: 'confirm',
244
245
  required: true,
245
246
  },
246
247
  ];
247
- const { createWorkspace } = await prompter.prompt(argv, recoveryQuestion);
248
- if (createWorkspace) {
248
+ const { workspace } = await prompter.prompt(argv, recoveryQuestion);
249
+ if (workspace) {
249
250
  return handleWorkspaceInit(argv, prompter, {
250
251
  fromPath: 'workspace',
251
252
  templateRepo: ctx.templateRepo,
@@ -1,4 +1,4 @@
1
- import { extractFirst } from '../utils';
1
+ import { extractFirst } from '@inquirerer/utils';
2
2
  import deps from './migrate/deps';
3
3
  // Migrate subcommands
4
4
  import init from './migrate/init';
@@ -1,9 +1,9 @@
1
+ import { cliExitWithError } from '@inquirerer/utils';
1
2
  import { PgpmPackage } from '@pgpmjs/core';
2
3
  import { getEnvOptions } from '@pgpmjs/env';
3
4
  import { Logger } from '@pgpmjs/logger';
4
5
  import { getPgEnvOptions } from 'pg-env';
5
6
  import { getTargetDatabase } from '../utils';
6
- import { cliExitWithError } from '../utils/cli-error';
7
7
  const log = new Logger('remove');
8
8
  export default async (argv, prompter, _options) => {
9
9
  if (!argv.to) {
@@ -1,6 +1,6 @@
1
+ import { cliExitWithError } from '@inquirerer/utils';
1
2
  import { PgpmPackage } from '@pgpmjs/core';
2
3
  import path from 'path';
3
- import { cliExitWithError } from '../utils/cli-error';
4
4
  export default async (argv, _prompter) => {
5
5
  const cwd = argv.cwd || process.cwd();
6
6
  const to = argv.to || (argv._ && argv._[0]);
@@ -1,9 +1,9 @@
1
+ import { cliExitWithError } from '@inquirerer/utils';
1
2
  import { PgpmPackage } from '@pgpmjs/core';
2
3
  import { getEnvOptions } from '@pgpmjs/env';
3
4
  import { Logger } from '@pgpmjs/logger';
4
5
  import { getPgEnvOptions } from 'pg-env';
5
6
  import { getTargetDatabase, resolvePackageAlias } from '../utils';
6
- import { cliExitWithError } from '../utils/cli-error';
7
7
  import { selectDeployedChange, selectDeployedPackage } from '../utils/deployed-changes';
8
8
  const log = new Logger('revert');
9
9
  const revertUsageText = `
@@ -1,8 +1,8 @@
1
+ import { extractFirst } from '@inquirerer/utils';
1
2
  import { PgpmPackage } from '@pgpmjs/core';
2
3
  import { Logger } from '@pgpmjs/logger';
3
4
  import { errors } from '@pgpmjs/types';
4
5
  import * as path from 'path';
5
- import { extractFirst } from '../utils/argv';
6
6
  import { selectPackage } from '../utils/module-utils';
7
7
  import { resolvePackageAlias } from '../utils/package-alias';
8
8
  const log = new Logger('tag');
@@ -1,8 +1,8 @@
1
+ import { cliExitWithError } from '@inquirerer/utils';
1
2
  import { findAndRequirePackageJson } from 'find-and-require-package-json';
2
3
  import { Logger } from '@pgpmjs/logger';
3
4
  import { spawn } from 'child_process';
4
5
  import { fetchLatestVersion } from '../utils/npm-version';
5
- import { cliExitWithError } from '../utils/cli-error';
6
6
  const log = new Logger('update');
7
7
  const updateUsageText = `
8
8
  Update Command:
@@ -61,7 +61,7 @@ export default async (argv, _prompter, _options) => {
61
61
  }
62
62
  }
63
63
  catch (error) {
64
- await cliExitWithError(error instanceof Error ? error.message : String(error), { package: pkgName, registry });
64
+ await cliExitWithError(error instanceof Error ? error.message : String(error), { context: { package: pkgName, registry } });
65
65
  }
66
66
  return argv;
67
67
  };
@@ -1,9 +1,9 @@
1
+ import { cliExitWithError } from '@inquirerer/utils';
1
2
  import { PgpmPackage } from '@pgpmjs/core';
2
3
  import { getEnvOptions } from '@pgpmjs/env';
3
4
  import { Logger } from '@pgpmjs/logger';
4
5
  import { getPgEnvOptions } from 'pg-env';
5
6
  import { getTargetDatabase, resolvePackageAlias } from '../utils';
6
- import { cliExitWithError } from '../utils/cli-error';
7
7
  import { selectDeployedChange, selectDeployedPackage } from '../utils/deployed-changes';
8
8
  const log = new Logger('verify');
9
9
  const verifyUsageText = `
package/esm/commands.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { findAndRequirePackageJson } from 'find-and-require-package-json';
2
+ import { cliExitWithError, checkForUpdates, extractFirst } from '@inquirerer/utils';
2
3
  import { teardownPgPools } from 'pg-cache';
3
4
  import add from './commands/add';
4
5
  import adminUsers from './commands/admin-users';
@@ -24,9 +25,7 @@ import revert from './commands/revert';
24
25
  import tag from './commands/tag';
25
26
  import testPackages from './commands/test-packages';
26
27
  import verify from './commands/verify';
27
- import { extractFirst, usageText } from './utils';
28
- import { cliExitWithError } from './utils/cli-error';
29
- import { checkForUpdates } from './utils/update-check';
28
+ import { usageText } from './utils';
30
29
  const withPgTeardown = (fn, skipTeardown = false) => async (...args) => {
31
30
  try {
32
31
  await fn(...args);
@@ -93,14 +92,24 @@ export const commands = async (argv, prompter, options) => {
93
92
  ]);
94
93
  command = answer.command;
95
94
  }
96
- try {
97
- await checkForUpdates({
98
- command,
99
- pkgVersion: findAndRequirePackageJson(__dirname).version
100
- });
101
- }
102
- catch {
103
- // ignore update check failures
95
+ // Run update check (skip on 'update' command to avoid redundant check)
96
+ // (checkForUpdates auto-skips in CI or when INQUIRERER_SKIP_UPDATE_CHECK / PGPM_SKIP_UPDATE_CHECK is set)
97
+ if (command !== 'update') {
98
+ try {
99
+ const pkg = findAndRequirePackageJson(__dirname);
100
+ const updateResult = await checkForUpdates({
101
+ pkgName: pkg.name,
102
+ pkgVersion: pkg.version,
103
+ toolName: 'pgpm',
104
+ });
105
+ if (updateResult.hasUpdate && updateResult.message) {
106
+ console.warn(updateResult.message);
107
+ console.warn('Run pgpm update to upgrade.');
108
+ }
109
+ }
110
+ catch {
111
+ // ignore update check failures
112
+ }
104
113
  }
105
114
  newArgv = await prompter.prompt(newArgv, [
106
115
  {
@@ -115,7 +124,7 @@ export const commands = async (argv, prompter, options) => {
115
124
  const commandFn = commandMap[command];
116
125
  if (!commandFn) {
117
126
  console.log(usageText);
118
- await cliExitWithError(`Unknown command: ${command}`);
127
+ await cliExitWithError(`Unknown command: ${command}`, { beforeExit: teardownPgPools });
119
128
  }
120
129
  await commandFn(newArgv, prompter, options);
121
130
  prompter.close();
@@ -1,10 +1,6 @@
1
- export * from './argv';
2
1
  export * from './database';
3
2
  export * from './display';
4
- export * from './cli-error';
5
3
  export * from './deployed-changes';
6
4
  export * from './module-utils';
7
5
  export * from './npm-version';
8
6
  export * from './package-alias';
9
- export * from './update-check';
10
- export * from './update-config';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pgpm",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "author": "Constructive <developers@constructive.io>",
5
5
  "description": "PostgreSQL Package Manager - Database migration and package management CLI",
6
6
  "main": "index.js",
@@ -46,14 +46,15 @@
46
46
  "ts-node": "^10.9.2"
47
47
  },
48
48
  "dependencies": {
49
- "@pgpmjs/core": "^4.2.0",
49
+ "@inquirerer/utils": "^3.1.1",
50
+ "@pgpmjs/core": "^4.3.0",
50
51
  "@pgpmjs/env": "^2.8.11",
51
52
  "@pgpmjs/logger": "^1.3.5",
52
53
  "@pgpmjs/types": "^2.12.8",
53
54
  "appstash": "^0.2.6",
54
- "create-gen-app": "^0.10.0",
55
55
  "find-and-require-package-json": "^0.8.2",
56
- "inquirerer": "^2.4.0",
56
+ "genomic": "^5.0.2",
57
+ "inquirerer": "^4.1.1",
57
58
  "js-yaml": "^4.1.0",
58
59
  "minimist": "^1.2.8",
59
60
  "pg-cache": "^1.6.11",
@@ -74,5 +75,5 @@
74
75
  "pg",
75
76
  "pgsql"
76
77
  ],
77
- "gitHead": "9b68e2d19937ad4e2a81a5de110a197a8572e3d9"
78
+ "gitHead": "7ac931c063d48e281349b748ba2eb9c9f47ffb06"
78
79
  }
package/utils/index.d.ts CHANGED
@@ -1,10 +1,6 @@
1
- export * from './argv';
2
1
  export * from './database';
3
2
  export * from './display';
4
- export * from './cli-error';
5
3
  export * from './deployed-changes';
6
4
  export * from './module-utils';
7
5
  export * from './npm-version';
8
6
  export * from './package-alias';
9
- export * from './update-check';
10
- export * from './update-config';
package/utils/index.js CHANGED
@@ -14,13 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./argv"), exports);
18
17
  __exportStar(require("./database"), exports);
19
18
  __exportStar(require("./display"), exports);
20
- __exportStar(require("./cli-error"), exports);
21
19
  __exportStar(require("./deployed-changes"), exports);
22
20
  __exportStar(require("./module-utils"), exports);
23
21
  __exportStar(require("./npm-version"), exports);
24
22
  __exportStar(require("./package-alias"), exports);
25
- __exportStar(require("./update-check"), exports);
26
- __exportStar(require("./update-config"), exports);
package/esm/utils/argv.js DELETED
@@ -1,8 +0,0 @@
1
- export const extractFirst = (argv) => {
2
- const first = argv._?.[0];
3
- const newArgv = {
4
- ...argv,
5
- _: argv._?.slice(1) ?? []
6
- };
7
- return { first, newArgv };
8
- };
@@ -1,48 +0,0 @@
1
- import { Logger } from '@pgpmjs/logger';
2
- import { PgpmError } from '@pgpmjs/types';
3
- import { teardownPgPools } from 'pg-cache';
4
- const log = new Logger('cli');
5
- /**
6
- * CLI error utility that logs error information and exits with code 1.
7
- * Provides consistent error handling and user experience across all CLI commands.
8
- *
9
- * IMPORTANT: This function properly cleans up PostgreSQL connections before exiting.
10
- */
11
- export const cliExitWithError = async (error, context) => {
12
- if (error instanceof PgpmError) {
13
- // For PgpmError instances, use structured logging
14
- log.error(`Error: ${error.message}`);
15
- // Log additional context if available
16
- if (error.context && Object.keys(error.context).length > 0) {
17
- log.debug('Error context:', error.context);
18
- }
19
- // Log any additional context provided
20
- if (context) {
21
- log.debug('Additional context:', context);
22
- }
23
- }
24
- else if (error instanceof Error) {
25
- // For generic Error instances
26
- log.error(`Error: ${error.message}`);
27
- if (context) {
28
- log.debug('Context:', context);
29
- }
30
- }
31
- else if (typeof error === 'string') {
32
- // For simple string messages
33
- log.error(`Error: ${error}`);
34
- if (context) {
35
- log.debug('Context:', context);
36
- }
37
- }
38
- // Perform cleanup before exiting
39
- try {
40
- await teardownPgPools();
41
- log.debug('Database connections cleaned up');
42
- }
43
- catch (cleanupError) {
44
- log.warn('Failed to cleanup database connections:', cleanupError);
45
- // Don't let cleanup errors prevent the exit
46
- }
47
- process.exit(1);
48
- };
@@ -1,57 +0,0 @@
1
- import { findAndRequirePackageJson } from 'find-and-require-package-json';
2
- import { Logger } from '@pgpmjs/logger';
3
- import { UPDATE_CHECK_APPSTASH_KEY, UPDATE_CHECK_TTL_MS, UPDATE_PACKAGE_NAME } from '@pgpmjs/types';
4
- import { compareVersions, fetchLatestVersion } from './npm-version';
5
- import { readUpdateConfig, shouldCheck, writeUpdateConfig } from './update-config';
6
- const log = new Logger('update-check');
7
- const shouldSkip = (command) => {
8
- if (process.env.PGPM_SKIP_UPDATE_CHECK)
9
- return true;
10
- if (process.env.CI === 'true')
11
- return true;
12
- if (command === 'update')
13
- return true;
14
- return false;
15
- };
16
- export async function checkForUpdates(options = {}) {
17
- const { pkgName = UPDATE_PACKAGE_NAME, pkgVersion = findAndRequirePackageJson(__dirname).version, command, now = Date.now(), key = UPDATE_CHECK_APPSTASH_KEY, toolName, baseDir } = options;
18
- if (shouldSkip(command)) {
19
- return null;
20
- }
21
- try {
22
- const existing = await readUpdateConfig({ toolName, baseDir, key });
23
- let latestKnownVersion = existing?.latestKnownVersion ?? pkgVersion;
24
- const needsCheck = shouldCheck(now, existing?.lastCheckedAt, UPDATE_CHECK_TTL_MS);
25
- if (needsCheck) {
26
- const fetched = await fetchLatestVersion(pkgName);
27
- if (fetched) {
28
- latestKnownVersion = fetched;
29
- }
30
- await writeUpdateConfig({
31
- lastCheckedAt: now,
32
- latestKnownVersion
33
- }, { toolName, baseDir, key });
34
- }
35
- const comparison = compareVersions(pkgVersion, latestKnownVersion);
36
- const isOutdated = comparison < 0;
37
- if (isOutdated) {
38
- const defaultUpdateCommand = pkgName === UPDATE_PACKAGE_NAME
39
- ? 'Run pgpm update to upgrade.'
40
- : `Run npm i -g ${pkgName}@latest to upgrade.`;
41
- const updateInstruction = options.updateCommand ?? defaultUpdateCommand;
42
- log.warn(`A new version of ${pkgName} is available (current ${pkgVersion}, latest ${latestKnownVersion}). ${updateInstruction}`);
43
- await writeUpdateConfig({
44
- lastCheckedAt: now,
45
- latestKnownVersion
46
- }, { toolName, baseDir, key });
47
- }
48
- return {
49
- lastCheckedAt: now,
50
- latestKnownVersion
51
- };
52
- }
53
- catch (error) {
54
- log.debug('Update check skipped due to error:', error);
55
- return null;
56
- }
57
- }
@@ -1,50 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import { appstash, resolve as resolveAppstash } from 'appstash';
4
- import { UPDATE_CHECK_APPSTASH_KEY } from '@pgpmjs/types';
5
- const defaultToolName = 'pgpm';
6
- const getConfigPath = (options = {}) => {
7
- const toolName = options.toolName ?? defaultToolName;
8
- const dirs = appstash(toolName, {
9
- ensure: true,
10
- baseDir: options.baseDir
11
- });
12
- const configDir = resolveAppstash(dirs, 'config');
13
- if (!fs.existsSync(configDir)) {
14
- fs.mkdirSync(configDir, { recursive: true });
15
- }
16
- const fileName = `${(options.key ?? UPDATE_CHECK_APPSTASH_KEY).replace(/[^a-z0-9-_]/gi, '_')}.json`;
17
- return path.join(configDir, fileName);
18
- };
19
- export const shouldCheck = (now, lastCheckedAt, ttlMs) => {
20
- if (!lastCheckedAt)
21
- return true;
22
- return now - lastCheckedAt > ttlMs;
23
- };
24
- export async function readUpdateConfig(options = {}) {
25
- const configPath = getConfigPath(options);
26
- if (!fs.existsSync(configPath)) {
27
- return null;
28
- }
29
- try {
30
- const contents = await fs.promises.readFile(configPath, 'utf8');
31
- const parsed = JSON.parse(contents);
32
- return parsed;
33
- }
34
- catch {
35
- // Corrupted config – clear it
36
- try {
37
- await fs.promises.rm(configPath, { force: true });
38
- }
39
- catch {
40
- // ignore
41
- }
42
- return null;
43
- }
44
- }
45
- export async function writeUpdateConfig(config, options = {}) {
46
- const configPath = getConfigPath(options);
47
- await fs.promises.writeFile(configPath, JSON.stringify(config, null, 2), 'utf8');
48
- }
49
- // Exposed for testing to locate the config path for a given namespace/baseDir
50
- export const resolveUpdateConfigPath = (options = {}) => getConfigPath(options);
package/utils/argv.d.ts DELETED
@@ -1,8 +0,0 @@
1
- import { ParsedArgs } from 'minimist';
2
- export declare const extractFirst: (argv: Partial<ParsedArgs>) => {
3
- first: string;
4
- newArgv: {
5
- _: string[];
6
- "--"?: string[] | undefined;
7
- };
8
- };
package/utils/argv.js DELETED
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extractFirst = void 0;
4
- const extractFirst = (argv) => {
5
- const first = argv._?.[0];
6
- const newArgv = {
7
- ...argv,
8
- _: argv._?.slice(1) ?? []
9
- };
10
- return { first, newArgv };
11
- };
12
- exports.extractFirst = extractFirst;
@@ -1,8 +0,0 @@
1
- import { PgpmError } from '@pgpmjs/types';
2
- /**
3
- * CLI error utility that logs error information and exits with code 1.
4
- * Provides consistent error handling and user experience across all CLI commands.
5
- *
6
- * IMPORTANT: This function properly cleans up PostgreSQL connections before exiting.
7
- */
8
- export declare const cliExitWithError: (error: PgpmError | Error | string, context?: Record<string, any>) => Promise<never>;
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cliExitWithError = void 0;
4
- const logger_1 = require("@pgpmjs/logger");
5
- const types_1 = require("@pgpmjs/types");
6
- const pg_cache_1 = require("pg-cache");
7
- const log = new logger_1.Logger('cli');
8
- /**
9
- * CLI error utility that logs error information and exits with code 1.
10
- * Provides consistent error handling and user experience across all CLI commands.
11
- *
12
- * IMPORTANT: This function properly cleans up PostgreSQL connections before exiting.
13
- */
14
- const cliExitWithError = async (error, context) => {
15
- if (error instanceof types_1.PgpmError) {
16
- // For PgpmError instances, use structured logging
17
- log.error(`Error: ${error.message}`);
18
- // Log additional context if available
19
- if (error.context && Object.keys(error.context).length > 0) {
20
- log.debug('Error context:', error.context);
21
- }
22
- // Log any additional context provided
23
- if (context) {
24
- log.debug('Additional context:', context);
25
- }
26
- }
27
- else if (error instanceof Error) {
28
- // For generic Error instances
29
- log.error(`Error: ${error.message}`);
30
- if (context) {
31
- log.debug('Context:', context);
32
- }
33
- }
34
- else if (typeof error === 'string') {
35
- // For simple string messages
36
- log.error(`Error: ${error}`);
37
- if (context) {
38
- log.debug('Context:', context);
39
- }
40
- }
41
- // Perform cleanup before exiting
42
- try {
43
- await (0, pg_cache_1.teardownPgPools)();
44
- log.debug('Database connections cleaned up');
45
- }
46
- catch (cleanupError) {
47
- log.warn('Failed to cleanup database connections:', cleanupError);
48
- // Don't let cleanup errors prevent the exit
49
- }
50
- process.exit(1);
51
- };
52
- exports.cliExitWithError = cliExitWithError;
@@ -1,10 +0,0 @@
1
- import { UpdateCheckConfig } from '@pgpmjs/types';
2
- import { UpdateConfigOptions } from './update-config';
3
- export interface CheckForUpdatesOptions extends UpdateConfigOptions {
4
- pkgName?: string;
5
- pkgVersion?: string;
6
- command?: string;
7
- now?: number;
8
- updateCommand?: string;
9
- }
10
- export declare function checkForUpdates(options?: CheckForUpdatesOptions): Promise<UpdateCheckConfig | null>;
@@ -1,60 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkForUpdates = checkForUpdates;
4
- const find_and_require_package_json_1 = require("find-and-require-package-json");
5
- const logger_1 = require("@pgpmjs/logger");
6
- const types_1 = require("@pgpmjs/types");
7
- const npm_version_1 = require("./npm-version");
8
- const update_config_1 = require("./update-config");
9
- const log = new logger_1.Logger('update-check');
10
- const shouldSkip = (command) => {
11
- if (process.env.PGPM_SKIP_UPDATE_CHECK)
12
- return true;
13
- if (process.env.CI === 'true')
14
- return true;
15
- if (command === 'update')
16
- return true;
17
- return false;
18
- };
19
- async function checkForUpdates(options = {}) {
20
- const { pkgName = types_1.UPDATE_PACKAGE_NAME, pkgVersion = (0, find_and_require_package_json_1.findAndRequirePackageJson)(__dirname).version, command, now = Date.now(), key = types_1.UPDATE_CHECK_APPSTASH_KEY, toolName, baseDir } = options;
21
- if (shouldSkip(command)) {
22
- return null;
23
- }
24
- try {
25
- const existing = await (0, update_config_1.readUpdateConfig)({ toolName, baseDir, key });
26
- let latestKnownVersion = existing?.latestKnownVersion ?? pkgVersion;
27
- const needsCheck = (0, update_config_1.shouldCheck)(now, existing?.lastCheckedAt, types_1.UPDATE_CHECK_TTL_MS);
28
- if (needsCheck) {
29
- const fetched = await (0, npm_version_1.fetchLatestVersion)(pkgName);
30
- if (fetched) {
31
- latestKnownVersion = fetched;
32
- }
33
- await (0, update_config_1.writeUpdateConfig)({
34
- lastCheckedAt: now,
35
- latestKnownVersion
36
- }, { toolName, baseDir, key });
37
- }
38
- const comparison = (0, npm_version_1.compareVersions)(pkgVersion, latestKnownVersion);
39
- const isOutdated = comparison < 0;
40
- if (isOutdated) {
41
- const defaultUpdateCommand = pkgName === types_1.UPDATE_PACKAGE_NAME
42
- ? 'Run pgpm update to upgrade.'
43
- : `Run npm i -g ${pkgName}@latest to upgrade.`;
44
- const updateInstruction = options.updateCommand ?? defaultUpdateCommand;
45
- log.warn(`A new version of ${pkgName} is available (current ${pkgVersion}, latest ${latestKnownVersion}). ${updateInstruction}`);
46
- await (0, update_config_1.writeUpdateConfig)({
47
- lastCheckedAt: now,
48
- latestKnownVersion
49
- }, { toolName, baseDir, key });
50
- }
51
- return {
52
- lastCheckedAt: now,
53
- latestKnownVersion
54
- };
55
- }
56
- catch (error) {
57
- log.debug('Update check skipped due to error:', error);
58
- return null;
59
- }
60
- }
@@ -1,10 +0,0 @@
1
- import { UpdateCheckConfig } from '@pgpmjs/types';
2
- export interface UpdateConfigOptions {
3
- toolName?: string;
4
- baseDir?: string;
5
- key?: string;
6
- }
7
- export declare const shouldCheck: (now: number, lastCheckedAt: number | undefined, ttlMs: number) => boolean;
8
- export declare function readUpdateConfig(options?: UpdateConfigOptions): Promise<UpdateCheckConfig | null>;
9
- export declare function writeUpdateConfig(config: UpdateCheckConfig, options?: UpdateConfigOptions): Promise<void>;
10
- export declare const resolveUpdateConfigPath: (options?: UpdateConfigOptions) => string;
@@ -1,60 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.resolveUpdateConfigPath = exports.shouldCheck = void 0;
7
- exports.readUpdateConfig = readUpdateConfig;
8
- exports.writeUpdateConfig = writeUpdateConfig;
9
- const fs_1 = __importDefault(require("fs"));
10
- const path_1 = __importDefault(require("path"));
11
- const appstash_1 = require("appstash");
12
- const types_1 = require("@pgpmjs/types");
13
- const defaultToolName = 'pgpm';
14
- const getConfigPath = (options = {}) => {
15
- const toolName = options.toolName ?? defaultToolName;
16
- const dirs = (0, appstash_1.appstash)(toolName, {
17
- ensure: true,
18
- baseDir: options.baseDir
19
- });
20
- const configDir = (0, appstash_1.resolve)(dirs, 'config');
21
- if (!fs_1.default.existsSync(configDir)) {
22
- fs_1.default.mkdirSync(configDir, { recursive: true });
23
- }
24
- const fileName = `${(options.key ?? types_1.UPDATE_CHECK_APPSTASH_KEY).replace(/[^a-z0-9-_]/gi, '_')}.json`;
25
- return path_1.default.join(configDir, fileName);
26
- };
27
- const shouldCheck = (now, lastCheckedAt, ttlMs) => {
28
- if (!lastCheckedAt)
29
- return true;
30
- return now - lastCheckedAt > ttlMs;
31
- };
32
- exports.shouldCheck = shouldCheck;
33
- async function readUpdateConfig(options = {}) {
34
- const configPath = getConfigPath(options);
35
- if (!fs_1.default.existsSync(configPath)) {
36
- return null;
37
- }
38
- try {
39
- const contents = await fs_1.default.promises.readFile(configPath, 'utf8');
40
- const parsed = JSON.parse(contents);
41
- return parsed;
42
- }
43
- catch {
44
- // Corrupted config – clear it
45
- try {
46
- await fs_1.default.promises.rm(configPath, { force: true });
47
- }
48
- catch {
49
- // ignore
50
- }
51
- return null;
52
- }
53
- }
54
- async function writeUpdateConfig(config, options = {}) {
55
- const configPath = getConfigPath(options);
56
- await fs_1.default.promises.writeFile(configPath, JSON.stringify(config, null, 2), 'utf8');
57
- }
58
- // Exposed for testing to locate the config path for a given namespace/baseDir
59
- const resolveUpdateConfigPath = (options = {}) => getConfigPath(options);
60
- exports.resolveUpdateConfigPath = resolveUpdateConfigPath;