@regressionproof/snapshotter 0.7.1 → 0.7.2

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.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,83 @@
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 { existsSync, mkdirSync, unlinkSync, writeFileSync } from 'fs';
11
+ import path from 'path';
12
+ import { buildLog } from '@sprucelabs/spruce-skill-utils';
13
+ import ErrorHandler from '../components/ErrorHandler.js.js';
14
+ import { gitPush } from '../git.js.js';
15
+ const LOCK_FILE_NAME = 'push.lock';
16
+ const PENDING_FILE_NAME = 'push.pending';
17
+ const log = buildLog('Snapshotter');
18
+ function main() {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ const mirrorPath = getEnvOrExit('MIRROR_PATH');
21
+ const remoteUrl = getEnvOrExit('REMOTE_URL');
22
+ const remoteToken = getEnvOrExit('REMOTE_TOKEN');
23
+ const snapshotterDir = path.join(mirrorPath, '.snapshotter');
24
+ mkdirSync(snapshotterDir, { recursive: true });
25
+ const lockPath = path.join(snapshotterDir, LOCK_FILE_NAME);
26
+ const pendingPath = path.join(snapshotterDir, PENDING_FILE_NAME);
27
+ if (existsSync(lockPath)) {
28
+ writeFileSync(pendingPath, new Date().toISOString());
29
+ log.info('Push already running, marked pending', mirrorPath);
30
+ return;
31
+ }
32
+ try {
33
+ writeFileSync(lockPath, process.pid.toString());
34
+ const remote = {
35
+ url: remoteUrl,
36
+ token: remoteToken,
37
+ };
38
+ yield processLoop(mirrorPath, remote, pendingPath);
39
+ }
40
+ finally {
41
+ if (existsSync(lockPath)) {
42
+ unlinkSync(lockPath);
43
+ }
44
+ }
45
+ });
46
+ }
47
+ function processLoop(mirrorPath, remote, pendingPath) {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ while (true) {
50
+ if (existsSync(pendingPath)) {
51
+ unlinkSync(pendingPath);
52
+ }
53
+ try {
54
+ log.info('Push starting', remote.url);
55
+ yield gitPush(mirrorPath, remote, log);
56
+ log.info('Push completed', remote.url);
57
+ ErrorHandler.Handler().clearError(mirrorPath);
58
+ }
59
+ catch (err) {
60
+ const message = err instanceof Error ? err.message : String(err);
61
+ log.error('Push failed', message);
62
+ ErrorHandler.Handler().persistError(mirrorPath, err);
63
+ writeFileSync(pendingPath, new Date().toISOString());
64
+ return;
65
+ }
66
+ if (!existsSync(pendingPath)) {
67
+ return;
68
+ }
69
+ }
70
+ });
71
+ }
72
+ function getEnvOrExit(name) {
73
+ const value = process.env[name];
74
+ if (!value) {
75
+ console.error(`Missing required env var: ${name}`);
76
+ process.exit(1);
77
+ }
78
+ return value;
79
+ }
80
+ main().catch((err) => {
81
+ console.error('Push script failed:', err);
82
+ process.exit(1);
83
+ });
@@ -2,7 +2,9 @@ import { SnapshotOptions } from '../snapshotter.types.js';
2
2
  import SnapshotStrategy from './SnapshotStrategy.js';
3
3
  export default class SyncStrategy implements SnapshotStrategy {
4
4
  private log;
5
+ private pushScriptPath;
5
6
  private constructor();
6
7
  static Strategy(): SyncStrategy;
7
8
  execute(options: SnapshotOptions): Promise<void>;
9
+ private spawnPushProcess;
8
10
  }
@@ -7,14 +7,17 @@ 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 { spawn } from 'child_process';
11
+ import path from 'path';
10
12
  import { buildLog } from '@sprucelabs/spruce-skill-utils';
11
13
  import ErrorHandler from '../components/ErrorHandler.js.js';
12
14
  import FileSyncer from '../components/FileSyncer.js.js';
13
15
  import TestResultsWriter from '../components/TestResultsWriter.js.js';
14
- import { gitCommit, gitPush } from '../git.js.js';
16
+ import { gitCommit } from '../git.js.js';
15
17
  export default class SyncStrategy {
16
18
  constructor() {
17
19
  this.log = buildLog('Snapshotter');
20
+ this.pushScriptPath = path.join(__dirname, '..', 'scripts', 'runPush.js');
18
21
  }
19
22
  static Strategy() {
20
23
  return new this();
@@ -36,10 +39,8 @@ export default class SyncStrategy {
36
39
  ErrorHandler.Handler().clearError(mirrorPath);
37
40
  return;
38
41
  }
39
- this.log.info('Commit created, pushing', remote.url);
40
- yield gitPush(mirrorPath, remote, this.log);
41
- this.log.info('Push completed', remote.url);
42
- ErrorHandler.Handler().clearError(mirrorPath);
42
+ this.log.info('Commit created, queueing push', remote.url);
43
+ this.spawnPushProcess(mirrorPath, remote);
43
44
  }
44
45
  catch (err) {
45
46
  const message = err instanceof Error ? err.message : String(err);
@@ -49,4 +50,12 @@ export default class SyncStrategy {
49
50
  }
50
51
  });
51
52
  }
53
+ spawnPushProcess(mirrorPath, remote) {
54
+ const child = spawn('node', [this.pushScriptPath], {
55
+ detached: true,
56
+ stdio: 'ignore',
57
+ env: Object.assign(Object.assign({}, process.env), { MIRROR_PATH: mirrorPath, REMOTE_URL: remote.url, REMOTE_TOKEN: remote.token }),
58
+ });
59
+ child.unref();
60
+ }
52
61
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,75 @@
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 fs_1 = require("fs");
7
+ const path_1 = __importDefault(require("path"));
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 LOCK_FILE_NAME = 'push.lock';
12
+ const PENDING_FILE_NAME = 'push.pending';
13
+ const log = (0, spruce_skill_utils_1.buildLog)('Snapshotter');
14
+ async function main() {
15
+ const mirrorPath = getEnvOrExit('MIRROR_PATH');
16
+ const remoteUrl = getEnvOrExit('REMOTE_URL');
17
+ const remoteToken = getEnvOrExit('REMOTE_TOKEN');
18
+ const snapshotterDir = path_1.default.join(mirrorPath, '.snapshotter');
19
+ (0, fs_1.mkdirSync)(snapshotterDir, { recursive: true });
20
+ const lockPath = path_1.default.join(snapshotterDir, LOCK_FILE_NAME);
21
+ const pendingPath = path_1.default.join(snapshotterDir, PENDING_FILE_NAME);
22
+ if ((0, fs_1.existsSync)(lockPath)) {
23
+ (0, fs_1.writeFileSync)(pendingPath, new Date().toISOString());
24
+ log.info('Push already running, marked pending', mirrorPath);
25
+ return;
26
+ }
27
+ try {
28
+ (0, fs_1.writeFileSync)(lockPath, process.pid.toString());
29
+ const remote = {
30
+ url: remoteUrl,
31
+ token: remoteToken,
32
+ };
33
+ await processLoop(mirrorPath, remote, pendingPath);
34
+ }
35
+ finally {
36
+ if ((0, fs_1.existsSync)(lockPath)) {
37
+ (0, fs_1.unlinkSync)(lockPath);
38
+ }
39
+ }
40
+ }
41
+ async function processLoop(mirrorPath, remote, pendingPath) {
42
+ while (true) {
43
+ if ((0, fs_1.existsSync)(pendingPath)) {
44
+ (0, fs_1.unlinkSync)(pendingPath);
45
+ }
46
+ try {
47
+ log.info('Push starting', remote.url);
48
+ await (0, git_js_1.gitPush)(mirrorPath, remote, log);
49
+ log.info('Push completed', remote.url);
50
+ ErrorHandler_js_1.default.Handler().clearError(mirrorPath);
51
+ }
52
+ catch (err) {
53
+ const message = err instanceof Error ? err.message : String(err);
54
+ log.error('Push failed', message);
55
+ ErrorHandler_js_1.default.Handler().persistError(mirrorPath, err);
56
+ (0, fs_1.writeFileSync)(pendingPath, new Date().toISOString());
57
+ return;
58
+ }
59
+ if (!(0, fs_1.existsSync)(pendingPath)) {
60
+ return;
61
+ }
62
+ }
63
+ }
64
+ function getEnvOrExit(name) {
65
+ const value = process.env[name];
66
+ if (!value) {
67
+ console.error(`Missing required env var: ${name}`);
68
+ process.exit(1);
69
+ }
70
+ return value;
71
+ }
72
+ main().catch((err) => {
73
+ console.error('Push script failed:', err);
74
+ process.exit(1);
75
+ });
@@ -2,7 +2,9 @@ import { SnapshotOptions } from '../snapshotter.types.js';
2
2
  import SnapshotStrategy from './SnapshotStrategy.js';
3
3
  export default class SyncStrategy implements SnapshotStrategy {
4
4
  private log;
5
+ private pushScriptPath;
5
6
  private constructor();
6
7
  static Strategy(): SyncStrategy;
7
8
  execute(options: SnapshotOptions): Promise<void>;
9
+ private spawnPushProcess;
8
10
  }
@@ -3,6 +3,8 @@ 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 child_process_1 = require("child_process");
7
+ const path_1 = __importDefault(require("path"));
6
8
  const spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils");
7
9
  const ErrorHandler_js_1 = __importDefault(require("../components/ErrorHandler.js"));
8
10
  const FileSyncer_js_1 = __importDefault(require("../components/FileSyncer.js"));
@@ -11,6 +13,7 @@ const git_js_1 = require("../git.js");
11
13
  class SyncStrategy {
12
14
  constructor() {
13
15
  this.log = (0, spruce_skill_utils_1.buildLog)('Snapshotter');
16
+ this.pushScriptPath = path_1.default.join(__dirname, '..', 'scripts', 'runPush.js');
14
17
  }
15
18
  static Strategy() {
16
19
  return new this();
@@ -30,10 +33,8 @@ class SyncStrategy {
30
33
  ErrorHandler_js_1.default.Handler().clearError(mirrorPath);
31
34
  return;
32
35
  }
33
- this.log.info('Commit created, pushing', remote.url);
34
- await (0, git_js_1.gitPush)(mirrorPath, remote, this.log);
35
- this.log.info('Push completed', remote.url);
36
- ErrorHandler_js_1.default.Handler().clearError(mirrorPath);
36
+ this.log.info('Commit created, queueing push', remote.url);
37
+ this.spawnPushProcess(mirrorPath, remote);
37
38
  }
38
39
  catch (err) {
39
40
  const message = err instanceof Error ? err.message : String(err);
@@ -42,5 +43,18 @@ class SyncStrategy {
42
43
  throw err;
43
44
  }
44
45
  }
46
+ spawnPushProcess(mirrorPath, remote) {
47
+ const child = (0, child_process_1.spawn)('node', [this.pushScriptPath], {
48
+ detached: true,
49
+ stdio: 'ignore',
50
+ env: {
51
+ ...process.env,
52
+ MIRROR_PATH: mirrorPath,
53
+ REMOTE_URL: remote.url,
54
+ REMOTE_TOKEN: remote.token,
55
+ },
56
+ });
57
+ child.unref();
58
+ }
45
59
  }
46
60
  exports.default = SyncStrategy;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@regressionproof/snapshotter",
3
- "version": "0.7.1",
3
+ "version": "0.7.2",
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": "c38dea336a4653790787044ca8b4209a9e5352fa"
97
+ "gitHead": "a557f1266fcb9720f9551efb6fa6523e7390101e"
98
98
  }