bertui 0.2.6 → 0.2.7
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 +1 -1
- package/src/client/compiler.js +29 -16
- package/src/server/dev-server.js +2 -19
package/package.json
CHANGED
package/src/client/compiler.js
CHANGED
|
@@ -602,13 +602,13 @@ async function compileDirectory(srcDir, outDir, root) {
|
|
|
602
602
|
const relativePath = relative(join(root, 'src'), srcPath);
|
|
603
603
|
|
|
604
604
|
if (['.jsx', '.tsx', '.ts'].includes(ext)) {
|
|
605
|
-
await compileFile(srcPath, outDir, file, relativePath);
|
|
605
|
+
await compileFile(srcPath, outDir, file, relativePath, root);
|
|
606
606
|
stats.files++;
|
|
607
607
|
} else if (ext === '.js') {
|
|
608
608
|
const outPath = join(outDir, file);
|
|
609
609
|
let code = await Bun.file(srcPath).text();
|
|
610
610
|
|
|
611
|
-
code = fixImports(code);
|
|
611
|
+
code = fixImports(code, srcPath, root);
|
|
612
612
|
|
|
613
613
|
await Bun.write(outPath, code);
|
|
614
614
|
logger.debug(`Copied: ${relativePath}`);
|
|
@@ -623,14 +623,14 @@ async function compileDirectory(srcDir, outDir, root) {
|
|
|
623
623
|
return stats;
|
|
624
624
|
}
|
|
625
625
|
|
|
626
|
-
async function compileFile(srcPath, outDir, filename, relativePath) {
|
|
626
|
+
async function compileFile(srcPath, outDir, filename, relativePath, root) {
|
|
627
627
|
const ext = extname(filename);
|
|
628
628
|
const loader = ext === '.tsx' ? 'tsx' : ext === '.ts' ? 'ts' : 'jsx';
|
|
629
629
|
|
|
630
630
|
try {
|
|
631
631
|
let code = await Bun.file(srcPath).text();
|
|
632
632
|
|
|
633
|
-
code = fixImports(code);
|
|
633
|
+
code = fixImports(code, srcPath, root);
|
|
634
634
|
|
|
635
635
|
const transpiler = new Bun.Transpiler({
|
|
636
636
|
loader,
|
|
@@ -661,21 +661,34 @@ async function compileFile(srcPath, outDir, filename, relativePath) {
|
|
|
661
661
|
}
|
|
662
662
|
}
|
|
663
663
|
|
|
664
|
-
function fixImports(code) {
|
|
664
|
+
function fixImports(code, srcPath, root) {
|
|
665
665
|
// Remove bertui/styles imports
|
|
666
666
|
code = code.replace(/import\s+['"]bertui\/styles['"]\s*;?\s*/g, '');
|
|
667
667
|
|
|
668
|
-
//
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
668
|
+
// Check if this is main.jsx - it will be in src/main.jsx
|
|
669
|
+
const isMainFile = srcPath.includes('main.jsx') || srcPath.includes('main.js');
|
|
670
|
+
|
|
671
|
+
if (isMainFile) {
|
|
672
|
+
// For main.jsx: router.js is in the same compiled directory
|
|
673
|
+
code = code.replace(
|
|
674
|
+
/from\s+['"]bertui\/router['"]/g,
|
|
675
|
+
"from './router.js'"
|
|
676
|
+
);
|
|
677
|
+
code = code.replace(
|
|
678
|
+
/from\s+['"]\/compiled\/router\.js['"]/g,
|
|
679
|
+
"from './router.js'"
|
|
680
|
+
);
|
|
681
|
+
code = code.replace(
|
|
682
|
+
/from\s+['"]\.\.\/\.bertui\/compiled\/router\.js['"]/g,
|
|
683
|
+
"from './router.js'"
|
|
684
|
+
);
|
|
685
|
+
} else {
|
|
686
|
+
// For page components: router.js is up one level from pages/
|
|
687
|
+
code = code.replace(
|
|
688
|
+
/from\s+['"]bertui\/router['"]/g,
|
|
689
|
+
"from '../router.js'"
|
|
690
|
+
);
|
|
691
|
+
}
|
|
679
692
|
|
|
680
693
|
return code;
|
|
681
694
|
}
|
package/src/server/dev-server.js
CHANGED
|
@@ -31,24 +31,7 @@ export async function startDevServer(options = {}) {
|
|
|
31
31
|
const path = params['*'];
|
|
32
32
|
|
|
33
33
|
if (path.includes('.')) {
|
|
34
|
-
// Handle
|
|
35
|
-
if (path.startsWith('.bertui/compiled/')) {
|
|
36
|
-
const filePath = join(root, path);
|
|
37
|
-
const file = Bun.file(filePath);
|
|
38
|
-
|
|
39
|
-
if (await file.exists()) {
|
|
40
|
-
const ext = extname(path);
|
|
41
|
-
const contentType = ext === '.js' ? 'application/javascript' : getContentType(ext);
|
|
42
|
-
|
|
43
|
-
return new Response(await file.text(), {
|
|
44
|
-
headers: {
|
|
45
|
-
'Content-Type': contentType,
|
|
46
|
-
'Cache-Control': 'no-store'
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
34
|
+
// Handle compiled directory files
|
|
52
35
|
if (path.startsWith('compiled/')) {
|
|
53
36
|
const filePath = join(compiledDir, path.replace('compiled/', ''));
|
|
54
37
|
const file = Bun.file(filePath);
|
|
@@ -225,7 +208,7 @@ function serveHTML(root, hasRouter, config) {
|
|
|
225
208
|
<body>
|
|
226
209
|
<div id="root"></div>
|
|
227
210
|
<script type="module" src="/hmr-client.js"></script>
|
|
228
|
-
<script type="module" src="
|
|
211
|
+
<script type="module" src="/compiled/main.js"></script>
|
|
229
212
|
</body>
|
|
230
213
|
</html>`;
|
|
231
214
|
|