From aa82aaf02c3ee8439011c14ac22eda7d08f4f727 Mon Sep 17 00:00:00 2001 From: Chad Curtis Date: Tue, 7 Oct 2025 23:41:23 +0000 Subject: [PATCH 1/6] init --- src/App.tsx | 1 + src/AppRouter.tsx | 2 + src/components/AppProvider.tsx | 1 + src/contexts/AppContext.ts | 2 + src/hooks/useBuildProject.ts | 3 ++ src/lib/build/esmPlugin.ts | 13 ++--- src/lib/build/index.test.ts | 7 +++ src/lib/build/index.ts | 24 ++++----- src/lib/build/shakespearePlugin.ts | 8 ++- src/lib/esbuild.ts | 8 +-- src/lib/i18n.ts | 36 ++++++++++++++ src/lib/tools/BuildProjectTool.ts | 1 + src/pages/Settings.tsx | 9 +++- src/pages/SystemSettings.tsx | 80 ++++++++++++++++++++++++++++++ src/test/TestApp.tsx | 1 + 15 files changed, 171 insertions(+), 25 deletions(-) create mode 100644 src/pages/SystemSettings.tsx diff --git a/src/App.tsx b/src/App.tsx index bd3cd3eb..b2a25377 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -43,6 +43,7 @@ const defaultConfig: AppConfig = { theme: "system", relayUrl: "wss://relay.primal.net", deployServer: "shakespeare.wtf", + esmUrl: "https://esm.shakespeare.diy", }; const presetRelays = [ diff --git a/src/AppRouter.tsx b/src/AppRouter.tsx index 5558d2db..c143e500 100644 --- a/src/AppRouter.tsx +++ b/src/AppRouter.tsx @@ -9,6 +9,7 @@ import Preferences from "./pages/Preferences"; import NostrSettings from "./pages/NostrSettings"; import AISettings from "./pages/AISettings"; import GitSettings from "./pages/GitSettings"; +import SystemSettings from "./pages/SystemSettings"; import DataSettings from "./pages/DataSettings"; import AboutSettings from "./pages/AboutSettings"; @@ -33,6 +34,7 @@ export function AppRouter() { } /> } /> } /> + } /> } /> } /> diff --git a/src/components/AppProvider.tsx b/src/components/AppProvider.tsx index b293fa20..1e6837b0 100644 --- a/src/components/AppProvider.tsx +++ b/src/components/AppProvider.tsx @@ -19,6 +19,7 @@ const AppConfigSchema: z.ZodType = z.object({ theme: z.enum(['dark', 'light', 'system']), relayUrl: z.string().url(), deployServer: z.string().min(1), + esmUrl: z.string().url(), language: z.string().optional(), }); diff --git a/src/contexts/AppContext.ts b/src/contexts/AppContext.ts index 28e9cb39..11e037fa 100644 --- a/src/contexts/AppContext.ts +++ b/src/contexts/AppContext.ts @@ -9,6 +9,8 @@ export interface AppConfig { relayUrl: string; /** Deploy server domain (e.g., "shakespeare.wtf") */ deployServer: string; + /** ESM CDN URL for package imports */ + esmUrl: string; /** Selected language */ language?: string; } diff --git a/src/hooks/useBuildProject.ts b/src/hooks/useBuildProject.ts index 3fd705db..6cb96e2b 100644 --- a/src/hooks/useBuildProject.ts +++ b/src/hooks/useBuildProject.ts @@ -1,9 +1,11 @@ import { useMutation } from "@tanstack/react-query"; import { buildProject } from "@/lib/build"; import { useFS } from "./useFS"; +import { useAppContext } from "./useAppContext"; export function useBuildProject(projectId: string) { const { fs } = useFS(); + const { config } = useAppContext(); return useMutation({ mutationFn: async () => { @@ -11,6 +13,7 @@ export function useBuildProject(projectId: string) { fs, projectPath: `/projects/${projectId}`, domParser: new DOMParser(), + esmUrl: config.esmUrl, }); }, }); diff --git a/src/lib/build/esmPlugin.ts b/src/lib/build/esmPlugin.ts index 9c2da0d0..ffcd563e 100644 --- a/src/lib/build/esmPlugin.ts +++ b/src/lib/build/esmPlugin.ts @@ -23,10 +23,11 @@ interface EsmPluginOptions { packageJson: PackageJson; packageLock?: PackageLock; target?: string; + esmUrl: string; } export function esmPlugin(options: EsmPluginOptions): Plugin { - const { packageJson, packageLock, target } = options; + const { packageJson, packageLock, target, esmUrl } = options; /** Cache of URL redirects */ const redirectedURLs = new Map(); @@ -222,7 +223,7 @@ export function esmPlugin(options: EsmPluginOptions): Plugin { switch (moduleName) { case "buffer": return { - path: `https://esm.sh/${moduleName}?target=${target ?? "esnext"}`, + path: `${esmUrl}/${moduleName}?target=${target ?? "esnext"}`, namespace: "esm", }; default: @@ -323,7 +324,7 @@ export function esmPlugin(options: EsmPluginOptions): Plugin { ? `${cdnName}@${version}${packagePath}` : `${cdnName}${packagePath}`; - const url = new URL(`https://esm.sh/*${specifier}`); + const url = new URL(`${esmUrl}/*${specifier}`); if (target) url.searchParams.set("target", target); if (childLockPath) url.searchParams.set("lp", encodeURIComponent(childLockPath)); @@ -441,9 +442,9 @@ export function esmPlugin(options: EsmPluginOptions): Plugin { }; } -/** Extract package name from esm.sh-style URL */ -function extractPackageName(esmShURL: string): { pkg?: string; version?: string } { - const full = new URL(esmShURL) +/** Extract package name from ESM CDN-style URL */ +function extractPackageName(esmURL: string): { pkg?: string; version?: string } { + const full = new URL(esmURL) .pathname .slice(1) .replace(/^\*/, ""); diff --git a/src/lib/build/index.test.ts b/src/lib/build/index.test.ts index 865ece6f..f56a05ca 100644 --- a/src/lib/build/index.test.ts +++ b/src/lib/build/index.test.ts @@ -161,6 +161,7 @@ describe('buildProject', () => { fs: mockFS, projectPath: '/test/project', domParser: mockDOMParser, + esmUrl: 'https://esm.shakespeare.diy', }); // Should include built files with hashed names @@ -220,6 +221,7 @@ describe('buildProject', () => { fs: mockFS, projectPath: '/test/project', domParser: mockDOMParser, + esmUrl: 'https://esm.shakespeare.diy', }); // Should still include built files with hashed names @@ -278,6 +280,7 @@ describe('buildProject', () => { fs: mockFS, projectPath: '/test/project', domParser: mockDOMParser, + esmUrl: 'https://esm.shakespeare.diy', }); // Should include built files with hashed names @@ -348,6 +351,7 @@ react@^18.0.0: fs: mockFS, projectPath: '/test/project', domParser: mockDOMParser, + esmUrl: 'https://esm.shakespeare.diy', }); // Should successfully build with yarn.lock @@ -398,6 +402,7 @@ react@^18.0.0: fs: mockFS, projectPath: '/test/project', domParser: mockDOMParser, + esmUrl: 'https://esm.shakespeare.diy', }); // Should successfully build with empty packages object @@ -457,6 +462,7 @@ react@^18.0.0: fs: mockFS, projectPath: '/test/project', domParser: mockDOMParser, + esmUrl: 'https://esm.shakespeare.diy', }); // Should successfully build using package.json dependencies @@ -519,6 +525,7 @@ react@^18.0.0: fs: mockFS, projectPath: '/test/project', domParser: mockDOMParser, + esmUrl: 'https://esm.shakespeare.diy', }); // Should successfully build with tsconfig.json diff --git a/src/lib/build/index.ts b/src/lib/build/index.ts index 933c36f1..23ceea44 100644 --- a/src/lib/build/index.ts +++ b/src/lib/build/index.ts @@ -17,14 +17,14 @@ export interface BuildProjectOptions { domParser: DOMParser; target?: string; outputPath?: string; + esmUrl: string; } async function bundle( options: BuildProjectOptions, ): Promise> { - const esbuild = await getEsbuild(); - - const { fs, projectPath, domParser, target = "esnext" } = options; + const { fs, projectPath, domParser, target = "esnext", esmUrl } = options; + const esbuild = await getEsbuild(esmUrl); const indexHtmlText = await fs.readFile( `${projectPath}/index.html`, @@ -124,9 +124,9 @@ async function bundle( chunkNames: "[name]-[hash]", assetNames: "[name]-[hash]", plugins: [ - shakespearePlugin(), + shakespearePlugin({ esmUrl }), fsPlugin({ fs, cwd: projectPath, tsconfig }), - esmPlugin({ packageJson, packageLock, target }), + esmPlugin({ packageJson, packageLock, target, esmUrl }), ], define: { "import.meta.env": JSON.stringify({}), @@ -161,12 +161,12 @@ async function bundle( } } - // Parse CSP and ensure esm.sh is allowed for necessary directives + // Parse CSP and ensure ESM CDN is allowed for necessary directives const cspMeta = doc.querySelector("meta[http-equiv=\"content-security-policy\"]"); if (cspMeta) { const cspContent = cspMeta.getAttribute("content"); if (cspContent) { - const updatedCSP = updateCSPForEsmSh(cspContent); + const updatedCSP = updateCSPForEsmSh(cspContent, esmUrl); cspMeta.setAttribute("content", updatedCSP); } } @@ -261,16 +261,16 @@ async function fileExists(fs: JSRuntimeFS, path: string): Promise { } } -/** Updates CSP to allow esm.sh for scripts, assets, fonts, and CSS */ -export function updateCSPForEsmSh(csp: string): string { - const esmShDirectives = [ +/** Updates CSP to allow ESM CDN for scripts, assets, fonts, and CSS */ +export function updateCSPForEsmSh(csp: string, esmUrl: string): string { + const esmDirectives = [ 'script-src', // For JavaScript modules 'img-src', // For images 'media-src', // For video/audio 'font-src', // For fonts 'style-src', // For CSS - 'connect-src' // For fetch/XHR requests to esm.sh + 'connect-src' // For fetch/XHR requests to ESM CDN ]; - return addDomainToCSP(csp, 'https://esm.sh', esmShDirectives); + return addDomainToCSP(csp, esmUrl, esmDirectives); } \ No newline at end of file diff --git a/src/lib/build/shakespearePlugin.ts b/src/lib/build/shakespearePlugin.ts index ec272afc..bf447250 100644 --- a/src/lib/build/shakespearePlugin.ts +++ b/src/lib/build/shakespearePlugin.ts @@ -1,11 +1,15 @@ import type { Plugin } from "esbuild-wasm"; +interface ShakespearePluginOptions { + esmUrl: string; +} + /** * Shakespeare plugin for dependency polyfills and workarounds. * This plugin handles specific dependencies that need custom implementations * or dummy APIs to work correctly in the browser environment. */ -export function shakespearePlugin(): Plugin { +export function shakespearePlugin(options?: ShakespearePluginOptions): Plugin { return { name: "shakespeare", @@ -23,7 +27,7 @@ export function shakespearePlugin(): Plugin { return { contents: ` import tailwindConfig from "@/../${pathname}"; - import "https://esm.sh/tailwindcss-cdn@3"; + import "${options?.esmUrl}/tailwindcss-cdn@3"; tailwind.config = tailwindConfig; `, loader: "js", diff --git a/src/lib/esbuild.ts b/src/lib/esbuild.ts index 9ee838c4..b051c1e9 100644 --- a/src/lib/esbuild.ts +++ b/src/lib/esbuild.ts @@ -4,19 +4,19 @@ type ESBuild = typeof _ESBuild; let promise: Promise | undefined; -export function getEsbuild(): Promise { +export function getEsbuild(esmUrl: string): Promise { if (!promise) { - promise = loadEsbuild(); + promise = loadEsbuild(esmUrl); } return promise; } -async function loadEsbuild(): Promise { +async function loadEsbuild(esmUrl: string): Promise { const { default: esbuild } = await import("esbuild-wasm"); await esbuild.initialize({ worker: false, - wasmURL: "https://esm.sh/esbuild-wasm@0.25.8/esbuild.wasm", + wasmURL: `${esmUrl}/esbuild-wasm@0.25.8/esbuild.wasm`, }); return esbuild; diff --git a/src/lib/i18n.ts b/src/lib/i18n.ts index 6a0256d0..14cc92ee 100644 --- a/src/lib/i18n.ts +++ b/src/lib/i18n.ts @@ -27,6 +27,12 @@ const resources = { language: 'Language', languageDescription: 'Select your preferred language for the interface.', + // System Settings Section + systemSettings: 'System Settings', + systemSettingsDescription: 'Configure system-level settings and advanced options.', + esmUrl: 'ESM CDN URL', + esmUrlDescription: 'Configure the ESM CDN URL for package imports. Default: https://esm.shakespeare.diy', + // Language Options english: 'English', portuguese: 'Portuguese', @@ -338,6 +344,12 @@ const resources = { language: 'Idioma', languageDescription: 'Selecione seu idioma preferido para a interface.', + // System Settings Section + systemSettings: 'Configurações do Sistema', + systemSettingsDescription: 'Configure configurações de nível de sistema e opções avançadas.', + esmUrl: 'URL do CDN ESM', + esmUrlDescription: 'Configure a URL do CDN ESM para importações de pacotes. Padrão: https://esm.shakespeare.diy', + // Language Options english: 'Inglês', portuguese: 'Português', @@ -649,6 +661,12 @@ const resources = { language: '语言', languageDescription: '选择您的界面首选语言。', + // System Settings Section + systemSettings: '系统设置', + systemSettingsDescription: '配置系统级设置和高级选项。', + esmUrl: 'ESM CDN URL', + esmUrlDescription: '配置包导入的 ESM CDN URL。默认:https://esm.shakespeare.diy', + // Language Options english: 'English', portuguese: 'Português', @@ -960,6 +978,12 @@ const resources = { language: 'Harshe', languageDescription: 'Zaɓi harshen da kuke so don dubawa.', + // System Settings Section + systemSettings: 'Saitunan Tsarin', + systemSettingsDescription: 'Saita saitunan matakin tsari da zaɓuɓɓuka na ci gaba.', + esmUrl: 'URL na CDN ESM', + esmUrlDescription: 'Saita URL na CDN ESM don shigo da fakitin. Tsoho: https://esm.shakespeare.diy', + // Language Options english: 'Turanci', portuguese: 'Fotigis', @@ -1271,6 +1295,12 @@ const resources = { language: 'Ede', languageDescription: 'Yan ede ti o fẹran fun wiwo.', + // System Settings Section + systemSettings: 'Saitunan Eto', + systemSettingsDescription: 'Tunto awọn saitan eto ati awọn ayanfẹ ti o pọju.', + esmUrl: 'URL CDN ESM', + esmUrlDescription: 'Tunto URL CDN ESM fun gbigbe awọn package. Aiyipada: https://esm.shakespeare.diy', + // Language Options english: 'Gẹẹsi', portuguese: 'Potogisi', @@ -1577,6 +1607,12 @@ const resources = { language: 'Asụsụ', languageDescription: 'Họrọ asụsụ ị chọrọ maka interface.', + // System Settings Section + systemSettings: 'Ntọala Sistemu', + systemSettingsDescription: 'Hazie ntọala ọkwa sistemu na nhọrọ ndị ọganihu.', + esmUrl: 'URL CDN ESM', + esmUrlDescription: 'Hazie URL CDN ESM maka mbubata ngwugwu. Default: https://esm.shakespeare.diy', + // Language Options english: 'Bekee', portuguese: 'Portuguese', diff --git a/src/lib/tools/BuildProjectTool.ts b/src/lib/tools/BuildProjectTool.ts index 979a3526..2a4f1ad9 100644 --- a/src/lib/tools/BuildProjectTool.ts +++ b/src/lib/tools/BuildProjectTool.ts @@ -17,6 +17,7 @@ export class BuildProjectTool implements Tool { try { // Build and write the project files const result = await buildProject({ + esmUrl: 'https://esm.shakespeare.diy', fs: this.fs, projectPath: this.cwd, domParser: new DOMParser(), diff --git a/src/pages/Settings.tsx b/src/pages/Settings.tsx index cf978600..74cd1b7f 100644 --- a/src/pages/Settings.tsx +++ b/src/pages/Settings.tsx @@ -1,6 +1,6 @@ import { useNavigate } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; -import { Bot, GitBranch, Database, Wifi, Settings2, Info } from 'lucide-react'; +import { Bot, GitBranch, Database, Wifi, Settings2, Info, Cog } from 'lucide-react'; import { useIsMobile } from '@/hooks/useIsMobile'; interface SettingsItem { @@ -41,6 +41,13 @@ const getSettingsItems = (t: (key: string) => string): SettingsItem[] => [ icon: Wifi, href: '/settings/nostr', }, + { + id: 'system', + title: t('systemSettings'), + description: t('systemSettingsDescription'), + icon: Cog, + href: '/settings/system', + }, { id: 'data', title: t('dataSettings'), diff --git a/src/pages/SystemSettings.tsx b/src/pages/SystemSettings.tsx new file mode 100644 index 00000000..756ed080 --- /dev/null +++ b/src/pages/SystemSettings.tsx @@ -0,0 +1,80 @@ +import { Settings2, ArrowLeft, Globe } from "lucide-react"; +import { useTranslation } from 'react-i18next'; +import { Button } from "@/components/ui/button"; +import { Input } from "@/components/ui/input"; + +import { Label } from "@/components/ui/label"; +import { useIsMobile } from "@/hooks/useIsMobile"; +import { useNavigate } from "react-router-dom"; +import { useAppContext } from "@/hooks/useAppContext"; + +export function SystemSettings() { + const { t } = useTranslation(); + const isMobile = useIsMobile(); + const navigate = useNavigate(); + const { config, updateConfig } = useAppContext(); + + return ( +
+ {isMobile && ( +
+ +
+

+ + {t('systemSettings')} +

+

+ {t('systemSettingsDescription')} +

+
+
+ )} + + {!isMobile && ( +
+

+ + {t('systemSettings')} +

+

+ {t('systemSettingsDescription')} +

+
+ )} + +
+
+ + updateConfig((current) => ({ + ...current, + esmUrl: e.target.value, + }))} + className="w-full max-w-xs" + placeholder="https://esm.shakespeare.diy" + /> +

+ {t('esmUrlDescription')} +

+
+
+
+ ); +} + +export default SystemSettings; \ No newline at end of file diff --git a/src/test/TestApp.tsx b/src/test/TestApp.tsx index e6909575..357ff959 100644 --- a/src/test/TestApp.tsx +++ b/src/test/TestApp.tsx @@ -31,6 +31,7 @@ export function TestApp({ children }: TestAppProps) { theme: 'light', relayUrl: 'wss://relay.nostr.band', deployServer: 'shakespeare.wtf', + esmUrl: 'https://esm.sh', language: 'en', }; From fb487ea6224d9cb10c1c4e52499959e651ba68f0 Mon Sep 17 00:00:00 2001 From: Chad Curtis Date: Wed, 8 Oct 2025 03:21:48 +0000 Subject: [PATCH 2/6] Actually show system settings in list. --- src/components/SettingsLayout.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/components/SettingsLayout.tsx b/src/components/SettingsLayout.tsx index ba1fe434..b6dfd7a8 100644 --- a/src/components/SettingsLayout.tsx +++ b/src/components/SettingsLayout.tsx @@ -3,7 +3,7 @@ import { useNavigate, useLocation, Outlet } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import { Button } from '@/components/ui/button'; import { ScrollArea } from '@/components/ui/scroll-area'; -import { Menu, Bot, GitBranch, Database, Wifi, Settings2, Info } from 'lucide-react'; +import { Menu, Bot, GitBranch, Database, Wifi, Settings2, Info, Cog } from 'lucide-react'; import { ProjectSidebar } from '@/components/ProjectSidebar'; import { useProjectsManager } from '@/hooks/useProjectsManager'; import { useIsMobile } from '@/hooks/useIsMobile'; @@ -49,6 +49,13 @@ const getSettingsItems = (t: (key: string) => string): SettingsItem[] => [ icon: Wifi, href: '/settings/nostr', }, + { + id: 'system', + title: t('systemSettings'), + description: t('systemSettingsDescription'), + icon: Cog, + href: '/settings/system', + }, { id: 'data', title: t('dataSettings'), From 9a6058fedb39d4439a959664fa032260ba822d34 Mon Sep 17 00:00:00 2001 From: Chad Curtis Date: Wed, 8 Oct 2025 03:55:10 +0000 Subject: [PATCH 3/6] Dynamic URL in more places. --- src/lib/build/shakespearePlugin.ts | 4 ++-- src/lib/tools/BuildProjectTool.test.ts | 14 +++++++++++++- src/lib/tools/BuildProjectTool.ts | 7 +++++-- src/test/TestApp.tsx | 2 +- 4 files changed, 21 insertions(+), 6 deletions(-) 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', }; From bacf6f2869326c1199fd9449015008e0a97e5669 Mon Sep 17 00:00:00 2001 From: Chad Curtis Date: Wed, 8 Oct 2025 04:44:13 +0000 Subject: [PATCH 4/6] Cleanup --- src/components/Shakespeare/ChatPane.tsx | 5 ++++- src/lib/tools/BuildProjectTool.test.ts | 12 ++---------- src/lib/tools/BuildProjectTool.ts | 9 ++++----- src/pages/SystemSettings.tsx | 17 ++++++++++++----- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/components/Shakespeare/ChatPane.tsx b/src/components/Shakespeare/ChatPane.tsx index 6d08e63f..e6f965f1 100644 --- a/src/components/Shakespeare/ChatPane.tsx +++ b/src/components/Shakespeare/ChatPane.tsx @@ -13,6 +13,7 @@ import { useAISettings } from '@/hooks/useAISettings'; import { useFS } from '@/hooks/useFS'; import { useCurrentUser } from '@/hooks/useCurrentUser'; import { useKeepAlive } from '@/hooks/useKeepAlive'; +import { useAppContext } from '@/hooks/useAppContext'; import { useAIChat } from '@/hooks/useAIChat'; import { useProviderModels } from '@/hooks/useProviderModels'; import { ModelSelector } from '@/components/ModelSelector'; @@ -77,6 +78,7 @@ export const ChatPane = forwardRef(({ const { git } = useGit(); const { user } = useCurrentUser(); const { models } = useProviderModels(); + const { config } = useAppContext(); const [input, setInput] = useState(''); const [showScrollToBottom, setShowScrollToBottom] = useState(false); const [attachedFiles, setAttachedFiles] = useState([]); @@ -133,6 +135,7 @@ export const ChatPane = forwardRef(({ // Initialize AI chat with tools const cwd = `/projects/${projectId}`; + const esmUrlRef = useRef(config.esmUrl); const customTools = useMemo(() => { const baseTools = { git_commit: new GitCommitTool(fs, cwd, git), @@ -141,7 +144,7 @@ export const ChatPane = forwardRef(({ text_editor_str_replace: new TextEditorStrReplaceTool(fs, cwd), npm_add_package: new NpmAddPackageTool(fs, cwd), npm_remove_package: new NpmRemovePackageTool(fs, cwd), - build_project: new BuildProjectTool(fs, cwd), + build_project: new BuildProjectTool(fs, cwd, esmUrlRef.current), typecheck: new TypecheckTool(fs, cwd), nostr_read_nip: new NostrReadNipTool(), nostr_fetch_event: new NostrFetchEventTool(), diff --git a/src/lib/tools/BuildProjectTool.test.ts b/src/lib/tools/BuildProjectTool.test.ts index b9a1585d..980de28d 100644 --- a/src/lib/tools/BuildProjectTool.test.ts +++ b/src/lib/tools/BuildProjectTool.test.ts @@ -1,7 +1,6 @@ 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', () => ({ @@ -12,7 +11,6 @@ import { buildProject } from '../build'; describe('BuildProjectTool', () => { let mockFS: JSRuntimeFS; - let mockConfig: AppConfig; let tool: BuildProjectTool; beforeEach(() => { @@ -26,15 +24,9 @@ describe('BuildProjectTool', () => { mkdir: vi.fn(), } as unknown as JSRuntimeFS; - 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); + + tool = new BuildProjectTool(mockFS, '/test/project', 'https://esm.shakespeare.diy'); }); it('should have correct description', () => { diff --git a/src/lib/tools/BuildProjectTool.ts b/src/lib/tools/BuildProjectTool.ts index 35762892..c250d945 100644 --- a/src/lib/tools/BuildProjectTool.ts +++ b/src/lib/tools/BuildProjectTool.ts @@ -1,26 +1,25 @@ 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; + private esmUrl: string; readonly description = "Build the project using esbuild. Creates optimized production files in the dist directory."; - constructor(fs: JSRuntimeFS, cwd: string, config: AppConfig) { + constructor(fs: JSRuntimeFS, cwd: string, esmUrl: string) { this.fs = fs; this.cwd = cwd; - this.config = config; + this.esmUrl = esmUrl; } async execute(): Promise { try { // Build and write the project files const result = await buildProject({ - esmUrl: this.config.esmUrl, + esmUrl: this.esmUrl, fs: this.fs, projectPath: this.cwd, domParser: new DOMParser(), diff --git a/src/pages/SystemSettings.tsx b/src/pages/SystemSettings.tsx index 756ed080..ef0fecd2 100644 --- a/src/pages/SystemSettings.tsx +++ b/src/pages/SystemSettings.tsx @@ -1,5 +1,6 @@ import { Settings2, ArrowLeft, Globe } from "lucide-react"; import { useTranslation } from 'react-i18next'; +import { useState } from "react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; @@ -13,6 +14,7 @@ export function SystemSettings() { const isMobile = useIsMobile(); const navigate = useNavigate(); const { config, updateConfig } = useAppContext(); + const [esmUrlInput, setEsmUrlInput] = useState(config.esmUrl); return (
@@ -60,11 +62,16 @@ export function SystemSettings() { updateConfig((current) => ({ - ...current, - esmUrl: e.target.value, - }))} + value={esmUrlInput} + onChange={(e) => { + // Strip trailing slash on save. + const value = e.target.value; + setEsmUrlInput(value); + updateConfig((current) => ({ + ...current, + esmUrl: value.replace(/\/+$/, ''), + })); + }} className="w-full max-w-xs" placeholder="https://esm.shakespeare.diy" /> From 00485a6889689542d2f3ce67c2c1d2ec92b23050 Mon Sep 17 00:00:00 2001 From: Chad Curtis Date: Wed, 8 Oct 2025 04:45:56 +0000 Subject: [PATCH 5/6] rm space --- src/lib/tools/BuildProjectTool.test.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/lib/tools/BuildProjectTool.test.ts b/src/lib/tools/BuildProjectTool.test.ts index 980de28d..f7453c47 100644 --- a/src/lib/tools/BuildProjectTool.test.ts +++ b/src/lib/tools/BuildProjectTool.test.ts @@ -24,8 +24,6 @@ describe('BuildProjectTool', () => { mkdir: vi.fn(), } as unknown as JSRuntimeFS; - - tool = new BuildProjectTool(mockFS, '/test/project', 'https://esm.shakespeare.diy'); }); @@ -85,8 +83,6 @@ describe('BuildProjectTool', () => { expect(result).toContain('📄 main.css'); }); - - it('should clean existing dist directory before building', async () => { const mockFiles = { 'index.html': new Uint8Array([1, 2, 3]), From 613f8b76bbdf631018cb6968ec3ab1bf766fbe1a Mon Sep 17 00:00:00 2001 From: Chad Curtis Date: Wed, 8 Oct 2025 05:37:05 +0000 Subject: [PATCH 6/6] Review fixes. --- src/components/SettingsLayout.tsx | 16 ++++++++-------- src/lib/i18n.ts | 24 ++++++++++++------------ src/pages/SystemSettings.tsx | 7 +++---- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/components/SettingsLayout.tsx b/src/components/SettingsLayout.tsx index b6dfd7a8..25d7f74d 100644 --- a/src/components/SettingsLayout.tsx +++ b/src/components/SettingsLayout.tsx @@ -3,7 +3,7 @@ import { useNavigate, useLocation, Outlet } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import { Button } from '@/components/ui/button'; import { ScrollArea } from '@/components/ui/scroll-area'; -import { Menu, Bot, GitBranch, Database, Wifi, Settings2, Info, Cog } from 'lucide-react'; +import { Menu, Bot, GitBranch, Database, Wifi, Settings2, Info, Settings } from 'lucide-react'; import { ProjectSidebar } from '@/components/ProjectSidebar'; import { useProjectsManager } from '@/hooks/useProjectsManager'; import { useIsMobile } from '@/hooks/useIsMobile'; @@ -49,13 +49,6 @@ const getSettingsItems = (t: (key: string) => string): SettingsItem[] => [ icon: Wifi, href: '/settings/nostr', }, - { - id: 'system', - title: t('systemSettings'), - description: t('systemSettingsDescription'), - icon: Cog, - href: '/settings/system', - }, { id: 'data', title: t('dataSettings'), @@ -63,6 +56,13 @@ const getSettingsItems = (t: (key: string) => string): SettingsItem[] => [ icon: Database, href: '/settings/data', }, + { + id: 'system', + title: t('systemSettings'), + description: t('systemSettingsDescription'), + icon: Settings, + href: '/settings/system', + }, { id: 'about', title: t('aboutShakespeare'), diff --git a/src/lib/i18n.ts b/src/lib/i18n.ts index 14cc92ee..fdc36307 100644 --- a/src/lib/i18n.ts +++ b/src/lib/i18n.ts @@ -30,8 +30,8 @@ const resources = { // System Settings Section systemSettings: 'System Settings', systemSettingsDescription: 'Configure system-level settings and advanced options.', - esmUrl: 'ESM CDN URL', - esmUrlDescription: 'Configure the ESM CDN URL for package imports. Default: https://esm.shakespeare.diy', + esmUrl: 'Javascript CDN', + esmUrlDescription: 'Configure the Javascript CDN URL for package imports.', // Language Options english: 'English', @@ -347,8 +347,8 @@ const resources = { // System Settings Section systemSettings: 'Configurações do Sistema', systemSettingsDescription: 'Configure configurações de nível de sistema e opções avançadas.', - esmUrl: 'URL do CDN ESM', - esmUrlDescription: 'Configure a URL do CDN ESM para importações de pacotes. Padrão: https://esm.shakespeare.diy', + esmUrl: 'URL do CDN Javascript', + esmUrlDescription: 'Configure a URL do CDN Javascript para importações de pacotes.', // Language Options english: 'Inglês', @@ -664,8 +664,8 @@ const resources = { // System Settings Section systemSettings: '系统设置', systemSettingsDescription: '配置系统级设置和高级选项。', - esmUrl: 'ESM CDN URL', - esmUrlDescription: '配置包导入的 ESM CDN URL。默认:https://esm.shakespeare.diy', + esmUrl: 'Javascript CDN URL', + esmUrlDescription: '配置包导入的 Javascript CDN URL。', // Language Options english: 'English', @@ -981,8 +981,8 @@ const resources = { // System Settings Section systemSettings: 'Saitunan Tsarin', systemSettingsDescription: 'Saita saitunan matakin tsari da zaɓuɓɓuka na ci gaba.', - esmUrl: 'URL na CDN ESM', - esmUrlDescription: 'Saita URL na CDN ESM don shigo da fakitin. Tsoho: https://esm.shakespeare.diy', + esmUrl: 'URL na CDN Javascript', + esmUrlDescription: 'Saita URL na CDN Javascript don shigo da fakitin.', // Language Options english: 'Turanci', @@ -1298,8 +1298,8 @@ const resources = { // System Settings Section systemSettings: 'Saitunan Eto', systemSettingsDescription: 'Tunto awọn saitan eto ati awọn ayanfẹ ti o pọju.', - esmUrl: 'URL CDN ESM', - esmUrlDescription: 'Tunto URL CDN ESM fun gbigbe awọn package. Aiyipada: https://esm.shakespeare.diy', + esmUrl: 'URL CDN Javascript', + esmUrlDescription: 'Tunto URL CDN Javascript fun gbigbe awọn package.', // Language Options english: 'Gẹẹsi', @@ -1610,8 +1610,8 @@ const resources = { // System Settings Section systemSettings: 'Ntọala Sistemu', systemSettingsDescription: 'Hazie ntọala ọkwa sistemu na nhọrọ ndị ọganihu.', - esmUrl: 'URL CDN ESM', - esmUrlDescription: 'Hazie URL CDN ESM maka mbubata ngwugwu. Default: https://esm.shakespeare.diy', + esmUrl: 'URL CDN Javascript', + esmUrlDescription: 'Hazie URL CDN Javascript maka mbubata ngwugwu.', // Language Options english: 'Bekee', diff --git a/src/pages/SystemSettings.tsx b/src/pages/SystemSettings.tsx index ef0fecd2..5ac0702d 100644 --- a/src/pages/SystemSettings.tsx +++ b/src/pages/SystemSettings.tsx @@ -1,4 +1,4 @@ -import { Settings2, ArrowLeft, Globe } from "lucide-react"; +import { Settings, ArrowLeft } from "lucide-react"; import { useTranslation } from 'react-i18next'; import { useState } from "react"; import { Button } from "@/components/ui/button"; @@ -31,7 +31,7 @@ export function SystemSettings() {

- + {t('systemSettings')}

@@ -44,7 +44,7 @@ export function SystemSettings() { {!isMobile && (

- + {t('systemSettings')}

@@ -56,7 +56,6 @@ export function SystemSettings() {