@mcoda/integrations 0.1.38 → 0.1.40
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/dist/vcs/VcsClient.d.ts +1 -0
- package/dist/vcs/VcsClient.d.ts.map +1 -1
- package/dist/vcs/VcsClient.js +48 -16
- package/package.json +2 -2
package/dist/vcs/VcsClient.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VcsClient.d.ts","sourceRoot":"","sources":["../../src/vcs/VcsClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"VcsClient.d.ts","sourceRoot":"","sources":["../../src/vcs/VcsClient.ts"],"names":[],"mappings":"AAOA,qBAAa,SAAS;YACN,MAAM;YAYN,eAAe;YA4Cf,YAAY;IASpB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IASrC,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKtC,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IASxC,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IASlD,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;YASnD,UAAU;YASV,gBAAgB;IAaxB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAY1D,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1D,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQhF,WAAW,CACf,GAAG,EAAE,MA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@
|
|
|
1
|
-
import {
|
|
1
|
+
import { execFile as execFileCb, spawn } from "node:child_process";
|
|
2
2
|
import { promisify } from "node:util";
|
|
3
3
|
import fs from "node:fs/promises";
|
|
4
4
|
import path from "node:path";
|
|
5
|
-
const exec = promisify(execCb);
|
|
6
5
|
const execFile = promisify(execFileCb);
|
|
7
6
|
export class VcsClient {
|
|
8
7
|
async runGit(cwd, args, options = {}) {
|
|
@@ -12,6 +11,48 @@ export class VcsClient {
|
|
|
12
11
|
stderr: typeof stderr === "string" ? stderr : stderr?.toString?.() ?? "",
|
|
13
12
|
};
|
|
14
13
|
}
|
|
14
|
+
async runGitWithInput(cwd, args, input) {
|
|
15
|
+
return await new Promise((resolve, reject) => {
|
|
16
|
+
const child = spawn("git", args, { cwd, stdio: ["pipe", "pipe", "pipe"] });
|
|
17
|
+
let stdout = "";
|
|
18
|
+
let stderr = "";
|
|
19
|
+
let settled = false;
|
|
20
|
+
const rejectOnce = (error) => {
|
|
21
|
+
if (settled)
|
|
22
|
+
return;
|
|
23
|
+
settled = true;
|
|
24
|
+
reject(error);
|
|
25
|
+
};
|
|
26
|
+
const resolveOnce = (result) => {
|
|
27
|
+
if (settled)
|
|
28
|
+
return;
|
|
29
|
+
settled = true;
|
|
30
|
+
resolve(result);
|
|
31
|
+
};
|
|
32
|
+
child.stdout.on("data", (chunk) => {
|
|
33
|
+
stdout += chunk.toString();
|
|
34
|
+
});
|
|
35
|
+
child.stderr.on("data", (chunk) => {
|
|
36
|
+
stderr += chunk.toString();
|
|
37
|
+
});
|
|
38
|
+
child.on("error", (error) => {
|
|
39
|
+
rejectOnce(error);
|
|
40
|
+
});
|
|
41
|
+
child.stdin.on("error", (error) => {
|
|
42
|
+
rejectOnce(error);
|
|
43
|
+
});
|
|
44
|
+
child.on("close", (code) => {
|
|
45
|
+
if (code === 0) {
|
|
46
|
+
resolveOnce({ stdout, stderr });
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const summary = stderr.trim() || stdout.trim() || `git ${args.join(" ")} failed with code ${code ?? "unknown"}`;
|
|
50
|
+
const error = Object.assign(new Error(summary), { stdout, stderr, code });
|
|
51
|
+
rejectOnce(error);
|
|
52
|
+
});
|
|
53
|
+
child.stdin.end(input);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
15
56
|
async gitDirExists(cwd) {
|
|
16
57
|
try {
|
|
17
58
|
await fs.access(path.join(cwd, ".git"));
|
|
@@ -130,24 +171,20 @@ export class VcsClient {
|
|
|
130
171
|
await this.runGit(cwd, ["cherry-pick", "--abort"]);
|
|
131
172
|
}
|
|
132
173
|
async applyPatch(cwd, patch) {
|
|
133
|
-
const opts = { cwd, shell: true };
|
|
134
|
-
const applyCmd = `cat <<'__PATCH__' | git apply --whitespace=nowarn\n${patch}\n__PATCH__`;
|
|
135
174
|
try {
|
|
136
|
-
await
|
|
175
|
+
await this.runGitWithInput(cwd, ["apply", "--whitespace=nowarn"], patch);
|
|
137
176
|
return;
|
|
138
177
|
}
|
|
139
178
|
catch (error) {
|
|
140
179
|
// Retry with 3-way merge for drifted files.
|
|
141
|
-
const apply3wayCmd = `cat <<'__PATCH__' | git apply --3way --whitespace=nowarn\n${patch}\n__PATCH__`;
|
|
142
180
|
try {
|
|
143
|
-
await
|
|
181
|
+
await this.runGitWithInput(cwd, ["apply", "--3way", "--whitespace=nowarn"], patch);
|
|
144
182
|
return;
|
|
145
183
|
}
|
|
146
184
|
catch {
|
|
147
185
|
// If the patch is already applied, a reverse --check succeeds; treat that as a no-op.
|
|
148
|
-
const reverseCheckCmd = `cat <<'__PATCH__' | git apply --reverse --check --whitespace=nowarn\n${patch}\n__PATCH__`;
|
|
149
186
|
try {
|
|
150
|
-
await
|
|
187
|
+
await this.runGitWithInput(cwd, ["apply", "--reverse", "--check", "--whitespace=nowarn"], patch);
|
|
151
188
|
return;
|
|
152
189
|
}
|
|
153
190
|
catch {
|
|
@@ -157,14 +194,9 @@ export class VcsClient {
|
|
|
157
194
|
}
|
|
158
195
|
}
|
|
159
196
|
async applyPatchWithReject(cwd, patch) {
|
|
160
|
-
const opts = { cwd, shell: true };
|
|
161
|
-
const applyCmd = `cat <<'__PATCH__' | git apply --reject --whitespace=nowarn\n${patch}\n__PATCH__`;
|
|
162
197
|
try {
|
|
163
|
-
const { stdout, stderr } = await
|
|
164
|
-
return {
|
|
165
|
-
stdout: typeof stdout === "string" ? stdout : stdout?.toString?.() ?? "",
|
|
166
|
-
stderr: typeof stderr === "string" ? stderr : stderr?.toString?.() ?? "",
|
|
167
|
-
};
|
|
198
|
+
const { stdout, stderr } = await this.runGitWithInput(cwd, ["apply", "--reject", "--whitespace=nowarn"], patch);
|
|
199
|
+
return { stdout, stderr };
|
|
168
200
|
}
|
|
169
201
|
catch (error) {
|
|
170
202
|
const stdout = typeof error?.stdout === "string" ? error.stdout : error?.stdout?.toString?.() ?? "";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcoda/integrations",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.40",
|
|
4
4
|
"description": "External integrations for mcoda (vcs, QA, telemetry).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"docdex": "^0.2.22",
|
|
41
|
-
"@mcoda/shared": "0.1.
|
|
41
|
+
"@mcoda/shared": "0.1.40"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "tsc -p tsconfig.json",
|