Skip to content

Commit 7ee92a2

Browse files
committed
fix: resolve app version in server via esm url
1 parent 2c8609e commit 7ee92a2

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

packages/server/src/config.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { execFileSync } from "node:child_process";
12
import { readFileSync } from "node:fs";
23
import { homedir, tmpdir } from "os";
34
import { join } from "path";
@@ -43,6 +44,27 @@ describe("parseServerConfig", () => {
4344
expect(config.appVersion).toBe(readCliPackageVersion());
4445
});
4546

47+
it("can resolve the CLI package version when imported via native ESM", () => {
48+
const env = { ...process.env };
49+
delete env.CODER_STUDIO_APP_VERSION;
50+
51+
const output = execFileSync(
52+
process.execPath,
53+
[
54+
"--input-type=module",
55+
"-e",
56+
"import('./src/config.ts').then((module) => { process.stdout.write(String(module.parseServerConfig().appVersion)); });",
57+
],
58+
{
59+
cwd: new URL("../", import.meta.url),
60+
env,
61+
encoding: "utf-8",
62+
}
63+
);
64+
65+
expect(output).toBe(readCliPackageVersion());
66+
});
67+
4668
it("prefers explicit appVersion override over inferred CLI version", () => {
4769
const config = parseServerConfig({ appVersion: "9.9.9" });
4870

packages/server/src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function resolveDefaultAppVersion(): string {
4747
return cachedAppVersion;
4848
}
4949

50-
const packageJsonPath = [path.resolve(__dirname, "../../cli/package.json")].find((candidate) =>
50+
const packageJsonPath = [new URL("../../cli/package.json", import.meta.url)].find((candidate) =>
5151
fs.existsSync(candidate)
5252
);
5353

0 commit comments

Comments
 (0)