Skip to content

Commit

Permalink
fix: Fix running yarn:test locally. (#1097)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenh authored Aug 21, 2024
1 parent 17edf89 commit 30385ed
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,17 @@ export async function getVersions(request: CodeGeneratorRequest) {
const { major, minor, patch } = request.compilerVersion;
protocVersion = `v${major}.${minor}.${patch}`;
}

const path: string = "../../package.json";
const packageJson = await import(path);
const packageJson = await readPackageJson();
const tsProtoVersion = `v${packageJson?.version ?? "unknown"}`;
return { protocVersion, tsProtoVersion };
}

return {
protocVersion,
tsProtoVersion,
};
/** Read from the distributed package.json file, or our local package.json when running ts-proto tests locally. */
async function readPackageJson(): Promise<any> {
try {
// Use `as string` to disable hints that the path doesn't exist
return await import("../../package.json" as string);
} catch (e) {
return await import("../package.json" as string);
}
}

0 comments on commit 30385ed

Please sign in to comment.