juxscript 1.0.83 → 1.0.84
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/machinery/compiler.js +23 -4
- package/package.json +1 -1
package/machinery/compiler.js
CHANGED
|
@@ -238,7 +238,8 @@ export async function bundleJuxFilesToRouter(projectRoot, distDir, options = {})
|
|
|
238
238
|
const hasExports = /^\s*export\s+(const|let|function|class|{)/m.test(fileContent);
|
|
239
239
|
if (hasExports) {
|
|
240
240
|
const exportKey = relativePath;
|
|
241
|
-
|
|
241
|
+
// ✅ FIX: Pass bundledPaths so imports can be resolved and rewritten in shared code
|
|
242
|
+
const exportCode = extractSharedModule(fileContent, rawFunctionName, relativePath, bundledPaths);
|
|
242
243
|
if (exportCode.trim()) sharedModules.set(exportKey, exportCode);
|
|
243
244
|
}
|
|
244
245
|
|
|
@@ -300,9 +301,8 @@ export async function bundleJuxFilesToRouter(projectRoot, distDir, options = {})
|
|
|
300
301
|
};
|
|
301
302
|
}
|
|
302
303
|
|
|
303
|
-
function extractSharedModule(juxContent, moduleName, sourceFilePath) {
|
|
304
|
+
function extractSharedModule(juxContent, moduleName, sourceFilePath, bundledPaths) {
|
|
304
305
|
// 1. Calculate Namespace
|
|
305
|
-
// Ensure we have a valid JS identifier suffix
|
|
306
306
|
const namespace = sourceFilePath.replace(/\.(jux|js)$/, '').replace(/[\/\\]/g, '$').replace(/[^a-zA-Z0-9$]/g, '_');
|
|
307
307
|
|
|
308
308
|
let ast;
|
|
@@ -312,10 +312,11 @@ function extractSharedModule(juxContent, moduleName, sourceFilePath) {
|
|
|
312
312
|
throw new Error(`Invalid JavaScript syntax in ${sourceFilePath}: ${err.message}`);
|
|
313
313
|
}
|
|
314
314
|
|
|
315
|
-
// 2. Identify ALL
|
|
315
|
+
// 2. Identify ALL Identifiers to rename (Local defs + Imports)
|
|
316
316
|
// We must rename everything to avoid global collision in the flat bundle
|
|
317
317
|
const identifiersToRename = new Map();
|
|
318
318
|
|
|
319
|
+
// A. Local Declarations (Self-namespacing)
|
|
319
320
|
const addId = (idNode) => {
|
|
320
321
|
if (idNode && idNode.type === 'Identifier') {
|
|
321
322
|
identifiersToRename.set(idNode.name, `${idNode.name}$${namespace}`);
|
|
@@ -331,6 +332,24 @@ function extractSharedModule(juxContent, moduleName, sourceFilePath) {
|
|
|
331
332
|
const d = node.declaration;
|
|
332
333
|
if (d.type === 'FunctionDeclaration' || d.type === 'ClassDeclaration') addId(d.id);
|
|
333
334
|
else if (d.type === 'VariableDeclaration') d.declarations.forEach(v => addId(v.id));
|
|
335
|
+
} else if (node.type === 'ImportDeclaration') {
|
|
336
|
+
// B. Imports (Rewriting references to other bundled modules)
|
|
337
|
+
const importPath = node.source.value;
|
|
338
|
+
const resolvedPath = resolveImportPath(importPath, sourceFilePath);
|
|
339
|
+
// Check if this import is pointing to a bundled file
|
|
340
|
+
const isBundled = (bundledPaths && bundledPaths.has(resolvedPath)) || importPath.endsWith('.jux');
|
|
341
|
+
|
|
342
|
+
if (isBundled) {
|
|
343
|
+
const targetNamespace = resolvedPath.replace(/\.(jux|js)$/, '').replace(/[\/\\]/g, '$').replace(/[^a-zA-Z0-9$]/g, '_');
|
|
344
|
+
node.specifiers.forEach(spec => {
|
|
345
|
+
if (spec.type === 'ImportSpecifier') {
|
|
346
|
+
identifiersToRename.set(spec.local.name, `${spec.imported.name}$${targetNamespace}`);
|
|
347
|
+
} else if (spec.type === 'ImportDefaultSpecifier') {
|
|
348
|
+
// Best effort for defaults in this flat bundle scheme usually implies named export match or similar convention
|
|
349
|
+
// For now, assuming standard View exports which don't usually default export to shared
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
}
|
|
334
353
|
}
|
|
335
354
|
});
|
|
336
355
|
|