@regressionproof/snapshotter 0.5.3 → 0.5.5

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.
@@ -6,6 +6,7 @@ export declare namespace SpruceErrors.RegressionproofSnapshotter {
6
6
  'command': string;
7
7
  'stdout'?: string | undefined | null;
8
8
  'stderr'?: string | undefined | null;
9
+ 'version': string;
9
10
  }
10
11
  interface ExecCommandFailedSchema extends SpruceSchema.Schema {
11
12
  id: 'execCommandFailed';
@@ -29,6 +30,12 @@ export declare namespace SpruceErrors.RegressionproofSnapshotter {
29
30
  type: 'text';
30
31
  options: undefined;
31
32
  };
33
+ /** . */
34
+ 'version': {
35
+ type: 'text';
36
+ isRequired: true;
37
+ options: undefined;
38
+ };
32
39
  };
33
40
  }
34
41
  type ExecCommandFailedEntity = SchemaEntity<SpruceErrors.RegressionproofSnapshotter.ExecCommandFailedSchema>;
@@ -23,6 +23,12 @@ const execCommandFailedSchema = {
23
23
  type: 'text',
24
24
  options: undefined
25
25
  },
26
+ /** . */
27
+ 'version': {
28
+ type: 'text',
29
+ isRequired: true,
30
+ options: undefined
31
+ },
26
32
  }
27
33
  };
28
34
  schema_1.SchemaRegistry.getInstance().trackSchema(execCommandFailedSchema);
@@ -25,7 +25,7 @@ ${options.stderr ?? '<no stderr>'}`;
25
25
  const fullMessage = options.friendlyMessage
26
26
  ? options.friendlyMessage
27
27
  : message;
28
- return fullMessage;
28
+ return `${fullMessage} (v${options.version})`;
29
29
  }
30
30
  }
31
31
  exports.default = SpruceError;
@@ -13,6 +13,10 @@ declare const _default: {
13
13
  stderr: {
14
14
  type: "text";
15
15
  };
16
+ version: {
17
+ type: "text";
18
+ isRequired: true;
19
+ };
16
20
  };
17
21
  };
18
22
  export default _default;
@@ -16,5 +16,9 @@ exports.default = (0, schema_1.buildErrorSchema)({
16
16
  stderr: {
17
17
  type: 'text',
18
18
  },
19
+ version: {
20
+ type: 'text',
21
+ isRequired: true,
22
+ },
19
23
  },
20
24
  });
@@ -6,6 +6,7 @@ export declare namespace SpruceErrors.RegressionproofSnapshotter {
6
6
  'command': string;
7
7
  'stdout'?: string | undefined | null;
8
8
  'stderr'?: string | undefined | null;
9
+ 'version': string;
9
10
  }
10
11
  interface ExecCommandFailedSchema extends SpruceSchema.Schema {
11
12
  id: 'execCommandFailed';
@@ -29,6 +30,12 @@ export declare namespace SpruceErrors.RegressionproofSnapshotter {
29
30
  type: 'text';
30
31
  options: undefined;
31
32
  };
33
+ /** . */
34
+ 'version': {
35
+ type: 'text';
36
+ isRequired: true;
37
+ options: undefined;
38
+ };
32
39
  };
33
40
  }
34
41
  type ExecCommandFailedEntity = SchemaEntity<SpruceErrors.RegressionproofSnapshotter.ExecCommandFailedSchema>;
@@ -21,6 +21,6 @@ ${(_b = options.stderr) !== null && _b !== void 0 ? _b : '<no stderr>'}`;
21
21
  const fullMessage = options.friendlyMessage
22
22
  ? options.friendlyMessage
23
23
  : message;
24
- return fullMessage;
24
+ return `${fullMessage} (v${options.version})`;
25
25
  }
26
26
  }
@@ -13,6 +13,10 @@ declare const _default: {
13
13
  stderr: {
14
14
  type: "text";
15
15
  };
16
+ version: {
17
+ type: "text";
18
+ isRequired: true;
19
+ };
16
20
  };
17
21
  };
18
22
  export default _default;
@@ -14,5 +14,9 @@ export default buildErrorSchema({
14
14
  stderr: {
15
15
  type: 'text',
16
16
  },
17
+ version: {
18
+ type: 'text',
19
+ isRequired: true,
20
+ },
17
21
  },
18
22
  });
package/build/esm/git.js CHANGED
@@ -8,10 +8,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { exec } from 'child_process';
11
- import { existsSync } from 'fs';
11
+ import { existsSync, unlinkSync } from 'fs';
12
12
  import path from 'path';
13
13
  import { promisify } from 'util';
14
14
  import SpruceError from './errors/SpruceError.js.js';
15
+ import { getPackageVersion } from './utilities/version.js.js';
15
16
  const execAsync = promisify(exec);
16
17
  export function gitCommit(mirrorPath, log) {
17
18
  return __awaiter(this, void 0, void 0, function* () {
@@ -19,6 +20,7 @@ export function gitCommit(mirrorPath, log) {
19
20
  if (!existsSync(gitDir)) {
20
21
  yield execOrThrow(`git -C "${mirrorPath}" init`, log);
21
22
  }
23
+ cleanupGitLockFiles(mirrorPath, log);
22
24
  yield execOrThrow(`git -C "${mirrorPath}" add -A`, log);
23
25
  const { stdout } = yield execOrThrow(`git -C "${mirrorPath}" status --porcelain`);
24
26
  if (!stdout.trim()) {
@@ -32,44 +34,73 @@ export function gitCommit(mirrorPath, log) {
32
34
  }
33
35
  export function gitPush(mirrorPath, remote, log) {
34
36
  return __awaiter(this, void 0, void 0, function* () {
37
+ cleanupGitLockFiles(mirrorPath, log);
35
38
  const authedUrl = remote.url.replace('://', `://${remote.token}@`);
36
- const originExists = yield remoteExists(mirrorPath, 'origin');
37
- if (originExists) {
38
- yield execOrThrow(`git -C "${mirrorPath}" remote set-url origin "${authedUrl}"`);
39
- }
40
- else {
39
+ const currentUrl = yield getRemoteUrl(mirrorPath, 'origin');
40
+ if (currentUrl === null) {
41
41
  yield execOrThrow(`git -C "${mirrorPath}" remote add origin "${authedUrl}"`);
42
42
  }
43
- yield execOrThrow(`git -C "${mirrorPath}" fetch origin`, log);
44
- if (yield hasRemoteHead(mirrorPath)) {
45
- yield execOrThrow(`git -C "${mirrorPath}" rebase origin/HEAD`, log);
43
+ else if (currentUrl !== authedUrl) {
44
+ yield execOrThrow(`git -C "${mirrorPath}" remote set-url origin "${authedUrl}"`);
46
45
  }
46
+ yield pullFromRemote(mirrorPath, log);
47
47
  yield execOrThrow(`git -C "${mirrorPath}" push -u origin HEAD`, log);
48
48
  });
49
49
  }
50
- function remoteExists(mirrorPath, remoteName) {
50
+ function pullFromRemote(mirrorPath, log) {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ yield execOrThrow(`git -C "${mirrorPath}" fetch origin`, log);
53
+ const branch = yield getCurrentBranch(mirrorPath);
54
+ const remoteBranchExists = yield checkRemoteBranchExists(mirrorPath, branch);
55
+ if (remoteBranchExists) {
56
+ yield execOrThrow(`git -C "${mirrorPath}" rebase origin/${branch}`, log);
57
+ }
58
+ });
59
+ }
60
+ function getCurrentBranch(mirrorPath) {
61
+ return __awaiter(this, void 0, void 0, function* () {
62
+ const { stdout } = yield execAsync(`git -C "${mirrorPath}" rev-parse --abbrev-ref HEAD`);
63
+ return stdout.trim();
64
+ });
65
+ }
66
+ function checkRemoteBranchExists(mirrorPath, branch) {
51
67
  return __awaiter(this, void 0, void 0, function* () {
52
68
  try {
53
- const { stdout } = yield execAsync(`git -C "${mirrorPath}" remote`);
54
- const remotes = stdout.trim().split('\n');
55
- return remotes.includes(remoteName);
69
+ const { stdout } = yield execAsync(`git -C "${mirrorPath}" ls-remote --heads origin ${branch}`);
70
+ return stdout.trim().length > 0;
56
71
  }
57
72
  catch (_a) {
58
73
  return false;
59
74
  }
60
75
  });
61
76
  }
62
- function hasRemoteHead(mirrorPath) {
77
+ function getRemoteUrl(mirrorPath, remoteName) {
63
78
  return __awaiter(this, void 0, void 0, function* () {
64
79
  try {
65
- yield execAsync(`git -C "${mirrorPath}" symbolic-ref -q refs/remotes/origin/HEAD`);
66
- return true;
80
+ const { stdout } = yield execAsync(`git -C "${mirrorPath}" remote get-url ${remoteName}`);
81
+ return stdout.trim();
67
82
  }
68
83
  catch (_a) {
69
- return false;
84
+ return null;
70
85
  }
71
86
  });
72
87
  }
88
+ function cleanupGitLockFiles(mirrorPath, log) {
89
+ var _a;
90
+ const lockFiles = ['config.lock', 'index.lock', 'HEAD.lock'];
91
+ for (const lockFile of lockFiles) {
92
+ const lockPath = path.join(mirrorPath, '.git', lockFile);
93
+ if (existsSync(lockPath)) {
94
+ try {
95
+ unlinkSync(lockPath);
96
+ log === null || log === void 0 ? void 0 : log.info(`Removed stale lock file: ${lockFile}`);
97
+ }
98
+ catch (_b) {
99
+ (_a = log === null || log === void 0 ? void 0 : log.warn) === null || _a === void 0 ? void 0 : _a.call(log, `Failed to remove lock file: ${lockFile}`);
100
+ }
101
+ }
102
+ }
103
+ }
73
104
  function execOrThrow(command, log) {
74
105
  return __awaiter(this, void 0, void 0, function* () {
75
106
  var _a, _b;
@@ -86,6 +117,7 @@ function execOrThrow(command, log) {
86
117
  command,
87
118
  stdout,
88
119
  stderr,
120
+ version: getPackageVersion(),
89
121
  });
90
122
  }
91
123
  });
@@ -0,0 +1 @@
1
+ export declare function getPackageVersion(): string;
@@ -0,0 +1,13 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import path from 'path';
3
+ export function getPackageVersion() {
4
+ var _a;
5
+ try {
6
+ const packagePath = path.join(__dirname, '../../package.json');
7
+ const packageJson = JSON.parse(readFileSync(packagePath, 'utf-8'));
8
+ return (_a = packageJson.version) !== null && _a !== void 0 ? _a : '*** unable to resolve version ***';
9
+ }
10
+ catch (_b) {
11
+ return '*** unable to resolve version ***';
12
+ }
13
+ }
package/build/git.js CHANGED
@@ -10,12 +10,14 @@ const fs_1 = require("fs");
10
10
  const path_1 = __importDefault(require("path"));
11
11
  const util_1 = require("util");
12
12
  const SpruceError_js_1 = __importDefault(require("./errors/SpruceError.js"));
13
+ const version_js_1 = require("./utilities/version.js");
13
14
  const execAsync = (0, util_1.promisify)(child_process_1.exec);
14
15
  async function gitCommit(mirrorPath, log) {
15
16
  const gitDir = path_1.default.join(mirrorPath, '.git');
16
17
  if (!(0, fs_1.existsSync)(gitDir)) {
17
18
  await execOrThrow(`git -C "${mirrorPath}" init`, log);
18
19
  }
20
+ cleanupGitLockFiles(mirrorPath, log);
19
21
  await execOrThrow(`git -C "${mirrorPath}" add -A`, log);
20
22
  const { stdout } = await execOrThrow(`git -C "${mirrorPath}" status --porcelain`);
21
23
  if (!stdout.trim()) {
@@ -27,37 +29,61 @@ async function gitCommit(mirrorPath, log) {
27
29
  return true;
28
30
  }
29
31
  async function gitPush(mirrorPath, remote, log) {
32
+ cleanupGitLockFiles(mirrorPath, log);
30
33
  const authedUrl = remote.url.replace('://', `://${remote.token}@`);
31
- const originExists = await remoteExists(mirrorPath, 'origin');
32
- if (originExists) {
33
- await execOrThrow(`git -C "${mirrorPath}" remote set-url origin "${authedUrl}"`);
34
- }
35
- else {
34
+ const currentUrl = await getRemoteUrl(mirrorPath, 'origin');
35
+ if (currentUrl === null) {
36
36
  await execOrThrow(`git -C "${mirrorPath}" remote add origin "${authedUrl}"`);
37
37
  }
38
- await execOrThrow(`git -C "${mirrorPath}" fetch origin`, log);
39
- if (await hasRemoteHead(mirrorPath)) {
40
- await execOrThrow(`git -C "${mirrorPath}" rebase origin/HEAD`, log);
38
+ else if (currentUrl !== authedUrl) {
39
+ await execOrThrow(`git -C "${mirrorPath}" remote set-url origin "${authedUrl}"`);
41
40
  }
41
+ await pullFromRemote(mirrorPath, log);
42
42
  await execOrThrow(`git -C "${mirrorPath}" push -u origin HEAD`, log);
43
43
  }
44
- async function remoteExists(mirrorPath, remoteName) {
44
+ async function pullFromRemote(mirrorPath, log) {
45
+ await execOrThrow(`git -C "${mirrorPath}" fetch origin`, log);
46
+ const branch = await getCurrentBranch(mirrorPath);
47
+ const remoteBranchExists = await checkRemoteBranchExists(mirrorPath, branch);
48
+ if (remoteBranchExists) {
49
+ await execOrThrow(`git -C "${mirrorPath}" rebase origin/${branch}`, log);
50
+ }
51
+ }
52
+ async function getCurrentBranch(mirrorPath) {
53
+ const { stdout } = await execAsync(`git -C "${mirrorPath}" rev-parse --abbrev-ref HEAD`);
54
+ return stdout.trim();
55
+ }
56
+ async function checkRemoteBranchExists(mirrorPath, branch) {
45
57
  try {
46
- const { stdout } = await execAsync(`git -C "${mirrorPath}" remote`);
47
- const remotes = stdout.trim().split('\n');
48
- return remotes.includes(remoteName);
58
+ const { stdout } = await execAsync(`git -C "${mirrorPath}" ls-remote --heads origin ${branch}`);
59
+ return stdout.trim().length > 0;
49
60
  }
50
61
  catch {
51
62
  return false;
52
63
  }
53
64
  }
54
- async function hasRemoteHead(mirrorPath) {
65
+ async function getRemoteUrl(mirrorPath, remoteName) {
55
66
  try {
56
- await execAsync(`git -C "${mirrorPath}" symbolic-ref -q refs/remotes/origin/HEAD`);
57
- return true;
67
+ const { stdout } = await execAsync(`git -C "${mirrorPath}" remote get-url ${remoteName}`);
68
+ return stdout.trim();
58
69
  }
59
70
  catch {
60
- return false;
71
+ return null;
72
+ }
73
+ }
74
+ function cleanupGitLockFiles(mirrorPath, log) {
75
+ const lockFiles = ['config.lock', 'index.lock', 'HEAD.lock'];
76
+ for (const lockFile of lockFiles) {
77
+ const lockPath = path_1.default.join(mirrorPath, '.git', lockFile);
78
+ if ((0, fs_1.existsSync)(lockPath)) {
79
+ try {
80
+ (0, fs_1.unlinkSync)(lockPath);
81
+ log?.info(`Removed stale lock file: ${lockFile}`);
82
+ }
83
+ catch {
84
+ log?.warn?.(`Failed to remove lock file: ${lockFile}`);
85
+ }
86
+ }
61
87
  }
62
88
  }
63
89
  async function execOrThrow(command, log) {
@@ -74,6 +100,7 @@ async function execOrThrow(command, log) {
74
100
  command,
75
101
  stdout,
76
102
  stderr,
103
+ version: (0, version_js_1.getPackageVersion)(),
77
104
  });
78
105
  }
79
106
  }
@@ -0,0 +1 @@
1
+ export declare function getPackageVersion(): string;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getPackageVersion = getPackageVersion;
7
+ const node_fs_1 = require("node:fs");
8
+ const path_1 = __importDefault(require("path"));
9
+ function getPackageVersion() {
10
+ try {
11
+ const packagePath = path_1.default.join(__dirname, '../../package.json');
12
+ const packageJson = JSON.parse((0, node_fs_1.readFileSync)(packagePath, 'utf-8'));
13
+ return packageJson.version ?? '*** unable to resolve version ***';
14
+ }
15
+ catch {
16
+ return '*** unable to resolve version ***';
17
+ }
18
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@regressionproof/snapshotter",
3
- "version": "0.5.3",
3
+ "version": "0.5.5",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -94,5 +94,5 @@
94
94
  "@sprucelabs/spruce-core-schemas": "^42.1.3",
95
95
  "@sprucelabs/spruce-skill-utils": "^34.0.3"
96
96
  },
97
- "gitHead": "d54c041a4d6b4cd88d35025ef1ee6d9acb6ad664"
97
+ "gitHead": "960e13b1ccdd3227d7e0aad8451e6eb851189746"
98
98
  }