@rvoh/psychic 2.3.4 → 2.3.6
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.
|
@@ -3,6 +3,7 @@ import * as cp from 'node:child_process';
|
|
|
3
3
|
import * as fs from 'node:fs';
|
|
4
4
|
import * as path from 'node:path';
|
|
5
5
|
import colorize from '../../cli/helpers/colorize.js';
|
|
6
|
+
import PsychicApp from '../../psychic-app/index.js';
|
|
6
7
|
/**
|
|
7
8
|
* Class-based OpenAPI specification diff tool
|
|
8
9
|
*
|
|
@@ -97,7 +98,7 @@ export class OpenApiSpecDiff {
|
|
|
97
98
|
};
|
|
98
99
|
}
|
|
99
100
|
throw new Error(`⚠️ oasdiff not found.
|
|
100
|
-
|
|
101
|
+
|
|
101
102
|
Install it via the instructions here:
|
|
102
103
|
https://github.com/tufin/oasdiff
|
|
103
104
|
`);
|
|
@@ -162,15 +163,25 @@ export class OpenApiSpecDiff {
|
|
|
162
163
|
}
|
|
163
164
|
/**
|
|
164
165
|
* Retrieves head branch content for a file
|
|
166
|
+
* @param absoluteFilePath - Absolute path to the file
|
|
165
167
|
*/
|
|
166
|
-
getHeadBranchContent(
|
|
168
|
+
getHeadBranchContent(absoluteFilePath) {
|
|
167
169
|
if (!this.oasdiffConfig) {
|
|
168
170
|
throw new Error('OasDiff config not initialized');
|
|
169
171
|
}
|
|
170
172
|
const branchRef = process.env.CI === '1' ? `origin/${this.oasdiffConfig.headBranch}` : this.oasdiffConfig.headBranch;
|
|
171
|
-
|
|
173
|
+
// Get git repo root
|
|
174
|
+
const gitRepoRoot = cp
|
|
175
|
+
.execSync('git rev-parse --show-toplevel', {
|
|
172
176
|
encoding: 'utf8',
|
|
173
177
|
cwd: process.cwd(),
|
|
178
|
+
})
|
|
179
|
+
.trim();
|
|
180
|
+
// Get relative path from git repo root to the file
|
|
181
|
+
const gitPath = path.relative(gitRepoRoot, absoluteFilePath).replace(/\\/g, '/');
|
|
182
|
+
return cp.execFileSync('git', ['show', `${branchRef}:${gitPath}`], {
|
|
183
|
+
encoding: 'utf8',
|
|
184
|
+
cwd: gitRepoRoot,
|
|
174
185
|
});
|
|
175
186
|
}
|
|
176
187
|
/**
|
|
@@ -183,13 +194,17 @@ export class OpenApiSpecDiff {
|
|
|
183
194
|
breaking: [],
|
|
184
195
|
changelog: [],
|
|
185
196
|
};
|
|
186
|
-
|
|
197
|
+
// Get absolute path using apiRoot
|
|
198
|
+
const psychicApp = PsychicApp.getOrFail();
|
|
199
|
+
const currentFilePath = path.isAbsolute(config.outputFilepath)
|
|
200
|
+
? config.outputFilepath
|
|
201
|
+
: path.join(psychicApp.apiRoot, config.outputFilepath);
|
|
187
202
|
if (!fs.existsSync(currentFilePath)) {
|
|
188
203
|
result.error = `File ${config.outputFilepath} does not exist in current branch`;
|
|
189
204
|
return result;
|
|
190
205
|
}
|
|
191
206
|
const tempMainFilePath = this.createTempFilePath(config.outputFilepath);
|
|
192
|
-
const mainContent = this.getHeadBranchContent(
|
|
207
|
+
const mainContent = this.getHeadBranchContent(currentFilePath);
|
|
193
208
|
fs.mkdirSync(path.dirname(tempMainFilePath), { recursive: true });
|
|
194
209
|
fs.writeFileSync(tempMainFilePath, mainContent);
|
|
195
210
|
try {
|
|
@@ -3,6 +3,7 @@ import * as cp from 'node:child_process';
|
|
|
3
3
|
import * as fs from 'node:fs';
|
|
4
4
|
import * as path from 'node:path';
|
|
5
5
|
import colorize from '../../cli/helpers/colorize.js';
|
|
6
|
+
import PsychicApp from '../../psychic-app/index.js';
|
|
6
7
|
/**
|
|
7
8
|
* Class-based OpenAPI specification diff tool
|
|
8
9
|
*
|
|
@@ -97,7 +98,7 @@ export class OpenApiSpecDiff {
|
|
|
97
98
|
};
|
|
98
99
|
}
|
|
99
100
|
throw new Error(`⚠️ oasdiff not found.
|
|
100
|
-
|
|
101
|
+
|
|
101
102
|
Install it via the instructions here:
|
|
102
103
|
https://github.com/tufin/oasdiff
|
|
103
104
|
`);
|
|
@@ -162,15 +163,25 @@ export class OpenApiSpecDiff {
|
|
|
162
163
|
}
|
|
163
164
|
/**
|
|
164
165
|
* Retrieves head branch content for a file
|
|
166
|
+
* @param absoluteFilePath - Absolute path to the file
|
|
165
167
|
*/
|
|
166
|
-
getHeadBranchContent(
|
|
168
|
+
getHeadBranchContent(absoluteFilePath) {
|
|
167
169
|
if (!this.oasdiffConfig) {
|
|
168
170
|
throw new Error('OasDiff config not initialized');
|
|
169
171
|
}
|
|
170
172
|
const branchRef = process.env.CI === '1' ? `origin/${this.oasdiffConfig.headBranch}` : this.oasdiffConfig.headBranch;
|
|
171
|
-
|
|
173
|
+
// Get git repo root
|
|
174
|
+
const gitRepoRoot = cp
|
|
175
|
+
.execSync('git rev-parse --show-toplevel', {
|
|
172
176
|
encoding: 'utf8',
|
|
173
177
|
cwd: process.cwd(),
|
|
178
|
+
})
|
|
179
|
+
.trim();
|
|
180
|
+
// Get relative path from git repo root to the file
|
|
181
|
+
const gitPath = path.relative(gitRepoRoot, absoluteFilePath).replace(/\\/g, '/');
|
|
182
|
+
return cp.execFileSync('git', ['show', `${branchRef}:${gitPath}`], {
|
|
183
|
+
encoding: 'utf8',
|
|
184
|
+
cwd: gitRepoRoot,
|
|
174
185
|
});
|
|
175
186
|
}
|
|
176
187
|
/**
|
|
@@ -183,13 +194,17 @@ export class OpenApiSpecDiff {
|
|
|
183
194
|
breaking: [],
|
|
184
195
|
changelog: [],
|
|
185
196
|
};
|
|
186
|
-
|
|
197
|
+
// Get absolute path using apiRoot
|
|
198
|
+
const psychicApp = PsychicApp.getOrFail();
|
|
199
|
+
const currentFilePath = path.isAbsolute(config.outputFilepath)
|
|
200
|
+
? config.outputFilepath
|
|
201
|
+
: path.join(psychicApp.apiRoot, config.outputFilepath);
|
|
187
202
|
if (!fs.existsSync(currentFilePath)) {
|
|
188
203
|
result.error = `File ${config.outputFilepath} does not exist in current branch`;
|
|
189
204
|
return result;
|
|
190
205
|
}
|
|
191
206
|
const tempMainFilePath = this.createTempFilePath(config.outputFilepath);
|
|
192
|
-
const mainContent = this.getHeadBranchContent(
|
|
207
|
+
const mainContent = this.getHeadBranchContent(currentFilePath);
|
|
193
208
|
fs.mkdirSync(path.dirname(tempMainFilePath), { recursive: true });
|
|
194
209
|
fs.writeFileSync(tempMainFilePath, mainContent);
|
|
195
210
|
try {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { DefaultPsychicOpenapiOptions } from '../../psychic-app/index.js';
|
|
2
2
|
/**
|
|
3
3
|
* Interface to hold the result of a comparison
|
|
4
4
|
* between the current local OpenAPI specification and the head branch
|
|
@@ -88,6 +88,7 @@ export declare class OpenApiSpecDiff {
|
|
|
88
88
|
private createTempFilePath;
|
|
89
89
|
/**
|
|
90
90
|
* Retrieves head branch content for a file
|
|
91
|
+
* @param absoluteFilePath - Absolute path to the file
|
|
91
92
|
*/
|
|
92
93
|
private getHeadBranchContent;
|
|
93
94
|
/**
|