Merge branch 'dots-in-project-name'

This commit is contained in:
Chris Wanstrath 2026-03-05 07:46:28 -08:00
commit ad8ef49439
7 changed files with 15 additions and 11 deletions

View File

@ -1,6 +1,6 @@
import { Hype } from '@because/hype'
import { define, stylesToCSS } from '@because/forge'
import { baseStyles, ToolScript, theme, on } from '@because/toes/tools'
import { baseStyles, ToolScript, theme, on, VALID_NAME } from '@because/toes/tools'
import { mkdirSync } from 'fs'
import { mkdir, readdir, readFile, rename, rm, stat, writeFile } from 'fs/promises'
import { join, resolve } from 'path'
@ -13,7 +13,6 @@ const DATA_ROOT = process.env.DATA_ROOT!
const TOES_URL = process.env.TOES_URL!
const REPOS_DIR = resolve(DATA_ROOT, 'repos')
const VALID_NAME = /^[a-zA-Z0-9_-]+$/
const VISIBILITY_PATH = join(DATA_DIR, 'visibility.json')
const TOGGLE_SCRIPT = `

View File

@ -1,3 +1,4 @@
import { VALID_NAME } from '../../shared/types'
import { closeModal, openModal, renderModal } from '../components/modal'
import { navigate } from '../router'
import { apps } from '../state'
@ -20,8 +21,8 @@ async function createNewApp() {
return
}
if (!/^[a-z][a-z0-9-]*$/.test(name)) {
newAppError = 'Name must start with a letter and contain only lowercase letters, numbers, and hyphens'
if (!VALID_NAME.test(name)) {
newAppError = 'Name must start with a letter and contain only lowercase letters, numbers, dots, and hyphens'
renderModal()
return
}

View File

@ -1,4 +1,5 @@
import type { App } from '../../shared/types'
import { VALID_NAME } from '../../shared/types'
import { closeModal, openModal, renderModal } from '../components/modal'
import { navigate } from '../router'
import { apps } from '../state'
@ -19,8 +20,8 @@ async function doRenameApp(input: HTMLInputElement) {
return
}
if (!/^[a-z][a-z0-9-]*$/.test(newName)) {
renameAppError = 'Name must start with a letter and contain only lowercase letters, numbers, and hyphens'
if (!VALID_NAME.test(newName)) {
renameAppError = 'Name must start with a letter and contain only lowercase letters, numbers, dots, and hyphens'
renderModal()
return
}

View File

@ -3,6 +3,7 @@ import { buildAppUrl } from '@urls'
import { isTunnelsAvailable, shareApp, unshareApp } from '../tunnels'
import type { App as BackendApp } from '$apps'
import type { App as SharedApp } from '@types'
import { VALID_NAME } from '@types'
import { generateTemplates, type TemplateType } from '%templates'
import { Hype } from '@because/hype'
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'fs'
@ -120,8 +121,8 @@ router.post('/', async c => {
const name = body.name?.trim().toLowerCase().replace(/\s+/g, '-')
if (!name) return c.json({ ok: false, error: 'App name is required' }, 400)
if (!/^[a-z][a-z0-9-]*$/.test(name)) {
return c.json({ ok: false, error: 'Name must start with a letter and contain only lowercase letters, numbers, and hyphens' }, 400)
if (!VALID_NAME.test(name)) {
return c.json({ ok: false, error: 'Name must start with a letter and contain only lowercase letters, numbers, dots, and hyphens' }, 400)
}
const appPath = join(APPS_DIR, name)

View File

@ -1,7 +1,7 @@
import type { App as SharedApp, AppState } from '@types'
import type { ToesEvent, ToesEventInput, ToesEventType } from '../shared/events'
import type { Subprocess } from 'bun'
import { DEFAULT_EMOJI } from '@types'
import { DEFAULT_EMOJI, VALID_NAME } from '@types'
import { buildAppUrl, toSubdomain } from '@urls'
import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from 'fs'
import { LOCAL_HOST } from '%config'
@ -176,8 +176,8 @@ export async function renameApp(oldName: string, newName: string): Promise<{ ok:
if (_apps.has(newName)) return { ok: false, error: 'An app with that name already exists' }
if (!/^[a-z][a-z0-9-]*$/.test(newName)) {
return { ok: false, error: 'Name must start with a letter and contain only lowercase letters, numbers, and hyphens' }
if (!VALID_NAME.test(newName)) {
return { ok: false, error: 'Name must start with a letter and contain only lowercase letters, numbers, dots, and hyphens' }
}
const oldPath = join(APPS_DIR, oldName)

View File

@ -1,4 +1,5 @@
export const DEFAULT_EMOJI = '🖥️'
export const VALID_NAME = /^[a-zA-Z][a-zA-Z0-9.-]*$/
export interface FileInfo {
hash: string

View File

@ -1,3 +1,4 @@
export { VALID_NAME } from '../shared/types'
export { theme } from '../client/themes'
export { loadAppEnv } from './env'
export type { ToesEvent, ToesEventType } from './events'