@pgpmjs/core 7.5.1 → 7.9.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.
@@ -3,6 +3,7 @@ import { PgConfig } from 'pg-env';
3
3
  import { ExtensionInfo } from '@pgpmjs/ast/files';
4
4
  import { PackageAnalysisResult, RenameOptions } from '@pgpmjs/ast/files/types';
5
5
  import { ModuleMap } from '../../modules/modules';
6
+ import { SyncVersionsOptions, SyncVersionsResult } from '../../packaging/sync-versions';
6
7
  /**
7
8
  * Options accepted by the {@link PgpmPackage} constructor.
8
9
  */
@@ -252,6 +253,13 @@ export declare class PgpmPackage {
252
253
  * @returns Array of module names that were updated
253
254
  */
254
255
  private updateWorkspaceModuleVersions;
256
+ /**
257
+ * Sync extension metadata (.control default_version, Makefile sql filename,
258
+ * and the sql/<name>--<version>.sql bundle) to the package.json version.
259
+ * Inside a module, syncs just that module; at a workspace root, syncs every
260
+ * workspace module. With `check: true`, reports skew without writing.
261
+ */
262
+ syncVersions(options?: SyncVersionsOptions): Promise<SyncVersionsResult>;
255
263
  /**
256
264
  * Get the set of modules that have been deployed to the database
257
265
  */
@@ -58,6 +58,7 @@ const validators_1 = require("@pgpmjs/ast/files/plan/validators");
58
58
  const client_1 = require("../../migrate/client");
59
59
  const modules_1 = require("../../modules/modules");
60
60
  const package_1 = require("../../packaging/package");
61
+ const sync_versions_1 = require("../../packaging/sync-versions");
61
62
  const deps_1 = require("../../resolution/deps");
62
63
  const fs_2 = require("../../utils/fs");
63
64
  const glob_1 = require("../../utils/glob");
@@ -1176,6 +1177,21 @@ ${dependencies.length > 0 ? dependencies.map(dep => `-- requires: ${dep}`).join(
1176
1177
  return affectedModules;
1177
1178
  }
1178
1179
  // ──────────────── Package Operations ────────────────
1180
+ /**
1181
+ * Sync extension metadata (.control default_version, Makefile sql filename,
1182
+ * and the sql/<name>--<version>.sql bundle) to the package.json version.
1183
+ * Inside a module, syncs just that module; at a workspace root, syncs every
1184
+ * workspace module. With `check: true`, reports skew without writing.
1185
+ */
1186
+ async syncVersions(options = {}) {
1187
+ if (this.isInModule()) {
1188
+ return (0, sync_versions_1.syncModuleVersions)([this.modulePath], options);
1189
+ }
1190
+ this.ensureWorkspace();
1191
+ const moduleMap = this.getModuleMap();
1192
+ const packageDirs = Object.values(moduleMap).map(mod => path_1.default.resolve(this.workspacePath, mod.path));
1193
+ return (0, sync_versions_1.syncModuleVersions)(packageDirs, options);
1194
+ }
1179
1195
  /**
1180
1196
  * Get the set of modules that have been deployed to the database
1181
1197
  */
@@ -19,6 +19,7 @@ import { isValidChangeName, isValidTagName, parseReference } from '@pgpmjs/ast/f
19
19
  import { PgpmMigrate } from '../../migrate/client';
20
20
  import { getExtensionsAndModules, getExtensionsAndModulesChanges, latestChange, latestChangeAndVersion } from '../../modules/modules';
21
21
  import { packageModule } from '../../packaging/package';
22
+ import { syncModuleVersions } from '../../packaging/sync-versions';
22
23
  import { resolveDependencies, resolveExtensionDependencies } from '../../resolution/deps';
23
24
  import { movePath } from '../../utils/fs';
24
25
  import { globPaths, globPattern, toPosixPath } from '../../utils/glob';
@@ -1137,6 +1138,21 @@ ${dependencies.length > 0 ? dependencies.map(dep => `-- requires: ${dep}`).join(
1137
1138
  return affectedModules;
1138
1139
  }
1139
1140
  // ──────────────── Package Operations ────────────────
1141
+ /**
1142
+ * Sync extension metadata (.control default_version, Makefile sql filename,
1143
+ * and the sql/<name>--<version>.sql bundle) to the package.json version.
1144
+ * Inside a module, syncs just that module; at a workspace root, syncs every
1145
+ * workspace module. With `check: true`, reports skew without writing.
1146
+ */
1147
+ async syncVersions(options = {}) {
1148
+ if (this.isInModule()) {
1149
+ return syncModuleVersions([this.modulePath], options);
1150
+ }
1151
+ this.ensureWorkspace();
1152
+ const moduleMap = this.getModuleMap();
1153
+ const packageDirs = Object.values(moduleMap).map(mod => path.resolve(this.workspacePath, mod.path));
1154
+ return syncModuleVersions(packageDirs, options);
1155
+ }
1140
1156
  /**
1141
1157
  * Get the set of modules that have been deployed to the database
1142
1158
  */
package/esm/index.js CHANGED
@@ -3,6 +3,7 @@ export * from './rebundle';
3
3
  export * from './extensions/extensions';
4
4
  export * from './modules/modules';
5
5
  export * from './packaging/package';
6
+ export * from './packaging/sync-versions';
6
7
  export * from './packaging/transform';
7
8
  export * from './resolution/deps';
8
9
  export * from './resolution/resolve';
@@ -98,7 +98,7 @@ export const writePackage = async ({ version, extension = true, usePlan = true,
98
98
  if (extension) {
99
99
  writeFileSync(controlPath, control.replace(/default_version = '[0-9\.]+'/, `default_version = '${version}'`));
100
100
  pkg.version = version;
101
- writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
101
+ writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
102
102
  const regex = new RegExp(`${extname}--[0-9.]+.sql`);
103
103
  writeFileSync(makePath, Makefile.replace(regex, sqlFileName));
104
104
  }
@@ -0,0 +1,53 @@
1
+ import { Logger } from '@pgpmjs/logger';
2
+ import { existsSync, readFileSync } from 'fs';
3
+ import { join } from 'path';
4
+ import { getExtensionInfo, parseControlContent } from '@pgpmjs/ast/files';
5
+ import { writePackage } from './package';
6
+ const log = new Logger('sync-versions');
7
+ /**
8
+ * Inspect a module directory and report whether its extension metadata
9
+ * (.control default_version + sql bundle) matches the package.json version.
10
+ */
11
+ export const getModuleVersionStatus = (packageDir) => {
12
+ const { extname, version, controlFile, sqlFile } = getExtensionInfo(packageDir);
13
+ const { version: controlVersion } = parseControlContent(readFileSync(controlFile, 'utf-8'));
14
+ const sqlFileExists = existsSync(join(packageDir, sqlFile));
15
+ return {
16
+ name: extname,
17
+ packageDir,
18
+ packageVersion: version,
19
+ controlVersion,
20
+ sqlFileExists,
21
+ inSync: version === controlVersion && sqlFileExists
22
+ };
23
+ };
24
+ /**
25
+ * Bring a set of module directories back in sync with their package.json
26
+ * versions by re-running the packaging flow (control file, Makefile, and
27
+ * sql/<name>--<version>.sql regenerate from the package.json version).
28
+ */
29
+ export const syncModuleVersions = async (packageDirs, { check = false, usePlan = true } = {}) => {
30
+ const result = { synced: [], skewed: [], ok: [] };
31
+ for (const packageDir of packageDirs) {
32
+ const status = getModuleVersionStatus(packageDir);
33
+ if (status.inSync) {
34
+ result.ok.push(status);
35
+ continue;
36
+ }
37
+ if (check) {
38
+ result.skewed.push(status);
39
+ log.warn(`✗ ${status.name}: package.json ${status.packageVersion} != control ${status.controlVersion}` +
40
+ (status.sqlFileExists ? '' : ` (missing sql/${status.name}--${status.packageVersion}.sql)`));
41
+ continue;
42
+ }
43
+ await writePackage({
44
+ version: status.packageVersion,
45
+ extension: true,
46
+ usePlan,
47
+ packageDir
48
+ });
49
+ result.synced.push(status);
50
+ log.success(`✓ ${status.name}: synced to ${status.packageVersion}`);
51
+ }
52
+ return result;
53
+ };
package/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export * from './rebundle';
3
3
  export * from './extensions/extensions';
4
4
  export * from './modules/modules';
5
5
  export * from './packaging/package';
6
+ export * from './packaging/sync-versions';
6
7
  export * from './packaging/transform';
7
8
  export * from './resolution/deps';
8
9
  export * from './resolution/resolve';
package/index.js CHANGED
@@ -20,6 +20,7 @@ __exportStar(require("./rebundle"), exports);
20
20
  __exportStar(require("./extensions/extensions"), exports);
21
21
  __exportStar(require("./modules/modules"), exports);
22
22
  __exportStar(require("./packaging/package"), exports);
23
+ __exportStar(require("./packaging/sync-versions"), exports);
23
24
  __exportStar(require("./packaging/transform"), exports);
24
25
  __exportStar(require("./resolution/deps"), exports);
25
26
  __exportStar(require("./resolution/resolve"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pgpmjs/core",
3
- "version": "7.5.1",
3
+ "version": "7.9.0",
4
4
  "author": "Constructive <developers@constructive.io>",
5
5
  "description": "PGPM Package and Migration Tools",
6
6
  "main": "index.js",
@@ -48,23 +48,23 @@
48
48
  "makage": "^0.3.0"
49
49
  },
50
50
  "dependencies": {
51
- "@pgpmjs/ast": "^0.2.2",
52
- "@pgpmjs/bundle": "^0.3.2",
53
- "@pgpmjs/env": "^2.30.2",
54
- "@pgpmjs/logger": "^2.15.2",
55
- "@pgpmjs/server-utils": "^3.16.2",
56
- "@pgpmjs/slice": "^0.2.0",
57
- "@pgpmjs/types": "^2.37.2",
58
- "csv-to-pg": "^4.1.2",
51
+ "@pgpmjs/ast": "^0.5.0",
52
+ "@pgpmjs/bundle": "^0.6.0",
53
+ "@pgpmjs/env": "^2.33.0",
54
+ "@pgpmjs/logger": "^2.18.0",
55
+ "@pgpmjs/server-utils": "^3.19.0",
56
+ "@pgpmjs/slice": "^0.5.0",
57
+ "@pgpmjs/types": "^2.40.0",
58
+ "csv-to-pg": "^4.4.0",
59
59
  "genomic": "^5.6.2",
60
60
  "glob": "^13.0.6",
61
61
  "parse-package-name": "^1.0.0",
62
62
  "pg": "^8.21.0",
63
- "pg-cache": "^3.16.2",
64
- "pg-env": "^1.19.2",
63
+ "pg-cache": "^3.19.0",
64
+ "pg-env": "^1.22.0",
65
65
  "pgsql-deparser": "^18.1.1",
66
66
  "pgsql-parser": "^18.1.1",
67
67
  "yanse": "^0.2.1"
68
68
  },
69
- "gitHead": "217ead37de876d05763874856347a48a6f356a69"
69
+ "gitHead": "f36bcdd2b5dada626955e9e05b19c80ca9f92ed5"
70
70
  }
@@ -104,7 +104,7 @@ const writePackage = async ({ version, extension = true, usePlan = true, package
104
104
  if (extension) {
105
105
  (0, fs_1.writeFileSync)(controlPath, control.replace(/default_version = '[0-9\.]+'/, `default_version = '${version}'`));
106
106
  pkg.version = version;
107
- (0, fs_1.writeFileSync)(pkgPath, JSON.stringify(pkg, null, 2));
107
+ (0, fs_1.writeFileSync)(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
108
108
  const regex = new RegExp(`${extname}--[0-9.]+.sql`);
109
109
  (0, fs_1.writeFileSync)(makePath, Makefile.replace(regex, sqlFileName));
110
110
  }
@@ -0,0 +1,36 @@
1
+ export interface ModuleVersionStatus {
2
+ /** Extension name from pgpm.plan */
3
+ name: string;
4
+ packageDir: string;
5
+ /** Version from package.json (source of truth) */
6
+ packageVersion: string;
7
+ /** default_version from the .control file */
8
+ controlVersion: string;
9
+ /** Whether sql/<name>--<packageVersion>.sql exists */
10
+ sqlFileExists: boolean;
11
+ inSync: boolean;
12
+ }
13
+ export interface SyncVersionsOptions {
14
+ /** Report skew without writing anything */
15
+ check?: boolean;
16
+ usePlan?: boolean;
17
+ }
18
+ export interface SyncVersionsResult {
19
+ /** Modules that were regenerated (empty in check mode) */
20
+ synced: ModuleVersionStatus[];
21
+ /** Modules found out of sync (populated in check mode) */
22
+ skewed: ModuleVersionStatus[];
23
+ /** Modules already in sync */
24
+ ok: ModuleVersionStatus[];
25
+ }
26
+ /**
27
+ * Inspect a module directory and report whether its extension metadata
28
+ * (.control default_version + sql bundle) matches the package.json version.
29
+ */
30
+ export declare const getModuleVersionStatus: (packageDir: string) => ModuleVersionStatus;
31
+ /**
32
+ * Bring a set of module directories back in sync with their package.json
33
+ * versions by re-running the packaging flow (control file, Makefile, and
34
+ * sql/<name>--<version>.sql regenerate from the package.json version).
35
+ */
36
+ export declare const syncModuleVersions: (packageDirs: string[], { check, usePlan }?: SyncVersionsOptions) => Promise<SyncVersionsResult>;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.syncModuleVersions = exports.getModuleVersionStatus = void 0;
4
+ const logger_1 = require("@pgpmjs/logger");
5
+ const fs_1 = require("fs");
6
+ const path_1 = require("path");
7
+ const files_1 = require("@pgpmjs/ast/files");
8
+ const package_1 = require("./package");
9
+ const log = new logger_1.Logger('sync-versions');
10
+ /**
11
+ * Inspect a module directory and report whether its extension metadata
12
+ * (.control default_version + sql bundle) matches the package.json version.
13
+ */
14
+ const getModuleVersionStatus = (packageDir) => {
15
+ const { extname, version, controlFile, sqlFile } = (0, files_1.getExtensionInfo)(packageDir);
16
+ const { version: controlVersion } = (0, files_1.parseControlContent)((0, fs_1.readFileSync)(controlFile, 'utf-8'));
17
+ const sqlFileExists = (0, fs_1.existsSync)((0, path_1.join)(packageDir, sqlFile));
18
+ return {
19
+ name: extname,
20
+ packageDir,
21
+ packageVersion: version,
22
+ controlVersion,
23
+ sqlFileExists,
24
+ inSync: version === controlVersion && sqlFileExists
25
+ };
26
+ };
27
+ exports.getModuleVersionStatus = getModuleVersionStatus;
28
+ /**
29
+ * Bring a set of module directories back in sync with their package.json
30
+ * versions by re-running the packaging flow (control file, Makefile, and
31
+ * sql/<name>--<version>.sql regenerate from the package.json version).
32
+ */
33
+ const syncModuleVersions = async (packageDirs, { check = false, usePlan = true } = {}) => {
34
+ const result = { synced: [], skewed: [], ok: [] };
35
+ for (const packageDir of packageDirs) {
36
+ const status = (0, exports.getModuleVersionStatus)(packageDir);
37
+ if (status.inSync) {
38
+ result.ok.push(status);
39
+ continue;
40
+ }
41
+ if (check) {
42
+ result.skewed.push(status);
43
+ log.warn(`✗ ${status.name}: package.json ${status.packageVersion} != control ${status.controlVersion}` +
44
+ (status.sqlFileExists ? '' : ` (missing sql/${status.name}--${status.packageVersion}.sql)`));
45
+ continue;
46
+ }
47
+ await (0, package_1.writePackage)({
48
+ version: status.packageVersion,
49
+ extension: true,
50
+ usePlan,
51
+ packageDir
52
+ });
53
+ result.synced.push(status);
54
+ log.success(`✓ ${status.name}: synced to ${status.packageVersion}`);
55
+ }
56
+ return result;
57
+ };
58
+ exports.syncModuleVersions = syncModuleVersions;