@pgpmjs/core 7.23.0 → 7.25.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/diff/sides.d.ts +0 -9
- package/diff/sides.js +14 -2
- package/esm/diff/sides.js +14 -2
- package/esm/packaging/check.js +90 -50
- package/package.json +15 -14
- package/packaging/check.d.ts +14 -9
- package/packaging/check.js +89 -49
package/diff/sides.d.ts
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Diff-side loading: turn a side spec — module directory, workspace
|
|
3
|
-
* directory, .sql file, or live database — into the single
|
|
4
|
-
* `DiffInputChange[]` seam the semantic diff consumes.
|
|
5
|
-
*
|
|
6
|
-
* `@pgpmjs/diff` owns the pure normalizations (classification, flattening,
|
|
7
|
-
* SQL wrapping); this module supplies the I/O they need and that only core
|
|
8
|
-
* has: workspace module-map resolution (`PgpmPackage`) and `pg_dump`.
|
|
9
|
-
*/
|
|
10
1
|
import type { DiffSide } from '@pgpmjs/diff';
|
|
11
2
|
import type { ModuleSource } from '@pgpmjs/transform';
|
|
12
3
|
/** A workspace's local modules, loaded in dependency order. */
|
package/diff/sides.js
CHANGED
|
@@ -34,6 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.loadPlanSideModules = exports.loadDiffSide = exports.loadDatabaseSide = exports.loadWorkspaceSide = exports.loadWorkspaceModuleSources = void 0;
|
|
37
|
+
const ast_1 = require("@pgpmjs/ast");
|
|
37
38
|
const diff_1 = require("@pgpmjs/diff");
|
|
38
39
|
const transform_1 = require("@pgpmjs/transform");
|
|
39
40
|
const fs = __importStar(require("fs"));
|
|
@@ -60,7 +61,11 @@ const loadWorkspaceModuleSources = async (workspaceDir) => {
|
|
|
60
61
|
const moduleMap = pkg.getModuleMap();
|
|
61
62
|
const { resolved, external } = await pkg.resolveWorkspaceExtensionDependencies();
|
|
62
63
|
const warnings = [];
|
|
63
|
-
|
|
64
|
+
// First pass: collect the plan-bearing local modules and their parsed plans,
|
|
65
|
+
// keyed by package name (`%project`), so the second pass can resolve
|
|
66
|
+
// cross-package tag dependencies (`pkg:@tag`) against the plan that owns them.
|
|
67
|
+
const eligible = [];
|
|
68
|
+
const crossPackagePlans = new Map();
|
|
64
69
|
for (const name of resolved) {
|
|
65
70
|
if (external.includes(name))
|
|
66
71
|
continue;
|
|
@@ -74,7 +79,14 @@ const loadWorkspaceModuleSources = async (workspaceDir) => {
|
|
|
74
79
|
warnings.push(`${name}: no pgpm.plan (proxy or apply-spec module); skipped`);
|
|
75
80
|
continue;
|
|
76
81
|
}
|
|
77
|
-
|
|
82
|
+
eligible.push({ name, moduleDir });
|
|
83
|
+
const parsed = (0, ast_1.parsePlanFile)(path.join(moduleDir, 'pgpm.plan'));
|
|
84
|
+
if (parsed.data)
|
|
85
|
+
crossPackagePlans.set(parsed.data.package, parsed.data);
|
|
86
|
+
}
|
|
87
|
+
const modules = [];
|
|
88
|
+
for (const { name, moduleDir } of eligible) {
|
|
89
|
+
const source = (0, transform_1.loadModuleSource)(moduleDir, { crossPackagePlans });
|
|
78
90
|
warnings.push(...source.warnings.map(w => `${name}: ${w}`));
|
|
79
91
|
modules.push(source);
|
|
80
92
|
}
|
package/esm/diff/sides.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { parsePlanFile } from '@pgpmjs/ast';
|
|
1
2
|
import { loadDiffSideFromDisk, resolveDiffSideKind, sqlToDiffChanges, workspaceModulesToDiffChanges } from '@pgpmjs/diff';
|
|
2
3
|
import { loadModuleSource } from '@pgpmjs/transform';
|
|
3
4
|
import * as fs from 'fs';
|
|
@@ -24,7 +25,11 @@ export const loadWorkspaceModuleSources = async (workspaceDir) => {
|
|
|
24
25
|
const moduleMap = pkg.getModuleMap();
|
|
25
26
|
const { resolved, external } = await pkg.resolveWorkspaceExtensionDependencies();
|
|
26
27
|
const warnings = [];
|
|
27
|
-
|
|
28
|
+
// First pass: collect the plan-bearing local modules and their parsed plans,
|
|
29
|
+
// keyed by package name (`%project`), so the second pass can resolve
|
|
30
|
+
// cross-package tag dependencies (`pkg:@tag`) against the plan that owns them.
|
|
31
|
+
const eligible = [];
|
|
32
|
+
const crossPackagePlans = new Map();
|
|
28
33
|
for (const name of resolved) {
|
|
29
34
|
if (external.includes(name))
|
|
30
35
|
continue;
|
|
@@ -38,7 +43,14 @@ export const loadWorkspaceModuleSources = async (workspaceDir) => {
|
|
|
38
43
|
warnings.push(`${name}: no pgpm.plan (proxy or apply-spec module); skipped`);
|
|
39
44
|
continue;
|
|
40
45
|
}
|
|
41
|
-
|
|
46
|
+
eligible.push({ name, moduleDir });
|
|
47
|
+
const parsed = parsePlanFile(path.join(moduleDir, 'pgpm.plan'));
|
|
48
|
+
if (parsed.data)
|
|
49
|
+
crossPackagePlans.set(parsed.data.package, parsed.data);
|
|
50
|
+
}
|
|
51
|
+
const modules = [];
|
|
52
|
+
for (const { name, moduleDir } of eligible) {
|
|
53
|
+
const source = loadModuleSource(moduleDir, { crossPackagePlans });
|
|
42
54
|
warnings.push(...source.warnings.map(w => `${name}: ${w}`));
|
|
43
55
|
modules.push(source);
|
|
44
56
|
}
|
package/esm/packaging/check.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { verifyBundle } from '@pgpmjs/bundle';
|
|
2
|
-
import {
|
|
2
|
+
import { execFileSync } from 'child_process';
|
|
3
|
+
import { existsSync } from 'fs';
|
|
4
|
+
import { changedFiles as gitChangedFiles, resolveBase as resolveChangedBase } from 'git-changed';
|
|
3
5
|
import { isAbsolute, relative, resolve as resolvePath } from 'path';
|
|
4
6
|
import { bundleMatchesModule, readBundleArtifact, resolveBundleArtifactPath, } from '../bundle/artifact';
|
|
5
7
|
import { PgpmPackage } from '../core/class/pgpm';
|
|
@@ -48,63 +50,98 @@ export function checkModuleArtifact(moduleDir, name) {
|
|
|
48
50
|
}
|
|
49
51
|
return null;
|
|
50
52
|
}
|
|
51
|
-
function git(args, cwd) {
|
|
52
|
-
return execSync(`git ${args}`, {
|
|
53
|
-
cwd,
|
|
54
|
-
encoding: 'utf-8',
|
|
55
|
-
stdio: ['ignore', 'pipe', 'ignore'],
|
|
56
|
-
maxBuffer: 64 * 1024 * 1024,
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
53
|
/**
|
|
60
|
-
* Resolve the git ref to diff against. Explicit `--since` wins; otherwise
|
|
61
|
-
*
|
|
62
|
-
*
|
|
54
|
+
* Resolve the git ref to diff against. Explicit `--since` wins; otherwise the
|
|
55
|
+
* PR base branch when running in GitHub Actions; otherwise the repository's
|
|
56
|
+
* default branch. `undefined` means there is nothing to diff against — a
|
|
57
|
+
* shallow or detached checkout — and only the working tree is inspected.
|
|
63
58
|
*/
|
|
64
|
-
export function resolveBase(since) {
|
|
65
|
-
|
|
66
|
-
return since;
|
|
67
|
-
const prBase = process.env.GITHUB_BASE_REF;
|
|
68
|
-
if (prBase && prBase.trim())
|
|
69
|
-
return `origin/${prBase.trim()}`;
|
|
70
|
-
return undefined;
|
|
59
|
+
export function resolveBase(since, cwd = process.cwd()) {
|
|
60
|
+
return resolveChangedBase(since, cwd);
|
|
71
61
|
}
|
|
72
62
|
/**
|
|
73
|
-
* Collect the set of changed files
|
|
74
|
-
*
|
|
75
|
-
*
|
|
63
|
+
* Collect the set of changed files: committed changes since the **merge base**
|
|
64
|
+
* with `base`, unioned with uncommitted and untracked working-tree changes.
|
|
65
|
+
*
|
|
66
|
+
* Returns absolute paths, including paths that no longer exist — deleting a
|
|
67
|
+
* `deploy/` file makes a module's bundle stale exactly as much as editing one,
|
|
68
|
+
* so the deletion has to reach {@link mapFilesToModules}.
|
|
76
69
|
*/
|
|
77
70
|
export function changedFiles(cwd, base) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
71
|
+
// `base: false` when there is no base: the ref is resolved by the caller, and
|
|
72
|
+
// git-changed would otherwise resolve one of its own.
|
|
73
|
+
return gitChangedFiles({ cwd, base: base ?? false, existingOnly: false }).paths.map(decodeGitPath);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Undo git's C-escaping of a path it decided to quote.
|
|
77
|
+
*
|
|
78
|
+
* With `core.quotepath` on (the default) git renders a path holding a non-ASCII
|
|
79
|
+
* byte as `"caf\303\251 dir/x.sql"`: octal escapes, one per UTF-8 byte. A caller
|
|
80
|
+
* that only strips the surrounding quotes is left with a filename that exists
|
|
81
|
+
* nowhere on disk, so the module owning it silently drops out of the check —
|
|
82
|
+
* `pgpm package --check` passes while the module's bundle is stale.
|
|
83
|
+
*
|
|
84
|
+
* Only applied when it actually resolves something: if the escaped form exists on
|
|
85
|
+
* disk and the decoded one does not, the backslashes were part of the filename.
|
|
86
|
+
*/
|
|
87
|
+
function decodeGitPath(path) {
|
|
88
|
+
if (!path.includes('\\'))
|
|
89
|
+
return path;
|
|
90
|
+
const decoded = cUnescape(path);
|
|
91
|
+
if (decoded === path)
|
|
92
|
+
return path;
|
|
93
|
+
if (existsSync(decoded))
|
|
94
|
+
return decoded;
|
|
95
|
+
// Neither form exists for a deleted file; the decoded name is the real one.
|
|
96
|
+
return existsSync(path) ? path : decoded;
|
|
97
|
+
}
|
|
98
|
+
const C_ESCAPES = {
|
|
99
|
+
a: 0x07,
|
|
100
|
+
b: 0x08,
|
|
101
|
+
f: 0x0c,
|
|
102
|
+
n: 0x0a,
|
|
103
|
+
r: 0x0d,
|
|
104
|
+
t: 0x09,
|
|
105
|
+
v: 0x0b,
|
|
106
|
+
'\\': 0x5c,
|
|
107
|
+
'"': 0x22,
|
|
108
|
+
};
|
|
109
|
+
/** Decode `\NNN` octal byte escapes and the single-character C escapes git emits. */
|
|
110
|
+
function cUnescape(input) {
|
|
111
|
+
const bytes = [];
|
|
112
|
+
for (let i = 0; i < input.length; i += 1) {
|
|
113
|
+
const ch = input[i];
|
|
114
|
+
if (ch !== '\\' || i + 1 >= input.length) {
|
|
115
|
+
bytes.push(...Buffer.from(ch, 'utf8'));
|
|
83
116
|
continue;
|
|
84
|
-
let p = line.slice(3);
|
|
85
|
-
const arrow = p.indexOf(' -> ');
|
|
86
|
-
if (arrow !== -1)
|
|
87
|
-
p = p.slice(arrow + 4);
|
|
88
|
-
p = p.replace(/^"|"$/g, '');
|
|
89
|
-
if (p)
|
|
90
|
-
files.add(resolvePath(cwd, p));
|
|
91
|
-
}
|
|
92
|
-
if (base) {
|
|
93
|
-
let diff;
|
|
94
|
-
try {
|
|
95
|
-
diff = git(`diff --name-only ${base}...HEAD`, cwd);
|
|
96
117
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
118
|
+
const next = input[i + 1];
|
|
119
|
+
const octal = input.slice(i + 1, i + 4);
|
|
120
|
+
if (/^[0-7]{3}$/.test(octal)) {
|
|
121
|
+
bytes.push(parseInt(octal, 8));
|
|
122
|
+
i += 3;
|
|
123
|
+
continue;
|
|
100
124
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
125
|
+
if (next in C_ESCAPES) {
|
|
126
|
+
bytes.push(C_ESCAPES[next]);
|
|
127
|
+
i += 1;
|
|
128
|
+
continue;
|
|
105
129
|
}
|
|
130
|
+
bytes.push(...Buffer.from(ch, 'utf8'));
|
|
131
|
+
}
|
|
132
|
+
return Buffer.from(bytes).toString('utf8');
|
|
133
|
+
}
|
|
134
|
+
function refExists(ref, cwd) {
|
|
135
|
+
try {
|
|
136
|
+
execFileSync('git', ['rev-parse', '--verify', '--quiet', ref], {
|
|
137
|
+
cwd,
|
|
138
|
+
stdio: 'ignore',
|
|
139
|
+
});
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
return false;
|
|
106
144
|
}
|
|
107
|
-
return [...files];
|
|
108
145
|
}
|
|
109
146
|
/** Enumerate the modules to consider — the whole workspace, or the single module. */
|
|
110
147
|
export function enumerateModules(pkg) {
|
|
@@ -181,9 +218,12 @@ export async function checkPackages(options = {}) {
|
|
|
181
218
|
targetNames = modules.map((m) => m.name);
|
|
182
219
|
}
|
|
183
220
|
else {
|
|
184
|
-
base = resolveBase(options.since);
|
|
185
|
-
|
|
186
|
-
|
|
221
|
+
base = resolveBase(options.since, cwd);
|
|
222
|
+
if (options.since && !refExists(options.since, cwd)) {
|
|
223
|
+
throw new Error(`Could not diff against '${options.since}'. Ensure the ref exists locally ` +
|
|
224
|
+
'(e.g. `git fetch origin`).');
|
|
225
|
+
}
|
|
226
|
+
changedModules = mapFilesToModules(changedFiles(cwd, base), modules);
|
|
187
227
|
const set = new Set(changedModules);
|
|
188
228
|
if (options.dependents && pkg.getWorkspacePath())
|
|
189
229
|
addDependents(set, pkg);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pgpmjs/core",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.25.0",
|
|
4
4
|
"author": "Constructive <developers@constructive.io>",
|
|
5
5
|
"description": "PGPM Package and Migration Tools",
|
|
6
6
|
"main": "index.js",
|
|
@@ -44,29 +44,30 @@
|
|
|
44
44
|
"@pgsql/types": "^18.0.0",
|
|
45
45
|
"@types/pg": "^8.20.0",
|
|
46
46
|
"copyfiles": "^2.4.1",
|
|
47
|
-
"inquirerer": "^4.9.
|
|
47
|
+
"inquirerer": "^4.9.3",
|
|
48
48
|
"makage": "^0.3.0"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@pgpmjs/ast": "^0.11.
|
|
52
|
-
"@pgpmjs/bundle": "^0.14.
|
|
53
|
-
"@pgpmjs/diff": "^0.3.
|
|
54
|
-
"@pgpmjs/env": "^2.41.
|
|
51
|
+
"@pgpmjs/ast": "^0.11.2",
|
|
52
|
+
"@pgpmjs/bundle": "^0.14.2",
|
|
53
|
+
"@pgpmjs/diff": "^0.3.2",
|
|
54
|
+
"@pgpmjs/env": "^2.41.2",
|
|
55
55
|
"@pgpmjs/logger": "^2.24.0",
|
|
56
|
-
"@pgpmjs/server-utils": "^3.25.
|
|
57
|
-
"@pgpmjs/slice": "^0.14.
|
|
58
|
-
"@pgpmjs/transform": "^0.
|
|
59
|
-
"@pgpmjs/types": "^2.50.
|
|
60
|
-
"csv-to-pg": "^4.10.
|
|
61
|
-
"genomic": "^5.6.
|
|
56
|
+
"@pgpmjs/server-utils": "^3.25.2",
|
|
57
|
+
"@pgpmjs/slice": "^0.14.3",
|
|
58
|
+
"@pgpmjs/transform": "^0.23.1",
|
|
59
|
+
"@pgpmjs/types": "^2.50.2",
|
|
60
|
+
"csv-to-pg": "^4.10.2",
|
|
61
|
+
"genomic": "^5.6.5",
|
|
62
|
+
"git-changed": "^0.3.0",
|
|
62
63
|
"glob": "^13.0.6",
|
|
63
64
|
"parse-package-name": "^1.0.0",
|
|
64
65
|
"pg": "^8.21.0",
|
|
65
|
-
"pg-cache": "^3.25.
|
|
66
|
+
"pg-cache": "^3.25.2",
|
|
66
67
|
"pg-env": "^1.29.0",
|
|
67
68
|
"pgsql-deparser": "^18.3.3",
|
|
68
69
|
"pgsql-parser": "^18.2.3",
|
|
69
70
|
"yanse": "^0.2.1"
|
|
70
71
|
},
|
|
71
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "43121004a8bedd2c5fcf7bf33208079d55bad01f"
|
|
72
73
|
}
|
package/packaging/check.d.ts
CHANGED
|
@@ -23,8 +23,9 @@ export interface PackageCheckOptions {
|
|
|
23
23
|
cwd?: string;
|
|
24
24
|
/**
|
|
25
25
|
* Git ref/branch/tag to diff `HEAD` against for change detection. When
|
|
26
|
-
* omitted, the
|
|
27
|
-
*
|
|
26
|
+
* omitted, the base is auto-detected: `origin/$GITHUB_BASE_REF` in a PR,
|
|
27
|
+
* otherwise the repository's default branch, falling back to working-tree
|
|
28
|
+
* changes only when neither is available.
|
|
28
29
|
*/
|
|
29
30
|
since?: string;
|
|
30
31
|
/** Check every module in the workspace, skipping git change detection. */
|
|
@@ -63,15 +64,19 @@ export interface PackageCheckResult {
|
|
|
63
64
|
*/
|
|
64
65
|
export declare function checkModuleArtifact(moduleDir: string, name: string): ModuleDrift | null;
|
|
65
66
|
/**
|
|
66
|
-
* Resolve the git ref to diff against. Explicit `--since` wins; otherwise
|
|
67
|
-
*
|
|
68
|
-
*
|
|
67
|
+
* Resolve the git ref to diff against. Explicit `--since` wins; otherwise the
|
|
68
|
+
* PR base branch when running in GitHub Actions; otherwise the repository's
|
|
69
|
+
* default branch. `undefined` means there is nothing to diff against — a
|
|
70
|
+
* shallow or detached checkout — and only the working tree is inspected.
|
|
69
71
|
*/
|
|
70
|
-
export declare function resolveBase(since?: string): string | undefined;
|
|
72
|
+
export declare function resolveBase(since?: string, cwd?: string): string | undefined;
|
|
71
73
|
/**
|
|
72
|
-
* Collect the set of changed files
|
|
73
|
-
*
|
|
74
|
-
*
|
|
74
|
+
* Collect the set of changed files: committed changes since the **merge base**
|
|
75
|
+
* with `base`, unioned with uncommitted and untracked working-tree changes.
|
|
76
|
+
*
|
|
77
|
+
* Returns absolute paths, including paths that no longer exist — deleting a
|
|
78
|
+
* `deploy/` file makes a module's bundle stale exactly as much as editing one,
|
|
79
|
+
* so the deletion has to reach {@link mapFilesToModules}.
|
|
75
80
|
*/
|
|
76
81
|
export declare function changedFiles(cwd: string, base?: string): string[];
|
|
77
82
|
/** Enumerate the modules to consider — the whole workspace, or the single module. */
|
package/packaging/check.js
CHANGED
|
@@ -9,6 +9,8 @@ exports.addDependents = addDependents;
|
|
|
9
9
|
exports.checkPackages = checkPackages;
|
|
10
10
|
const bundle_1 = require("@pgpmjs/bundle");
|
|
11
11
|
const child_process_1 = require("child_process");
|
|
12
|
+
const fs_1 = require("fs");
|
|
13
|
+
const git_changed_1 = require("git-changed");
|
|
12
14
|
const path_1 = require("path");
|
|
13
15
|
const artifact_1 = require("../bundle/artifact");
|
|
14
16
|
const pgpm_1 = require("../core/class/pgpm");
|
|
@@ -57,63 +59,98 @@ function checkModuleArtifact(moduleDir, name) {
|
|
|
57
59
|
}
|
|
58
60
|
return null;
|
|
59
61
|
}
|
|
60
|
-
function git(args, cwd) {
|
|
61
|
-
return (0, child_process_1.execSync)(`git ${args}`, {
|
|
62
|
-
cwd,
|
|
63
|
-
encoding: 'utf-8',
|
|
64
|
-
stdio: ['ignore', 'pipe', 'ignore'],
|
|
65
|
-
maxBuffer: 64 * 1024 * 1024,
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
62
|
/**
|
|
69
|
-
* Resolve the git ref to diff against. Explicit `--since` wins; otherwise
|
|
70
|
-
*
|
|
71
|
-
*
|
|
63
|
+
* Resolve the git ref to diff against. Explicit `--since` wins; otherwise the
|
|
64
|
+
* PR base branch when running in GitHub Actions; otherwise the repository's
|
|
65
|
+
* default branch. `undefined` means there is nothing to diff against — a
|
|
66
|
+
* shallow or detached checkout — and only the working tree is inspected.
|
|
72
67
|
*/
|
|
73
|
-
function resolveBase(since) {
|
|
74
|
-
|
|
75
|
-
return since;
|
|
76
|
-
const prBase = process.env.GITHUB_BASE_REF;
|
|
77
|
-
if (prBase && prBase.trim())
|
|
78
|
-
return `origin/${prBase.trim()}`;
|
|
79
|
-
return undefined;
|
|
68
|
+
function resolveBase(since, cwd = process.cwd()) {
|
|
69
|
+
return (0, git_changed_1.resolveBase)(since, cwd);
|
|
80
70
|
}
|
|
81
71
|
/**
|
|
82
|
-
* Collect the set of changed files
|
|
83
|
-
*
|
|
84
|
-
*
|
|
72
|
+
* Collect the set of changed files: committed changes since the **merge base**
|
|
73
|
+
* with `base`, unioned with uncommitted and untracked working-tree changes.
|
|
74
|
+
*
|
|
75
|
+
* Returns absolute paths, including paths that no longer exist — deleting a
|
|
76
|
+
* `deploy/` file makes a module's bundle stale exactly as much as editing one,
|
|
77
|
+
* so the deletion has to reach {@link mapFilesToModules}.
|
|
85
78
|
*/
|
|
86
79
|
function changedFiles(cwd, base) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
80
|
+
// `base: false` when there is no base: the ref is resolved by the caller, and
|
|
81
|
+
// git-changed would otherwise resolve one of its own.
|
|
82
|
+
return (0, git_changed_1.changedFiles)({ cwd, base: base ?? false, existingOnly: false }).paths.map(decodeGitPath);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Undo git's C-escaping of a path it decided to quote.
|
|
86
|
+
*
|
|
87
|
+
* With `core.quotepath` on (the default) git renders a path holding a non-ASCII
|
|
88
|
+
* byte as `"caf\303\251 dir/x.sql"`: octal escapes, one per UTF-8 byte. A caller
|
|
89
|
+
* that only strips the surrounding quotes is left with a filename that exists
|
|
90
|
+
* nowhere on disk, so the module owning it silently drops out of the check —
|
|
91
|
+
* `pgpm package --check` passes while the module's bundle is stale.
|
|
92
|
+
*
|
|
93
|
+
* Only applied when it actually resolves something: if the escaped form exists on
|
|
94
|
+
* disk and the decoded one does not, the backslashes were part of the filename.
|
|
95
|
+
*/
|
|
96
|
+
function decodeGitPath(path) {
|
|
97
|
+
if (!path.includes('\\'))
|
|
98
|
+
return path;
|
|
99
|
+
const decoded = cUnescape(path);
|
|
100
|
+
if (decoded === path)
|
|
101
|
+
return path;
|
|
102
|
+
if ((0, fs_1.existsSync)(decoded))
|
|
103
|
+
return decoded;
|
|
104
|
+
// Neither form exists for a deleted file; the decoded name is the real one.
|
|
105
|
+
return (0, fs_1.existsSync)(path) ? path : decoded;
|
|
106
|
+
}
|
|
107
|
+
const C_ESCAPES = {
|
|
108
|
+
a: 0x07,
|
|
109
|
+
b: 0x08,
|
|
110
|
+
f: 0x0c,
|
|
111
|
+
n: 0x0a,
|
|
112
|
+
r: 0x0d,
|
|
113
|
+
t: 0x09,
|
|
114
|
+
v: 0x0b,
|
|
115
|
+
'\\': 0x5c,
|
|
116
|
+
'"': 0x22,
|
|
117
|
+
};
|
|
118
|
+
/** Decode `\NNN` octal byte escapes and the single-character C escapes git emits. */
|
|
119
|
+
function cUnescape(input) {
|
|
120
|
+
const bytes = [];
|
|
121
|
+
for (let i = 0; i < input.length; i += 1) {
|
|
122
|
+
const ch = input[i];
|
|
123
|
+
if (ch !== '\\' || i + 1 >= input.length) {
|
|
124
|
+
bytes.push(...Buffer.from(ch, 'utf8'));
|
|
92
125
|
continue;
|
|
93
|
-
let p = line.slice(3);
|
|
94
|
-
const arrow = p.indexOf(' -> ');
|
|
95
|
-
if (arrow !== -1)
|
|
96
|
-
p = p.slice(arrow + 4);
|
|
97
|
-
p = p.replace(/^"|"$/g, '');
|
|
98
|
-
if (p)
|
|
99
|
-
files.add((0, path_1.resolve)(cwd, p));
|
|
100
|
-
}
|
|
101
|
-
if (base) {
|
|
102
|
-
let diff;
|
|
103
|
-
try {
|
|
104
|
-
diff = git(`diff --name-only ${base}...HEAD`, cwd);
|
|
105
126
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
127
|
+
const next = input[i + 1];
|
|
128
|
+
const octal = input.slice(i + 1, i + 4);
|
|
129
|
+
if (/^[0-7]{3}$/.test(octal)) {
|
|
130
|
+
bytes.push(parseInt(octal, 8));
|
|
131
|
+
i += 3;
|
|
132
|
+
continue;
|
|
109
133
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
134
|
+
if (next in C_ESCAPES) {
|
|
135
|
+
bytes.push(C_ESCAPES[next]);
|
|
136
|
+
i += 1;
|
|
137
|
+
continue;
|
|
114
138
|
}
|
|
139
|
+
bytes.push(...Buffer.from(ch, 'utf8'));
|
|
140
|
+
}
|
|
141
|
+
return Buffer.from(bytes).toString('utf8');
|
|
142
|
+
}
|
|
143
|
+
function refExists(ref, cwd) {
|
|
144
|
+
try {
|
|
145
|
+
(0, child_process_1.execFileSync)('git', ['rev-parse', '--verify', '--quiet', ref], {
|
|
146
|
+
cwd,
|
|
147
|
+
stdio: 'ignore',
|
|
148
|
+
});
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
return false;
|
|
115
153
|
}
|
|
116
|
-
return [...files];
|
|
117
154
|
}
|
|
118
155
|
/** Enumerate the modules to consider — the whole workspace, or the single module. */
|
|
119
156
|
function enumerateModules(pkg) {
|
|
@@ -190,9 +227,12 @@ async function checkPackages(options = {}) {
|
|
|
190
227
|
targetNames = modules.map((m) => m.name);
|
|
191
228
|
}
|
|
192
229
|
else {
|
|
193
|
-
base = resolveBase(options.since);
|
|
194
|
-
|
|
195
|
-
|
|
230
|
+
base = resolveBase(options.since, cwd);
|
|
231
|
+
if (options.since && !refExists(options.since, cwd)) {
|
|
232
|
+
throw new Error(`Could not diff against '${options.since}'. Ensure the ref exists locally ` +
|
|
233
|
+
'(e.g. `git fetch origin`).');
|
|
234
|
+
}
|
|
235
|
+
changedModules = mapFilesToModules(changedFiles(cwd, base), modules);
|
|
196
236
|
const set = new Set(changedModules);
|
|
197
237
|
if (options.dependents && pkg.getWorkspacePath())
|
|
198
238
|
addDependents(set, pkg);
|