@regressionproof/cli 0.7.3 → 0.8.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 (56) hide show
  1. package/build/cli.js +44 -0
  2. package/build/commands/invite/CreateInvite.js +3 -3
  3. package/build/components/Doctor.d.ts +7 -0
  4. package/build/components/Doctor.js +49 -0
  5. package/build/components/Doctor.tsx +75 -0
  6. package/build/config/ConfigManager.d.ts +9 -0
  7. package/build/config/ConfigManager.js +15 -0
  8. package/build/doctor/Doctor.d.ts +7 -0
  9. package/build/doctor/Doctor.js +23 -0
  10. package/build/doctor/DoctorContext.d.ts +12 -0
  11. package/build/doctor/DoctorContext.js +44 -0
  12. package/build/doctor/DoctorOutput.d.ts +6 -0
  13. package/build/doctor/DoctorOutput.js +32 -0
  14. package/build/doctor/DoctorResult.d.ts +8 -0
  15. package/build/doctor/DoctorResult.js +1 -0
  16. package/build/doctor/DoctorRunner.d.ts +7 -0
  17. package/build/doctor/DoctorRunner.js +9 -0
  18. package/build/doctor/checks/CredentialsCheck.d.ts +6 -0
  19. package/build/doctor/checks/CredentialsCheck.js +55 -0
  20. package/build/doctor/checks/JestReporterCheck.d.ts +5 -0
  21. package/build/doctor/checks/JestReporterCheck.js +35 -0
  22. package/build/doctor/checks/LocalConfigCheck.d.ts +5 -0
  23. package/build/doctor/checks/LocalConfigCheck.js +17 -0
  24. package/build/doctor/checks/MirrorAccessCheck.d.ts +9 -0
  25. package/build/doctor/checks/MirrorAccessCheck.js +129 -0
  26. package/build/esm/cli.js +44 -0
  27. package/build/esm/commands/invite/CreateInvite.js +3 -3
  28. package/build/esm/components/Doctor.d.ts +7 -0
  29. package/build/esm/components/Doctor.js +49 -0
  30. package/build/esm/config/ConfigManager.d.ts +9 -0
  31. package/build/esm/config/ConfigManager.js +16 -0
  32. package/build/esm/doctor/Doctor.d.ts +7 -0
  33. package/build/esm/doctor/Doctor.js +33 -0
  34. package/build/esm/doctor/DoctorContext.d.ts +12 -0
  35. package/build/esm/doctor/DoctorContext.js +41 -0
  36. package/build/esm/doctor/DoctorOutput.d.ts +6 -0
  37. package/build/esm/doctor/DoctorOutput.js +32 -0
  38. package/build/esm/doctor/DoctorResult.d.ts +8 -0
  39. package/build/esm/doctor/DoctorResult.js +1 -0
  40. package/build/esm/doctor/DoctorRunner.d.ts +7 -0
  41. package/build/esm/doctor/DoctorRunner.js +21 -0
  42. package/build/esm/doctor/checks/CredentialsCheck.d.ts +6 -0
  43. package/build/esm/doctor/checks/CredentialsCheck.js +66 -0
  44. package/build/esm/doctor/checks/JestReporterCheck.d.ts +5 -0
  45. package/build/esm/doctor/checks/JestReporterCheck.js +46 -0
  46. package/build/esm/doctor/checks/LocalConfigCheck.d.ts +5 -0
  47. package/build/esm/doctor/checks/LocalConfigCheck.js +28 -0
  48. package/build/esm/doctor/checks/MirrorAccessCheck.d.ts +9 -0
  49. package/build/esm/doctor/checks/MirrorAccessCheck.js +141 -0
  50. package/build/esm/jest/JestConfigurator.js +9 -0
  51. package/build/esm/jest/JestReporterConfigInspector.d.ts +13 -0
  52. package/build/esm/jest/JestReporterConfigInspector.js +60 -0
  53. package/build/jest/JestConfigurator.js +9 -0
  54. package/build/jest/JestReporterConfigInspector.d.ts +13 -0
  55. package/build/jest/JestReporterConfigInspector.js +56 -0
  56. package/package.json +3 -3
@@ -0,0 +1,9 @@
1
+ import DoctorContext from '../DoctorContext.js';
2
+ import type { DoctorResult } from '../DoctorResult.js';
3
+ export default class MirrorAccessCheck {
4
+ run(context: DoctorContext): Promise<DoctorResult>;
5
+ private checkPullAccess;
6
+ private checkPushAccess;
7
+ private isNoCommitsError;
8
+ private getErrorMessage;
9
+ }
@@ -0,0 +1,141 @@
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 { execSync } from 'child_process';
11
+ import fs from 'fs';
12
+ import ConfigManager from '../../config/ConfigManager.js.js';
13
+ export default class MirrorAccessCheck {
14
+ run(context) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ var _a, _b, _c;
17
+ if (!context.projectName) {
18
+ return {
19
+ name: 'Mirror directory',
20
+ status: 'warn',
21
+ details: [
22
+ 'Unable to resolve project name from .regressionproof.json.',
23
+ ],
24
+ fix: 'Run `npx regressionproof init` from the project root.',
25
+ };
26
+ }
27
+ const configManager = new ConfigManager();
28
+ const mirrorPath = context.mirrorPath;
29
+ const credentials = configManager.loadCredentials(context.projectName);
30
+ if (!mirrorPath || !fs.existsSync(mirrorPath)) {
31
+ return {
32
+ name: 'Mirror directory',
33
+ status: 'warn',
34
+ details: [
35
+ `Mirror directory not found at ${mirrorPath !== null && mirrorPath !== void 0 ? mirrorPath : configManager.getConfigDir(context.projectName)}.`,
36
+ 'This is normal before the first snapshot is created.',
37
+ ],
38
+ fix: 'Run your tests to create the first snapshot.',
39
+ };
40
+ }
41
+ if (!credentials) {
42
+ return {
43
+ name: 'Mirror directory',
44
+ status: 'warn',
45
+ details: ['Credentials not found; remote access not checked.'],
46
+ fix: 'Run `npx regressionproof invite accept <token>` (teammate) or `npx regressionproof init` (owner).',
47
+ };
48
+ }
49
+ const authedUrl = credentials.url.replace('://', `://${credentials.token}@`);
50
+ const pullResult = this.checkPullAccess(authedUrl);
51
+ if (!pullResult.ok) {
52
+ return {
53
+ name: 'Mirror directory',
54
+ status: 'fail',
55
+ details: [
56
+ 'Unable to access remote (pull).',
57
+ (_a = pullResult.message) !== null && _a !== void 0 ? _a : 'Unknown error.',
58
+ ],
59
+ fix: 'Run `npx regressionproof invite accept <token>` to refresh credentials.',
60
+ };
61
+ }
62
+ const pushResult = this.checkPushAccess(mirrorPath, authedUrl);
63
+ if (pushResult.status === 'fail') {
64
+ return {
65
+ name: 'Mirror directory',
66
+ status: 'fail',
67
+ details: [
68
+ 'Unable to access remote (push).',
69
+ (_b = pushResult.message) !== null && _b !== void 0 ? _b : 'Unknown error.',
70
+ ],
71
+ fix: 'Run `npx regressionproof invite accept <token>` to refresh credentials.',
72
+ };
73
+ }
74
+ if (pushResult.status === 'warn') {
75
+ return {
76
+ name: 'Mirror directory',
77
+ status: 'warn',
78
+ details: [
79
+ 'Remote access confirmed (pull).',
80
+ (_c = pushResult.message) !== null && _c !== void 0 ? _c : 'Unknown error.',
81
+ ],
82
+ fix: 'Run your tests to create the first snapshot.',
83
+ };
84
+ }
85
+ return {
86
+ name: 'Mirror directory',
87
+ status: 'ok',
88
+ details: [
89
+ `Mirror directory exists at ${mirrorPath}.`,
90
+ 'Remote access confirmed (pull/push).',
91
+ ],
92
+ };
93
+ });
94
+ }
95
+ checkPullAccess(url) {
96
+ try {
97
+ execSync(`git ls-remote "${url}"`, { stdio: 'pipe' });
98
+ return { ok: true };
99
+ }
100
+ catch (err) {
101
+ return {
102
+ ok: false,
103
+ message: this.getErrorMessage(err),
104
+ };
105
+ }
106
+ }
107
+ checkPushAccess(mirrorPath, url) {
108
+ try {
109
+ execSync(`git -C "${mirrorPath}" push --dry-run "${url}" HEAD`, {
110
+ stdio: 'pipe',
111
+ });
112
+ return { status: 'ok' };
113
+ }
114
+ catch (err) {
115
+ const message = this.getErrorMessage(err);
116
+ if (this.isNoCommitsError(message)) {
117
+ return {
118
+ status: 'warn',
119
+ message: 'No commits in mirror; push check skipped.',
120
+ };
121
+ }
122
+ return { status: 'fail', message };
123
+ }
124
+ }
125
+ isNoCommitsError(message) {
126
+ const normalized = message.toLowerCase();
127
+ return (normalized.includes('src refspec') ||
128
+ normalized.includes('does not match any') ||
129
+ normalized.includes('no commits'));
130
+ }
131
+ getErrorMessage(err) {
132
+ var _a, _b;
133
+ if (err && typeof err === 'object') {
134
+ const error = err;
135
+ return (((_a = error.stderr) === null || _a === void 0 ? void 0 : _a.toString().trim()) ||
136
+ ((_b = error.stdout) === null || _b === void 0 ? void 0 : _b.toString().trim()) ||
137
+ error.message);
138
+ }
139
+ return String(err);
140
+ }
141
+ }
@@ -1,5 +1,6 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
+ import JestReporterConfigInspector from './JestReporterConfigInspector.js.js';
3
4
  export default class JestConfigurator {
4
5
  constructor(cwd = process.cwd()) {
5
6
  this.reporterPackage = '@regressionproof/jest-reporter';
@@ -7,6 +8,14 @@ export default class JestConfigurator {
7
8
  }
8
9
  configure() {
9
10
  var _a, _b, _c;
11
+ const inspector = new JestReporterConfigInspector();
12
+ const inspection = inspector.inspect(this.cwd);
13
+ if (inspection.isConfigured) {
14
+ return {
15
+ configured: true,
16
+ location: inspection.configuredLocations[0],
17
+ };
18
+ }
10
19
  return ((_c = (_b = (_a = this.tryConfigurePackageJson()) !== null && _a !== void 0 ? _a : this.tryConfigureJestConfig('jest.config.ts')) !== null && _b !== void 0 ? _b : this.tryConfigureJestConfig('jest.config.js')) !== null && _c !== void 0 ? _c : {
11
20
  configured: false,
12
21
  location: '',
@@ -0,0 +1,13 @@
1
+ export default class JestReporterConfigInspector {
2
+ private reporterPackage;
3
+ inspect(cwd: string): InspectionResult;
4
+ private isConfiguredInPackageJson;
5
+ private isConfiguredInFile;
6
+ private safeReadJson;
7
+ }
8
+ export interface InspectionResult {
9
+ hasPackageJson: boolean;
10
+ isInstalled: boolean;
11
+ configuredLocations: string[];
12
+ isConfigured: boolean;
13
+ }
@@ -0,0 +1,60 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ export default class JestReporterConfigInspector {
4
+ constructor() {
5
+ this.reporterPackage = '@regressionproof/jest-reporter';
6
+ }
7
+ inspect(cwd) {
8
+ var _a, _b;
9
+ const packageJsonPath = path.join(cwd, 'package.json');
10
+ const hasPackageJson = fs.existsSync(packageJsonPath);
11
+ const packageJson = hasPackageJson
12
+ ? this.safeReadJson(packageJsonPath)
13
+ : null;
14
+ const isInstalled = Boolean((_a = packageJson === null || packageJson === void 0 ? void 0 : packageJson.dependencies) === null || _a === void 0 ? void 0 : _a[this.reporterPackage]) ||
15
+ Boolean((_b = packageJson === null || packageJson === void 0 ? void 0 : packageJson.devDependencies) === null || _b === void 0 ? void 0 : _b[this.reporterPackage]);
16
+ const configuredLocations = [];
17
+ if (this.isConfiguredInPackageJson(packageJson)) {
18
+ configuredLocations.push('package.json');
19
+ }
20
+ if (this.isConfiguredInFile(cwd, 'jest.config.js')) {
21
+ configuredLocations.push('jest.config.js');
22
+ }
23
+ if (this.isConfiguredInFile(cwd, 'jest.config.ts')) {
24
+ configuredLocations.push('jest.config.ts');
25
+ }
26
+ return {
27
+ hasPackageJson,
28
+ isInstalled,
29
+ configuredLocations,
30
+ isConfigured: configuredLocations.length > 0,
31
+ };
32
+ }
33
+ isConfiguredInPackageJson(packageJson) {
34
+ var _a, _b;
35
+ const reporters = (_b = (_a = packageJson === null || packageJson === void 0 ? void 0 : packageJson.jest) === null || _a === void 0 ? void 0 : _a.reporters) !== null && _b !== void 0 ? _b : [];
36
+ const isConfigured = Array.isArray(reporters) && reporters.includes(this.reporterPackage);
37
+ return isConfigured;
38
+ }
39
+ isConfiguredInFile(cwd, filename) {
40
+ const configPath = path.join(cwd, filename);
41
+ if (!fs.existsSync(configPath)) {
42
+ return false;
43
+ }
44
+ try {
45
+ const content = fs.readFileSync(configPath, 'utf-8');
46
+ return content.includes(this.reporterPackage);
47
+ }
48
+ catch (_a) {
49
+ return false;
50
+ }
51
+ }
52
+ safeReadJson(filePath) {
53
+ try {
54
+ return JSON.parse(fs.readFileSync(filePath, 'utf-8'));
55
+ }
56
+ catch (_a) {
57
+ return null;
58
+ }
59
+ }
60
+ }
@@ -1,5 +1,6 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
+ import JestReporterConfigInspector from './JestReporterConfigInspector.js';
3
4
  export default class JestConfigurator {
4
5
  cwd;
5
6
  reporterPackage = '@regressionproof/jest-reporter';
@@ -7,6 +8,14 @@ export default class JestConfigurator {
7
8
  this.cwd = cwd;
8
9
  }
9
10
  configure() {
11
+ const inspector = new JestReporterConfigInspector();
12
+ const inspection = inspector.inspect(this.cwd);
13
+ if (inspection.isConfigured) {
14
+ return {
15
+ configured: true,
16
+ location: inspection.configuredLocations[0],
17
+ };
18
+ }
10
19
  return (this.tryConfigurePackageJson() ??
11
20
  this.tryConfigureJestConfig('jest.config.ts') ??
12
21
  this.tryConfigureJestConfig('jest.config.js') ?? {
@@ -0,0 +1,13 @@
1
+ export default class JestReporterConfigInspector {
2
+ private reporterPackage;
3
+ inspect(cwd: string): InspectionResult;
4
+ private isConfiguredInPackageJson;
5
+ private isConfiguredInFile;
6
+ private safeReadJson;
7
+ }
8
+ export interface InspectionResult {
9
+ hasPackageJson: boolean;
10
+ isInstalled: boolean;
11
+ configuredLocations: string[];
12
+ isConfigured: boolean;
13
+ }
@@ -0,0 +1,56 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ export default class JestReporterConfigInspector {
4
+ reporterPackage = '@regressionproof/jest-reporter';
5
+ inspect(cwd) {
6
+ const packageJsonPath = path.join(cwd, 'package.json');
7
+ const hasPackageJson = fs.existsSync(packageJsonPath);
8
+ const packageJson = hasPackageJson
9
+ ? this.safeReadJson(packageJsonPath)
10
+ : null;
11
+ const isInstalled = Boolean(packageJson?.dependencies?.[this.reporterPackage]) ||
12
+ Boolean(packageJson?.devDependencies?.[this.reporterPackage]);
13
+ const configuredLocations = [];
14
+ if (this.isConfiguredInPackageJson(packageJson)) {
15
+ configuredLocations.push('package.json');
16
+ }
17
+ if (this.isConfiguredInFile(cwd, 'jest.config.js')) {
18
+ configuredLocations.push('jest.config.js');
19
+ }
20
+ if (this.isConfiguredInFile(cwd, 'jest.config.ts')) {
21
+ configuredLocations.push('jest.config.ts');
22
+ }
23
+ return {
24
+ hasPackageJson,
25
+ isInstalled,
26
+ configuredLocations,
27
+ isConfigured: configuredLocations.length > 0,
28
+ };
29
+ }
30
+ isConfiguredInPackageJson(packageJson) {
31
+ const reporters = packageJson?.jest?.reporters ?? [];
32
+ const isConfigured = Array.isArray(reporters) && reporters.includes(this.reporterPackage);
33
+ return isConfigured;
34
+ }
35
+ isConfiguredInFile(cwd, filename) {
36
+ const configPath = path.join(cwd, filename);
37
+ if (!fs.existsSync(configPath)) {
38
+ return false;
39
+ }
40
+ try {
41
+ const content = fs.readFileSync(configPath, 'utf-8');
42
+ return content.includes(this.reporterPackage);
43
+ }
44
+ catch {
45
+ return false;
46
+ }
47
+ }
48
+ safeReadJson(filePath) {
49
+ try {
50
+ return JSON.parse(fs.readFileSync(filePath, 'utf-8'));
51
+ }
52
+ catch {
53
+ return null;
54
+ }
55
+ }
56
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@regressionproof/cli",
3
- "version": "0.7.3",
3
+ "version": "0.8.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -38,7 +38,7 @@
38
38
  "watch.tsc": "tsc -w"
39
39
  },
40
40
  "dependencies": {
41
- "@regressionproof/client": "^0.7.3",
41
+ "@regressionproof/client": "^0.8.0",
42
42
  "dotenv": "^17.2.3",
43
43
  "ink": "^5.1.0",
44
44
  "ink-big-text": "^2.0.0",
@@ -84,5 +84,5 @@
84
84
  "^#spruce/(.*)$": "<rootDir>/build/.spruce/$1"
85
85
  }
86
86
  },
87
- "gitHead": "11e6ee4957dfa9a0160dac49bb007f196c9beab4"
87
+ "gitHead": "991c41905951b8c069c69b9a016affe53e819238"
88
88
  }