diff --git a/src/lib/build/shakespearePlugin.ts b/src/lib/build/shakespearePlugin.ts index bf447250..f9a13f40 100644 --- a/src/lib/build/shakespearePlugin.ts +++ b/src/lib/build/shakespearePlugin.ts @@ -9,7 +9,7 @@ interface ShakespearePluginOptions { * This plugin handles specific dependencies that need custom implementations * or dummy APIs to work correctly in the browser environment. */ -export function shakespearePlugin(options?: ShakespearePluginOptions): Plugin { +export function shakespearePlugin(options: ShakespearePluginOptions): Plugin { return { name: "shakespeare", @@ -27,7 +27,7 @@ export function shakespearePlugin(options?: ShakespearePluginOptions): Plugin { return { contents: ` import tailwindConfig from "@/../${pathname}"; - import "${options?.esmUrl}/tailwindcss-cdn@3"; + import "${options.esmUrl}/tailwindcss-cdn@3"; tailwind.config = tailwindConfig; `, loader: "js", diff --git a/src/lib/tools/BuildProjectTool.test.ts b/src/lib/tools/BuildProjectTool.test.ts index b668c694..b9a1585d 100644 --- a/src/lib/tools/BuildProjectTool.test.ts +++ b/src/lib/tools/BuildProjectTool.test.ts @@ -1,6 +1,7 @@ import { describe, it, expect, beforeEach, vi } from 'vitest'; import { BuildProjectTool } from './BuildProjectTool'; import type { JSRuntimeFS } from '../JSRuntime'; +import type { AppConfig } from '../../contexts/AppContext'; // Mock the build functions vi.mock('../build', () => ({ @@ -11,6 +12,7 @@ import { buildProject } from '../build'; describe('BuildProjectTool', () => { let mockFS: JSRuntimeFS; + let mockConfig: AppConfig; let tool: BuildProjectTool; beforeEach(() => { @@ -24,7 +26,15 @@ describe('BuildProjectTool', () => { mkdir: vi.fn(), } as unknown as JSRuntimeFS; - tool = new BuildProjectTool(mockFS, '/test/project'); + mockConfig = { + theme: 'light', + relayUrl: 'wss://relay.nostr.band', + deployServer: 'shakespeare.wtf', + esmUrl: 'https://esm.shakespeare.diy', + language: 'en', + }; + + tool = new BuildProjectTool(mockFS, '/test/project', mockConfig); }); it('should have correct description', () => { @@ -69,6 +79,7 @@ describe('BuildProjectTool', () => { const result = await tool.execute(); expect(buildProject).toHaveBeenCalledWith({ + esmUrl: 'https://esm.shakespeare.diy', fs: mockFS, projectPath: '/test/project', domParser: expect.any(DOMParser), @@ -100,6 +111,7 @@ describe('BuildProjectTool', () => { await tool.execute(); expect(buildProject).toHaveBeenCalledWith({ + esmUrl: 'https://esm.shakespeare.diy', fs: mockFS, projectPath: '/test/project', domParser: expect.any(DOMParser), diff --git a/src/lib/tools/BuildProjectTool.ts b/src/lib/tools/BuildProjectTool.ts index 2a4f1ad9..35762892 100644 --- a/src/lib/tools/BuildProjectTool.ts +++ b/src/lib/tools/BuildProjectTool.ts @@ -1,23 +1,26 @@ import type { Tool } from "./Tool"; import type { JSRuntimeFS } from "../JSRuntime"; +import type { AppConfig } from "../../contexts/AppContext"; import { buildProject } from "../build"; export class BuildProjectTool implements Tool { private fs: JSRuntimeFS; private cwd: string; + private config: AppConfig; readonly description = "Build the project using esbuild. Creates optimized production files in the dist directory."; - constructor(fs: JSRuntimeFS, cwd: string) { + constructor(fs: JSRuntimeFS, cwd: string, config: AppConfig) { this.fs = fs; this.cwd = cwd; + this.config = config; } async execute(): Promise { try { // Build and write the project files const result = await buildProject({ - esmUrl: 'https://esm.shakespeare.diy', + esmUrl: this.config.esmUrl, fs: this.fs, projectPath: this.cwd, domParser: new DOMParser(), diff --git a/src/test/TestApp.tsx b/src/test/TestApp.tsx index 357ff959..5594272b 100644 --- a/src/test/TestApp.tsx +++ b/src/test/TestApp.tsx @@ -31,7 +31,7 @@ export function TestApp({ children }: TestAppProps) { theme: 'light', relayUrl: 'wss://relay.nostr.band', deployServer: 'shakespeare.wtf', - esmUrl: 'https://esm.sh', + esmUrl: 'https://esm.shakespeare.diy', language: 'en', };