pgpm 0.5.0 → 0.6.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/deploy.js +3 -2
- package/commands/revert.js +5 -4
- package/commands/tag.js +2 -1
- package/commands/verify.js +5 -4
- package/esm/commands/deploy.js +4 -3
- package/esm/commands/revert.js +6 -5
- package/esm/commands/tag.js +2 -1
- package/esm/commands/verify.js +6 -5
- package/esm/utils/deployed-changes.js +5 -4
- package/esm/utils/index.js +1 -0
- package/esm/utils/module-utils.js +3 -1
- package/esm/utils/package-alias.js +86 -0
- package/package.json +6 -6
- package/utils/deployed-changes.d.ts +2 -2
- package/utils/deployed-changes.js +5 -4
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/module-utils.js +3 -1
- package/utils/package-alias.d.ts +36 -0
- package/utils/package-alias.js +92 -0
package/commands/deploy.js
CHANGED
|
@@ -135,10 +135,11 @@ exports.default = async (argv, prompter, _options) => {
|
|
|
135
135
|
target = packageName;
|
|
136
136
|
}
|
|
137
137
|
else if (argv.package && argv.to) {
|
|
138
|
-
|
|
138
|
+
const resolvedPackage = (0, utils_1.resolvePackageAlias)(argv.package, cwd);
|
|
139
|
+
target = `${resolvedPackage}:${argv.to}`;
|
|
139
140
|
}
|
|
140
141
|
else if (argv.package) {
|
|
141
|
-
target = argv.package;
|
|
142
|
+
target = (0, utils_1.resolvePackageAlias)(argv.package, cwd);
|
|
142
143
|
}
|
|
143
144
|
await project.deploy(opts, target, recursive);
|
|
144
145
|
log.success('Deployment complete.');
|
package/commands/revert.js
CHANGED
|
@@ -70,7 +70,7 @@ exports.default = async (argv, prompter, _options) => {
|
|
|
70
70
|
log.debug(`Using current directory: ${cwd}`);
|
|
71
71
|
let packageName;
|
|
72
72
|
if (recursive && argv.to !== true) {
|
|
73
|
-
packageName = await (0, deployed_changes_1.selectDeployedPackage)(database, argv, prompter, log, 'revert');
|
|
73
|
+
packageName = await (0, deployed_changes_1.selectDeployedPackage)(database, argv, prompter, log, 'revert', cwd);
|
|
74
74
|
if (!packageName) {
|
|
75
75
|
await (0, cli_error_1.cliExitWithError)('No package found to revert');
|
|
76
76
|
}
|
|
@@ -84,7 +84,7 @@ exports.default = async (argv, prompter, _options) => {
|
|
|
84
84
|
});
|
|
85
85
|
let target;
|
|
86
86
|
if (argv.to === true) {
|
|
87
|
-
target = await (0, deployed_changes_1.selectDeployedChange)(database, argv, prompter, log, 'revert');
|
|
87
|
+
target = await (0, deployed_changes_1.selectDeployedChange)(database, argv, prompter, log, 'revert', cwd);
|
|
88
88
|
if (!target) {
|
|
89
89
|
await (0, cli_error_1.cliExitWithError)('No target selected, operation cancelled');
|
|
90
90
|
}
|
|
@@ -96,10 +96,11 @@ exports.default = async (argv, prompter, _options) => {
|
|
|
96
96
|
target = packageName;
|
|
97
97
|
}
|
|
98
98
|
else if (argv.package && argv.to) {
|
|
99
|
-
|
|
99
|
+
const resolvedPackage = (0, utils_1.resolvePackageAlias)(argv.package, cwd);
|
|
100
|
+
target = `${resolvedPackage}:${argv.to}`;
|
|
100
101
|
}
|
|
101
102
|
else if (argv.package) {
|
|
102
|
-
target = argv.package;
|
|
103
|
+
target = (0, utils_1.resolvePackageAlias)(argv.package, cwd);
|
|
103
104
|
}
|
|
104
105
|
await pkg.revert(opts, target, recursive);
|
|
105
106
|
log.success('Revert complete.');
|
package/commands/tag.js
CHANGED
|
@@ -39,6 +39,7 @@ const types_1 = require("@pgpmjs/types");
|
|
|
39
39
|
const path = __importStar(require("path"));
|
|
40
40
|
const argv_1 = require("../utils/argv");
|
|
41
41
|
const module_utils_1 = require("../utils/module-utils");
|
|
42
|
+
const package_alias_1 = require("../utils/package-alias");
|
|
42
43
|
const log = new logger_1.Logger('tag');
|
|
43
44
|
const tagUsageText = `
|
|
44
45
|
Tag Command:
|
|
@@ -83,7 +84,7 @@ exports.default = async (argv, prompter, _options) => {
|
|
|
83
84
|
const pkg = new core_1.PgpmPackage(cwd);
|
|
84
85
|
let packageName;
|
|
85
86
|
if (argv.package) {
|
|
86
|
-
packageName = argv.package;
|
|
87
|
+
packageName = (0, package_alias_1.resolvePackageAlias)(argv.package, cwd);
|
|
87
88
|
log.info(`Using specified package: ${packageName}`);
|
|
88
89
|
}
|
|
89
90
|
else if (pkg.isInModule()) {
|
package/commands/verify.js
CHANGED
|
@@ -51,7 +51,7 @@ exports.default = async (argv, prompter, _options) => {
|
|
|
51
51
|
log.debug(`Using current directory: ${cwd}`);
|
|
52
52
|
let packageName;
|
|
53
53
|
if (recursive && argv.to !== true) {
|
|
54
|
-
packageName = await (0, deployed_changes_1.selectDeployedPackage)(database, argv, prompter, log, 'verify');
|
|
54
|
+
packageName = await (0, deployed_changes_1.selectDeployedPackage)(database, argv, prompter, log, 'verify', cwd);
|
|
55
55
|
if (!packageName) {
|
|
56
56
|
await (0, cli_error_1.cliExitWithError)('No package found to verify');
|
|
57
57
|
}
|
|
@@ -62,7 +62,7 @@ exports.default = async (argv, prompter, _options) => {
|
|
|
62
62
|
});
|
|
63
63
|
let target;
|
|
64
64
|
if (argv.to === true) {
|
|
65
|
-
target = await (0, deployed_changes_1.selectDeployedChange)(database, argv, prompter, log, 'verify');
|
|
65
|
+
target = await (0, deployed_changes_1.selectDeployedChange)(database, argv, prompter, log, 'verify', cwd);
|
|
66
66
|
if (!target) {
|
|
67
67
|
await (0, cli_error_1.cliExitWithError)('No target selected, operation cancelled');
|
|
68
68
|
}
|
|
@@ -74,10 +74,11 @@ exports.default = async (argv, prompter, _options) => {
|
|
|
74
74
|
target = packageName;
|
|
75
75
|
}
|
|
76
76
|
else if (argv.package && argv.to) {
|
|
77
|
-
|
|
77
|
+
const resolvedPackage = (0, utils_1.resolvePackageAlias)(argv.package, cwd);
|
|
78
|
+
target = `${resolvedPackage}:${argv.to}`;
|
|
78
79
|
}
|
|
79
80
|
else if (argv.package) {
|
|
80
|
-
target = argv.package;
|
|
81
|
+
target = (0, utils_1.resolvePackageAlias)(argv.package, cwd);
|
|
81
82
|
}
|
|
82
83
|
await project.verify(opts, target, recursive);
|
|
83
84
|
log.success('Verify complete.');
|
package/esm/commands/deploy.js
CHANGED
|
@@ -3,7 +3,7 @@ import { getEnvOptions } from '@pgpmjs/env';
|
|
|
3
3
|
import { Logger } from '@pgpmjs/logger';
|
|
4
4
|
import { execSync } from 'child_process';
|
|
5
5
|
import { getPgEnvOptions, getSpawnEnvWithPg, } from 'pg-env';
|
|
6
|
-
import { getTargetDatabase } from '../utils';
|
|
6
|
+
import { getTargetDatabase, resolvePackageAlias } from '../utils';
|
|
7
7
|
import { selectPackage } from '../utils/module-utils';
|
|
8
8
|
const deployUsageText = `
|
|
9
9
|
Deploy Command:
|
|
@@ -133,10 +133,11 @@ export default async (argv, prompter, _options) => {
|
|
|
133
133
|
target = packageName;
|
|
134
134
|
}
|
|
135
135
|
else if (argv.package && argv.to) {
|
|
136
|
-
|
|
136
|
+
const resolvedPackage = resolvePackageAlias(argv.package, cwd);
|
|
137
|
+
target = `${resolvedPackage}:${argv.to}`;
|
|
137
138
|
}
|
|
138
139
|
else if (argv.package) {
|
|
139
|
-
target = argv.package;
|
|
140
|
+
target = resolvePackageAlias(argv.package, cwd);
|
|
140
141
|
}
|
|
141
142
|
await project.deploy(opts, target, recursive);
|
|
142
143
|
log.success('Deployment complete.');
|
package/esm/commands/revert.js
CHANGED
|
@@ -2,7 +2,7 @@ import { PgpmPackage } from '@pgpmjs/core';
|
|
|
2
2
|
import { getEnvOptions } from '@pgpmjs/env';
|
|
3
3
|
import { Logger } from '@pgpmjs/logger';
|
|
4
4
|
import { getPgEnvOptions } from 'pg-env';
|
|
5
|
-
import { getTargetDatabase } from '../utils';
|
|
5
|
+
import { getTargetDatabase, resolvePackageAlias } from '../utils';
|
|
6
6
|
import { cliExitWithError } from '../utils/cli-error';
|
|
7
7
|
import { selectDeployedChange, selectDeployedPackage } from '../utils/deployed-changes';
|
|
8
8
|
const log = new Logger('revert');
|
|
@@ -68,7 +68,7 @@ export default async (argv, prompter, _options) => {
|
|
|
68
68
|
log.debug(`Using current directory: ${cwd}`);
|
|
69
69
|
let packageName;
|
|
70
70
|
if (recursive && argv.to !== true) {
|
|
71
|
-
packageName = await selectDeployedPackage(database, argv, prompter, log, 'revert');
|
|
71
|
+
packageName = await selectDeployedPackage(database, argv, prompter, log, 'revert', cwd);
|
|
72
72
|
if (!packageName) {
|
|
73
73
|
await cliExitWithError('No package found to revert');
|
|
74
74
|
}
|
|
@@ -82,7 +82,7 @@ export default async (argv, prompter, _options) => {
|
|
|
82
82
|
});
|
|
83
83
|
let target;
|
|
84
84
|
if (argv.to === true) {
|
|
85
|
-
target = await selectDeployedChange(database, argv, prompter, log, 'revert');
|
|
85
|
+
target = await selectDeployedChange(database, argv, prompter, log, 'revert', cwd);
|
|
86
86
|
if (!target) {
|
|
87
87
|
await cliExitWithError('No target selected, operation cancelled');
|
|
88
88
|
}
|
|
@@ -94,10 +94,11 @@ export default async (argv, prompter, _options) => {
|
|
|
94
94
|
target = packageName;
|
|
95
95
|
}
|
|
96
96
|
else if (argv.package && argv.to) {
|
|
97
|
-
|
|
97
|
+
const resolvedPackage = resolvePackageAlias(argv.package, cwd);
|
|
98
|
+
target = `${resolvedPackage}:${argv.to}`;
|
|
98
99
|
}
|
|
99
100
|
else if (argv.package) {
|
|
100
|
-
target = argv.package;
|
|
101
|
+
target = resolvePackageAlias(argv.package, cwd);
|
|
101
102
|
}
|
|
102
103
|
await pkg.revert(opts, target, recursive);
|
|
103
104
|
log.success('Revert complete.');
|
package/esm/commands/tag.js
CHANGED
|
@@ -4,6 +4,7 @@ import { errors } from '@pgpmjs/types';
|
|
|
4
4
|
import * as path from 'path';
|
|
5
5
|
import { extractFirst } from '../utils/argv';
|
|
6
6
|
import { selectPackage } from '../utils/module-utils';
|
|
7
|
+
import { resolvePackageAlias } from '../utils/package-alias';
|
|
7
8
|
const log = new Logger('tag');
|
|
8
9
|
const tagUsageText = `
|
|
9
10
|
Tag Command:
|
|
@@ -48,7 +49,7 @@ export default async (argv, prompter, _options) => {
|
|
|
48
49
|
const pkg = new PgpmPackage(cwd);
|
|
49
50
|
let packageName;
|
|
50
51
|
if (argv.package) {
|
|
51
|
-
packageName = argv.package;
|
|
52
|
+
packageName = resolvePackageAlias(argv.package, cwd);
|
|
52
53
|
log.info(`Using specified package: ${packageName}`);
|
|
53
54
|
}
|
|
54
55
|
else if (pkg.isInModule()) {
|
package/esm/commands/verify.js
CHANGED
|
@@ -2,7 +2,7 @@ import { PgpmPackage } from '@pgpmjs/core';
|
|
|
2
2
|
import { getEnvOptions } from '@pgpmjs/env';
|
|
3
3
|
import { Logger } from '@pgpmjs/logger';
|
|
4
4
|
import { getPgEnvOptions } from 'pg-env';
|
|
5
|
-
import { getTargetDatabase } from '../utils';
|
|
5
|
+
import { getTargetDatabase, resolvePackageAlias } from '../utils';
|
|
6
6
|
import { cliExitWithError } from '../utils/cli-error';
|
|
7
7
|
import { selectDeployedChange, selectDeployedPackage } from '../utils/deployed-changes';
|
|
8
8
|
const log = new Logger('verify');
|
|
@@ -49,7 +49,7 @@ export default async (argv, prompter, _options) => {
|
|
|
49
49
|
log.debug(`Using current directory: ${cwd}`);
|
|
50
50
|
let packageName;
|
|
51
51
|
if (recursive && argv.to !== true) {
|
|
52
|
-
packageName = await selectDeployedPackage(database, argv, prompter, log, 'verify');
|
|
52
|
+
packageName = await selectDeployedPackage(database, argv, prompter, log, 'verify', cwd);
|
|
53
53
|
if (!packageName) {
|
|
54
54
|
await cliExitWithError('No package found to verify');
|
|
55
55
|
}
|
|
@@ -60,7 +60,7 @@ export default async (argv, prompter, _options) => {
|
|
|
60
60
|
});
|
|
61
61
|
let target;
|
|
62
62
|
if (argv.to === true) {
|
|
63
|
-
target = await selectDeployedChange(database, argv, prompter, log, 'verify');
|
|
63
|
+
target = await selectDeployedChange(database, argv, prompter, log, 'verify', cwd);
|
|
64
64
|
if (!target) {
|
|
65
65
|
await cliExitWithError('No target selected, operation cancelled');
|
|
66
66
|
}
|
|
@@ -72,10 +72,11 @@ export default async (argv, prompter, _options) => {
|
|
|
72
72
|
target = packageName;
|
|
73
73
|
}
|
|
74
74
|
else if (argv.package && argv.to) {
|
|
75
|
-
|
|
75
|
+
const resolvedPackage = resolvePackageAlias(argv.package, cwd);
|
|
76
|
+
target = `${resolvedPackage}:${argv.to}`;
|
|
76
77
|
}
|
|
77
78
|
else if (argv.package) {
|
|
78
|
-
target = argv.package;
|
|
79
|
+
target = resolvePackageAlias(argv.package, cwd);
|
|
79
80
|
}
|
|
80
81
|
await project.verify(opts, target, recursive);
|
|
81
82
|
log.success('Verify complete.');
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { PgpmMigrate } from '@pgpmjs/core';
|
|
2
2
|
import { getPgEnvOptions } from 'pg-env';
|
|
3
|
-
|
|
3
|
+
import { resolvePackageAlias } from './package-alias';
|
|
4
|
+
export async function selectDeployedChange(database, argv, prompter, log, action = 'revert', cwd = process.cwd()) {
|
|
4
5
|
const pgEnv = getPgEnvOptions({ database });
|
|
5
6
|
const client = new PgpmMigrate(pgEnv);
|
|
6
7
|
let selectedPackage;
|
|
7
8
|
if (argv.package) {
|
|
8
|
-
selectedPackage = argv.package;
|
|
9
|
+
selectedPackage = resolvePackageAlias(argv.package, cwd);
|
|
9
10
|
}
|
|
10
11
|
else {
|
|
11
12
|
const packageStatuses = await client.status();
|
|
@@ -43,9 +44,9 @@ export async function selectDeployedChange(database, argv, prompter, log, action
|
|
|
43
44
|
const selectedChange = changeAnswer.change;
|
|
44
45
|
return `${selectedPackage}:${selectedChange}`;
|
|
45
46
|
}
|
|
46
|
-
export async function selectDeployedPackage(database, argv, prompter, log, action = 'revert') {
|
|
47
|
+
export async function selectDeployedPackage(database, argv, prompter, log, action = 'revert', cwd = process.cwd()) {
|
|
47
48
|
if (argv.package) {
|
|
48
|
-
return argv.package;
|
|
49
|
+
return resolvePackageAlias(argv.package, cwd);
|
|
49
50
|
}
|
|
50
51
|
const pgEnv = getPgEnvOptions({ database });
|
|
51
52
|
const client = new PgpmMigrate(pgEnv);
|
package/esm/utils/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PgpmPackage } from '@pgpmjs/core';
|
|
2
2
|
import { errors } from '@pgpmjs/types';
|
|
3
|
+
import { resolvePackageAlias } from './package-alias';
|
|
3
4
|
/**
|
|
4
5
|
* Handle package selection for operations that need a specific package
|
|
5
6
|
* Returns the selected package name, or undefined if validation fails or no packages exist
|
|
@@ -22,7 +23,8 @@ export async function selectPackage(argv, prompter, cwd, operationName, log) {
|
|
|
22
23
|
}
|
|
23
24
|
// If a specific package was provided, validate it
|
|
24
25
|
if (argv.package) {
|
|
25
|
-
const
|
|
26
|
+
const inputPackage = argv.package;
|
|
27
|
+
const packageName = resolvePackageAlias(inputPackage, cwd);
|
|
26
28
|
if (log)
|
|
27
29
|
log.info(`Using specified package: ${packageName}`);
|
|
28
30
|
if (!moduleNames.includes(packageName)) {
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { PgpmPackage } from '@pgpmjs/core';
|
|
2
|
+
import { existsSync, readFileSync } from 'fs';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
/**
|
|
5
|
+
* Build a map of npm package names to control file names (extension names).
|
|
6
|
+
* This allows users to reference packages by their npm name (e.g., @scope/my-module)
|
|
7
|
+
* instead of the control file name (e.g., my-module).
|
|
8
|
+
*/
|
|
9
|
+
export function buildPackageAliasMap(cwd) {
|
|
10
|
+
const aliasMap = {};
|
|
11
|
+
try {
|
|
12
|
+
const pkg = new PgpmPackage(cwd);
|
|
13
|
+
const workspacePath = pkg.getWorkspacePath();
|
|
14
|
+
if (!workspacePath) {
|
|
15
|
+
return aliasMap;
|
|
16
|
+
}
|
|
17
|
+
const modules = pkg.getModuleMap();
|
|
18
|
+
for (const [controlName, moduleInfo] of Object.entries(modules)) {
|
|
19
|
+
const modulePath = join(workspacePath, moduleInfo.path);
|
|
20
|
+
const packageJsonPath = join(modulePath, 'package.json');
|
|
21
|
+
if (existsSync(packageJsonPath)) {
|
|
22
|
+
try {
|
|
23
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
|
|
24
|
+
const npmName = packageJson.name;
|
|
25
|
+
if (npmName && npmName !== controlName) {
|
|
26
|
+
aliasMap[npmName] = controlName;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
// Skip modules with invalid package.json
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// Return empty map if we can't access workspace
|
|
37
|
+
}
|
|
38
|
+
return aliasMap;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Resolve a package name that might be an npm alias to its control file name.
|
|
42
|
+
* If the input is already a control file name or not found in aliases, returns as-is.
|
|
43
|
+
*
|
|
44
|
+
* @param input - The package name (could be npm name like @scope/pkg or control name)
|
|
45
|
+
* @param cwd - The current working directory
|
|
46
|
+
* @returns The resolved control file name
|
|
47
|
+
*/
|
|
48
|
+
export function resolvePackageAlias(input, cwd) {
|
|
49
|
+
if (!input) {
|
|
50
|
+
return input;
|
|
51
|
+
}
|
|
52
|
+
const aliasMap = buildPackageAliasMap(cwd);
|
|
53
|
+
return aliasMap[input] ?? input;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Get the npm package name for a given control file name, if available.
|
|
57
|
+
* Returns undefined if no npm alias exists.
|
|
58
|
+
*
|
|
59
|
+
* @param controlName - The control file name (extension name)
|
|
60
|
+
* @param cwd - The current working directory
|
|
61
|
+
* @returns The npm package name or undefined
|
|
62
|
+
*/
|
|
63
|
+
export function getNpmNameForControl(controlName, cwd) {
|
|
64
|
+
const aliasMap = buildPackageAliasMap(cwd);
|
|
65
|
+
for (const [npmName, ctrlName] of Object.entries(aliasMap)) {
|
|
66
|
+
if (ctrlName === controlName) {
|
|
67
|
+
return npmName;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Format a module name for display, showing both control name and npm alias if available.
|
|
74
|
+
* Example: "my-module (@scope/my-module)" or just "my-module" if no alias
|
|
75
|
+
*
|
|
76
|
+
* @param controlName - The control file name
|
|
77
|
+
* @param cwd - The current working directory
|
|
78
|
+
* @returns Formatted display string
|
|
79
|
+
*/
|
|
80
|
+
export function formatModuleNameWithAlias(controlName, cwd) {
|
|
81
|
+
const npmName = getNpmNameForControl(controlName, cwd);
|
|
82
|
+
if (npmName) {
|
|
83
|
+
return `${controlName} (${npmName})`;
|
|
84
|
+
}
|
|
85
|
+
return controlName;
|
|
86
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pgpm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.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",
|
|
@@ -45,17 +45,17 @@
|
|
|
45
45
|
"ts-node": "^10.9.2"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@pgpmjs/core": "^3.0.
|
|
49
|
-
"@pgpmjs/env": "^2.
|
|
48
|
+
"@pgpmjs/core": "^3.0.1",
|
|
49
|
+
"@pgpmjs/env": "^2.8.0",
|
|
50
50
|
"@pgpmjs/logger": "^1.3.0",
|
|
51
|
-
"@pgpmjs/types": "^2.
|
|
51
|
+
"@pgpmjs/types": "^2.12.0",
|
|
52
52
|
"appstash": "^0.2.4",
|
|
53
53
|
"create-gen-app": "^0.3.3",
|
|
54
54
|
"find-and-require-package-json": "^0.8.0",
|
|
55
55
|
"inquirerer": "^2.1.11",
|
|
56
56
|
"js-yaml": "^4.1.0",
|
|
57
57
|
"minimist": "^1.2.8",
|
|
58
|
-
"pg-cache": "^1.6.
|
|
58
|
+
"pg-cache": "^1.6.1",
|
|
59
59
|
"pg-env": "^1.2.1",
|
|
60
60
|
"semver": "^7.6.2",
|
|
61
61
|
"shelljs": "^0.10.0",
|
|
@@ -73,5 +73,5 @@
|
|
|
73
73
|
"pg",
|
|
74
74
|
"pgsql"
|
|
75
75
|
],
|
|
76
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "b2f5da76158dcd3629c7e7db9c984ccf1d9eff1b"
|
|
77
77
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Logger } from '@pgpmjs/logger';
|
|
2
2
|
import { Inquirerer } from 'inquirerer';
|
|
3
|
-
export declare function selectDeployedChange(database: string, argv: Partial<Record<string, any>>, prompter: Inquirerer, log: Logger, action?: 'revert' | 'verify'): Promise<string | undefined>;
|
|
4
|
-
export declare function selectDeployedPackage(database: string, argv: Partial<Record<string, any>>, prompter: Inquirerer, log: Logger, action?: 'revert' | 'verify'): Promise<string | undefined>;
|
|
3
|
+
export declare function selectDeployedChange(database: string, argv: Partial<Record<string, any>>, prompter: Inquirerer, log: Logger, action?: 'revert' | 'verify', cwd?: string): Promise<string | undefined>;
|
|
4
|
+
export declare function selectDeployedPackage(database: string, argv: Partial<Record<string, any>>, prompter: Inquirerer, log: Logger, action?: 'revert' | 'verify', cwd?: string): Promise<string | undefined>;
|
|
@@ -4,12 +4,13 @@ exports.selectDeployedChange = selectDeployedChange;
|
|
|
4
4
|
exports.selectDeployedPackage = selectDeployedPackage;
|
|
5
5
|
const core_1 = require("@pgpmjs/core");
|
|
6
6
|
const pg_env_1 = require("pg-env");
|
|
7
|
-
|
|
7
|
+
const package_alias_1 = require("./package-alias");
|
|
8
|
+
async function selectDeployedChange(database, argv, prompter, log, action = 'revert', cwd = process.cwd()) {
|
|
8
9
|
const pgEnv = (0, pg_env_1.getPgEnvOptions)({ database });
|
|
9
10
|
const client = new core_1.PgpmMigrate(pgEnv);
|
|
10
11
|
let selectedPackage;
|
|
11
12
|
if (argv.package) {
|
|
12
|
-
selectedPackage = argv.package;
|
|
13
|
+
selectedPackage = (0, package_alias_1.resolvePackageAlias)(argv.package, cwd);
|
|
13
14
|
}
|
|
14
15
|
else {
|
|
15
16
|
const packageStatuses = await client.status();
|
|
@@ -47,9 +48,9 @@ async function selectDeployedChange(database, argv, prompter, log, action = 'rev
|
|
|
47
48
|
const selectedChange = changeAnswer.change;
|
|
48
49
|
return `${selectedPackage}:${selectedChange}`;
|
|
49
50
|
}
|
|
50
|
-
async function selectDeployedPackage(database, argv, prompter, log, action = 'revert') {
|
|
51
|
+
async function selectDeployedPackage(database, argv, prompter, log, action = 'revert', cwd = process.cwd()) {
|
|
51
52
|
if (argv.package) {
|
|
52
|
-
return argv.package;
|
|
53
|
+
return (0, package_alias_1.resolvePackageAlias)(argv.package, cwd);
|
|
53
54
|
}
|
|
54
55
|
const pgEnv = (0, pg_env_1.getPgEnvOptions)({ database });
|
|
55
56
|
const client = new core_1.PgpmMigrate(pgEnv);
|
package/utils/index.d.ts
CHANGED
package/utils/index.js
CHANGED
|
@@ -21,5 +21,6 @@ __exportStar(require("./cli-error"), exports);
|
|
|
21
21
|
__exportStar(require("./deployed-changes"), exports);
|
|
22
22
|
__exportStar(require("./module-utils"), exports);
|
|
23
23
|
__exportStar(require("./npm-version"), exports);
|
|
24
|
+
__exportStar(require("./package-alias"), exports);
|
|
24
25
|
__exportStar(require("./update-check"), exports);
|
|
25
26
|
__exportStar(require("./update-config"), exports);
|
package/utils/module-utils.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.selectPackage = selectPackage;
|
|
4
4
|
const core_1 = require("@pgpmjs/core");
|
|
5
5
|
const types_1 = require("@pgpmjs/types");
|
|
6
|
+
const package_alias_1 = require("./package-alias");
|
|
6
7
|
/**
|
|
7
8
|
* Handle package selection for operations that need a specific package
|
|
8
9
|
* Returns the selected package name, or undefined if validation fails or no packages exist
|
|
@@ -25,7 +26,8 @@ async function selectPackage(argv, prompter, cwd, operationName, log) {
|
|
|
25
26
|
}
|
|
26
27
|
// If a specific package was provided, validate it
|
|
27
28
|
if (argv.package) {
|
|
28
|
-
const
|
|
29
|
+
const inputPackage = argv.package;
|
|
30
|
+
const packageName = (0, package_alias_1.resolvePackageAlias)(inputPackage, cwd);
|
|
29
31
|
if (log)
|
|
30
32
|
log.info(`Using specified package: ${packageName}`);
|
|
31
33
|
if (!moduleNames.includes(packageName)) {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface PackageAliasMap {
|
|
2
|
+
[npmName: string]: string;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Build a map of npm package names to control file names (extension names).
|
|
6
|
+
* This allows users to reference packages by their npm name (e.g., @scope/my-module)
|
|
7
|
+
* instead of the control file name (e.g., my-module).
|
|
8
|
+
*/
|
|
9
|
+
export declare function buildPackageAliasMap(cwd: string): PackageAliasMap;
|
|
10
|
+
/**
|
|
11
|
+
* Resolve a package name that might be an npm alias to its control file name.
|
|
12
|
+
* If the input is already a control file name or not found in aliases, returns as-is.
|
|
13
|
+
*
|
|
14
|
+
* @param input - The package name (could be npm name like @scope/pkg or control name)
|
|
15
|
+
* @param cwd - The current working directory
|
|
16
|
+
* @returns The resolved control file name
|
|
17
|
+
*/
|
|
18
|
+
export declare function resolvePackageAlias(input: string, cwd: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Get the npm package name for a given control file name, if available.
|
|
21
|
+
* Returns undefined if no npm alias exists.
|
|
22
|
+
*
|
|
23
|
+
* @param controlName - The control file name (extension name)
|
|
24
|
+
* @param cwd - The current working directory
|
|
25
|
+
* @returns The npm package name or undefined
|
|
26
|
+
*/
|
|
27
|
+
export declare function getNpmNameForControl(controlName: string, cwd: string): string | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Format a module name for display, showing both control name and npm alias if available.
|
|
30
|
+
* Example: "my-module (@scope/my-module)" or just "my-module" if no alias
|
|
31
|
+
*
|
|
32
|
+
* @param controlName - The control file name
|
|
33
|
+
* @param cwd - The current working directory
|
|
34
|
+
* @returns Formatted display string
|
|
35
|
+
*/
|
|
36
|
+
export declare function formatModuleNameWithAlias(controlName: string, cwd: string): string;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildPackageAliasMap = buildPackageAliasMap;
|
|
4
|
+
exports.resolvePackageAlias = resolvePackageAlias;
|
|
5
|
+
exports.getNpmNameForControl = getNpmNameForControl;
|
|
6
|
+
exports.formatModuleNameWithAlias = formatModuleNameWithAlias;
|
|
7
|
+
const core_1 = require("@pgpmjs/core");
|
|
8
|
+
const fs_1 = require("fs");
|
|
9
|
+
const path_1 = require("path");
|
|
10
|
+
/**
|
|
11
|
+
* Build a map of npm package names to control file names (extension names).
|
|
12
|
+
* This allows users to reference packages by their npm name (e.g., @scope/my-module)
|
|
13
|
+
* instead of the control file name (e.g., my-module).
|
|
14
|
+
*/
|
|
15
|
+
function buildPackageAliasMap(cwd) {
|
|
16
|
+
const aliasMap = {};
|
|
17
|
+
try {
|
|
18
|
+
const pkg = new core_1.PgpmPackage(cwd);
|
|
19
|
+
const workspacePath = pkg.getWorkspacePath();
|
|
20
|
+
if (!workspacePath) {
|
|
21
|
+
return aliasMap;
|
|
22
|
+
}
|
|
23
|
+
const modules = pkg.getModuleMap();
|
|
24
|
+
for (const [controlName, moduleInfo] of Object.entries(modules)) {
|
|
25
|
+
const modulePath = (0, path_1.join)(workspacePath, moduleInfo.path);
|
|
26
|
+
const packageJsonPath = (0, path_1.join)(modulePath, 'package.json');
|
|
27
|
+
if ((0, fs_1.existsSync)(packageJsonPath)) {
|
|
28
|
+
try {
|
|
29
|
+
const packageJson = JSON.parse((0, fs_1.readFileSync)(packageJsonPath, 'utf-8'));
|
|
30
|
+
const npmName = packageJson.name;
|
|
31
|
+
if (npmName && npmName !== controlName) {
|
|
32
|
+
aliasMap[npmName] = controlName;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// Skip modules with invalid package.json
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
// Return empty map if we can't access workspace
|
|
43
|
+
}
|
|
44
|
+
return aliasMap;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Resolve a package name that might be an npm alias to its control file name.
|
|
48
|
+
* If the input is already a control file name or not found in aliases, returns as-is.
|
|
49
|
+
*
|
|
50
|
+
* @param input - The package name (could be npm name like @scope/pkg or control name)
|
|
51
|
+
* @param cwd - The current working directory
|
|
52
|
+
* @returns The resolved control file name
|
|
53
|
+
*/
|
|
54
|
+
function resolvePackageAlias(input, cwd) {
|
|
55
|
+
if (!input) {
|
|
56
|
+
return input;
|
|
57
|
+
}
|
|
58
|
+
const aliasMap = buildPackageAliasMap(cwd);
|
|
59
|
+
return aliasMap[input] ?? input;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Get the npm package name for a given control file name, if available.
|
|
63
|
+
* Returns undefined if no npm alias exists.
|
|
64
|
+
*
|
|
65
|
+
* @param controlName - The control file name (extension name)
|
|
66
|
+
* @param cwd - The current working directory
|
|
67
|
+
* @returns The npm package name or undefined
|
|
68
|
+
*/
|
|
69
|
+
function getNpmNameForControl(controlName, cwd) {
|
|
70
|
+
const aliasMap = buildPackageAliasMap(cwd);
|
|
71
|
+
for (const [npmName, ctrlName] of Object.entries(aliasMap)) {
|
|
72
|
+
if (ctrlName === controlName) {
|
|
73
|
+
return npmName;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Format a module name for display, showing both control name and npm alias if available.
|
|
80
|
+
* Example: "my-module (@scope/my-module)" or just "my-module" if no alias
|
|
81
|
+
*
|
|
82
|
+
* @param controlName - The control file name
|
|
83
|
+
* @param cwd - The current working directory
|
|
84
|
+
* @returns Formatted display string
|
|
85
|
+
*/
|
|
86
|
+
function formatModuleNameWithAlias(controlName, cwd) {
|
|
87
|
+
const npmName = getNpmNameForControl(controlName, cwd);
|
|
88
|
+
if (npmName) {
|
|
89
|
+
return `${controlName} (${npmName})`;
|
|
90
|
+
}
|
|
91
|
+
return controlName;
|
|
92
|
+
}
|