@regressionproof/snapshotter 0.8.0 → 0.9.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.
Files changed (39) hide show
  1. package/build/GitCommandRunner.d.ts +10 -0
  2. package/build/GitCommandRunner.js +33 -0
  3. package/build/MirrorSyncer.d.ts +10 -0
  4. package/build/MirrorSyncer.js +39 -0
  5. package/build/Snapshotter.d.ts +1 -1
  6. package/build/Snapshotter.js +5 -5
  7. package/build/components/ErrorHandler.js +3 -3
  8. package/build/components/TestResultsWriter.d.ts +1 -1
  9. package/build/esm/GitCommandRunner.d.ts +10 -0
  10. package/build/esm/GitCommandRunner.js +41 -0
  11. package/build/esm/MirrorSyncer.d.ts +10 -0
  12. package/build/esm/MirrorSyncer.js +48 -0
  13. package/build/esm/Snapshotter.d.ts +1 -1
  14. package/build/esm/Snapshotter.js +3 -3
  15. package/build/esm/components/ErrorHandler.js +1 -1
  16. package/build/esm/components/TestResultsWriter.d.ts +1 -1
  17. package/build/esm/git.d.ts +1 -1
  18. package/build/esm/git.js +14 -38
  19. package/build/esm/index.d.ts +4 -3
  20. package/build/esm/index.js +3 -2
  21. package/build/esm/scripts/runPush.js +3 -3
  22. package/build/esm/scripts/runSnapshot.js +2 -2
  23. package/build/esm/strategies/AsyncStrategy.d.ts +2 -2
  24. package/build/esm/strategies/AsyncStrategy.js +2 -2
  25. package/build/esm/strategies/SnapshotStrategy.d.ts +1 -1
  26. package/build/esm/strategies/SyncStrategy.d.ts +2 -2
  27. package/build/esm/strategies/SyncStrategy.js +6 -6
  28. package/build/git.d.ts +1 -1
  29. package/build/git.js +13 -33
  30. package/build/index.d.ts +4 -3
  31. package/build/index.js +6 -4
  32. package/build/scripts/runPush.js +7 -7
  33. package/build/scripts/runSnapshot.js +4 -4
  34. package/build/strategies/AsyncStrategy.d.ts +2 -2
  35. package/build/strategies/AsyncStrategy.js +3 -3
  36. package/build/strategies/SnapshotStrategy.d.ts +1 -1
  37. package/build/strategies/SyncStrategy.d.ts +2 -2
  38. package/build/strategies/SyncStrategy.js +12 -12
  39. package/package.json +4 -4
@@ -0,0 +1,10 @@
1
+ export default class GitCommandRunner {
2
+ exec(command: string): Promise<{
3
+ stdout: string;
4
+ stderr: string;
5
+ }>;
6
+ execOrThrow(command: string): Promise<{
7
+ stdout: string;
8
+ stderr: string;
9
+ }>;
10
+ }
@@ -0,0 +1,33 @@
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
+ const child_process_1 = require("child_process");
7
+ const util_1 = require("util");
8
+ const SpruceError_1 = __importDefault(require("./errors/SpruceError"));
9
+ const version_1 = require("./utilities/version");
10
+ const execAsync = (0, util_1.promisify)(child_process_1.exec);
11
+ class GitCommandRunner {
12
+ async exec(command) {
13
+ return await execAsync(command);
14
+ }
15
+ async execOrThrow(command) {
16
+ try {
17
+ return await execAsync(command);
18
+ }
19
+ catch (err) {
20
+ const error = err;
21
+ const stdout = error.stdout ?? '';
22
+ const stderr = error.stderr ?? '';
23
+ throw new SpruceError_1.default({
24
+ code: 'EXEC_COMMAND_FAILED',
25
+ command,
26
+ stdout,
27
+ stderr,
28
+ version: (0, version_1.getPackageVersion)(),
29
+ });
30
+ }
31
+ }
32
+ }
33
+ exports.default = GitCommandRunner;
@@ -0,0 +1,10 @@
1
+ export default class MirrorSyncer {
2
+ private commandRunner;
3
+ syncBlocking(mirrorPath: string): Promise<void>;
4
+ /**
5
+ * Fire-and-forget sync to avoid slowing down callers like doctor --fix.
6
+ */
7
+ syncInBackground(mirrorPath: string): void;
8
+ private getCurrentBranch;
9
+ private checkRemoteBranchExists;
10
+ }
@@ -0,0 +1,39 @@
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
+ const GitCommandRunner_1 = __importDefault(require("./GitCommandRunner"));
7
+ class MirrorSyncer {
8
+ constructor() {
9
+ this.commandRunner = new GitCommandRunner_1.default();
10
+ }
11
+ async syncBlocking(mirrorPath) {
12
+ await this.commandRunner.execOrThrow(`git -C "${mirrorPath}" fetch origin`);
13
+ const branch = await this.getCurrentBranch(mirrorPath);
14
+ const remoteBranchExists = await this.checkRemoteBranchExists(mirrorPath, branch);
15
+ if (remoteBranchExists) {
16
+ await this.commandRunner.execOrThrow(`git -C "${mirrorPath}" rebase -X theirs origin/${branch}`);
17
+ }
18
+ }
19
+ /**
20
+ * Fire-and-forget sync to avoid slowing down callers like doctor --fix.
21
+ */
22
+ syncInBackground(mirrorPath) {
23
+ void this.syncBlocking(mirrorPath);
24
+ }
25
+ async getCurrentBranch(mirrorPath) {
26
+ const { stdout } = await this.commandRunner.exec(`git -C "${mirrorPath}" rev-parse --abbrev-ref HEAD`);
27
+ return stdout.trim();
28
+ }
29
+ async checkRemoteBranchExists(mirrorPath, branch) {
30
+ try {
31
+ const { stdout } = await this.commandRunner.exec(`git -C "${mirrorPath}" ls-remote --heads origin ${branch}`);
32
+ return stdout.trim().length > 0;
33
+ }
34
+ catch {
35
+ return false;
36
+ }
37
+ }
38
+ }
39
+ exports.default = MirrorSyncer;
@@ -1,4 +1,4 @@
1
- import { SnapshotOptions } from './snapshotter.types.js';
1
+ import { SnapshotOptions } from './snapshotter.types';
2
2
  export default class Snapshotter {
3
3
  private strategy;
4
4
  private constructor();
@@ -3,23 +3,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const ErrorHandler_js_1 = __importDefault(require("./components/ErrorHandler.js"));
7
- const AsyncStrategy_js_1 = __importDefault(require("./strategies/AsyncStrategy.js"));
8
- const SyncStrategy_js_1 = __importDefault(require("./strategies/SyncStrategy.js"));
6
+ const ErrorHandler_1 = __importDefault(require("./components/ErrorHandler"));
7
+ const AsyncStrategy_1 = __importDefault(require("./strategies/AsyncStrategy"));
8
+ const SyncStrategy_1 = __importDefault(require("./strategies/SyncStrategy"));
9
9
  class Snapshotter {
10
10
  constructor(strategy) {
11
11
  this.strategy = strategy;
12
12
  }
13
13
  static Snapshotter(options) {
14
14
  const mode = options?.mode ?? 'async';
15
- const strategy = mode === 'sync' ? SyncStrategy_js_1.default.Strategy() : AsyncStrategy_js_1.default.Strategy();
15
+ const strategy = mode === 'sync' ? SyncStrategy_1.default.Strategy() : AsyncStrategy_1.default.Strategy();
16
16
  return new this(strategy);
17
17
  }
18
18
  snapshot(options) {
19
19
  return this.strategy.execute(options);
20
20
  }
21
21
  checkForPreviousFailure(mirrorPath) {
22
- ErrorHandler_js_1.default.Handler().checkForPreviousFailure(mirrorPath);
22
+ ErrorHandler_1.default.Handler().checkForPreviousFailure(mirrorPath);
23
23
  }
24
24
  }
25
25
  exports.default = Snapshotter;
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const fs_1 = require("fs");
7
7
  const path_1 = __importDefault(require("path"));
8
- const SnapshotterState_js_1 = __importDefault(require("../utilities/SnapshotterState.js"));
8
+ const SnapshotterState_1 = __importDefault(require("../utilities/SnapshotterState"));
9
9
  class ErrorHandler {
10
10
  constructor() { }
11
11
  static Handler() {
@@ -23,7 +23,7 @@ class ErrorHandler {
23
23
  }
24
24
  }
25
25
  persistError(mirrorPath, err) {
26
- SnapshotterState_js_1.default.EnsureStateDir(mirrorPath);
26
+ SnapshotterState_1.default.EnsureStateDir(mirrorPath);
27
27
  const errorPath = this.getErrorFilePath(mirrorPath);
28
28
  const errorData = {
29
29
  message: err instanceof Error ? err.message : String(err),
@@ -39,7 +39,7 @@ class ErrorHandler {
39
39
  }
40
40
  }
41
41
  getErrorFilePath(mirrorPath) {
42
- const stateDir = SnapshotterState_js_1.default.GetStateDir(mirrorPath);
42
+ const stateDir = SnapshotterState_1.default.GetStateDir(mirrorPath);
43
43
  return path_1.default.join(stateDir, ErrorHandler.ERROR_FILE_NAME);
44
44
  }
45
45
  }
@@ -1,4 +1,4 @@
1
- import { TestResults } from '../snapshotter.types.js';
1
+ import { TestResults } from '../snapshotter.types';
2
2
  export default class TestResultsWriter {
3
3
  private constructor();
4
4
  static Writer(): TestResultsWriter;
@@ -0,0 +1,10 @@
1
+ export default class GitCommandRunner {
2
+ exec(command: string): Promise<{
3
+ stdout: string;
4
+ stderr: string;
5
+ }>;
6
+ execOrThrow(command: string): Promise<{
7
+ stdout: string;
8
+ stderr: string;
9
+ }>;
10
+ }
@@ -0,0 +1,41 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { exec } from 'child_process';
11
+ import { promisify } from 'util';
12
+ import SpruceError from './errors/SpruceError.js';
13
+ import { getPackageVersion } from './utilities/version.js';
14
+ const execAsync = promisify(exec);
15
+ export default class GitCommandRunner {
16
+ exec(command) {
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ return yield execAsync(command);
19
+ });
20
+ }
21
+ execOrThrow(command) {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ var _a, _b;
24
+ try {
25
+ return yield execAsync(command);
26
+ }
27
+ catch (err) {
28
+ const error = err;
29
+ const stdout = (_a = error.stdout) !== null && _a !== void 0 ? _a : '';
30
+ const stderr = (_b = error.stderr) !== null && _b !== void 0 ? _b : '';
31
+ throw new SpruceError({
32
+ code: 'EXEC_COMMAND_FAILED',
33
+ command,
34
+ stdout,
35
+ stderr,
36
+ version: getPackageVersion(),
37
+ });
38
+ }
39
+ });
40
+ }
41
+ }
@@ -0,0 +1,10 @@
1
+ export default class MirrorSyncer {
2
+ private commandRunner;
3
+ syncBlocking(mirrorPath: string): Promise<void>;
4
+ /**
5
+ * Fire-and-forget sync to avoid slowing down callers like doctor --fix.
6
+ */
7
+ syncInBackground(mirrorPath: string): void;
8
+ private getCurrentBranch;
9
+ private checkRemoteBranchExists;
10
+ }
@@ -0,0 +1,48 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import GitCommandRunner from './GitCommandRunner.js';
11
+ export default class MirrorSyncer {
12
+ constructor() {
13
+ this.commandRunner = new GitCommandRunner();
14
+ }
15
+ syncBlocking(mirrorPath) {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ yield this.commandRunner.execOrThrow(`git -C "${mirrorPath}" fetch origin`);
18
+ const branch = yield this.getCurrentBranch(mirrorPath);
19
+ const remoteBranchExists = yield this.checkRemoteBranchExists(mirrorPath, branch);
20
+ if (remoteBranchExists) {
21
+ yield this.commandRunner.execOrThrow(`git -C "${mirrorPath}" rebase -X theirs origin/${branch}`);
22
+ }
23
+ });
24
+ }
25
+ /**
26
+ * Fire-and-forget sync to avoid slowing down callers like doctor --fix.
27
+ */
28
+ syncInBackground(mirrorPath) {
29
+ void this.syncBlocking(mirrorPath);
30
+ }
31
+ getCurrentBranch(mirrorPath) {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ const { stdout } = yield this.commandRunner.exec(`git -C "${mirrorPath}" rev-parse --abbrev-ref HEAD`);
34
+ return stdout.trim();
35
+ });
36
+ }
37
+ checkRemoteBranchExists(mirrorPath, branch) {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ try {
40
+ const { stdout } = yield this.commandRunner.exec(`git -C "${mirrorPath}" ls-remote --heads origin ${branch}`);
41
+ return stdout.trim().length > 0;
42
+ }
43
+ catch (_a) {
44
+ return false;
45
+ }
46
+ });
47
+ }
48
+ }
@@ -1,4 +1,4 @@
1
- import { SnapshotOptions } from './snapshotter.types.js';
1
+ import { SnapshotOptions } from './snapshotter.types';
2
2
  export default class Snapshotter {
3
3
  private strategy;
4
4
  private constructor();
@@ -1,6 +1,6 @@
1
- import ErrorHandler from './components/ErrorHandler.js.js';
2
- import AsyncStrategy from './strategies/AsyncStrategy.js.js';
3
- import SyncStrategy from './strategies/SyncStrategy.js.js';
1
+ import ErrorHandler from './components/ErrorHandler.js';
2
+ import AsyncStrategy from './strategies/AsyncStrategy.js';
3
+ import SyncStrategy from './strategies/SyncStrategy.js';
4
4
  export default class Snapshotter {
5
5
  constructor(strategy) {
6
6
  this.strategy = strategy;
@@ -1,6 +1,6 @@
1
1
  import { existsSync, readFileSync, unlinkSync, writeFileSync } from 'fs';
2
2
  import path from 'path';
3
- import SnapshotterState from '../utilities/SnapshotterState.js.js';
3
+ import SnapshotterState from '../utilities/SnapshotterState.js';
4
4
  class ErrorHandler {
5
5
  constructor() { }
6
6
  static Handler() {
@@ -1,4 +1,4 @@
1
- import { TestResults } from '../snapshotter.types.js';
1
+ import { TestResults } from '../snapshotter.types';
2
2
  export default class TestResultsWriter {
3
3
  private constructor();
4
4
  static Writer(): TestResultsWriter;
@@ -1,4 +1,4 @@
1
1
  import { Log } from '@sprucelabs/spruce-skill-utils';
2
- import { RemoteOptions } from './snapshotter.types.js';
2
+ import { RemoteOptions } from './snapshotter.types';
3
3
  export declare function gitCommit(mirrorPath: string, log?: Log): Promise<boolean>;
4
4
  export declare function gitPush(mirrorPath: string, remote: RemoteOptions, log?: Log): Promise<void>;
package/build/esm/git.js CHANGED
@@ -7,13 +7,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { exec } from 'child_process';
11
10
  import { existsSync, unlinkSync } from 'fs';
12
11
  import path from 'path';
13
- import { promisify } from 'util';
14
- import SpruceError from './errors/SpruceError.js.js';
15
- import { getPackageVersion } from './utilities/version.js.js';
16
- const execAsync = promisify(exec);
12
+ import GitCommandRunner from './GitCommandRunner.js';
13
+ import MirrorSyncer from './MirrorSyncer.js';
14
+ const mirrorSyncer = new MirrorSyncer();
15
+ const commandRunner = new GitCommandRunner();
17
16
  export function gitCommit(mirrorPath, log) {
18
17
  return __awaiter(this, void 0, void 0, function* () {
19
18
  const gitDir = path.join(mirrorPath, '.git');
@@ -48,36 +47,21 @@ export function gitPush(mirrorPath, remote, log) {
48
47
  });
49
48
  }
50
49
  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 -X theirs 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) {
67
50
  return __awaiter(this, void 0, void 0, function* () {
68
51
  try {
69
- const { stdout } = yield execAsync(`git -C "${mirrorPath}" ls-remote --heads origin ${branch}`);
70
- return stdout.trim().length > 0;
52
+ yield mirrorSyncer.syncBlocking(mirrorPath);
71
53
  }
72
- catch (_a) {
73
- return false;
54
+ catch (err) {
55
+ const message = err instanceof Error ? err.message : String(err);
56
+ log === null || log === void 0 ? void 0 : log.error('Mirror sync failed', message);
57
+ throw err;
74
58
  }
75
59
  });
76
60
  }
77
61
  function getRemoteUrl(mirrorPath, remoteName) {
78
62
  return __awaiter(this, void 0, void 0, function* () {
79
63
  try {
80
- const { stdout } = yield execAsync(`git -C "${mirrorPath}" remote get-url ${remoteName}`);
64
+ const { stdout } = yield commandRunner.exec(`git -C "${mirrorPath}" remote get-url ${remoteName}`);
81
65
  return stdout.trim();
82
66
  }
83
67
  catch (_a) {
@@ -103,22 +87,14 @@ function cleanupGitLockFiles(mirrorPath, log) {
103
87
  }
104
88
  function execOrThrow(command, log) {
105
89
  return __awaiter(this, void 0, void 0, function* () {
106
- var _a, _b;
90
+ var _a;
107
91
  try {
108
- return yield execAsync(command);
92
+ return yield commandRunner.execOrThrow(command);
109
93
  }
110
94
  catch (err) {
111
95
  const error = err;
112
- const stdout = (_a = error.stdout) !== null && _a !== void 0 ? _a : '';
113
- const stderr = (_b = error.stderr) !== null && _b !== void 0 ? _b : '';
114
- log === null || log === void 0 ? void 0 : log.error('Command failed', command, stderr);
115
- throw new SpruceError({
116
- code: 'EXEC_COMMAND_FAILED',
117
- command,
118
- stdout,
119
- stderr,
120
- version: getPackageVersion(),
121
- });
96
+ log === null || log === void 0 ? void 0 : log.error('Command failed', command, (_a = error.stderr) !== null && _a !== void 0 ? _a : error.message);
97
+ throw err;
122
98
  }
123
99
  });
124
100
  }
@@ -1,3 +1,4 @@
1
- export { default as Snapshotter } from './Snapshotter.js';
2
- export type { SnapshotterOptions } from './Snapshotter.js';
3
- export * from './snapshotter.types.js';
1
+ export { default as Snapshotter } from './Snapshotter';
2
+ export type { SnapshotterOptions } from './Snapshotter';
3
+ export * from './snapshotter.types';
4
+ export { default as MirrorSyncer } from './MirrorSyncer';
@@ -1,2 +1,3 @@
1
- export { default as Snapshotter } from './Snapshotter.js.js';
2
- export * from './snapshotter.types.js.js';
1
+ export { default as Snapshotter } from './Snapshotter.js';
2
+ export * from './snapshotter.types.js';
3
+ export { default as MirrorSyncer } from './MirrorSyncer.js';
@@ -10,9 +10,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { existsSync, unlinkSync, writeFileSync } from 'fs';
11
11
  import path from 'path';
12
12
  import { buildLog } from '@sprucelabs/spruce-skill-utils';
13
- import ErrorHandler from '../components/ErrorHandler.js.js';
14
- import { gitPush } from '../git.js.js';
15
- import SnapshotterState from '../utilities/SnapshotterState.js.js';
13
+ import ErrorHandler from '../components/ErrorHandler.js';
14
+ import { gitPush } from '../git.js';
15
+ import SnapshotterState from '../utilities/SnapshotterState.js';
16
16
  const LOCK_FILE_NAME = 'push.lock';
17
17
  const PENDING_FILE_NAME = 'push.pending';
18
18
  const log = buildLog('Snapshotter');
@@ -10,8 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { existsSync, readFileSync, unlinkSync, writeFileSync } from 'fs';
11
11
  import path from 'path';
12
12
  import { buildLog } from '@sprucelabs/spruce-skill-utils';
13
- import ErrorHandler from '../components/ErrorHandler.js.js';
14
- import SyncStrategy from '../strategies/SyncStrategy.js.js';
13
+ import ErrorHandler from '../components/ErrorHandler.js';
14
+ import SyncStrategy from '../strategies/SyncStrategy.js';
15
15
  const LOCK_FILE_NAME = 'snapshot.lock';
16
16
  const PENDING_FILE_NAME = 'pending.json';
17
17
  const log = buildLog('Snapshotter');
@@ -1,5 +1,5 @@
1
- import { SnapshotOptions } from '../snapshotter.types.js';
2
- import SnapshotStrategy from './SnapshotStrategy.js';
1
+ import { SnapshotOptions } from '../snapshotter.types';
2
+ import SnapshotStrategy from './SnapshotStrategy';
3
3
  export default class AsyncStrategy implements SnapshotStrategy {
4
4
  private log;
5
5
  private scriptPath;
@@ -2,11 +2,11 @@ import { spawn } from 'child_process';
2
2
  import { writeFileSync } from 'fs';
3
3
  import path from 'path';
4
4
  import { buildLog } from '@sprucelabs/spruce-skill-utils';
5
- import SnapshotterState from '../utilities/SnapshotterState.js.js';
5
+ import SnapshotterState from '../utilities/SnapshotterState.js';
6
6
  export default class AsyncStrategy {
7
7
  constructor() {
8
8
  this.log = buildLog('Snapshotter');
9
- this.scriptPath = path.join(__dirname, '..', 'scripts', 'runSnapshot.js');
9
+ this.scriptPath = path.join(__dirname, '..', 'scripts', 'runSnapshot');
10
10
  }
11
11
  static Strategy() {
12
12
  return new this();
@@ -1,4 +1,4 @@
1
- import { SnapshotOptions } from '../snapshotter.types.js';
1
+ import { SnapshotOptions } from '../snapshotter.types';
2
2
  export default interface SnapshotStrategy {
3
3
  execute(options: SnapshotOptions): Promise<void> | void;
4
4
  }
@@ -1,5 +1,5 @@
1
- import { SnapshotOptions } from '../snapshotter.types.js';
2
- import SnapshotStrategy from './SnapshotStrategy.js';
1
+ import { SnapshotOptions } from '../snapshotter.types';
2
+ import SnapshotStrategy from './SnapshotStrategy';
3
3
  export default class SyncStrategy implements SnapshotStrategy {
4
4
  private log;
5
5
  private pushScriptPath;
@@ -10,15 +10,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { spawn } from 'child_process';
11
11
  import path from 'path';
12
12
  import { buildLog } from '@sprucelabs/spruce-skill-utils';
13
- import ErrorHandler from '../components/ErrorHandler.js.js';
14
- import FileSyncer from '../components/FileSyncer.js.js';
15
- import TestResultsWriter from '../components/TestResultsWriter.js.js';
16
- import { gitCommit } from '../git.js.js';
17
- import SnapshotterState from '../utilities/SnapshotterState.js.js';
13
+ import ErrorHandler from '../components/ErrorHandler.js';
14
+ import FileSyncer from '../components/FileSyncer.js';
15
+ import TestResultsWriter from '../components/TestResultsWriter.js';
16
+ import { gitCommit } from '../git.js';
17
+ import SnapshotterState from '../utilities/SnapshotterState.js';
18
18
  export default class SyncStrategy {
19
19
  constructor() {
20
20
  this.log = buildLog('Snapshotter');
21
- this.pushScriptPath = path.join(__dirname, '..', 'scripts', 'runPush.js');
21
+ this.pushScriptPath = path.join(__dirname, '..', 'scripts', 'runPush');
22
22
  }
23
23
  static Strategy() {
24
24
  return new this();
package/build/git.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import { Log } from '@sprucelabs/spruce-skill-utils';
2
- import { RemoteOptions } from './snapshotter.types.js';
2
+ import { RemoteOptions } from './snapshotter.types';
3
3
  export declare function gitCommit(mirrorPath: string, log?: Log): Promise<boolean>;
4
4
  export declare function gitPush(mirrorPath: string, remote: RemoteOptions, log?: Log): Promise<void>;
package/build/git.js CHANGED
@@ -5,13 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.gitCommit = gitCommit;
7
7
  exports.gitPush = gitPush;
8
- const child_process_1 = require("child_process");
9
8
  const fs_1 = require("fs");
10
9
  const path_1 = __importDefault(require("path"));
11
- const util_1 = require("util");
12
- const SpruceError_js_1 = __importDefault(require("./errors/SpruceError.js"));
13
- const version_js_1 = require("./utilities/version.js");
14
- const execAsync = (0, util_1.promisify)(child_process_1.exec);
10
+ const GitCommandRunner_1 = __importDefault(require("./GitCommandRunner"));
11
+ const MirrorSyncer_1 = __importDefault(require("./MirrorSyncer"));
12
+ const mirrorSyncer = new MirrorSyncer_1.default();
13
+ const commandRunner = new GitCommandRunner_1.default();
15
14
  async function gitCommit(mirrorPath, log) {
16
15
  const gitDir = path_1.default.join(mirrorPath, '.git');
17
16
  if (!(0, fs_1.existsSync)(gitDir)) {
@@ -42,29 +41,18 @@ async function gitPush(mirrorPath, remote, log) {
42
41
  await execOrThrow(`git -C "${mirrorPath}" push -u origin HEAD`, log);
43
42
  }
44
43
  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 -X theirs 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) {
57
44
  try {
58
- const { stdout } = await execAsync(`git -C "${mirrorPath}" ls-remote --heads origin ${branch}`);
59
- return stdout.trim().length > 0;
45
+ await mirrorSyncer.syncBlocking(mirrorPath);
60
46
  }
61
- catch {
62
- return false;
47
+ catch (err) {
48
+ const message = err instanceof Error ? err.message : String(err);
49
+ log?.error('Mirror sync failed', message);
50
+ throw err;
63
51
  }
64
52
  }
65
53
  async function getRemoteUrl(mirrorPath, remoteName) {
66
54
  try {
67
- const { stdout } = await execAsync(`git -C "${mirrorPath}" remote get-url ${remoteName}`);
55
+ const { stdout } = await commandRunner.exec(`git -C "${mirrorPath}" remote get-url ${remoteName}`);
68
56
  return stdout.trim();
69
57
  }
70
58
  catch {
@@ -88,19 +76,11 @@ function cleanupGitLockFiles(mirrorPath, log) {
88
76
  }
89
77
  async function execOrThrow(command, log) {
90
78
  try {
91
- return await execAsync(command);
79
+ return await commandRunner.execOrThrow(command);
92
80
  }
93
81
  catch (err) {
94
82
  const error = err;
95
- const stdout = error.stdout ?? '';
96
- const stderr = error.stderr ?? '';
97
- log?.error('Command failed', command, stderr);
98
- throw new SpruceError_js_1.default({
99
- code: 'EXEC_COMMAND_FAILED',
100
- command,
101
- stdout,
102
- stderr,
103
- version: (0, version_js_1.getPackageVersion)(),
104
- });
83
+ log?.error('Command failed', command, error.stderr ?? error.message);
84
+ throw err;
105
85
  }
106
86
  }
package/build/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- export { default as Snapshotter } from './Snapshotter.js';
2
- export type { SnapshotterOptions } from './Snapshotter.js';
3
- export * from './snapshotter.types.js';
1
+ export { default as Snapshotter } from './Snapshotter';
2
+ export type { SnapshotterOptions } from './Snapshotter';
3
+ export * from './snapshotter.types';
4
+ export { default as MirrorSyncer } from './MirrorSyncer';
package/build/index.js CHANGED
@@ -17,7 +17,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.Snapshotter = void 0;
21
- var Snapshotter_js_1 = require("./Snapshotter.js");
22
- Object.defineProperty(exports, "Snapshotter", { enumerable: true, get: function () { return __importDefault(Snapshotter_js_1).default; } });
23
- __exportStar(require("./snapshotter.types.js"), exports);
20
+ exports.MirrorSyncer = exports.Snapshotter = void 0;
21
+ var Snapshotter_1 = require("./Snapshotter");
22
+ Object.defineProperty(exports, "Snapshotter", { enumerable: true, get: function () { return __importDefault(Snapshotter_1).default; } });
23
+ __exportStar(require("./snapshotter.types"), exports);
24
+ var MirrorSyncer_1 = require("./MirrorSyncer");
25
+ Object.defineProperty(exports, "MirrorSyncer", { enumerable: true, get: function () { return __importDefault(MirrorSyncer_1).default; } });
@@ -6,9 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const fs_1 = require("fs");
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils");
9
- const ErrorHandler_js_1 = __importDefault(require("../components/ErrorHandler.js"));
10
- const git_js_1 = require("../git.js");
11
- const SnapshotterState_js_1 = __importDefault(require("../utilities/SnapshotterState.js"));
9
+ const ErrorHandler_1 = __importDefault(require("../components/ErrorHandler"));
10
+ const git_1 = require("../git");
11
+ const SnapshotterState_1 = __importDefault(require("../utilities/SnapshotterState"));
12
12
  const LOCK_FILE_NAME = 'push.lock';
13
13
  const PENDING_FILE_NAME = 'push.pending';
14
14
  const log = (0, spruce_skill_utils_1.buildLog)('Snapshotter');
@@ -16,7 +16,7 @@ async function main() {
16
16
  const mirrorPath = getEnvOrExit('MIRROR_PATH');
17
17
  const remoteUrl = getEnvOrExit('REMOTE_URL');
18
18
  const remoteToken = getEnvOrExit('REMOTE_TOKEN');
19
- const stateDir = SnapshotterState_js_1.default.EnsureStateDir(mirrorPath);
19
+ const stateDir = SnapshotterState_1.default.EnsureStateDir(mirrorPath);
20
20
  const lockPath = path_1.default.join(stateDir, LOCK_FILE_NAME);
21
21
  const pendingPath = path_1.default.join(stateDir, PENDING_FILE_NAME);
22
22
  if ((0, fs_1.existsSync)(lockPath)) {
@@ -45,14 +45,14 @@ async function processLoop(mirrorPath, remote, pendingPath) {
45
45
  }
46
46
  try {
47
47
  log.info('Push starting', remote.url);
48
- await (0, git_js_1.gitPush)(mirrorPath, remote, log);
48
+ await (0, git_1.gitPush)(mirrorPath, remote, log);
49
49
  log.info('Push completed', remote.url);
50
- ErrorHandler_js_1.default.Handler().clearError(mirrorPath);
50
+ ErrorHandler_1.default.Handler().clearError(mirrorPath);
51
51
  }
52
52
  catch (err) {
53
53
  const message = err instanceof Error ? err.message : String(err);
54
54
  log.error('Push failed', message);
55
- ErrorHandler_js_1.default.Handler().persistError(mirrorPath, err);
55
+ ErrorHandler_1.default.Handler().persistError(mirrorPath, err);
56
56
  (0, fs_1.writeFileSync)(pendingPath, new Date().toISOString());
57
57
  return;
58
58
  }
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const fs_1 = require("fs");
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils");
9
- const ErrorHandler_js_1 = __importDefault(require("../components/ErrorHandler.js"));
10
- const SyncStrategy_js_1 = __importDefault(require("../strategies/SyncStrategy.js"));
9
+ const ErrorHandler_1 = __importDefault(require("../components/ErrorHandler"));
10
+ const SyncStrategy_1 = __importDefault(require("../strategies/SyncStrategy"));
11
11
  const LOCK_FILE_NAME = 'snapshot.lock';
12
12
  const PENDING_FILE_NAME = 'pending.json';
13
13
  const log = (0, spruce_skill_utils_1.buildLog)('Snapshotter');
@@ -42,12 +42,12 @@ async function processLoop(stateDir) {
42
42
  }
43
43
  async function executeSnapshot(options) {
44
44
  try {
45
- await SyncStrategy_js_1.default.Strategy().execute(options);
45
+ await SyncStrategy_1.default.Strategy().execute(options);
46
46
  }
47
47
  catch (err) {
48
48
  const message = err instanceof Error ? err.message : String(err);
49
49
  log.error('Snapshot failed (will surface on next test run)', message);
50
- ErrorHandler_js_1.default.Handler().persistError(options.mirrorPath, err);
50
+ ErrorHandler_1.default.Handler().persistError(options.mirrorPath, err);
51
51
  }
52
52
  }
53
53
  main().catch((err) => {
@@ -1,5 +1,5 @@
1
- import { SnapshotOptions } from '../snapshotter.types.js';
2
- import SnapshotStrategy from './SnapshotStrategy.js';
1
+ import { SnapshotOptions } from '../snapshotter.types';
2
+ import SnapshotStrategy from './SnapshotStrategy';
3
3
  export default class AsyncStrategy implements SnapshotStrategy {
4
4
  private log;
5
5
  private scriptPath;
@@ -7,11 +7,11 @@ const child_process_1 = require("child_process");
7
7
  const fs_1 = require("fs");
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils");
10
- const SnapshotterState_js_1 = __importDefault(require("../utilities/SnapshotterState.js"));
10
+ const SnapshotterState_1 = __importDefault(require("../utilities/SnapshotterState"));
11
11
  class AsyncStrategy {
12
12
  constructor() {
13
13
  this.log = (0, spruce_skill_utils_1.buildLog)('Snapshotter');
14
- this.scriptPath = path_1.default.join(__dirname, '..', 'scripts', 'runSnapshot.js');
14
+ this.scriptPath = path_1.default.join(__dirname, '..', 'scripts', 'runSnapshot');
15
15
  }
16
16
  static Strategy() {
17
17
  return new this();
@@ -22,7 +22,7 @@ class AsyncStrategy {
22
22
  this.log.info('Snapshot queued (running in background)', options.mirrorPath);
23
23
  }
24
24
  writeOptionsFile(options) {
25
- const stateDir = SnapshotterState_js_1.default.EnsureStateDir(options.mirrorPath);
25
+ const stateDir = SnapshotterState_1.default.EnsureStateDir(options.mirrorPath);
26
26
  const optionsPath = path_1.default.join(stateDir, 'pending.json');
27
27
  (0, fs_1.writeFileSync)(optionsPath, JSON.stringify(options, null, 2));
28
28
  return stateDir;
@@ -1,4 +1,4 @@
1
- import { SnapshotOptions } from '../snapshotter.types.js';
1
+ import { SnapshotOptions } from '../snapshotter.types';
2
2
  export default interface SnapshotStrategy {
3
3
  execute(options: SnapshotOptions): Promise<void> | void;
4
4
  }
@@ -1,5 +1,5 @@
1
- import { SnapshotOptions } from '../snapshotter.types.js';
2
- import SnapshotStrategy from './SnapshotStrategy.js';
1
+ import { SnapshotOptions } from '../snapshotter.types';
2
+ import SnapshotStrategy from './SnapshotStrategy';
3
3
  export default class SyncStrategy implements SnapshotStrategy {
4
4
  private log;
5
5
  private pushScriptPath;
@@ -6,15 +6,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const child_process_1 = require("child_process");
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils");
9
- const ErrorHandler_js_1 = __importDefault(require("../components/ErrorHandler.js"));
10
- const FileSyncer_js_1 = __importDefault(require("../components/FileSyncer.js"));
11
- const TestResultsWriter_js_1 = __importDefault(require("../components/TestResultsWriter.js"));
12
- const git_js_1 = require("../git.js");
13
- const SnapshotterState_js_1 = __importDefault(require("../utilities/SnapshotterState.js"));
9
+ const ErrorHandler_1 = __importDefault(require("../components/ErrorHandler"));
10
+ const FileSyncer_1 = __importDefault(require("../components/FileSyncer"));
11
+ const TestResultsWriter_1 = __importDefault(require("../components/TestResultsWriter"));
12
+ const git_1 = require("../git");
13
+ const SnapshotterState_1 = __importDefault(require("../utilities/SnapshotterState"));
14
14
  class SyncStrategy {
15
15
  constructor() {
16
16
  this.log = (0, spruce_skill_utils_1.buildLog)('Snapshotter');
17
- this.pushScriptPath = path_1.default.join(__dirname, '..', 'scripts', 'runPush.js');
17
+ this.pushScriptPath = path_1.default.join(__dirname, '..', 'scripts', 'runPush');
18
18
  }
19
19
  static Strategy() {
20
20
  return new this();
@@ -24,15 +24,15 @@ class SyncStrategy {
24
24
  const { mirrorPath, testResults, remote } = options;
25
25
  this.log.info('Starting snapshot', sourcePath, mirrorPath);
26
26
  try {
27
- await FileSyncer_js_1.default.Syncer().sync(sourcePath, mirrorPath);
28
- SnapshotterState_js_1.default.CleanupLegacyMirrorState(mirrorPath);
27
+ await FileSyncer_1.default.Syncer().sync(sourcePath, mirrorPath);
28
+ SnapshotterState_1.default.CleanupLegacyMirrorState(mirrorPath);
29
29
  this.log.info('Files synced', mirrorPath);
30
- TestResultsWriter_js_1.default.Writer().write(mirrorPath, testResults);
30
+ TestResultsWriter_1.default.Writer().write(mirrorPath, testResults);
31
31
  this.log.info('Test results saved', mirrorPath);
32
- const committed = await (0, git_js_1.gitCommit)(mirrorPath, this.log);
32
+ const committed = await (0, git_1.gitCommit)(mirrorPath, this.log);
33
33
  if (!committed) {
34
34
  this.log.info('No changes to commit', mirrorPath);
35
- ErrorHandler_js_1.default.Handler().clearError(mirrorPath);
35
+ ErrorHandler_1.default.Handler().clearError(mirrorPath);
36
36
  return;
37
37
  }
38
38
  this.log.info('Commit created, queueing push', remote.url);
@@ -41,7 +41,7 @@ class SyncStrategy {
41
41
  catch (err) {
42
42
  const message = err instanceof Error ? err.message : String(err);
43
43
  this.log.error('Snapshot failed', message);
44
- ErrorHandler_js_1.default.Handler().persistError(mirrorPath, err);
44
+ ErrorHandler_1.default.Handler().persistError(mirrorPath, err);
45
45
  throw err;
46
46
  }
47
47
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@regressionproof/snapshotter",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -14,7 +14,7 @@
14
14
  "exports": {
15
15
  ".": {
16
16
  "import": {
17
- "types": "./build/esm/index.d.ts",
17
+ "types": "./build/index.d.ts",
18
18
  "default": "./build/esm/index.js"
19
19
  },
20
20
  "require": {
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "scripts": {
27
27
  "build.ci": "yarn run build.tsc && yarn run build.resolve-paths && yarn run lint",
28
- "build.dev": "yarn run build.tsc --sourceMap ; yarn run resolve-paths.lint",
28
+ "build.dev": "yarn run build.dist",
29
29
  "build.copy-files": "mkdir -p build && rsync -avzq --exclude='*.ts' ./src/ ./build/",
30
30
  "build.resolve-paths": "resolve-path-aliases --target build --patterns '**/*.js,**/*.d.ts'",
31
31
  "build.tsc": "yarn run build.copy-files && tsc",
@@ -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": "991c41905951b8c069c69b9a016affe53e819238"
97
+ "gitHead": "6f734949b5cd75ead7249cd6d6b4305cf350274e"
98
98
  }