@absolutejs/absolute 0.19.0-beta.700 → 0.19.0-beta.702

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/dist/build.js CHANGED
@@ -366,11 +366,7 @@ var defineIslandComponent = (component, options) => ({
366
366
  var init_islands = () => {};
367
367
 
368
368
  // src/build/islandEntries.ts
369
- import {
370
- mkdirSync,
371
- rmSync,
372
- writeFileSync
373
- } from "fs";
369
+ import { mkdirSync, rmSync, writeFileSync } from "fs";
374
370
  import { dirname, extname as extname2, join, relative, resolve } from "path";
375
371
  import ts from "typescript";
376
372
  var frameworks, isRecord2 = (value) => typeof value === "object" && value !== null, resolveRegistryExport = (mod) => {
@@ -379,7 +375,7 @@ var frameworks, isRecord2 = (value) => typeof value === "object" && value !== nu
379
375
  if (isRecord2(mod.default))
380
376
  return mod.default;
381
377
  throw new Error("Island registry module must export `islandRegistry` or a default registry object.");
382
- }, normalizeImportPath = (wrapperPath, targetPath) => {
378
+ }, hasSvelteImport = (source) => /from\s+['"][^'"]+\.svelte['"]/.test(source), normalizeImportPath = (wrapperPath, targetPath) => {
383
379
  const importPath = relative(dirname(wrapperPath), targetPath).replace(/\\/g, "/");
384
380
  return importPath.startsWith(".") ? importPath : `./${importPath}`;
385
381
  }, isIdentifier = (value) => /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(value), resolveIslandSourcePath = (registryPath, sourcePath) => {
@@ -409,7 +405,13 @@ var frameworks, isRecord2 = (value) => typeof value === "object" && value !== nu
409
405
  source
410
406
  });
411
407
  }
412
- }, addRegistryEntries = (frameworkNode, framework, imports, references) => {
408
+ }, createRegistryEntryValue = (reference) => ({
409
+ component: reference.source,
410
+ export: reference.export,
411
+ source: reference.source
412
+ }), addRegistryEntries = (frameworkNode, framework, imports, definitions, registry) => {
413
+ const frameworkRegistry = registry[framework] ?? {};
414
+ registry[framework] = frameworkRegistry;
413
415
  for (const property of frameworkNode.properties) {
414
416
  if (!ts.isPropertyAssignment(property) && !ts.isShorthandPropertyAssignment(property))
415
417
  continue;
@@ -422,13 +424,23 @@ var frameworks, isRecord2 = (value) => typeof value === "object" && value !== nu
422
424
  const reference = imports.get(initializer.text);
423
425
  if (!reference)
424
426
  continue;
425
- references.set(`${framework}:${componentName}`, reference);
427
+ frameworkRegistry[componentName] = createRegistryEntryValue(reference);
428
+ definitions.push({
429
+ buildReference: reference,
430
+ component: componentName,
431
+ framework
432
+ });
426
433
  }
427
- }, processDefineIslandRegistry = (node, imports, references) => {
434
+ }, processDefineIslandRegistry = (node, imports, definitions, registry) => {
428
435
  const [firstArg] = node.arguments;
429
436
  if (!firstArg || !ts.isObjectLiteralExpression(firstArg))
430
437
  return;
431
- const validFrameworks = ["react", "svelte", "vue", "angular"];
438
+ const validFrameworks = [
439
+ "react",
440
+ "svelte",
441
+ "vue",
442
+ "angular"
443
+ ];
432
444
  for (const property of firstArg.properties) {
433
445
  if (!ts.isPropertyAssignment(property))
434
446
  continue;
@@ -440,13 +452,27 @@ var frameworks, isRecord2 = (value) => typeof value === "object" && value !== nu
440
452
  continue;
441
453
  if (!ts.isObjectLiteralExpression(property.initializer))
442
454
  continue;
443
- addRegistryEntries(property.initializer, framework, imports, references);
455
+ addRegistryEntries(property.initializer, framework, imports, definitions, registry);
444
456
  }
445
- }, walkRegistryNode = (node, imports, references) => {
457
+ }, walkRegistryNode = (node, imports, definitions, registry) => {
446
458
  if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === "defineIslandRegistry") {
447
- processDefineIslandRegistry(node, imports, references);
459
+ processDefineIslandRegistry(node, imports, definitions, registry);
460
+ }
461
+ ts.forEachChild(node, (child) => walkRegistryNode(child, imports, definitions, registry));
462
+ }, hasIslandRegistryNamedExport = (sourceFile) => {
463
+ for (const statement of sourceFile.statements) {
464
+ if (ts.isVariableStatement(statement) && statement.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword) && statement.declarationList.declarations.some((declaration) => ts.isIdentifier(declaration.name) && declaration.name.text === "islandRegistry")) {
465
+ return true;
466
+ }
467
+ if (!ts.isExportDeclaration(statement) || !statement.exportClause)
468
+ continue;
469
+ if (!ts.isNamedExports(statement.exportClause))
470
+ continue;
471
+ if (statement.exportClause.elements.some((element) => element.name.text === "islandRegistry")) {
472
+ return true;
473
+ }
448
474
  }
449
- ts.forEachChild(node, (child) => walkRegistryNode(child, imports, references));
475
+ return false;
450
476
  }, collectImportDeclarations = (sourceFile, registryPath, imports) => {
451
477
  for (const statement of sourceFile.statements) {
452
478
  if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier))
@@ -458,13 +484,36 @@ var frameworks, isRecord2 = (value) => typeof value === "object" && value !== nu
458
484
  collectDefaultImport(imports, importClause, source);
459
485
  collectNamedImports(imports, importClause, source);
460
486
  }
461
- }, extractRegistryImportReferences = (registrySource, registryPath) => {
487
+ }, parseIslandRegistryBuildInfo = (registrySource, registryPath) => {
462
488
  const sourceFile = ts.createSourceFile(registryPath, registrySource, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
463
489
  const imports = new Map;
464
- const references = new Map;
490
+ const definitions = [];
491
+ const registry = {};
465
492
  collectImportDeclarations(sourceFile, registryPath, imports);
466
- walkRegistryNode(sourceFile, imports, references);
467
- return references;
493
+ walkRegistryNode(sourceFile, imports, definitions, registry);
494
+ return {
495
+ definitions,
496
+ hasNamedExport: hasIslandRegistryNamedExport(sourceFile),
497
+ registry
498
+ };
499
+ }, loadDynamicIslandRegistryBuildInfo = async (resolvedRegistryPath) => {
500
+ const registryModule = await import(resolvedRegistryPath);
501
+ const registry = resolveRegistryExport(registryModule);
502
+ const definitions = frameworks.flatMap((framework) => {
503
+ const frameworkRegistry = registry[framework];
504
+ if (!isRecord2(frameworkRegistry))
505
+ return [];
506
+ return Object.entries(frameworkRegistry).map(([component, value]) => ({
507
+ buildReference: getIslandBuildReference(value),
508
+ component,
509
+ framework
510
+ }));
511
+ });
512
+ return {
513
+ definitions,
514
+ hasNamedExport: isRecord2(registryModule.islandRegistry),
515
+ registry
516
+ };
468
517
  }, createRegistryImportCode = (wrapperPath, registryPath, hasNamedExport) => {
469
518
  const normalizedPath = normalizeImportPath(wrapperPath, registryPath);
470
519
  if (hasNamedExport) {
@@ -552,34 +601,29 @@ export default component;
552
601
  const resolvedRegistryPath = resolve(registryPath);
553
602
  const registrySource = Bun.file(resolvedRegistryPath);
554
603
  const registrySourceText = await registrySource.text();
555
- const registryModule = await import(resolvedRegistryPath);
556
- const registry = resolveRegistryExport(registryModule);
557
- const parsedBuildReferences = extractRegistryImportReferences(registrySourceText, resolvedRegistryPath);
558
- const definitions = frameworks.flatMap((framework) => {
559
- const frameworkRegistry = registry[framework];
560
- if (!isRecord2(frameworkRegistry))
561
- return [];
562
- return Object.entries(frameworkRegistry).map(([component, value]) => ({
563
- buildReference: getIslandBuildReference(value) ?? parsedBuildReferences.get(`${framework}:${component}`) ?? null,
564
- component,
565
- framework
566
- }));
567
- });
604
+ const parsedInfo = parseIslandRegistryBuildInfo(registrySourceText, resolvedRegistryPath);
605
+ if (parsedInfo.definitions.length > 0) {
606
+ return {
607
+ definitions: parsedInfo.definitions,
608
+ hasNamedExport: parsedInfo.hasNamedExport,
609
+ registry: parsedInfo.registry,
610
+ resolvedRegistryPath
611
+ };
612
+ }
613
+ if (hasSvelteImport(registrySourceText)) {
614
+ throw new Error("Unable to statically analyze the island registry. Registries that import .svelte files must use defineIslandRegistry({ ... }) with direct imported component references.");
615
+ }
616
+ const dynamicInfo = await loadDynamicIslandRegistryBuildInfo(resolvedRegistryPath);
568
617
  return {
569
- definitions,
570
- hasNamedExport: isRecord2(registryModule.islandRegistry),
571
- registry,
618
+ definitions: dynamicInfo.definitions,
619
+ hasNamedExport: dynamicInfo.hasNamedExport,
620
+ registry: dynamicInfo.registry,
572
621
  resolvedRegistryPath
573
622
  };
574
623
  };
575
624
  var init_islandEntries = __esm(() => {
576
625
  init_islands();
577
- frameworks = [
578
- "react",
579
- "svelte",
580
- "vue",
581
- "angular"
582
- ];
626
+ frameworks = ["react", "svelte", "vue", "angular"];
583
627
  });
584
628
 
585
629
  // src/build/generateReactIndexes.ts
@@ -3019,10 +3063,13 @@ var islandSequence = 0, resolvedServerComponentCache, resolvedServerBuildCompone
3019
3063
  const loadPromise = loadAndCompileServerBuildComponent(buildReferencePath);
3020
3064
  resolvedServerBuildComponentCache.set(buildReferencePath, loadPromise);
3021
3065
  return loadPromise;
3022
- }, loadServerImportComponent = async (resolvedComponent) => {
3066
+ }, loadServerImportComponent = async (resolvedComponent, exportName) => {
3023
3067
  const resolvedModulePath = resolvedComponent.startsWith(".") ? new URL(resolvedComponent, import.meta.url).pathname : resolvedComponent;
3024
3068
  const importTarget = resolvedModulePath.endsWith(".svelte") ? await compileSvelteServerModule(resolvedModulePath) : resolvedModulePath;
3025
3069
  const loadedModule = await import(importTarget);
3070
+ if (exportName && exportName !== "default" && exportName in loadedModule) {
3071
+ return loadedModule[exportName];
3072
+ }
3026
3073
  return "default" in loadedModule ? loadedModule.default : loadedModule;
3027
3074
  }, resolveIslandComponent = async (component) => {
3028
3075
  const buildReference = getIslandBuildReference(component);
@@ -3030,6 +3077,9 @@ var islandSequence = 0, resolvedServerComponentCache, resolvedServerBuildCompone
3030
3077
  if (buildReferencePath?.endsWith(".svelte")) {
3031
3078
  return loadServerBuildComponent(buildReferencePath);
3032
3079
  }
3080
+ if (buildReferencePath) {
3081
+ return loadServerImportComponent(buildReferencePath, buildReference?.export);
3082
+ }
3033
3083
  const resolvedComponent = getIslandComponent(component);
3034
3084
  if (typeof resolvedComponent !== "string") {
3035
3085
  return resolvedComponent;
@@ -49450,5 +49500,5 @@ export {
49450
49500
  build
49451
49501
  };
49452
49502
 
49453
- //# debugId=0A7D6E8A4383D37264756E2164756E21
49503
+ //# debugId=2F504DCD19D0582A64756E2164756E21
49454
49504
  //# sourceMappingURL=build.js.map