@regressionproof/jest-reporter 0.5.0 → 0.5.1

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,20 @@
1
+ export default class LocalConfigUpgrader {
2
+ private currentVersion;
3
+ constructor(currentVersion: string);
4
+ upgrade(existing: LocalConfig | null, desired: LocalConfig): UpgradeResult;
5
+ private applyMigrations;
6
+ private getMigrations;
7
+ private isEquivalent;
8
+ }
9
+ export interface UpgradeResult {
10
+ config: LocalConfig;
11
+ shouldWrite: boolean;
12
+ }
13
+ export interface LocalConfig {
14
+ version: string;
15
+ projectName: string;
16
+ remote: {
17
+ url: string;
18
+ };
19
+ [key: string]: unknown;
20
+ }
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class LocalConfigUpgrader {
4
+ constructor(currentVersion) {
5
+ this.currentVersion = currentVersion;
6
+ }
7
+ upgrade(existing, desired) {
8
+ const starting = existing ?? { ...desired, version: '0.0.0' };
9
+ const migrated = this.applyMigrations(starting, desired);
10
+ const finalConfig = {
11
+ ...migrated,
12
+ projectName: desired.projectName,
13
+ remote: desired.remote,
14
+ version: this.currentVersion,
15
+ };
16
+ return {
17
+ config: finalConfig,
18
+ shouldWrite: !this.isEquivalent(existing, finalConfig),
19
+ };
20
+ }
21
+ applyMigrations(config, desired) {
22
+ let current = config;
23
+ for (const migration of this.getMigrations()) {
24
+ if (compareVersions(current.version, migration.toVersion) < 0 &&
25
+ compareVersions(this.currentVersion, migration.toVersion) >= 0) {
26
+ current = migration.run(current, desired);
27
+ current = { ...current, version: migration.toVersion };
28
+ }
29
+ }
30
+ return current;
31
+ }
32
+ getMigrations() {
33
+ return [];
34
+ }
35
+ isEquivalent(existing, next) {
36
+ if (!existing) {
37
+ return false;
38
+ }
39
+ return (existing.version === next.version &&
40
+ existing.projectName === next.projectName &&
41
+ existing.remote?.url === next.remote.url);
42
+ }
43
+ }
44
+ exports.default = LocalConfigUpgrader;
45
+ function compareVersions(left, right) {
46
+ const leftParts = normalizeVersion(left).split('.').map(Number);
47
+ const rightParts = normalizeVersion(right).split('.').map(Number);
48
+ const maxLength = Math.max(leftParts.length, rightParts.length);
49
+ for (let i = 0; i < maxLength; i += 1) {
50
+ const leftPart = leftParts[i] ?? 0;
51
+ const rightPart = rightParts[i] ?? 0;
52
+ if (leftPart === rightPart) {
53
+ continue;
54
+ }
55
+ return leftPart > rightPart ? 1 : -1;
56
+ }
57
+ return 0;
58
+ }
59
+ function normalizeVersion(version) {
60
+ return version.split('-')[0] ?? version;
61
+ }
@@ -9,6 +9,7 @@ const child_process_1 = require("child_process");
9
9
  const fs_1 = __importDefault(require("fs"));
10
10
  const os_1 = __importDefault(require("os"));
11
11
  const path_1 = __importDefault(require("path"));
12
+ const LocalConfigUpgrader_js_1 = __importDefault(require("./LocalConfigUpgrader.js"));
12
13
  function loadConfig(cwd) {
13
14
  const localConfig = readLocalConfig(cwd);
14
15
  const projectName = localConfig?.projectName ?? getProjectNameFromGit(cwd);
@@ -29,8 +30,10 @@ function loadConfig(cwd) {
29
30
  url: config.remote.url,
30
31
  },
31
32
  };
32
- if (shouldWriteLocalConfig(localConfig, expectedLocalConfig)) {
33
- writeLocalConfig(cwd, expectedLocalConfig);
33
+ const upgrader = new LocalConfigUpgrader_js_1.default(reporterVersion);
34
+ const upgradeResult = upgrader.upgrade(localConfig, expectedLocalConfig);
35
+ if (upgradeResult.shouldWrite) {
36
+ writeLocalConfig(cwd, upgradeResult.config);
34
37
  }
35
38
  return {
36
39
  projectName,
@@ -82,14 +85,6 @@ function readLocalConfig(cwd) {
82
85
  return null;
83
86
  }
84
87
  }
85
- function shouldWriteLocalConfig(existing, expected) {
86
- if (!existing) {
87
- return true;
88
- }
89
- return (existing.version !== expected.version ||
90
- existing.projectName !== expected.projectName ||
91
- existing.remote?.url !== expected.remote.url);
92
- }
93
88
  function writeLocalConfig(cwd, config) {
94
89
  const localConfigPath = path_1.default.join(cwd, '.regressionproof.json');
95
90
  fs_1.default.writeFileSync(localConfigPath, JSON.stringify(config, null, 2));
@@ -0,0 +1,20 @@
1
+ export default class LocalConfigUpgrader {
2
+ private currentVersion;
3
+ constructor(currentVersion: string);
4
+ upgrade(existing: LocalConfig | null, desired: LocalConfig): UpgradeResult;
5
+ private applyMigrations;
6
+ private getMigrations;
7
+ private isEquivalent;
8
+ }
9
+ export interface UpgradeResult {
10
+ config: LocalConfig;
11
+ shouldWrite: boolean;
12
+ }
13
+ export interface LocalConfig {
14
+ version: string;
15
+ projectName: string;
16
+ remote: {
17
+ url: string;
18
+ };
19
+ [key: string]: unknown;
20
+ }
@@ -0,0 +1,56 @@
1
+ export default class LocalConfigUpgrader {
2
+ constructor(currentVersion) {
3
+ this.currentVersion = currentVersion;
4
+ }
5
+ upgrade(existing, desired) {
6
+ const starting = existing !== null && existing !== void 0 ? existing : Object.assign(Object.assign({}, desired), { version: '0.0.0' });
7
+ const migrated = this.applyMigrations(starting, desired);
8
+ const finalConfig = Object.assign(Object.assign({}, migrated), { projectName: desired.projectName, remote: desired.remote, version: this.currentVersion });
9
+ return {
10
+ config: finalConfig,
11
+ shouldWrite: !this.isEquivalent(existing, finalConfig),
12
+ };
13
+ }
14
+ applyMigrations(config, desired) {
15
+ let current = config;
16
+ for (const migration of this.getMigrations()) {
17
+ if (compareVersions(current.version, migration.toVersion) < 0 &&
18
+ compareVersions(this.currentVersion, migration.toVersion) >= 0) {
19
+ current = migration.run(current, desired);
20
+ current = Object.assign(Object.assign({}, current), { version: migration.toVersion });
21
+ }
22
+ }
23
+ return current;
24
+ }
25
+ getMigrations() {
26
+ return [];
27
+ }
28
+ isEquivalent(existing, next) {
29
+ var _a;
30
+ if (!existing) {
31
+ return false;
32
+ }
33
+ return (existing.version === next.version &&
34
+ existing.projectName === next.projectName &&
35
+ ((_a = existing.remote) === null || _a === void 0 ? void 0 : _a.url) === next.remote.url);
36
+ }
37
+ }
38
+ function compareVersions(left, right) {
39
+ var _a, _b;
40
+ const leftParts = normalizeVersion(left).split('.').map(Number);
41
+ const rightParts = normalizeVersion(right).split('.').map(Number);
42
+ const maxLength = Math.max(leftParts.length, rightParts.length);
43
+ for (let i = 0; i < maxLength; i += 1) {
44
+ const leftPart = (_a = leftParts[i]) !== null && _a !== void 0 ? _a : 0;
45
+ const rightPart = (_b = rightParts[i]) !== null && _b !== void 0 ? _b : 0;
46
+ if (leftPart === rightPart) {
47
+ continue;
48
+ }
49
+ return leftPart > rightPart ? 1 : -1;
50
+ }
51
+ return 0;
52
+ }
53
+ function normalizeVersion(version) {
54
+ var _a;
55
+ return (_a = version.split('-')[0]) !== null && _a !== void 0 ? _a : version;
56
+ }
@@ -2,6 +2,7 @@ import { execSync } from 'child_process';
2
2
  import fs from 'fs';
3
3
  import os from 'os';
4
4
  import path from 'path';
5
+ import LocalConfigUpgrader from './LocalConfigUpgrader.js.js';
5
6
  export function loadConfig(cwd) {
6
7
  var _a;
7
8
  const localConfig = readLocalConfig(cwd);
@@ -23,8 +24,10 @@ export function loadConfig(cwd) {
23
24
  url: config.remote.url,
24
25
  },
25
26
  };
26
- if (shouldWriteLocalConfig(localConfig, expectedLocalConfig)) {
27
- writeLocalConfig(cwd, expectedLocalConfig);
27
+ const upgrader = new LocalConfigUpgrader(reporterVersion);
28
+ const upgradeResult = upgrader.upgrade(localConfig, expectedLocalConfig);
29
+ if (upgradeResult.shouldWrite) {
30
+ writeLocalConfig(cwd, upgradeResult.config);
28
31
  }
29
32
  return {
30
33
  projectName,
@@ -77,15 +80,6 @@ function readLocalConfig(cwd) {
77
80
  return null;
78
81
  }
79
82
  }
80
- function shouldWriteLocalConfig(existing, expected) {
81
- var _a;
82
- if (!existing) {
83
- return true;
84
- }
85
- return (existing.version !== expected.version ||
86
- existing.projectName !== expected.projectName ||
87
- ((_a = existing.remote) === null || _a === void 0 ? void 0 : _a.url) !== expected.remote.url);
88
- }
89
83
  function writeLocalConfig(cwd, config) {
90
84
  const localConfigPath = path.join(cwd, '.regressionproof.json');
91
85
  fs.writeFileSync(localConfigPath, JSON.stringify(config, null, 2));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@regressionproof/jest-reporter",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -35,7 +35,7 @@
35
35
  "watch.tsc": "tsc -w"
36
36
  },
37
37
  "dependencies": {
38
- "@regressionproof/snapshotter": "^0.5.0",
38
+ "@regressionproof/snapshotter": "^0.5.1",
39
39
  "@sprucelabs/error": "^8.1.2",
40
40
  "@sprucelabs/schema": "^33.1.3",
41
41
  "@sprucelabs/spruce-core-schemas": "^42.1.3",
@@ -82,5 +82,5 @@
82
82
  "^#spruce/(.*)$": "<rootDir>/build/.spruce/$1"
83
83
  }
84
84
  },
85
- "gitHead": "ab68e3b894ee0e1bed01d35bc6f42bd1d4a2487f"
85
+ "gitHead": "5628058a784a7bbf4f9f2c80ecd69a49c8be1088"
86
86
  }