Skip to content

Commit 602cf4b

Browse files
committed
Fix CI/CD
1 parent bc6347e commit 602cf4b

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

.claude/CLAUDE-KNOWLEDGE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,3 +394,6 @@ A: The environment override endpoint validates the new environment override agai
394394

395395
## Q: Why can `pnpm run dev` fail with `ERR_MODULE_NOT_FOUND` for `@stackframe/stack/dist/esm/index.js` during OpenAPI docs generation?
396396
A: Root `dev` starts the OpenAPI docs watcher at the same time as package `dev` watchers. If a package `dev` script removes `dist` before `tsdown --watch` recreates it, the docs generator can import `apps/backend/src/stack.tsx` while `@stackframe/stack`'s ESM entrypoint is temporarily missing. Package watch scripts should update `dist` in place, and eager generators should wait for package imports to resolve before running.
397+
398+
## Q: How do SDK source tests replace the compile-time client version sentinel?
399+
A: `packages/template/vitest.config.ts` installs a Vite transform plugin for Vitest that replaces `STACK_COMPILE_TIME_CLIENT_PACKAGE_VERSION_SENTINEL` with `js <package-name>@<version>` from the local package.json. Keep the plugin in `packages/template` so `pnpm pre`/`scripts/generate-sdks.ts` propagates it to `packages/js`, `packages/react`, and `packages/stack`; otherwise tests importing `common.ts` throw `Client version was not replaced` before test collection.

packages/template/vitest.config.ts

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,50 @@
1+
import fs from 'node:fs'
2+
import { fileURLToPath } from 'node:url'
13
import { defineConfig, mergeConfig } from 'vitest/config'
24
import sharedConfig from '../../vitest.shared'
35

6+
const SOURCE_FILE_PATTERN = /\.(jsx?|tsx?)$/;
7+
const CLIENT_VERSION_SENTINEL = "STACK_COMPILE_TIME_CLIENT_PACKAGE_VERSION_SENTINEL";
8+
const ENFORCE_PRE: "pre" = "pre";
9+
10+
function getPackageVersionLabel() {
11+
const packageJson: unknown = JSON.parse(fs.readFileSync(fileURLToPath(new URL("./package.json", import.meta.url)), "utf-8"));
12+
if (
13+
typeof packageJson !== "object"
14+
|| packageJson === null
15+
|| !("name" in packageJson)
16+
|| typeof packageJson.name !== "string"
17+
|| !("version" in packageJson)
18+
|| typeof packageJson.version !== "string"
19+
) {
20+
throw new Error("Expected package.json to include string name and version fields.");
21+
}
22+
23+
return `js ${packageJson.name}@${packageJson.version}`;
24+
}
25+
26+
const replaceCompileTimeClientVersion = () => {
27+
const packageVersionLabel = getPackageVersionLabel();
28+
return {
29+
name: 'stackframe vitest client version replacement',
30+
enforce: ENFORCE_PRE,
31+
transform(code: string, id: string) {
32+
const filePath = id.split(/[?#]/, 1)[0];
33+
if (!SOURCE_FILE_PATTERN.test(filePath) || !code.includes(CLIENT_VERSION_SENTINEL)) {
34+
return null;
35+
}
36+
37+
return {
38+
code: code.replaceAll(CLIENT_VERSION_SENTINEL, packageVersionLabel),
39+
map: null,
40+
};
41+
},
42+
};
43+
};
44+
445
export default mergeConfig(
546
sharedConfig,
6-
defineConfig({}),
47+
defineConfig({
48+
plugins: [replaceCompileTimeClientVersion()],
49+
}),
750
)

0 commit comments

Comments
 (0)