alchemy 0.10.0 → 0.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/lib/alchemy.js +4 -1
  2. package/lib/cloudflare/api.js +1 -1
  3. package/lib/cloudflare/assets.js +2 -2
  4. package/lib/cloudflare/d1-database.d.ts +28 -1
  5. package/lib/cloudflare/d1-database.js +39 -1
  6. package/lib/cloudflare/d1-migrations.d.ts +46 -0
  7. package/lib/cloudflare/d1-migrations.js +82 -0
  8. package/lib/cloudflare/worker.js +2 -2
  9. package/lib/cloudflare/wrangler.json.js +1 -1
  10. package/lib/esbuild/bundle.d.ts +2 -2
  11. package/lib/esbuild/bundle.js +28 -15
  12. package/lib/internal/docs/providers.d.ts +2 -2
  13. package/lib/internal/docs/providers.js +5 -4
  14. package/lib/test/bun.js +1 -1
  15. package/lib/test/prune.d.ts +13 -0
  16. package/lib/test/prune.js +130 -0
  17. package/lib/util/content-type.js +1 -1
  18. package/lib/util/rm.js +1 -1
  19. package/lib/web/astro.js +6 -3
  20. package/lib/web/shadcn-component.js +2 -2
  21. package/lib/web/shadcn.d.ts +1 -1
  22. package/lib/web/shadcn.js +3 -2
  23. package/lib/web/tailwind.js +3 -2
  24. package/lib/web/vite.js +5 -3
  25. package/lib/web/vitepress/config.js +1 -1
  26. package/lib/web/vitepress/custom-theme.js +2 -2
  27. package/lib/web/vitepress/home-page.d.ts +1 -1
  28. package/lib/web/vitepress/home-page.js +1 -1
  29. package/lib/web/vitepress/vitepress.js +7 -4
  30. package/package.json +1 -1
  31. package/src/alchemy.ts +4 -1
  32. package/src/cloudflare/api.ts +1 -1
  33. package/src/cloudflare/assets.ts +2 -2
  34. package/src/cloudflare/d1-database.ts +65 -1
  35. package/src/cloudflare/d1-migrations.ts +137 -0
  36. package/src/cloudflare/worker.ts +2 -2
  37. package/src/cloudflare/wrangler.json.ts +1 -1
  38. package/src/esbuild/bundle.ts +44 -22
  39. package/src/internal/docs/providers.ts +5 -4
  40. package/src/test/bun.ts +1 -1
  41. package/src/test/prune.ts +165 -0
  42. package/src/util/content-type.ts +1 -1
  43. package/src/util/rm.ts +1 -1
  44. package/src/web/astro.ts +15 -17
  45. package/src/web/shadcn-component.ts +6 -6
  46. package/src/web/shadcn.ts +9 -8
  47. package/src/web/tailwind.ts +5 -4
  48. package/src/web/vite.ts +14 -12
  49. package/src/web/vitepress/config.ts +1 -1
  50. package/src/web/vitepress/custom-theme.ts +9 -9
  51. package/src/web/vitepress/home-page.ts +21 -17
  52. package/src/web/vitepress/vitepress.ts +7 -9
package/src/web/astro.ts CHANGED
@@ -1,14 +1,12 @@
1
1
  import { exec } from "child_process";
2
- import fs from "fs/promises";
3
- import path from "path";
2
+ import fs from "node:fs/promises";
3
+ import path from "node:path";
4
4
  import { promisify } from "util";
5
5
  import type { Context } from "../context";
6
- import {
7
- Folder,
8
- StaticJsonFile,
9
- StaticTextFile,
10
- StaticTypeScriptFile,
11
- } from "../fs";
6
+ import { Folder } from "../fs/folder";
7
+ import { StaticJsonFile } from "../fs/static-json-file";
8
+ import { StaticTextFile } from "../fs/static-text-file";
9
+ import { StaticTypeScriptFile } from "../fs/static-typescript-file";
12
10
  import { Resource } from "../resource";
13
11
  import { ShadcnUI } from "./shadcn";
14
12
 
@@ -198,7 +196,7 @@ export const AstroProject = Resource(
198
196
  async function (
199
197
  this: Context<AstroProject>,
200
198
  id: string,
201
- props: AstroProjectProps,
199
+ props: AstroProjectProps
202
200
  ): Promise<AstroProject> {
203
201
  const dir = props.dir ?? props.name;
204
202
 
@@ -396,7 +394,7 @@ export const AstroProject = Resource(
396
394
  export default defineConfig({${integrationsStr}${vitePluginsStr}
397
395
  site: "https://example.com",
398
396
  output: "static"
399
- });`,
397
+ });`
400
398
  );
401
399
  }
402
400
 
@@ -427,14 +425,14 @@ pnpm-debug.log*
427
425
  # macOS-specific files
428
426
  .DS_Store
429
427
  .astro/
430
- `,
428
+ `
431
429
  );
432
430
 
433
431
  // Create .env.d.ts
434
432
  await StaticTextFile(
435
433
  path.join(dir, "src", "env.d.ts"),
436
434
  `/// <reference types="astro/client" />
437
- `,
435
+ `
438
436
  );
439
437
 
440
438
  // Create a basic layout
@@ -478,7 +476,7 @@ const { title, description = "Welcome to my Astro site" } = Astro.props;
478
476
  Bitstream Vera Sans Mono, Courier New, monospace;
479
477
  }
480
478
  </style>
481
- `,
479
+ `
482
480
  );
483
481
 
484
482
  // Create a basic index page
@@ -532,7 +530,7 @@ import Layout from '../layouts/Layout.astro';
532
530
  padding: 0.3em 0.45em;
533
531
  }
534
532
  </style>
535
- `,
533
+ `
536
534
  );
537
535
 
538
536
  // Create public/favicon.svg
@@ -548,7 +546,7 @@ import Layout from '../layouts/Layout.astro';
548
546
  </linearGradient>
549
547
  </defs>
550
548
  </svg>
551
- `,
549
+ `
552
550
  );
553
551
  }
554
552
 
@@ -590,7 +588,7 @@ import Layout from '../layouts/Layout.astro';
590
588
  `@tailwind base;
591
589
  @tailwind components;
592
590
  @tailwind utilities;
593
- `,
591
+ `
594
592
  );
595
593
  break;
596
594
  case "mdx":
@@ -640,5 +638,5 @@ import Layout from '../layouts/Layout.astro';
640
638
  await exec(`bun add ${depsArg}`);
641
639
  }
642
640
  }
643
- },
641
+ }
644
642
  );
@@ -1,6 +1,6 @@
1
1
  import { exec } from "child_process";
2
- import fs from "fs/promises";
3
- import path from "path";
2
+ import fs from "node:fs/promises";
3
+ import path from "node:path";
4
4
  import { promisify } from "util";
5
5
  import type { Context } from "../context";
6
6
  import { Resource } from "../resource";
@@ -44,13 +44,13 @@ export const ShadcnComponent = Resource(
44
44
  async function (
45
45
  this: Context<ShadcnComponent>,
46
46
  id: string,
47
- props: ShadcnComponentProps,
47
+ props: ShadcnComponentProps
48
48
  ): Promise<ShadcnComponent> {
49
49
  if (this.phase === "delete") {
50
50
  await ignore("ENOENT", () =>
51
51
  fs.unlink(
52
- path.join(props.cwd, "src", "components", "ui", `${props.name}.tsx`),
53
- ),
52
+ path.join(props.cwd, "src", "components", "ui", `${props.name}.tsx`)
53
+ )
54
54
  );
55
55
  return this.destroy();
56
56
  }
@@ -68,5 +68,5 @@ export const ShadcnComponent = Resource(
68
68
  await execAsync(addCommand, { cwd: props.cwd });
69
69
 
70
70
  return this(props);
71
- },
71
+ }
72
72
  );
package/src/web/shadcn.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { exec } from "child_process";
2
- import path from "path";
2
+ import path from "node:path";
3
3
  import { promisify } from "util";
4
4
  import type { Context } from "../context";
5
- import { Folder, StaticJsonFile } from "../fs";
5
+ import { Folder } from "../fs/folder";
6
+ import { StaticJsonFile } from "../fs/static-json-file";
6
7
  import { StaticTypeScriptFile } from "../fs/static-typescript-file";
7
8
  import { Resource } from "../resource";
8
9
  import { ShadcnComponent } from "./shadcn-component";
@@ -120,14 +121,14 @@ export const ShadcnUI = Resource(
120
121
  async function (
121
122
  this: Context<ShadcnUI>,
122
123
  id: string,
123
- props: ShadcnUIProps,
124
+ props: ShadcnUIProps
124
125
  ): Promise<ShadcnUI> {
125
126
  if (this.phase === "delete") {
126
127
  // For a delete phase, we don't perform any action
127
128
  // as removing Shadcn UI would require removing many files
128
129
  // which could be destructive to the project
129
130
  console.log(
130
- "Note: ShadcnUI delete phase does not remove installed components",
131
+ "Note: ShadcnUI delete phase does not remove installed components"
131
132
  );
132
133
 
133
134
  return this.destroy();
@@ -171,15 +172,15 @@ export const ShadcnUI = Resource(
171
172
  props.cwd,
172
173
  props.srcDir !== false ? "src" : "",
173
174
  "components",
174
- "ui",
175
- ),
175
+ "ui"
176
+ )
176
177
  );
177
178
 
178
179
  // Create lib directory
179
180
  const libPath = path.join(
180
181
  props.cwd,
181
182
  props.srcDir !== false ? "src" : "",
182
- "lib",
183
+ "lib"
183
184
  );
184
185
  const lib = await Folder(libPath);
185
186
 
@@ -215,5 +216,5 @@ export const ShadcnUI = Resource(
215
216
  ui,
216
217
  lib,
217
218
  });
218
- },
219
+ }
219
220
  );
@@ -1,8 +1,9 @@
1
1
  import { exec } from "child_process";
2
- import path from "path";
2
+ import path from "node:path";
3
3
  import { promisify } from "util";
4
4
  import type { Context } from "../context";
5
- import { Folder, StaticTextFile } from "../fs";
5
+ import { Folder } from "../fs/folder";
6
+ import { StaticTextFile } from "../fs/static-text-file";
6
7
  import { Resource } from "../resource";
7
8
 
8
9
  const execAsync = promisify(exec);
@@ -81,7 +82,7 @@ export const TailwindConfig = Resource(
81
82
  async function (
82
83
  this: Context<TailwindConfig>,
83
84
  id: string,
84
- props: TailwindConfigProps,
85
+ props: TailwindConfigProps
85
86
  ): Promise<TailwindConfig> {
86
87
  if (this.phase === "delete") {
87
88
  // Nothing to clean up specifically for Tailwind
@@ -163,5 +164,5 @@ export const TailwindConfig = Resource(
163
164
  // Create CSS file with Tailwind directives
164
165
  await StaticTextFile(cssPath, tailwindDirectives);
165
166
  }
166
- },
167
+ }
167
168
  );
package/src/web/vite.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  import { exec } from "child_process";
2
- import path from "path";
2
+ import path from "node:path";
3
3
  import { promisify } from "util";
4
4
  import type { Context } from "../context";
5
- import { Folder, StaticJsonFile, StaticTypeScriptFile } from "../fs";
5
+ import { Folder } from "../fs/folder";
6
+ import { StaticJsonFile } from "../fs/static-json-file";
7
+ import { StaticTypeScriptFile } from "../fs/static-typescript-file";
6
8
  import { Resource } from "../resource";
7
9
  import { rm } from "../util/rm";
8
10
  import { ShadcnComponent } from "./shadcn-component";
@@ -136,7 +138,7 @@ export const ViteProject = Resource(
136
138
  async function (
137
139
  this: Context<ViteProject>,
138
140
  id: string,
139
- props: ViteProjectProps,
141
+ props: ViteProjectProps
140
142
  ): Promise<ViteProject> {
141
143
  const phase = this.phase;
142
144
  if (this.phase === "delete") {
@@ -155,7 +157,7 @@ export const ViteProject = Resource(
155
157
  await modifyConfig(props);
156
158
  } else {
157
159
  console.warn(
158
- "ViteProject does not support updates - the project must be recreated to change the template",
160
+ "ViteProject does not support updates - the project must be recreated to change the template"
159
161
  );
160
162
  }
161
163
  } else {
@@ -220,7 +222,7 @@ export const ViteProject = Resource(
220
222
 
221
223
  await StaticTypeScriptFile(
222
224
  path.join(props.name, "vite.config.ts"),
223
- `import path from "path";
225
+ `import path from "node:path";
224
226
  import react from "@vitejs/plugin-react";
225
227
  import { defineConfig } from "vite";
226
228
  ${tailwind ? "import tailwindcss from '@tailwindcss/vite';" : ""}
@@ -234,7 +236,7 @@ export default defineConfig({
234
236
  "@": path.resolve(__dirname, "./src"),
235
237
  },
236
238
  },
237
- });`,
239
+ });`
238
240
  );
239
241
  }
240
242
 
@@ -272,7 +274,7 @@ export default defineConfig({
272
274
  async function installTanstack() {
273
275
  await exec(`bun add @tanstack/react-router`);
274
276
  await exec(
275
- `bun add -D @tanstack/router-plugin @tanstack/react-router-devtools`,
277
+ `bun add -D @tanstack/router-plugin @tanstack/react-router-devtools`
276
278
  );
277
279
 
278
280
  const src = path.join(props.name, "src");
@@ -306,7 +308,7 @@ export const Route = createRootRoute({
306
308
  </div>
307
309
  ),
308
310
  });
309
- `,
311
+ `
310
312
  );
311
313
 
312
314
  // Create index route file
@@ -324,7 +326,7 @@ function Index() {
324
326
  <h3>Welcome Home!</h3>
325
327
  </div>
326
328
  )
327
- }`,
329
+ }`
328
330
  );
329
331
 
330
332
  // Create about route file
@@ -338,7 +340,7 @@ export const Route = createLazyFileRoute('/about')({
338
340
 
339
341
  function About() {
340
342
  return <div className="p-2">Hello from About!</div>
341
- }`,
343
+ }`
342
344
  );
343
345
 
344
346
  // Create main.tsx
@@ -371,7 +373,7 @@ if (!rootElement.innerHTML) {
371
373
  <RouterProvider router={router} />
372
374
  </StrictMode>,
373
375
  )
374
- }`,
376
+ }`
375
377
  );
376
378
  }
377
379
 
@@ -400,5 +402,5 @@ if (!rootElement.innerHTML) {
400
402
  });
401
403
  }
402
404
  }
403
- },
405
+ }
404
406
  );
@@ -1,4 +1,4 @@
1
- import path from "path";
1
+ import path from "node:path";
2
2
  import type { DefaultTheme, HeadConfig, ThemeOptions } from "vitepress";
3
3
  import { StaticTypeScriptFile } from "../../fs/static-typescript-file";
4
4
 
@@ -1,5 +1,5 @@
1
1
  import { type } from "arktype";
2
- import path from "path";
2
+ import path from "node:path";
3
3
  import type { ModelConfig } from "../../ai/client";
4
4
  import { CSSFile } from "../../ai/css-file";
5
5
  import { Data } from "../../ai/data";
@@ -7,7 +7,7 @@ import { TypeScriptFile } from "../../ai/typescript-file";
7
7
  import { VueFile } from "../../ai/vue-file";
8
8
  import { alchemy } from "../../alchemy";
9
9
  import type { Context } from "../../context";
10
- import { Folder } from "../../fs";
10
+ import { Folder } from "../../fs/folder";
11
11
  import { Resource } from "../../resource";
12
12
  import type { Secret } from "../../secret";
13
13
 
@@ -208,7 +208,7 @@ export const CustomTheme = Resource(
208
208
  async function (
209
209
  this: Context<CustomTheme>,
210
210
  id: string,
211
- props: CustomThemeProps,
211
+ props: CustomThemeProps
212
212
  ): Promise<CustomTheme> {
213
213
  // Handle deletion
214
214
  if (this.phase === "delete") {
@@ -325,13 +325,13 @@ Break down the layout into logical components like NavBar, Sidebar, Footer, etc.
325
325
  schema: type({
326
326
  components: type({
327
327
  name: type("string").describe(
328
- "Component name as used in the import statement (e.g., NavBar, Footer)",
328
+ "Component name as used in the import statement (e.g., NavBar, Footer)"
329
329
  ),
330
330
  path: type("string").describe(
331
- "Import path as written in the import statement (e.g., './components/NavBar.vue')",
331
+ "Import path as written in the import statement (e.g., './components/NavBar.vue')"
332
332
  ),
333
333
  purpose: type("string").describe(
334
- "A clear description of the component's purpose, functionality, and responsibilities in the layout",
334
+ "A clear description of the component's purpose, functionality, and responsibilities in the layout"
335
335
  ),
336
336
  }).array(),
337
337
  }),
@@ -406,7 +406,7 @@ Make sure it integrates well with the overall layout and theme style.`,
406
406
  model: props.model,
407
407
  temperature: props.temperature,
408
408
  });
409
- }),
409
+ })
410
410
  );
411
411
 
412
412
  // Generate user-specified components if provided
@@ -444,7 +444,7 @@ You are writing a Vue component for a VitePress theme.`,
444
444
  model: props.model,
445
445
  temperature: props.temperature,
446
446
  });
447
- }),
447
+ })
448
448
  );
449
449
 
450
450
  // Generate styles file
@@ -510,5 +510,5 @@ You are writing CSS styles for a VitePress theme.`,
510
510
  createdAt: this.output?.createdAt || now,
511
511
  updatedAt: now,
512
512
  });
513
- },
513
+ }
514
514
  );
@@ -1,7 +1,7 @@
1
1
  import yaml from "yaml";
2
2
  import { Document } from "../../ai/document";
3
3
  import { alchemy } from "../../alchemy";
4
- import { StaticTextFile } from "../../fs";
4
+ import { StaticTextFile } from "../../fs/static-text-file";
5
5
  import type { Secret } from "../../secret";
6
6
 
7
7
  /**
@@ -291,7 +291,7 @@ export function parseHomePage(content: string): HomePageConfig {
291
291
  */
292
292
  export async function HomePage(
293
293
  id: string,
294
- props: HomePageProps,
294
+ props: HomePageProps
295
295
  ): Promise<HomePage> {
296
296
  // Build the system prompt with optional extension
297
297
  const systemPrompt = `
@@ -323,18 +323,18 @@ ${props.system || ""}
323
323
  ? JSON.stringify(props.features, null, 2)
324
324
  : "";
325
325
 
326
- if (props.prompt) {
327
- return Document(id, {
328
- title: props.title,
329
- path: props.outFile,
330
- baseURL: props.baseURL,
331
- apiKey: props.apiKey,
332
- model: props.model ?? {
333
- id: "claude-3-7-sonnet-latest",
334
- provider: "anthropic",
335
- },
336
- temperature: props.temperature ?? 0.7,
337
- prompt: await alchemy`
326
+ if (props.prompt) {
327
+ return Document(id, {
328
+ title: props.title,
329
+ path: props.outFile,
330
+ baseURL: props.baseURL,
331
+ apiKey: props.apiKey,
332
+ model: props.model ?? {
333
+ id: "claude-3-7-sonnet-latest",
334
+ provider: "anthropic",
335
+ },
336
+ temperature: props.temperature ?? 0.7,
337
+ prompt: await alchemy`
338
338
  ${systemPrompt}
339
339
 
340
340
  Create a VitePress homepage based on the following description:
@@ -360,9 +360,12 @@ ${props.system || ""}
360
360
 
361
361
  The output should be a complete index.md file with proper YAML frontmatter and markdown content.
362
362
  `,
363
- });
363
+ });
364
364
  } else {
365
- return StaticTextFile(id, props.outFile, `---
365
+ return StaticTextFile(
366
+ id,
367
+ props.outFile,
368
+ `---
366
369
  ${yaml.stringify({
367
370
  layout: "home",
368
371
  name: props.title,
@@ -370,6 +373,7 @@ ${yaml.stringify({
370
373
  features: props.features,
371
374
  })}
372
375
  ---
373
- `);
376
+ `
377
+ );
374
378
  }
375
379
  }
@@ -1,14 +1,12 @@
1
1
  import { exec } from "child_process";
2
- import fs from "fs/promises";
3
- import path from "path";
2
+ import fs from "node:fs/promises";
3
+ import path from "node:path";
4
4
  import { promisify } from "util";
5
5
  import type { Context } from "../../context";
6
- import {
7
- Folder,
8
- StaticJsonFile,
9
- StaticTextFile,
10
- StaticTypeScriptFile,
11
- } from "../../fs";
6
+ import { Folder } from "../../fs/folder";
7
+ import { StaticJsonFile } from "../../fs/static-json-file";
8
+ import { StaticTextFile } from "../../fs/static-text-file";
9
+ import { StaticTypeScriptFile } from "../../fs/static-typescript-file";
12
10
  import { Resource } from "../../resource";
13
11
  import { InstallDependencies, fixedDependencies } from "./dependencies";
14
12
 
@@ -188,7 +186,7 @@ export const VitepressProject = Resource(
188
186
  // `import alchemy from "alchemy";
189
187
  // import { Folder } from "alchemy/fs";
190
188
  // import { Document } from "alchemy/docs";
191
- // import path from "path";
189
+ // import path from "node:path";
192
190
 
193
191
  // const app = await alchemy("alchemy.run", {
194
192
  // stage: "prod",