bertui 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bertui",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Lightning-fast React dev server powered by Bun and Elysia",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
"bertui": "./bin/bertui.js"
|
|
9
9
|
},
|
|
10
10
|
"exports": {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
".": "./index.js",
|
|
12
|
+
"./styles": "./src/styles/bertui.css",
|
|
13
|
+
"./logger": "./src/logger/logger.js",
|
|
14
|
+
"./router": "./src/router/Router.jsx"
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
|
17
17
|
"bin",
|
|
@@ -34,7 +34,8 @@
|
|
|
34
34
|
"build-tool",
|
|
35
35
|
"bundler",
|
|
36
36
|
"fast",
|
|
37
|
-
"hmr"
|
|
37
|
+
"hmr",
|
|
38
|
+
"file-based-routing"
|
|
38
39
|
],
|
|
39
40
|
"author": "Pease Ernest",
|
|
40
41
|
"license": "MIT",
|
package/src/client/compiler.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// src/client/compiler.js
|
|
2
1
|
import { existsSync, mkdirSync, readdirSync, statSync } from 'fs';
|
|
3
2
|
import { join, extname, relative } from 'path';
|
|
4
3
|
import logger from '../logger/logger.js';
|
|
@@ -112,7 +111,6 @@ async function generateRouter(routes, outDir, root) {
|
|
|
112
111
|
return ` { path: '${route.route}', component: ${componentName}, type: '${route.type}' }`;
|
|
113
112
|
}).join(',\n');
|
|
114
113
|
|
|
115
|
-
// CRITICAL: Copy Router component into compiled folder
|
|
116
114
|
const routerComponentCode = `
|
|
117
115
|
import { useState, useEffect, createContext, useContext } from 'react';
|
|
118
116
|
|
|
@@ -139,7 +137,7 @@ export function Router({ routes }) {
|
|
|
139
137
|
|
|
140
138
|
window.addEventListener('popstate', handlePopState);
|
|
141
139
|
return () => window.removeEventListener('popstate', handlePopState);
|
|
142
|
-
}, []);
|
|
140
|
+
}, [routes]);
|
|
143
141
|
|
|
144
142
|
function matchAndSetRoute(pathname) {
|
|
145
143
|
for (const route of routes) {
|
|
@@ -266,7 +264,6 @@ async function compileDirectory(srcDir, outDir, root) {
|
|
|
266
264
|
const outPath = join(outDir, file);
|
|
267
265
|
let code = await Bun.file(srcPath).text();
|
|
268
266
|
|
|
269
|
-
// Fix imports in .js files too
|
|
270
267
|
code = fixImports(code);
|
|
271
268
|
|
|
272
269
|
await Bun.write(outPath, code);
|
|
@@ -289,13 +286,11 @@ async function compileFile(srcPath, outDir, filename, relativePath) {
|
|
|
289
286
|
try {
|
|
290
287
|
let code = await Bun.file(srcPath).text();
|
|
291
288
|
|
|
292
|
-
// Fix imports BEFORE transpiling
|
|
293
289
|
code = fixImports(code);
|
|
294
290
|
|
|
295
291
|
const transpiler = new Bun.Transpiler({ loader });
|
|
296
292
|
let compiled = await transpiler.transform(code);
|
|
297
293
|
|
|
298
|
-
// Add .js extensions to relative imports
|
|
299
294
|
compiled = fixRelativeImports(compiled);
|
|
300
295
|
|
|
301
296
|
const outFilename = filename.replace(/\.(jsx|tsx|ts)$/, '.js');
|
|
@@ -310,16 +305,13 @@ async function compileFile(srcPath, outDir, filename, relativePath) {
|
|
|
310
305
|
}
|
|
311
306
|
|
|
312
307
|
function fixImports(code) {
|
|
313
|
-
// Remove bertui/styles imports
|
|
314
308
|
code = code.replace(/import\s+['"]bertui\/styles['"]\s*;?\s*/g, '');
|
|
315
309
|
|
|
316
|
-
// Replace bertui/router with /compiled/router.js
|
|
317
310
|
code = code.replace(
|
|
318
311
|
/from\s+['"]bertui\/router['"]/g,
|
|
319
312
|
"from '/compiled/router.js'"
|
|
320
313
|
);
|
|
321
314
|
|
|
322
|
-
// Fix ../.bertui/compiled paths to /compiled
|
|
323
315
|
code = code.replace(
|
|
324
316
|
/from\s+['"]\.\.\/\.bertui\/compiled\/([^'"]+)['"]/g,
|
|
325
317
|
"from '/compiled/$1'"
|
package/src/router/Router.js
CHANGED
|
@@ -23,9 +23,10 @@ export function Router({ routes }) {
|
|
|
23
23
|
|
|
24
24
|
window.addEventListener('popstate', handlePopState);
|
|
25
25
|
return () => window.removeEventListener('popstate', handlePopState);
|
|
26
|
-
}, []);
|
|
26
|
+
}, [routes]);
|
|
27
27
|
|
|
28
28
|
function matchAndSetRoute(pathname) {
|
|
29
|
+
// Try static routes first
|
|
29
30
|
for (const route of routes) {
|
|
30
31
|
if (route.type === 'static' && route.path === pathname) {
|
|
31
32
|
setCurrentRoute(route);
|
|
@@ -34,6 +35,7 @@ export function Router({ routes }) {
|
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
|
|
38
|
+
// Try dynamic routes
|
|
37
39
|
for (const route of routes) {
|
|
38
40
|
if (route.type === 'dynamic') {
|
|
39
41
|
const pattern = route.path.replace(/\[([^\]]+)\]/g, '([^/]+)');
|
|
@@ -54,6 +56,7 @@ export function Router({ routes }) {
|
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
58
|
|
|
59
|
+
// No match found
|
|
57
60
|
setCurrentRoute(null);
|
|
58
61
|
setParams({});
|
|
59
62
|
}
|
package/src/server/dev-server.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// src/server/dev-server.js
|
|
2
1
|
import { Elysia } from 'elysia';
|
|
3
2
|
import { watch } from 'fs';
|
|
4
3
|
import { join, extname } from 'path';
|
|
@@ -17,7 +16,7 @@ export async function startDevServer(options = {}) {
|
|
|
17
16
|
const routerPath = join(compiledDir, 'router.js');
|
|
18
17
|
if (existsSync(routerPath)) {
|
|
19
18
|
hasRouter = true;
|
|
20
|
-
logger.info('
|
|
19
|
+
logger.info('File-based routing enabled');
|
|
21
20
|
}
|
|
22
21
|
|
|
23
22
|
const app = new Elysia()
|
|
@@ -158,7 +157,6 @@ function serveHTML(root, hasRouter) {
|
|
|
158
157
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
159
158
|
<title>BertUI App - Dev</title>
|
|
160
159
|
|
|
161
|
-
<!-- Import Map for React and dependencies -->
|
|
162
160
|
<script type="importmap">
|
|
163
161
|
{
|
|
164
162
|
"imports": {
|
|
@@ -171,7 +169,6 @@ function serveHTML(root, hasRouter) {
|
|
|
171
169
|
</script>
|
|
172
170
|
|
|
173
171
|
<style>
|
|
174
|
-
/* Inline basic styles since we're skipping CSS for now */
|
|
175
172
|
* {
|
|
176
173
|
margin: 0;
|
|
177
174
|
padding: 0;
|
|
@@ -186,10 +183,9 @@ function serveHTML(root, hasRouter) {
|
|
|
186
183
|
<div id="root"></div>
|
|
187
184
|
<script type="module" src="/hmr-client.js"></script>
|
|
188
185
|
${hasRouter
|
|
189
|
-
? '<script type="module" src="/compiled/
|
|
190
|
-
: ''
|
|
186
|
+
? '<script type="module" src="/compiled/main.js"></script>'
|
|
187
|
+
: '<script type="module" src="/compiled/main.js"></script>'
|
|
191
188
|
}
|
|
192
|
-
<script type="module" src="/compiled/main.js"></script>
|
|
193
189
|
</body>
|
|
194
190
|
</html>`;
|
|
195
191
|
|