Skip to content

Commit b477308

Browse files
committed
test(tanstack-addon): prevent working tree mutation and assert template drift in compile tests
1 parent bbdfb2b commit b477308

3 files changed

Lines changed: 29 additions & 15 deletions

File tree

apps/www/content/docs/frameworks/tanstack-start.mdx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,17 @@ Generate a new TanStack Start project with the ArkEnv add-on:
3131
npx @tanstack/cli create my-app --add-ons https://arkenv.js.org/tanstack/info.json
3232
```
3333

34-
The CLI prompts you with configuration choices:
34+
By default, the add-on scaffolds with **ArkType** (`@arkenv/core`) and includes the interactive demo route at `/demo/arkenv`.
35+
36+
Configuration options supported by the add-on:
3537

3638
- **Validator Engine**:
3739
- **ArkType** (default) — installs `@arkenv/core` and `arktype`
3840
- **Zod** — installs `@arkenv/standard` and `zod`
3941
- **Valibot** — installs `@arkenv/standard` and `valibot`
4042
- **Interactive Demo Route**:
4143
- **Include `/demo/arkenv`** (default) — scaffolds an interactive secret leak test showcasing server-only isolation in the browser
42-
- **Skip demo route** — scaffolds only the schema definition and plugin configuration
44+
- **Skip demo route** — scaffolds only the schema definition and plugin configuration (automatically skipped when creating a project with `--no-examples` or the `blank` preset)
4345

4446
The add-on automatically:
4547

packages/tanstack-addon/scripts/build.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ function gatherFilesRecursively(
4343
return result;
4444
}
4545

46-
export function buildAddon() {
47-
console.log("Building @arkenv/tanstack-addon...");
48-
46+
export function compileAddon() {
4947
const infoPath = join(addonDir, "info.json");
5048
const packageTemplatePath = join(addonDir, "package.json.ejs");
5149

@@ -61,13 +59,15 @@ export function buildAddon() {
6159

6260
const files = gatherFilesRecursively(assetsDir, assetsDir);
6361

64-
const compiled = {
62+
return {
6563
...info,
6664
packageTemplate,
6765
files,
6866
deletedFiles: [],
6967
};
68+
}
7069

70+
export function writeAddon(compiled = compileAddon()) {
7171
// Ensure distDir exists
7272
mkdirSync(distDir, { recursive: true });
7373
const compiledJson = JSON.stringify(compiled, null, 2);
@@ -80,7 +80,10 @@ export function buildAddon() {
8080
mkdirSync(docsPublicDir, { recursive: true });
8181
writeFileSync(join(docsPublicDir, "info.json"), compiledJson);
8282
writeFileSync(join(docsPublicDir, "add-on.json"), compiledJson);
83-
writeFileSync(join(docsPublicDir, "package.json.ejs"), packageTemplate);
83+
writeFileSync(
84+
join(docsPublicDir, "package.json.ejs"),
85+
compiled.packageTemplate,
86+
);
8487

8588
// Copy assets directory recursively to apps/www/public/tanstack/assets
8689
const targetAssetsDir = join(docsPublicDir, "assets");
@@ -89,12 +92,17 @@ export function buildAddon() {
8992
cpSync(assetsDir, targetAssetsDir, { recursive: true });
9093

9194
console.log(
92-
`Successfully compiled ${Object.keys(files).length} asset files into:`,
95+
`Successfully compiled ${Object.keys(compiled.files).length} asset files into:`,
9396
);
9497
console.log(` - ${join(distDir, "info.json")}`);
9598
console.log(` - ${join(docsPublicDir, "info.json")}`);
9699
console.log(` - ${targetAssetsDir}`);
100+
}
97101

102+
export function buildAddon() {
103+
console.log("Building @arkenv/tanstack-addon...");
104+
const compiled = compileAddon();
105+
writeAddon(compiled);
98106
return compiled;
99107
}
100108

packages/tanstack-addon/tests/compile.test.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ import { dirname, resolve } from "node:path";
33
import { fileURLToPath } from "node:url";
44
import { AddOnCompiledSchema } from "@tanstack/create";
55
import { describe, expect, it } from "vitest";
6-
import { buildAddon } from "../scripts/build";
6+
import { compileAddon } from "../scripts/build";
77

88
const __filename = fileURLToPath(import.meta.url);
99
const __dirname = dirname(__filename);
1010
const packageRoot = resolve(__dirname, "..");
1111
const repoRoot = resolve(packageRoot, "../..");
1212

1313
describe("TanStack Add-on Compilation", () => {
14-
it("compiles a schema-valid add-on bundle", () => {
15-
const compiled = buildAddon();
14+
it("compiles a schema-valid add-on bundle in memory without disk side-effects", () => {
15+
const compiled = compileAddon();
1616

1717
// Validate against TanStack CLI's AddOnCompiledSchema
1818
const parsed = AddOnCompiledSchema.safeParse(compiled);
@@ -57,7 +57,9 @@ describe("TanStack Add-on Compilation", () => {
5757
expect(compiled.options?.demo.default).toBe("true");
5858
});
5959

60-
it("mirrors compiled files and assets to apps/www/public/tanstack", () => {
60+
it("ensures committed public bundles match source templates without drift", () => {
61+
const freshCompiled = compileAddon();
62+
6163
const publicInfo = resolve(repoRoot, "apps/www/public/tanstack/info.json");
6264
const publicAddon = resolve(
6365
repoRoot,
@@ -69,8 +71,10 @@ describe("TanStack Add-on Compilation", () => {
6971
expect(existsSync(publicAddon)).toBe(true);
7072
expect(existsSync(publicAssets)).toBe(true);
7173

72-
const content = JSON.parse(readFileSync(publicInfo, "utf-8"));
73-
expect(content.id).toBe("arkenv");
74-
expect(content.files["src/env.ts.ejs"]).toBeDefined();
74+
const committedInfo = JSON.parse(readFileSync(publicInfo, "utf-8"));
75+
const committedAddon = JSON.parse(readFileSync(publicAddon, "utf-8"));
76+
77+
expect(committedInfo).toEqual(freshCompiled);
78+
expect(committedAddon).toEqual(freshCompiled);
7579
});
7680
});

0 commit comments

Comments
 (0)