From dc21e6a488a823f4c1f8aca29667ab02dc245d12 Mon Sep 17 00:00:00 2001 From: Benjamin Wegener Date: Thu, 11 Jan 2024 17:12:24 +0000 Subject: [PATCH] chore(examples) prepare examples; cleanup --- examples/index.html | 17 +++++++++++++++++ examples/server.js | 27 ++++++++++++++++++++++++--- lib/core/Cetra.js | 5 +---- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/examples/index.html b/examples/index.html index 0497ad5..112565d 100644 --- a/examples/index.html +++ b/examples/index.html @@ -11,6 +11,23 @@ Document +
+ +
+ +
+
+

Title

+

Description

+
+ +
+ diff --git a/examples/server.js b/examples/server.js index 4ac837c..675db3b 100644 --- a/examples/server.js +++ b/examples/server.js @@ -1,15 +1,36 @@ +import { unlinkSync } from 'node:fs'; +const transpiler = Bun.Transpiler({ + loader: 'cjs', +}); + export default { port: Bun.env.BUN_PORT || Bun.env.APP_PORT || 3000, async fetch(req) { + const magicKey = Math.random().toString(36).substring(2, 10); const url = new URL(req.url); if (url.pathname == '/main.js') { - await Bun.build({ + const path = `./.cache/`; + const filename = `${magicKey}.js`; + const file = Bun.file(`${path}/${filename}`); + const result = await Bun.build({ entrypoints: ['./src/main.js'], - outdir: '.', + outdir: path, + target: 'browser', + splitting: true, + naming: `[dir]/${filename}`, }); - return new Response(Bun.file('./main.js'), { + + console.log(result); + + const resp = new Response(file, { headers: { 'Cache-Control': 'no-cache' }, }); + + setTimeout(() => { + unlinkSync(`${path}/${filename}`); + }, 400); + + return resp; } if (url.pathname == '/') return new Response(Bun.file('./index.html')); return new Response('ERR 404: Not Found', { status: 404 }); diff --git a/lib/core/Cetra.js b/lib/core/Cetra.js index 0b49644..a9e2efb 100644 --- a/lib/core/Cetra.js +++ b/lib/core/Cetra.js @@ -34,12 +34,9 @@ class Cetra extends Emitter { if (typeof value == 'undefined') { value = Cetra.#defaultSettings.get(key); } - this.#internals - .get('settings') - .set(key, value); + this.#internals.get('settings').set(key, value); } - for (const [key, cb] of options) { if (!key.startsWith('on') || typeof cb != 'function') continue; this.on(key, cb);