@pgpmjs/ast 0.1.0 → 0.1.1

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,24 @@
1
1
  import { readFileSync } from 'fs';
2
- import { basename, dirname, relative } from 'path';
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 contents = readFileSync(filePath, 'utf-8');
10
- const key = basename(filePath).split('.control')[0];
9
+ const { requires, version } = parseControlContent(readFileSync(filePath, 'utf-8'));
10
+ return {
11
+ path: dirname(relative(basePath, filePath)),
12
+ requires,
13
+ version,
14
+ };
15
+ }
16
+ /**
17
+ * Parse .control file content and extract its metadata. The in-memory core of
18
+ * {@link parseControlFile}, for control text that does not live on disk (e.g.
19
+ * inside a migration bundle artifact).
20
+ */
21
+ export function parseControlContent(contents) {
11
22
  const requires = contents
12
23
  .split('\n')
13
24
  .find((line) => /^requires/.test(line))
@@ -20,11 +31,7 @@ export function parseControlFile(filePath, basePath) {
20
31
  ?.split('=')[1]
21
32
  .replace(/[\']*/g, '')
22
33
  .trim() || '';
23
- return {
24
- path: dirname(relative(basePath, filePath)),
25
- requires,
26
- version,
27
- };
34
+ return { requires, version };
28
35
  }
29
36
  /**
30
37
  * Parse the pgpm.plan file to get the extension name.
@@ -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
- const content = readFileSync(planPath, 'utf-8');
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,19 @@ 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 contents = (0, fs_1.readFileSync)(filePath, 'utf-8');
14
- const key = (0, path_1.basename)(filePath).split('.control')[0];
14
+ const { requires, version } = parseControlContent((0, fs_1.readFileSync)(filePath, 'utf-8'));
15
+ return {
16
+ path: (0, path_1.dirname)((0, path_1.relative)(basePath, filePath)),
17
+ requires,
18
+ version,
19
+ };
20
+ }
21
+ /**
22
+ * Parse .control file content and extract its metadata. The in-memory core of
23
+ * {@link parseControlFile}, for control text that does not live on disk (e.g.
24
+ * inside a migration bundle artifact).
25
+ */
26
+ function parseControlContent(contents) {
15
27
  const requires = contents
16
28
  .split('\n')
17
29
  .find((line) => /^requires/.test(line))
@@ -24,11 +36,7 @@ function parseControlFile(filePath, basePath) {
24
36
  ?.split('=')[1]
25
37
  .replace(/[\']*/g, '')
26
38
  .trim() || '';
27
- return {
28
- path: (0, path_1.dirname)((0, path_1.relative)(basePath, filePath)),
29
- requires,
30
- version,
31
- };
39
+ return { requires, version };
32
40
  }
33
41
  /**
34
42
  * Parse the pgpm.plan file to get the extension name.
@@ -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
@@ -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
- const content = (0, fs_1.readFileSync)(planPath, 'utf-8');
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.0",
3
+ "version": "0.1.1",
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",
@@ -44,5 +44,5 @@
44
44
  "@pgpmjs/env": "^2.28.2",
45
45
  "@pgpmjs/types": "^2.35.1"
46
46
  },
47
- "gitHead": "15a831fa029544068ee64e3386e4b08715d2b86d"
47
+ "gitHead": "51c3e15e9d509154d0a8102bb18f6e39cfa4e0c6"
48
48
  }