Skip to content

Commit

Permalink
Make version function synchronous
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey committed Jul 7, 2024
1 parent b9060b0 commit c60db9f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/__tests__/cli/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ test("main print version", async (t) => {
.setup((d) => d.argv)
.returns(["node", "cli.js", "--version"])
.setup((d) => d.version)
.returns(async () => version)
.returns(() => version)
.setup((d) => d.cwd)
.returns(() => fixturesPath)
.setup((d) => d.log)
Expand Down
2 changes: 1 addition & 1 deletion src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async function mainWorker(d: D) {
}

if (args.version) {
d.log(`hereby ${await d.version()}`);
d.log(`hereby ${d.version()}`);
return;
}

Expand Down
6 changes: 3 additions & 3 deletions src/cli/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export interface D {
readonly simplifyPath: (p: string) => string;
readonly argv: string[];
readonly setExitCode: (code: number) => void;
readonly version: () => Promise<string>;
readonly version: () => string;

// Third-party package imports.
readonly resolve: (specifier: string, parent: string) => Promise<string>;
Expand All @@ -84,9 +84,9 @@ export async function real(): Promise<D> {
setExitCode: (code) => {
process.exitCode = code;
},
version: async () => {
version: () => {
const packageJsonURL = new URL("../../package.json", import.meta.url);
const packageJson = await fs.promises.readFile(packageJsonURL, "utf8");
const packageJson = fs.readFileSync(packageJsonURL, "utf8");
return JSON.parse(packageJson).version;
},
resolve: async (specifier, parent) => {
Expand Down

0 comments on commit c60db9f

Please sign in to comment.