bertui 0.1.8 → 0.1.9
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/index.js +1 -1
- package/package.json +1 -1
- package/src/client/compiler.js +24 -7
package/index.js
CHANGED
package/package.json
CHANGED
package/src/client/compiler.js
CHANGED
|
@@ -40,7 +40,7 @@ export async function compileProject(root) {
|
|
|
40
40
|
const stats = await compileDirectory(srcDir, outDir, root);
|
|
41
41
|
const duration = Date.now() - startTime;
|
|
42
42
|
|
|
43
|
-
// Generate router AFTER compilation
|
|
43
|
+
// Generate router AFTER compilation
|
|
44
44
|
if (routes.length > 0) {
|
|
45
45
|
await generateRouter(routes, outDir, root);
|
|
46
46
|
logger.info('Generated router.js');
|
|
@@ -104,7 +104,6 @@ async function discoverRoutes(pagesDir) {
|
|
|
104
104
|
async function generateRouter(routes, outDir, root) {
|
|
105
105
|
const imports = routes.map((route, i) => {
|
|
106
106
|
const componentName = `Page${i}`;
|
|
107
|
-
// CRITICAL FIX: Import .js files (compiled), not .jsx
|
|
108
107
|
const importPath = `./pages/${route.file.replace(/\.(jsx|tsx|ts)$/, '.js')}`;
|
|
109
108
|
return `import ${componentName} from '${importPath}';`;
|
|
110
109
|
}).join('\n');
|
|
@@ -198,14 +197,14 @@ async function compileFile(srcPath, outDir, filename, relativePath) {
|
|
|
198
197
|
try {
|
|
199
198
|
let code = await Bun.file(srcPath).text();
|
|
200
199
|
|
|
201
|
-
// Remove bertui/styles imports
|
|
200
|
+
// Remove bertui/styles imports
|
|
202
201
|
code = code.replace(/import\s+['"]bertui\/styles['"]\s*;?\s*/g, '');
|
|
203
202
|
|
|
204
|
-
// Replace bertui/router imports with CDN React Router (we'll use a simpler approach)
|
|
205
|
-
// For now, keep the import as-is and handle it differently
|
|
206
|
-
|
|
207
203
|
const transpiler = new Bun.Transpiler({ loader });
|
|
208
|
-
|
|
204
|
+
let compiled = await transpiler.transform(code);
|
|
205
|
+
|
|
206
|
+
// CRITICAL FIX: Add .js extensions to all relative imports
|
|
207
|
+
compiled = fixRelativeImports(compiled);
|
|
209
208
|
|
|
210
209
|
const outFilename = filename.replace(/\.(jsx|tsx|ts)$/, '.js');
|
|
211
210
|
const outPath = join(outDir, outFilename);
|
|
@@ -216,4 +215,22 @@ async function compileFile(srcPath, outDir, filename, relativePath) {
|
|
|
216
215
|
logger.error(`Failed to compile ${relativePath}: ${error.message}`);
|
|
217
216
|
throw error;
|
|
218
217
|
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function fixRelativeImports(code) {
|
|
221
|
+
// Match import statements with relative paths that don't already have extensions
|
|
222
|
+
// Matches: import X from './path' or import X from '../path'
|
|
223
|
+
// But NOT: import X from './path.js' or import X from 'package'
|
|
224
|
+
|
|
225
|
+
const importRegex = /from\s+['"](\.\.[\/\\]|\.\/)((?:[^'"]+?)(?<!\.js|\.jsx|\.ts|\.tsx|\.json))['"];?/g;
|
|
226
|
+
|
|
227
|
+
code = code.replace(importRegex, (match, prefix, path) => {
|
|
228
|
+
// Don't add .js if path already has an extension or ends with /
|
|
229
|
+
if (path.endsWith('/') || /\.\w+$/.test(path)) {
|
|
230
|
+
return match;
|
|
231
|
+
}
|
|
232
|
+
return `from '${prefix}${path}.js';`;
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
return code;
|
|
219
236
|
}
|