@pgpmjs/ast 0.1.0 → 0.1.2
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.
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
import { readFileSync } from 'fs';
|
|
2
|
-
import {
|
|
2
|
+
import { dirname, relative } from 'path';
|
|
3
3
|
import { parsePlanFileSimple } from '../plan';
|
|
4
4
|
/**
|
|
5
5
|
* Parse a .control file and extract its metadata.
|
|
6
6
|
* https://www.postgresql.org/docs/current/extend-extensions.html
|
|
7
7
|
*/
|
|
8
8
|
export function parseControlFile(filePath, basePath) {
|
|
9
|
-
const
|
|
10
|
-
|
|
9
|
+
const { requires, version } = parseControlContent(readFileSync(filePath, 'utf-8'));
|
|
10
|
+
return {
|
|
11
|
+
// posix separators: this path is a portable identifier recorded in
|
|
12
|
+
// pgpm.json and plan metadata, not a filesystem path
|
|
13
|
+
path: dirname(relative(basePath, filePath)).replace(/\\/g, '/'),
|
|
14
|
+
requires,
|
|
15
|
+
version,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Parse .control file content and extract its metadata. The in-memory core of
|
|
20
|
+
* {@link parseControlFile}, for control text that does not live on disk (e.g.
|
|
21
|
+
* inside a migration bundle artifact).
|
|
22
|
+
*/
|
|
23
|
+
export function parseControlContent(contents) {
|
|
11
24
|
const requires = contents
|
|
12
25
|
.split('\n')
|
|
13
26
|
.find((line) => /^requires/.test(line))
|
|
@@ -20,11 +33,7 @@ export function parseControlFile(filePath, basePath) {
|
|
|
20
33
|
?.split('=')[1]
|
|
21
34
|
.replace(/[\']*/g, '')
|
|
22
35
|
.trim() || '';
|
|
23
|
-
return {
|
|
24
|
-
path: dirname(relative(basePath, filePath)),
|
|
25
|
-
requires,
|
|
26
|
-
version,
|
|
27
|
-
};
|
|
36
|
+
return { requires, version };
|
|
28
37
|
}
|
|
29
38
|
/**
|
|
30
39
|
* Parse the pgpm.plan file to get the extension name.
|
package/esm/files/plan/parser.js
CHANGED
|
@@ -6,7 +6,14 @@ import { errors } from '@pgpmjs/types';
|
|
|
6
6
|
* Supports both changes and tags
|
|
7
7
|
*/
|
|
8
8
|
export function parsePlanFile(planPath) {
|
|
9
|
-
|
|
9
|
+
return parsePlanContent(readFileSync(planPath, 'utf-8'));
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Parse Sqitch plan content (the text of a `pgpm.plan`) with full validation.
|
|
13
|
+
* The in-memory core of {@link parsePlanFile}, for plan text that does not
|
|
14
|
+
* live on disk (e.g. inside a migration bundle artifact).
|
|
15
|
+
*/
|
|
16
|
+
export function parsePlanContent(content) {
|
|
10
17
|
const lines = content.split('\n');
|
|
11
18
|
let project = '';
|
|
12
19
|
let uri = '';
|
|
@@ -9,6 +9,15 @@ export interface Module {
|
|
|
9
9
|
* https://www.postgresql.org/docs/current/extend-extensions.html
|
|
10
10
|
*/
|
|
11
11
|
export declare function parseControlFile(filePath: string, basePath: string): Module;
|
|
12
|
+
/**
|
|
13
|
+
* Parse .control file content and extract its metadata. The in-memory core of
|
|
14
|
+
* {@link parseControlFile}, for control text that does not live on disk (e.g.
|
|
15
|
+
* inside a migration bundle artifact).
|
|
16
|
+
*/
|
|
17
|
+
export declare function parseControlContent(contents: string): {
|
|
18
|
+
requires: string[];
|
|
19
|
+
version: string;
|
|
20
|
+
};
|
|
12
21
|
/**
|
|
13
22
|
* Parse the pgpm.plan file to get the extension name.
|
|
14
23
|
*/
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getInstalledExtensions = exports.getExtensionInfo = exports.getExtensionName = void 0;
|
|
4
4
|
exports.parseControlFile = parseControlFile;
|
|
5
|
+
exports.parseControlContent = parseControlContent;
|
|
5
6
|
const fs_1 = require("fs");
|
|
6
7
|
const path_1 = require("path");
|
|
7
8
|
const plan_1 = require("../plan");
|
|
@@ -10,8 +11,21 @@ const plan_1 = require("../plan");
|
|
|
10
11
|
* https://www.postgresql.org/docs/current/extend-extensions.html
|
|
11
12
|
*/
|
|
12
13
|
function parseControlFile(filePath, basePath) {
|
|
13
|
-
const
|
|
14
|
-
|
|
14
|
+
const { requires, version } = parseControlContent((0, fs_1.readFileSync)(filePath, 'utf-8'));
|
|
15
|
+
return {
|
|
16
|
+
// posix separators: this path is a portable identifier recorded in
|
|
17
|
+
// pgpm.json and plan metadata, not a filesystem path
|
|
18
|
+
path: (0, path_1.dirname)((0, path_1.relative)(basePath, filePath)).replace(/\\/g, '/'),
|
|
19
|
+
requires,
|
|
20
|
+
version,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Parse .control file content and extract its metadata. The in-memory core of
|
|
25
|
+
* {@link parseControlFile}, for control text that does not live on disk (e.g.
|
|
26
|
+
* inside a migration bundle artifact).
|
|
27
|
+
*/
|
|
28
|
+
function parseControlContent(contents) {
|
|
15
29
|
const requires = contents
|
|
16
30
|
.split('\n')
|
|
17
31
|
.find((line) => /^requires/.test(line))
|
|
@@ -24,11 +38,7 @@ function parseControlFile(filePath, basePath) {
|
|
|
24
38
|
?.split('=')[1]
|
|
25
39
|
.replace(/[\']*/g, '')
|
|
26
40
|
.trim() || '';
|
|
27
|
-
return {
|
|
28
|
-
path: (0, path_1.dirname)((0, path_1.relative)(basePath, filePath)),
|
|
29
|
-
requires,
|
|
30
|
-
version,
|
|
31
|
-
};
|
|
41
|
+
return { requires, version };
|
|
32
42
|
}
|
|
33
43
|
/**
|
|
34
44
|
* Parse the pgpm.plan file to get the extension name.
|
package/files/plan/parser.d.ts
CHANGED
|
@@ -4,6 +4,12 @@ import { ExtendedPlanFile, ParseResult, PlanFile } from '../types';
|
|
|
4
4
|
* Supports both changes and tags
|
|
5
5
|
*/
|
|
6
6
|
export declare function parsePlanFile(planPath: string): ParseResult<ExtendedPlanFile>;
|
|
7
|
+
/**
|
|
8
|
+
* Parse Sqitch plan content (the text of a `pgpm.plan`) with full validation.
|
|
9
|
+
* The in-memory core of {@link parsePlanFile}, for plan text that does not
|
|
10
|
+
* live on disk (e.g. inside a migration bundle artifact).
|
|
11
|
+
*/
|
|
12
|
+
export declare function parsePlanContent(content: string): ParseResult<ExtendedPlanFile>;
|
|
7
13
|
/**
|
|
8
14
|
* Resolve a reference within a plan file context
|
|
9
15
|
* Handles symbolic references (HEAD, ROOT) and relative references
|
package/files/plan/parser.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parsePlanFile = parsePlanFile;
|
|
4
|
+
exports.parsePlanContent = parsePlanContent;
|
|
4
5
|
exports.resolveReference = resolveReference;
|
|
5
6
|
exports.parsePlanFileSimple = parsePlanFileSimple;
|
|
6
7
|
exports.getChanges = getChanges;
|
|
@@ -13,7 +14,14 @@ const types_1 = require("@pgpmjs/types");
|
|
|
13
14
|
* Supports both changes and tags
|
|
14
15
|
*/
|
|
15
16
|
function parsePlanFile(planPath) {
|
|
16
|
-
|
|
17
|
+
return parsePlanContent((0, fs_1.readFileSync)(planPath, 'utf-8'));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Parse Sqitch plan content (the text of a `pgpm.plan`) with full validation.
|
|
21
|
+
* The in-memory core of {@link parsePlanFile}, for plan text that does not
|
|
22
|
+
* live on disk (e.g. inside a migration bundle artifact).
|
|
23
|
+
*/
|
|
24
|
+
function parsePlanContent(content) {
|
|
17
25
|
const lines = content.split('\n');
|
|
18
26
|
let project = '';
|
|
19
27
|
let uri = '';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pgpmjs/ast",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"author": "Constructive <developers@constructive.io>",
|
|
5
5
|
"description": "PGPM module AST — plan/control/SQL-header parsers and the lossless module read/write layer",
|
|
6
6
|
"main": "index.js",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"makage": "^0.3.0"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@pgpmjs/env": "^2.
|
|
45
|
-
"@pgpmjs/types": "^2.
|
|
44
|
+
"@pgpmjs/env": "^2.29.0",
|
|
45
|
+
"@pgpmjs/types": "^2.36.0"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "39db6d576bce7bc1de8123849f237b1695779d88"
|
|
48
48
|
}
|