diff --git a/src/compiler/bundler.ts b/src/compiler/bundler.ts index b5ec48d..fa9a637 100644 --- a/src/compiler/bundler.ts +++ b/src/compiler/bundler.ts @@ -20,6 +20,7 @@ import { outputPath, refsAndTemplatesFilePath, virtualFilesPath } from './client-script/generate-data-files' +import {resolveBundlerReadyPromise} from './bundler/bundler-ready-promise' export const isProduction = process.env.BUN_ENV === 'production' export const inputFilePath = '/input.js' @@ -113,6 +114,7 @@ function handleResult(result: BuildResult) { : contents) }) if (!measuredEnd) { + resolveBundlerReadyPromise() addMarker('bundler', 'end') measuredEnd = true } diff --git a/src/compiler/bundler/bundler-ready-promise.ts b/src/compiler/bundler/bundler-ready-promise.ts new file mode 100644 index 0000000..0723cef --- /dev/null +++ b/src/compiler/bundler/bundler-ready-promise.ts @@ -0,0 +1,7 @@ +let resolveBundlerReadyPromise +const bundlerReadyPromise = new Promise(res => resolveBundlerReadyPromise = res) + +export function getBundlerReadyPromise() { + return bundlerReadyPromise +} +export {resolveBundlerReadyPromise} diff --git a/src/compiler/client-script/generate-data-files.ts b/src/compiler/client-script/generate-data-files.ts index 06cafc6..a9cdf1b 100644 --- a/src/compiler/client-script/generate-data-files.ts +++ b/src/compiler/client-script/generate-data-files.ts @@ -25,7 +25,6 @@ export async function generateClientScriptFile() { let inputFile = '' const hfs = getVolume() inputFile += getAssetsFilePaths().map(path => `import '${path}'`).join(newLine) - console.log(inputFile) inputFile += newLine iterateObject(getStateListenersAsCode(), ([fileName, fileContents]) => { if (fileName === stateListenersFileName) { diff --git a/src/compiler/generate-code.ts b/src/compiler/generate-code.ts index dac1e2a..7a209d7 100644 --- a/src/compiler/generate-code.ts +++ b/src/compiler/generate-code.ts @@ -33,7 +33,7 @@ export function clientTemplatesToJs(): string { mapMapToArray(getClientTemplates(), ([componentId, template]) => { code += wrapQuoteIfStartsWithNumber(componentId) code += ':' - code += `'${template.replace(/'/, '\\\'')}'` + code += `'${template.replace(/(['"])/g, '\\$1')}'` code += ',' }) code += '},' diff --git a/src/server/bun.ts b/src/server/bun.ts index 7836a66..83f421c 100644 --- a/src/server/bun.ts +++ b/src/server/bun.ts @@ -9,11 +9,11 @@ export default function cherrySoda(entry): (req: Request) => Promise { process.env.CHERRY_COLA_ENTRY = entry const {fs, outputPath} = compile(entry) const render = getRenderer() - let serveStaticListener: (req: Request) => Response = serveStatic(outputPath, fs) + let serveStaticListener: (req: Request) => Promise = serveStatic(outputPath, fs) return async (req) => { // todo: routing; next if request should not be handled - const res: Response = serveStaticListener(req) + const res: Response = await serveStaticListener(req) if (res.status < 400) return res // try { return new Response(render(), { diff --git a/src/server/serve-static.ts b/src/server/serve-static.ts index 76b9bc4..56c321c 100644 --- a/src/server/serve-static.ts +++ b/src/server/serve-static.ts @@ -3,8 +3,11 @@ import * as nfs from 'fs' import mime from 'mime' -export default function serveStatic(outputPath: string, fs: { existsSync: Function, readFileSync: Function } = nfs): (req: Request) => Response { - return (req) => { +import {getBundlerReadyPromise} from '../compiler/bundler/bundler-ready-promise' + +export default function serveStatic(outputPath: string, fs: { existsSync: Function, readFileSync: Function } = nfs): (req: Request) => Promise { + return async (req) => { + await getBundlerReadyPromise() const url = new URL(req.url) const filePath = path.join(outputPath, url.pathname) if (url.pathname === '/' || !fs.existsSync(filePath))