@rvoh/psychic 2.3.3 → 2.3.5

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(filePath) {
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
- return cp.execSync(`git show ${branchRef}:${filePath}`, {
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
- const currentFilePath = config.outputFilepath;
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(config.outputFilepath);
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(filePath) {
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
- return cp.execSync(`git show ${branchRef}:${filePath}`, {
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
- const currentFilePath = config.outputFilepath;
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(config.outputFilepath);
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 type { DefaultPsychicOpenapiOptions } from '../../psychic-app/index.js';
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
  /**
@@ -252,10 +252,10 @@ export interface CustomCookieMaxAgeOptions {
252
252
  days?: number;
253
253
  }
254
254
  export interface PsychicSslCredentials {
255
- key: string | undefined;
256
- cert: string | undefined;
257
- ca: string[] | undefined;
258
- rejectUnauthorized: boolean | undefined;
255
+ key?: string | undefined;
256
+ cert?: string | undefined;
257
+ ca?: string[] | undefined;
258
+ rejectUnauthorized?: boolean | undefined;
259
259
  }
260
260
  export interface DefaultPsychicOpenapiOptions extends PsychicOpenapiBaseOptions {
261
261
  outputFilepath?: string;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "type": "module",
3
3
  "name": "@rvoh/psychic",
4
4
  "description": "Typescript web framework",
5
- "version": "2.3.3",
5
+ "version": "2.3.5",
6
6
  "author": "RVOHealth",
7
7
  "repository": {
8
8
  "type": "git",