@pgpmjs/core 7.1.0 → 7.2.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/bundle/apply.d.ts +93 -0
- package/bundle/apply.js +137 -0
- package/bundle/index.d.ts +12 -0
- package/bundle/index.js +31 -0
- package/core/class/pgpm.d.ts +2 -2
- package/core/class/pgpm.js +6 -6
- package/esm/bundle/apply.js +131 -0
- package/esm/bundle/index.js +15 -0
- package/esm/core/class/pgpm.js +6 -6
- package/esm/index.js +5 -3
- package/esm/migrate/client.js +1 -1
- package/esm/migrate/utils/hash.js +3 -6
- package/esm/modules/modules.js +1 -1
- package/esm/packaging/package.js +1 -1
- package/esm/rebundle/module.js +1 -1
- package/esm/rebundle/rebundle.js +2 -2
- package/esm/rebundle/workspace.js +1 -1
- package/esm/refactor/rename.js +5 -27
- package/esm/resolution/deps.js +2 -2
- package/esm/resolution/resolve.js +2 -2
- package/esm/slice/slice.js +1 -1
- package/index.d.ts +4 -2
- package/index.js +6 -4
- package/migrate/client.js +1 -1
- package/migrate/utils/hash.d.ts +2 -4
- package/migrate/utils/hash.js +4 -8
- package/modules/modules.d.ts +1 -1
- package/modules/modules.js +1 -1
- package/package.json +4 -2
- package/packaging/package.js +1 -1
- package/rebundle/module.js +1 -1
- package/rebundle/rebundle.js +2 -2
- package/rebundle/types.d.ts +1 -1
- package/rebundle/workspace.js +1 -1
- package/refactor/rename.d.ts +2 -8
- package/refactor/rename.js +6 -29
- package/resolution/deps.d.ts +1 -1
- package/resolution/deps.js +2 -2
- package/resolution/resolve.js +2 -2
- package/slice/slice.d.ts +1 -1
- package/slice/slice.js +1 -1
- package/slice/types.d.ts +1 -1
- package/workspace/minimal.d.ts +1 -1
- package/esm/files/extension/index.js +0 -3
- package/esm/files/extension/reader.js +0 -79
- package/esm/files/extension/writer.js +0 -99
- package/esm/files/index.js +0 -6
- package/esm/files/plan/generator.js +0 -82
- package/esm/files/plan/index.js +0 -5
- package/esm/files/plan/parser.js +0 -297
- package/esm/files/plan/validators.js +0 -181
- package/esm/files/plan/writer.js +0 -142
- package/esm/files/sql/header.js +0 -259
- package/esm/files/sql/index.js +0 -2
- package/esm/files/sql/writer.js +0 -107
- package/esm/files/sql-scripts/index.js +0 -2
- package/esm/files/sql-scripts/reader.js +0 -19
- package/esm/files/types/index.js +0 -1
- package/esm/files/types/package.js +0 -1
- package/esm/utils/author.js +0 -11
- package/files/extension/index.d.ts +0 -2
- package/files/extension/index.js +0 -19
- package/files/extension/reader.d.ts +0 -24
- package/files/extension/reader.js +0 -86
- package/files/extension/writer.d.ts +0 -48
- package/files/extension/writer.js +0 -107
- package/files/index.d.ts +0 -5
- package/files/index.js +0 -22
- package/files/plan/generator.d.ts +0 -23
- package/files/plan/generator.js +0 -90
- package/files/plan/index.d.ts +0 -4
- package/files/plan/index.js +0 -21
- package/files/plan/parser.d.ts +0 -28
- package/files/plan/parser.js +0 -304
- package/files/plan/validators.d.ts +0 -52
- package/files/plan/validators.js +0 -187
- package/files/plan/writer.d.ts +0 -27
- package/files/plan/writer.js +0 -152
- package/files/sql/header.d.ts +0 -114
- package/files/sql/header.js +0 -266
- package/files/sql/index.d.ts +0 -2
- package/files/sql/index.js +0 -18
- package/files/sql/writer.d.ts +0 -12
- package/files/sql/writer.js +0 -114
- package/files/sql-scripts/index.d.ts +0 -1
- package/files/sql-scripts/index.js +0 -18
- package/files/sql-scripts/reader.d.ts +0 -8
- package/files/sql-scripts/reader.js +0 -23
- package/files/types/index.d.ts +0 -46
- package/files/types/index.js +0 -17
- package/files/types/package.d.ts +0 -20
- package/files/types/package.js +0 -2
- package/utils/author.d.ts +0 -5
- package/utils/author.js +0 -14
package/index.d.ts
CHANGED
|
@@ -13,13 +13,15 @@ export * from './workspace/minimal';
|
|
|
13
13
|
export * from './core/template-scaffold';
|
|
14
14
|
export * from './core/boilerplate-types';
|
|
15
15
|
export * from './core/boilerplate-scanner';
|
|
16
|
-
export * from '
|
|
16
|
+
export * from '@pgpmjs/ast/files';
|
|
17
|
+
export * from '@pgpmjs/ast/module';
|
|
18
|
+
export * from './bundle';
|
|
17
19
|
export * from './refactor';
|
|
18
20
|
export { cleanSql } from './migrate/clean';
|
|
19
21
|
export { PgpmMigrate } from './migrate/client';
|
|
20
22
|
export { PgpmInit } from './init/client';
|
|
21
23
|
export * from './roles';
|
|
22
|
-
export { parseAuthor } from '
|
|
24
|
+
export { parseAuthor } from '@pgpmjs/ast';
|
|
23
25
|
export { DeployOptions, DeployResult, MigrateChange, MigratePlanFile, RevertOptions, RevertResult, StatusResult, VerifyOptions, VerifyResult } from './migrate/types';
|
|
24
26
|
export { hashFile, hashString } from './migrate/utils/hash';
|
|
25
27
|
export { executeQuery, TransactionContext, TransactionOptions, withTransaction } from './migrate/utils/transaction';
|
package/index.js
CHANGED
|
@@ -30,8 +30,10 @@ __exportStar(require("./workspace/minimal"), exports);
|
|
|
30
30
|
__exportStar(require("./core/template-scaffold"), exports);
|
|
31
31
|
__exportStar(require("./core/boilerplate-types"), exports);
|
|
32
32
|
__exportStar(require("./core/boilerplate-scanner"), exports);
|
|
33
|
-
//
|
|
34
|
-
__exportStar(require("
|
|
33
|
+
// Re-export the module AST layer (moved to the @pgpmjs/ast leaf package)
|
|
34
|
+
__exportStar(require("@pgpmjs/ast/files"), exports);
|
|
35
|
+
__exportStar(require("@pgpmjs/ast/module"), exports);
|
|
36
|
+
__exportStar(require("./bundle"), exports);
|
|
35
37
|
__exportStar(require("./refactor"), exports);
|
|
36
38
|
var clean_1 = require("./migrate/clean");
|
|
37
39
|
Object.defineProperty(exports, "cleanSql", { enumerable: true, get: function () { return clean_1.cleanSql; } });
|
|
@@ -40,8 +42,8 @@ Object.defineProperty(exports, "PgpmMigrate", { enumerable: true, get: function
|
|
|
40
42
|
var client_2 = require("./init/client");
|
|
41
43
|
Object.defineProperty(exports, "PgpmInit", { enumerable: true, get: function () { return client_2.PgpmInit; } });
|
|
42
44
|
__exportStar(require("./roles"), exports);
|
|
43
|
-
var
|
|
44
|
-
Object.defineProperty(exports, "parseAuthor", { enumerable: true, get: function () { return
|
|
45
|
+
var ast_1 = require("@pgpmjs/ast");
|
|
46
|
+
Object.defineProperty(exports, "parseAuthor", { enumerable: true, get: function () { return ast_1.parseAuthor; } });
|
|
45
47
|
var hash_1 = require("./migrate/utils/hash");
|
|
46
48
|
Object.defineProperty(exports, "hashFile", { enumerable: true, get: function () { return hash_1.hashFile; } });
|
|
47
49
|
Object.defineProperty(exports, "hashString", { enumerable: true, get: function () { return hash_1.hashString; } });
|
package/migrate/client.js
CHANGED
|
@@ -6,7 +6,7 @@ const types_1 = require("@pgpmjs/types");
|
|
|
6
6
|
const fs_1 = require("fs");
|
|
7
7
|
const path_1 = require("path");
|
|
8
8
|
const pg_cache_1 = require("pg-cache");
|
|
9
|
-
const files_1 = require("
|
|
9
|
+
const files_1 = require("@pgpmjs/ast/files");
|
|
10
10
|
const deps_1 = require("../resolution/deps");
|
|
11
11
|
const resolve_1 = require("../resolution/resolve");
|
|
12
12
|
const clean_1 = require("./clean");
|
package/migrate/utils/hash.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
+
import { hashString } from '@pgpmjs/ast';
|
|
2
|
+
export { hashString };
|
|
1
3
|
/**
|
|
2
4
|
* Generate SHA256 hash of a file's contents
|
|
3
5
|
*/
|
|
4
6
|
export declare function hashFile(filePath: string): Promise<string>;
|
|
5
|
-
/**
|
|
6
|
-
* Generate SHA256 hash of a string
|
|
7
|
-
*/
|
|
8
|
-
export declare function hashString(content: string): string;
|
|
9
7
|
/**
|
|
10
8
|
* Generate SHA256 hash of a SQL file's parsed and cleaned AST
|
|
11
9
|
*/
|
package/migrate/utils/hash.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hashString = void 0;
|
|
3
4
|
exports.hashFile = hashFile;
|
|
4
|
-
exports.hashString = hashString;
|
|
5
5
|
exports.hashSqlFile = hashSqlFile;
|
|
6
|
+
const ast_1 = require("@pgpmjs/ast");
|
|
7
|
+
Object.defineProperty(exports, "hashString", { enumerable: true, get: function () { return ast_1.hashString; } });
|
|
6
8
|
const crypto_1 = require("crypto");
|
|
7
9
|
const promises_1 = require("fs/promises");
|
|
8
10
|
const pgsql_parser_1 = require("pgsql-parser");
|
|
@@ -14,12 +16,6 @@ async function hashFile(filePath) {
|
|
|
14
16
|
const content = await (0, promises_1.readFile)(filePath, 'utf-8');
|
|
15
17
|
return (0, crypto_1.createHash)('sha256').update(content).digest('hex');
|
|
16
18
|
}
|
|
17
|
-
/**
|
|
18
|
-
* Generate SHA256 hash of a string
|
|
19
|
-
*/
|
|
20
|
-
function hashString(content) {
|
|
21
|
-
return (0, crypto_1.createHash)('sha256').update(content).digest('hex');
|
|
22
|
-
}
|
|
23
19
|
/**
|
|
24
20
|
* Generate SHA256 hash of a SQL file's parsed and cleaned AST
|
|
25
21
|
*/
|
|
@@ -28,5 +24,5 @@ async function hashSqlFile(filePath) {
|
|
|
28
24
|
const parsed = await (0, pgsql_parser_1.parse)(content);
|
|
29
25
|
const cleaned = (0, package_1.cleanTree)(parsed);
|
|
30
26
|
const astString = JSON.stringify(cleaned);
|
|
31
|
-
return hashString(astString);
|
|
27
|
+
return (0, ast_1.hashString)(astString);
|
|
32
28
|
}
|
package/modules/modules.d.ts
CHANGED
package/modules/modules.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getExtensionsAndModulesChanges = exports.getExtensionsAndModules = exports.latestChangeAndVersion = exports.latestChange = exports.getMissingInstallableModules = exports.PGPM_MODULE_MAP = void 0;
|
|
4
|
-
const files_1 = require("
|
|
4
|
+
const files_1 = require("@pgpmjs/ast/files");
|
|
5
5
|
const types_1 = require("@pgpmjs/types");
|
|
6
6
|
/**
|
|
7
7
|
* Mapping from control file names (used in extensions list) to npm package names.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pgpmjs/core",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.2.0",
|
|
4
4
|
"author": "Constructive <developers@constructive.io>",
|
|
5
5
|
"description": "PGPM Package and Migration Tools",
|
|
6
6
|
"main": "index.js",
|
|
@@ -48,6 +48,8 @@
|
|
|
48
48
|
"makage": "^0.3.0"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
+
"@pgpmjs/ast": "^0.1.0",
|
|
52
|
+
"@pgpmjs/bundle": "^0.1.0",
|
|
51
53
|
"@pgpmjs/env": "^2.28.2",
|
|
52
54
|
"@pgpmjs/logger": "^2.14.0",
|
|
53
55
|
"@pgpmjs/server-utils": "^3.15.3",
|
|
@@ -64,5 +66,5 @@
|
|
|
64
66
|
"pgsql-parser": "^18.1.1",
|
|
65
67
|
"yanse": "^0.2.1"
|
|
66
68
|
},
|
|
67
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "15a831fa029544068ee64e3386e4b08715d2b86d"
|
|
68
70
|
}
|
package/packaging/package.js
CHANGED
|
@@ -6,7 +6,7 @@ const fs_1 = require("fs");
|
|
|
6
6
|
const path_1 = require("path");
|
|
7
7
|
const pgsql_deparser_1 = require("pgsql-deparser");
|
|
8
8
|
const pgsql_parser_1 = require("pgsql-parser");
|
|
9
|
-
const files_1 = require("
|
|
9
|
+
const files_1 = require("@pgpmjs/ast/files");
|
|
10
10
|
const resolve_1 = require("../resolution/resolve");
|
|
11
11
|
const transform_1 = require("./transform");
|
|
12
12
|
const log = new logger_1.Logger('package');
|
package/rebundle/module.js
CHANGED
|
@@ -5,7 +5,7 @@ exports.mergeChunkScript = mergeChunkScript;
|
|
|
5
5
|
exports.rebundleModule = rebundleModule;
|
|
6
6
|
const fs_1 = require("fs");
|
|
7
7
|
const path_1 = require("path");
|
|
8
|
-
const parser_1 = require("
|
|
8
|
+
const parser_1 = require("@pgpmjs/ast/files/plan/parser");
|
|
9
9
|
const package_1 = require("../packaging/package");
|
|
10
10
|
const slice_1 = require("../slice/slice");
|
|
11
11
|
const rebundle_1 = require("./rebundle");
|
package/rebundle/rebundle.js
CHANGED
|
@@ -5,10 +5,10 @@ exports.assembleChunkSql = assembleChunkSql;
|
|
|
5
5
|
exports.verifyRebundleInvariant = verifyRebundleInvariant;
|
|
6
6
|
const fs_1 = require("fs");
|
|
7
7
|
const path_1 = require("path");
|
|
8
|
-
const parser_1 = require("
|
|
8
|
+
const parser_1 = require("@pgpmjs/ast/files/plan/parser");
|
|
9
9
|
const resolve_1 = require("../resolution/resolve");
|
|
10
10
|
const slice_1 = require("../slice/slice");
|
|
11
|
-
const parser_2 = require("
|
|
11
|
+
const parser_2 = require("@pgpmjs/ast/files/plan/parser");
|
|
12
12
|
/**
|
|
13
13
|
* Derive the boundary key for a change under the given strategy.
|
|
14
14
|
* Consecutive changes sharing a key may be merged into the same chunk.
|
package/rebundle/types.d.ts
CHANGED
package/rebundle/workspace.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.rebundleWorkspace = rebundleWorkspace;
|
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
5
|
const path_1 = require("path");
|
|
6
6
|
const template_scaffold_1 = require("../core/template-scaffold");
|
|
7
|
-
const parser_1 = require("
|
|
7
|
+
const parser_1 = require("@pgpmjs/ast/files/plan/parser");
|
|
8
8
|
const package_1 = require("../packaging/package");
|
|
9
9
|
const resolve_1 = require("../resolution/resolve");
|
|
10
10
|
const minimal_1 = require("../workspace/minimal");
|
package/refactor/rename.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { renameInPlanContent } from '@pgpmjs/ast/plan-rename';
|
|
2
|
+
export { renameInPlanContent };
|
|
1
3
|
/**
|
|
2
4
|
* Options for {@link renameChanges}.
|
|
3
5
|
*/
|
|
@@ -29,14 +31,6 @@ export interface RenameChangesResult {
|
|
|
29
31
|
* @throws on any violation.
|
|
30
32
|
*/
|
|
31
33
|
export declare function validateRenames(moduleDir: string, renames: Map<string, string>): void;
|
|
32
|
-
/**
|
|
33
|
-
* Rewrite change names in a pgpm.plan's content according to a rename map.
|
|
34
|
-
* Textual and format-preserving: only the change-name token at the start of a
|
|
35
|
-
* change line, plain (same-package) dependency refs inside `[...]`, and tag
|
|
36
|
-
* lines' change field are rewritten; timestamps, planners, comments,
|
|
37
|
-
* cross-package refs, and tag refs are untouched.
|
|
38
|
-
*/
|
|
39
|
-
export declare function renameInPlanContent(content: string, renames: Map<string, string>): string;
|
|
40
34
|
/**
|
|
41
35
|
* Atomically rename/move changes within a pgpm module: the coupled 4-way
|
|
42
36
|
* rewrite of (1) deploy/revert/verify script files on disk, (2) the moved
|
package/refactor/rename.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.renameInPlanContent = void 0;
|
|
3
4
|
exports.validateRenames = validateRenames;
|
|
4
|
-
exports.renameInPlanContent = renameInPlanContent;
|
|
5
5
|
exports.renameChanges = renameChanges;
|
|
6
6
|
exports.deriveRenamesFromSchemaMapping = deriveRenamesFromSchemaMapping;
|
|
7
7
|
const fs_1 = require("fs");
|
|
8
8
|
const path_1 = require("path");
|
|
9
|
-
const parser_1 = require("
|
|
10
|
-
const header_1 = require("
|
|
9
|
+
const parser_1 = require("@pgpmjs/ast/files/plan/parser");
|
|
10
|
+
const header_1 = require("@pgpmjs/ast/files/sql/header");
|
|
11
|
+
const plan_rename_1 = require("@pgpmjs/ast/plan-rename");
|
|
12
|
+
Object.defineProperty(exports, "renameInPlanContent", { enumerable: true, get: function () { return plan_rename_1.renameInPlanContent; } });
|
|
11
13
|
const SCRIPT_DIRS = ['deploy', 'revert', 'verify'];
|
|
12
14
|
function escapeRe(str) {
|
|
13
15
|
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
@@ -65,31 +67,6 @@ function validateRenames(moduleDir, renames) {
|
|
|
65
67
|
targets.add(to);
|
|
66
68
|
}
|
|
67
69
|
}
|
|
68
|
-
/**
|
|
69
|
-
* Rewrite change names in a pgpm.plan's content according to a rename map.
|
|
70
|
-
* Textual and format-preserving: only the change-name token at the start of a
|
|
71
|
-
* change line, plain (same-package) dependency refs inside `[...]`, and tag
|
|
72
|
-
* lines' change field are rewritten; timestamps, planners, comments,
|
|
73
|
-
* cross-package refs, and tag refs are untouched.
|
|
74
|
-
*/
|
|
75
|
-
function renameInPlanContent(content, renames) {
|
|
76
|
-
const froms = Array.from(renames.keys()).sort((a, b) => b.length - a.length);
|
|
77
|
-
return content
|
|
78
|
-
.split('\n')
|
|
79
|
-
.map(line => {
|
|
80
|
-
const trimmed = line.trim();
|
|
81
|
-
if (!trimmed || trimmed.startsWith('#') || trimmed.startsWith('%'))
|
|
82
|
-
return line;
|
|
83
|
-
let result = line;
|
|
84
|
-
for (const from of froms) {
|
|
85
|
-
const to = renames.get(from);
|
|
86
|
-
const re = new RegExp(`(^|[\\s\\[])${escapeRe(from)}(?=$|[\\s\\]@])`, 'g');
|
|
87
|
-
result = result.replace(re, `$1${to}`);
|
|
88
|
-
}
|
|
89
|
-
return result;
|
|
90
|
-
})
|
|
91
|
-
.join('\n');
|
|
92
|
-
}
|
|
93
70
|
/**
|
|
94
71
|
* Atomically rename/move changes within a pgpm module: the coupled 4-way
|
|
95
72
|
* rewrite of (1) deploy/revert/verify script files on disk, (2) the moved
|
|
@@ -163,7 +140,7 @@ function renameChanges(moduleDir, renames, options = {}) {
|
|
|
163
140
|
// 4. Rewrite pgpm.plan
|
|
164
141
|
const planPath = (0, path_1.join)(moduleDir, 'pgpm.plan');
|
|
165
142
|
const planContent = (0, fs_1.readFileSync)(planPath, 'utf-8');
|
|
166
|
-
const newPlanContent = renameInPlanContent(planContent, renames);
|
|
143
|
+
const newPlanContent = (0, plan_rename_1.renameInPlanContent)(planContent, renames);
|
|
167
144
|
if (newPlanContent !== planContent) {
|
|
168
145
|
if (dryRun) {
|
|
169
146
|
result.dryRunReport.push('Would rewrite: pgpm.plan');
|
package/resolution/deps.d.ts
CHANGED
package/resolution/deps.js
CHANGED
|
@@ -5,8 +5,8 @@ const fs_1 = require("fs");
|
|
|
5
5
|
const glob_1 = require("glob");
|
|
6
6
|
const path_1 = require("path");
|
|
7
7
|
const pgpm_1 = require("../core/class/pgpm");
|
|
8
|
-
const parser_1 = require("
|
|
9
|
-
const header_1 = require("
|
|
8
|
+
const parser_1 = require("@pgpmjs/ast/files/plan/parser");
|
|
9
|
+
const header_1 = require("@pgpmjs/ast/files/sql/header");
|
|
10
10
|
const types_1 = require("@pgpmjs/types");
|
|
11
11
|
/**
|
|
12
12
|
* Core dependency resolution algorithm that handles circular dependency detection
|
package/resolution/resolve.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resolveTagToChangeName = exports.resolveWithPlan = exports.resolve = void 0;
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
|
-
const files_1 = require("
|
|
6
|
-
const parser_1 = require("
|
|
5
|
+
const files_1 = require("@pgpmjs/ast/files");
|
|
6
|
+
const parser_1 = require("@pgpmjs/ast/files/plan/parser");
|
|
7
7
|
const deps_1 = require("./deps");
|
|
8
8
|
const types_1 = require("@pgpmjs/types");
|
|
9
9
|
/**
|
package/slice/slice.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Change, Tag, ExtendedPlanFile } from '
|
|
1
|
+
import { Change, Tag, ExtendedPlanFile } from '@pgpmjs/ast/files/types';
|
|
2
2
|
import { SliceConfig, SliceResult, DependencyGraph, PackageOutput, GroupingStrategy, PatternStrategy, CrossPackageDepMode } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* Build a dependency graph from a parsed plan file
|
package/slice/slice.js
CHANGED
|
@@ -14,7 +14,7 @@ exports.generatePlanContent = generatePlanContent;
|
|
|
14
14
|
exports.generateControlContent = generateControlContent;
|
|
15
15
|
exports.generateSinglePackage = generateSinglePackage;
|
|
16
16
|
exports.slicePlan = slicePlan;
|
|
17
|
-
const parser_1 = require("
|
|
17
|
+
const parser_1 = require("@pgpmjs/ast/files/plan/parser");
|
|
18
18
|
const minimatch_1 = require("minimatch");
|
|
19
19
|
/**
|
|
20
20
|
* Build a dependency graph from a parsed plan file
|
package/slice/types.d.ts
CHANGED
package/workspace/minimal.d.ts
CHANGED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from 'fs';
|
|
2
|
-
import { basename, dirname, relative } from 'path';
|
|
3
|
-
import { parsePlanFileSimple } from '../plan';
|
|
4
|
-
/**
|
|
5
|
-
* Parse a .control file and extract its metadata.
|
|
6
|
-
* https://www.postgresql.org/docs/current/extend-extensions.html
|
|
7
|
-
*/
|
|
8
|
-
export function parseControlFile(filePath, basePath) {
|
|
9
|
-
const contents = readFileSync(filePath, 'utf-8');
|
|
10
|
-
const key = basename(filePath).split('.control')[0];
|
|
11
|
-
const requires = contents
|
|
12
|
-
.split('\n')
|
|
13
|
-
.find((line) => /^requires/.test(line))
|
|
14
|
-
?.split('=')[1]
|
|
15
|
-
.split(',')
|
|
16
|
-
.map((req) => req.replace(/[\'\s]*/g, '').trim()) || [];
|
|
17
|
-
const version = contents
|
|
18
|
-
.split('\n')
|
|
19
|
-
.find((line) => /^default_version/.test(line))
|
|
20
|
-
?.split('=')[1]
|
|
21
|
-
.replace(/[\']*/g, '')
|
|
22
|
-
.trim() || '';
|
|
23
|
-
return {
|
|
24
|
-
path: dirname(relative(basePath, filePath)),
|
|
25
|
-
requires,
|
|
26
|
-
version,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Parse the pgpm.plan file to get the extension name.
|
|
31
|
-
*/
|
|
32
|
-
export const getExtensionName = (packageDir) => {
|
|
33
|
-
const planPath = `${packageDir}/pgpm.plan`;
|
|
34
|
-
const plan = parsePlanFileSimple(planPath);
|
|
35
|
-
if (!plan.package) {
|
|
36
|
-
throw new Error('No package name found in pgpm.plan!');
|
|
37
|
-
}
|
|
38
|
-
return plan.package;
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Get detailed information about an extension in the specified directory.
|
|
42
|
-
*/
|
|
43
|
-
export const getExtensionInfo = (packageDir) => {
|
|
44
|
-
const pkgPath = `${packageDir}/package.json`;
|
|
45
|
-
const pkg = require(pkgPath);
|
|
46
|
-
const extname = getExtensionName(packageDir);
|
|
47
|
-
const version = pkg.version;
|
|
48
|
-
const Makefile = `${packageDir}/Makefile`;
|
|
49
|
-
const controlFile = `${packageDir}/${extname}.control`;
|
|
50
|
-
const sqlFile = `sql/${extname}--${version}.sql`;
|
|
51
|
-
return { extname, packageDir, version, Makefile, controlFile, sqlFile };
|
|
52
|
-
};
|
|
53
|
-
/**
|
|
54
|
-
* Get a list of extensions required by an extension from its control file.
|
|
55
|
-
* Returns an empty array if the file doesn't exist or has no requires line.
|
|
56
|
-
*/
|
|
57
|
-
export const getInstalledExtensions = (controlFilePath) => {
|
|
58
|
-
try {
|
|
59
|
-
const contents = readFileSync(controlFilePath, 'utf-8');
|
|
60
|
-
const match = contents.match(/^\s*requires\s*=\s*'([^']*)'/m);
|
|
61
|
-
if (!match) {
|
|
62
|
-
return [];
|
|
63
|
-
}
|
|
64
|
-
const requiresValue = match[1];
|
|
65
|
-
if (!requiresValue || requiresValue.trim() === '') {
|
|
66
|
-
return [];
|
|
67
|
-
}
|
|
68
|
-
return requiresValue
|
|
69
|
-
.split(',')
|
|
70
|
-
.map((ext) => ext.trim())
|
|
71
|
-
.filter((ext) => ext.length > 0);
|
|
72
|
-
}
|
|
73
|
-
catch (e) {
|
|
74
|
-
if (e.code === 'ENOENT') {
|
|
75
|
-
return [];
|
|
76
|
-
}
|
|
77
|
-
throw new Error(`Error reading control file at ${controlFilePath}: ${e.message}`);
|
|
78
|
-
}
|
|
79
|
-
};
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { existsSync, readFileSync, writeFileSync } from 'fs';
|
|
2
|
-
import { getExtensionInfo } from './reader';
|
|
3
|
-
/**
|
|
4
|
-
* Write the Makefile for the extension.
|
|
5
|
-
*/
|
|
6
|
-
export const writeExtensionMakefile = (outputPath, extname, version) => {
|
|
7
|
-
const content = `EXTENSION = ${extname}
|
|
8
|
-
DATA = sql/${extname}--${version}.sql
|
|
9
|
-
|
|
10
|
-
PG_CONFIG = pg_config
|
|
11
|
-
PGXS := $(shell $(PG_CONFIG) --pgxs)
|
|
12
|
-
include $(PGXS)
|
|
13
|
-
`;
|
|
14
|
-
writeFileSync(outputPath, content);
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* Generate content for a .control file
|
|
18
|
-
* https://www.postgresql.org/docs/current/extend-extensions.html
|
|
19
|
-
*/
|
|
20
|
-
export function generateControlFileContent(options) {
|
|
21
|
-
const { name, version, comment = `${name} extension`, requires = [], default_version = version, relocatable = false, superuser = false, schema, module_pathname } = options;
|
|
22
|
-
let content = `# ${name} extension
|
|
23
|
-
comment = '${comment}'
|
|
24
|
-
default_version = '${default_version}'
|
|
25
|
-
`;
|
|
26
|
-
if (module_pathname) {
|
|
27
|
-
content += `module_pathname = '${module_pathname}'\n`;
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
content += `module_pathname = '$libdir/${name}'\n`;
|
|
31
|
-
}
|
|
32
|
-
if (requires.length > 0) {
|
|
33
|
-
content += `requires = '${requires.join(',')}'\n`;
|
|
34
|
-
}
|
|
35
|
-
content += `relocatable = ${relocatable}
|
|
36
|
-
superuser = ${superuser}\n`;
|
|
37
|
-
if (schema) {
|
|
38
|
-
content += `schema = ${schema}\n`;
|
|
39
|
-
}
|
|
40
|
-
return content;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Update (or insert/remove) the `requires =` line of an existing .control file
|
|
44
|
-
* in place, preserving every other field and the file's formatting. Used when
|
|
45
|
-
* changing a module's dependencies after init (e.g. via `pgpm extension`) so
|
|
46
|
-
* hand-tuned fields (comment, schema, relocatable, module_pathname) survive.
|
|
47
|
-
*/
|
|
48
|
-
export function upsertRequiresLine(content, requires) {
|
|
49
|
-
const lines = content.split('\n');
|
|
50
|
-
const idx = lines.findIndex((line) => /^\s*requires\s*=/.test(line));
|
|
51
|
-
if (requires.length === 0) {
|
|
52
|
-
if (idx !== -1)
|
|
53
|
-
lines.splice(idx, 1);
|
|
54
|
-
return lines.join('\n');
|
|
55
|
-
}
|
|
56
|
-
const requiresLine = `requires = '${requires.join(',')}'`;
|
|
57
|
-
if (idx !== -1) {
|
|
58
|
-
lines[idx] = requiresLine;
|
|
59
|
-
return lines.join('\n');
|
|
60
|
-
}
|
|
61
|
-
// Insert to match generated ordering (before relocatable/superuser/schema).
|
|
62
|
-
const insertAt = lines.findIndex((line) => /^\s*(relocatable|superuser|schema)\s*=/.test(line));
|
|
63
|
-
if (insertAt !== -1) {
|
|
64
|
-
lines.splice(insertAt, 0, requiresLine);
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
lines.push(requiresLine);
|
|
68
|
-
}
|
|
69
|
-
return lines.join('\n');
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Write the control file for the extension.
|
|
73
|
-
* If the file already exists, only its `requires` line is updated so that any
|
|
74
|
-
* custom fields are preserved; otherwise a fresh file is generated.
|
|
75
|
-
*/
|
|
76
|
-
export const writeExtensionControlFile = (outputPath, extname, extensions, version) => {
|
|
77
|
-
if (existsSync(outputPath)) {
|
|
78
|
-
const existing = readFileSync(outputPath, 'utf-8');
|
|
79
|
-
writeFileSync(outputPath, upsertRequiresLine(existing, extensions));
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
const content = generateControlFileContent({
|
|
83
|
-
name: extname,
|
|
84
|
-
version,
|
|
85
|
-
requires: extensions
|
|
86
|
-
});
|
|
87
|
-
writeFileSync(outputPath, content);
|
|
88
|
-
};
|
|
89
|
-
/**
|
|
90
|
-
* Write control and Makefile for the extension with given data.
|
|
91
|
-
* If extInfo is not provided, it will be generated from packageDir.
|
|
92
|
-
*/
|
|
93
|
-
export const writeExtensions = (packageDir, extensions, extInfo) => {
|
|
94
|
-
// If extInfo is not provided, get it from packageDir
|
|
95
|
-
const info = extInfo || getExtensionInfo(packageDir);
|
|
96
|
-
const { controlFile, Makefile, extname, version } = info;
|
|
97
|
-
writeExtensionControlFile(controlFile, extname, extensions, version);
|
|
98
|
-
writeExtensionMakefile(Makefile, extname, version);
|
|
99
|
-
};
|
package/esm/files/index.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
/**
|
|
3
|
-
* Fixed epoch timestamp used for deterministic plan generation.
|
|
4
|
-
* Can be overridden with the PGPM_FROZEN_TIME environment variable.
|
|
5
|
-
*/
|
|
6
|
-
const DEFAULT_FROZEN_TIME = '2017-08-11T08:11:51Z';
|
|
7
|
-
/**
|
|
8
|
-
* Get a UTC timestamp string from a Date object.
|
|
9
|
-
*/
|
|
10
|
-
function getUTCTimestamp(d) {
|
|
11
|
-
return (d.getUTCFullYear() +
|
|
12
|
-
'-' + String(d.getUTCMonth() + 1).padStart(2, '0') +
|
|
13
|
-
'-' + String(d.getUTCDate()).padStart(2, '0') +
|
|
14
|
-
'T' + String(d.getUTCHours()).padStart(2, '0') +
|
|
15
|
-
':' + String(d.getUTCMinutes()).padStart(2, '0') +
|
|
16
|
-
':' + String(d.getUTCSeconds()).padStart(2, '0') +
|
|
17
|
-
'Z');
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Get a timestamp for the plan file.
|
|
21
|
-
* Uses the PGPM_FROZEN_TIME env var if present, otherwise the fixed epoch.
|
|
22
|
-
*/
|
|
23
|
-
export function getNow() {
|
|
24
|
-
const frozen = process.env.PGPM_FROZEN_TIME;
|
|
25
|
-
if (frozen) {
|
|
26
|
-
return getUTCTimestamp(new Date(frozen));
|
|
27
|
-
}
|
|
28
|
-
return DEFAULT_FROZEN_TIME;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Sort dependencies by their order in the supplied plan, so prerequisites
|
|
32
|
-
* (parent migrations) appear before their dependents in the bracket.
|
|
33
|
-
* Internal dependencies are sorted by their plan index, and external
|
|
34
|
-
* dependencies (not in the plan) preserve their original order.
|
|
35
|
-
*/
|
|
36
|
-
const sortDependencies = (deps, order) => {
|
|
37
|
-
const originalOrder = new Map(deps.map((dep, index) => [dep, index]));
|
|
38
|
-
return [...deps].sort((a, b) => {
|
|
39
|
-
const aIndex = order.get(a);
|
|
40
|
-
const bIndex = order.get(b);
|
|
41
|
-
const aOriginal = originalOrder.get(a);
|
|
42
|
-
const bOriginal = originalOrder.get(b);
|
|
43
|
-
if (aIndex !== undefined && bIndex !== undefined)
|
|
44
|
-
return aIndex - bIndex || aOriginal - bOriginal;
|
|
45
|
-
if (aIndex !== undefined)
|
|
46
|
-
return -1;
|
|
47
|
-
if (bIndex !== undefined)
|
|
48
|
-
return 1;
|
|
49
|
-
return aOriginal - bOriginal;
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* Generate a plan file content from structured data
|
|
54
|
-
*/
|
|
55
|
-
export function generatePlan(options) {
|
|
56
|
-
const { moduleName, uri, entries } = options;
|
|
57
|
-
const now = getNow();
|
|
58
|
-
const planfile = [
|
|
59
|
-
`%syntax-version=1.0.0`,
|
|
60
|
-
`%project=${moduleName}`,
|
|
61
|
-
`%uri=${uri || moduleName}`
|
|
62
|
-
];
|
|
63
|
-
// Build an order map from the entry list so brackets can be sorted by plan order
|
|
64
|
-
const entryOrder = new Map(entries.map((entry, index) => [entry.change, index]));
|
|
65
|
-
// Generate the plan entries
|
|
66
|
-
entries.forEach(entry => {
|
|
67
|
-
const deps = sortDependencies(entry.dependencies || [], entryOrder);
|
|
68
|
-
if (deps.length > 0) {
|
|
69
|
-
planfile.push(`${entry.change} [${deps.join(' ')}] ${now} constructive <constructive@5b0c196eeb62>${entry.comment ? ` # ${entry.comment}` : ''}`);
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
planfile.push(`${entry.change} ${now} constructive <constructive@5b0c196eeb62>${entry.comment ? ` # ${entry.comment}` : ''}`);
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
return planfile.join('\n');
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Write a generated plan file to disk
|
|
79
|
-
*/
|
|
80
|
-
export function writePlan(planPath, plan) {
|
|
81
|
-
fs.writeFileSync(planPath, plan);
|
|
82
|
-
}
|