@regressionproof/snapshotter 0.5.3 → 0.5.4

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
@@ -12,6 +12,7 @@ import { existsSync } 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* () {
@@ -40,30 +41,43 @@ export function gitPush(mirrorPath, remote, log) {
40
41
  else {
41
42
  yield execOrThrow(`git -C "${mirrorPath}" remote add origin "${authedUrl}"`);
42
43
  }
44
+ yield pullFromRemote(mirrorPath, log);
45
+ yield execOrThrow(`git -C "${mirrorPath}" push -u origin HEAD`, log);
46
+ });
47
+ }
48
+ function pullFromRemote(mirrorPath, log) {
49
+ return __awaiter(this, void 0, void 0, function* () {
43
50
  yield execOrThrow(`git -C "${mirrorPath}" fetch origin`, log);
44
- if (yield hasRemoteHead(mirrorPath)) {
45
- yield execOrThrow(`git -C "${mirrorPath}" rebase origin/HEAD`, log);
51
+ const branch = yield getCurrentBranch(mirrorPath);
52
+ const remoteBranchExists = yield checkRemoteBranchExists(mirrorPath, branch);
53
+ if (remoteBranchExists) {
54
+ yield execOrThrow(`git -C "${mirrorPath}" rebase origin/${branch}`, log);
46
55
  }
47
- yield execOrThrow(`git -C "${mirrorPath}" push -u origin HEAD`, log);
48
56
  });
49
57
  }
50
- function remoteExists(mirrorPath, remoteName) {
58
+ function getCurrentBranch(mirrorPath) {
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ const { stdout } = yield execAsync(`git -C "${mirrorPath}" rev-parse --abbrev-ref HEAD`);
61
+ return stdout.trim();
62
+ });
63
+ }
64
+ function checkRemoteBranchExists(mirrorPath, branch) {
51
65
  return __awaiter(this, void 0, void 0, function* () {
52
66
  try {
53
- const { stdout } = yield execAsync(`git -C "${mirrorPath}" remote`);
54
- const remotes = stdout.trim().split('\n');
55
- return remotes.includes(remoteName);
67
+ const { stdout } = yield execAsync(`git -C "${mirrorPath}" ls-remote --heads origin ${branch}`);
68
+ return stdout.trim().length > 0;
56
69
  }
57
70
  catch (_a) {
58
71
  return false;
59
72
  }
60
73
  });
61
74
  }
62
- function hasRemoteHead(mirrorPath) {
75
+ function remoteExists(mirrorPath, remoteName) {
63
76
  return __awaiter(this, void 0, void 0, function* () {
64
77
  try {
65
- yield execAsync(`git -C "${mirrorPath}" symbolic-ref -q refs/remotes/origin/HEAD`);
66
- return true;
78
+ const { stdout } = yield execAsync(`git -C "${mirrorPath}" remote`);
79
+ const remotes = stdout.trim().split('\n');
80
+ return remotes.includes(remoteName);
67
81
  }
68
82
  catch (_a) {
69
83
  return false;
@@ -86,6 +100,7 @@ function execOrThrow(command, log) {
86
100
  command,
87
101
  stdout,
88
102
  stderr,
103
+ version: getPackageVersion(),
89
104
  });
90
105
  }
91
106
  });
@@ -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,6 +10,7 @@ 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');
@@ -35,26 +36,35 @@ async function gitPush(mirrorPath, remote, log) {
35
36
  else {
36
37
  await execOrThrow(`git -C "${mirrorPath}" remote add origin "${authedUrl}"`);
37
38
  }
39
+ await pullFromRemote(mirrorPath, log);
40
+ await execOrThrow(`git -C "${mirrorPath}" push -u origin HEAD`, log);
41
+ }
42
+ async function pullFromRemote(mirrorPath, log) {
38
43
  await execOrThrow(`git -C "${mirrorPath}" fetch origin`, log);
39
- if (await hasRemoteHead(mirrorPath)) {
40
- await execOrThrow(`git -C "${mirrorPath}" rebase origin/HEAD`, log);
44
+ const branch = await getCurrentBranch(mirrorPath);
45
+ const remoteBranchExists = await checkRemoteBranchExists(mirrorPath, branch);
46
+ if (remoteBranchExists) {
47
+ await execOrThrow(`git -C "${mirrorPath}" rebase origin/${branch}`, log);
41
48
  }
42
- await execOrThrow(`git -C "${mirrorPath}" push -u origin HEAD`, log);
43
49
  }
44
- async function remoteExists(mirrorPath, remoteName) {
50
+ async function getCurrentBranch(mirrorPath) {
51
+ const { stdout } = await execAsync(`git -C "${mirrorPath}" rev-parse --abbrev-ref HEAD`);
52
+ return stdout.trim();
53
+ }
54
+ async function checkRemoteBranchExists(mirrorPath, branch) {
45
55
  try {
46
- const { stdout } = await execAsync(`git -C "${mirrorPath}" remote`);
47
- const remotes = stdout.trim().split('\n');
48
- return remotes.includes(remoteName);
56
+ const { stdout } = await execAsync(`git -C "${mirrorPath}" ls-remote --heads origin ${branch}`);
57
+ return stdout.trim().length > 0;
49
58
  }
50
59
  catch {
51
60
  return false;
52
61
  }
53
62
  }
54
- async function hasRemoteHead(mirrorPath) {
63
+ async function remoteExists(mirrorPath, remoteName) {
55
64
  try {
56
- await execAsync(`git -C "${mirrorPath}" symbolic-ref -q refs/remotes/origin/HEAD`);
57
- return true;
65
+ const { stdout } = await execAsync(`git -C "${mirrorPath}" remote`);
66
+ const remotes = stdout.trim().split('\n');
67
+ return remotes.includes(remoteName);
58
68
  }
59
69
  catch {
60
70
  return false;
@@ -74,6 +84,7 @@ async function execOrThrow(command, log) {
74
84
  command,
75
85
  stdout,
76
86
  stderr,
87
+ version: (0, version_js_1.getPackageVersion)(),
77
88
  });
78
89
  }
79
90
  }
@@ -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.4",
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": "01c36085fc6f8c0fdc7778de7f7dee6e194cb3f4"
98
98
  }