@absolutejs/absolute 0.20.0-beta.178 → 0.20.0-beta.179

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.
@@ -2226,7 +2226,7 @@ import { basename, dirname as dirname3, extname as extname2, join as join6, rela
2226
2226
  var serverCacheRoot2, compiledModuleCache2, originalSourcePathCache, syncIslandGeneration, transpiler, ensureRelativeImportPath = (from, target) => {
2227
2227
  const importPath = relative3(dirname3(from), target).replace(/\\/g, "/");
2228
2228
  return importPath.startsWith(".") ? importPath : `./${importPath}`;
2229
- }, processDirectoryEntries = (entries, dir, targetFileName, stack) => {
2229
+ }, escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), replaceQuotedSpecifier = (code, spec, target) => code.replace(new RegExp(`(['"])${escapeRegExp(spec)}\\1`, "g"), (_match, quote) => `${quote}${target}${quote}`), processDirectoryEntries = (entries, dir, targetFileName, stack) => {
2230
2230
  for (const entry of entries) {
2231
2231
  const entryPath = join6(dir, entry.name);
2232
2232
  if (entry.isDirectory())
@@ -2271,18 +2271,21 @@ var serverCacheRoot2, compiledModuleCache2, originalSourcePathCache, syncIslandG
2271
2271
  return null;
2272
2272
  }
2273
2273
  const basePath = resolve4(dirname3(from), spec);
2274
+ const extensions = [
2275
+ ".ts",
2276
+ ".tsx",
2277
+ ".mts",
2278
+ ".cts",
2279
+ ".js",
2280
+ ".jsx",
2281
+ ".mjs",
2282
+ ".cjs",
2283
+ ".json"
2284
+ ];
2274
2285
  const candidates = [
2275
2286
  basePath,
2276
- `${basePath}.ts`,
2277
- `${basePath}.js`,
2278
- `${basePath}.mjs`,
2279
- `${basePath}.cjs`,
2280
- `${basePath}.json`,
2281
- join6(basePath, "index.ts"),
2282
- join6(basePath, "index.js"),
2283
- join6(basePath, "index.mjs"),
2284
- join6(basePath, "index.cjs"),
2285
- join6(basePath, "index.json")
2287
+ ...extensions.map((extension) => `${basePath}${extension}`),
2288
+ ...extensions.map((extension) => join6(basePath, `index${extension}`))
2286
2289
  ];
2287
2290
  const existResults = await Promise.all(candidates.map((candidate) => Bun.file(candidate).exists()));
2288
2291
  const foundIndex = existResults.indexOf(true);
@@ -2367,7 +2370,7 @@ var serverCacheRoot2, compiledModuleCache2, originalSourcePathCache, syncIslandG
2367
2370
  rewrittenModulePaths.set(spec, ensureRelativeImportPath(getCachedModulePath2(sourcePath), resolvedModuleImport));
2368
2371
  }
2369
2372
  for (const [spec, resolvedModuleImport] of rewrittenModulePaths) {
2370
- transpiled = transpiled.replaceAll(spec, resolvedModuleImport);
2373
+ transpiled = replaceQuotedSpecifier(transpiled, spec, resolvedModuleImport);
2371
2374
  }
2372
2375
  let compiledCode = compile(transpiled, {
2373
2376
  css: "injected",
@@ -2379,10 +2382,10 @@ var serverCacheRoot2, compiledModuleCache2, originalSourcePathCache, syncIslandG
2379
2382
  hmr: isDevelopmentRuntime()
2380
2383
  }).js.code;
2381
2384
  for (const [spec, compiledChildPath] of childModulePaths) {
2382
- compiledCode = compiledCode.replaceAll(spec, ensureRelativeImportPath(getCachedModulePath2(sourcePath), compiledChildPath));
2385
+ compiledCode = replaceQuotedSpecifier(compiledCode, spec, ensureRelativeImportPath(getCachedModulePath2(sourcePath), compiledChildPath));
2383
2386
  }
2384
2387
  for (const [spec, resolvedModuleImport] of rewrittenModulePaths) {
2385
- compiledCode = compiledCode.replaceAll(spec, resolvedModuleImport);
2388
+ compiledCode = replaceQuotedSpecifier(compiledCode, spec, resolvedModuleImport);
2386
2389
  }
2387
2390
  const sourceId = JSON.stringify(relative3(process.cwd(), resolutionSourcePath).replace(/\\/g, "/"));
2388
2391
  const componentName = /export default function ([\w$]+)\s*\(/.exec(compiledCode)?.[1];
@@ -2486,7 +2489,13 @@ var serverCacheRoot3, compiledModuleCache3, syncIslandGeneration2, transpiler2,
2486
2489
  ].join(`
2487
2490
  `) : nonVueLines.join(`
2488
2491
  `);
2489
- }, extractRelativeVueImports = (sourceCode) => Array.from(sourceCode.matchAll(/import\s+[\s\S]+?['"]([^'"]+)['"]/g)).map((match) => match[1]).filter((importPath) => typeof importPath === "string" && importPath.startsWith(".") && importPath.endsWith(".vue")), compileVueServerModule = async (sourcePath) => {
2492
+ }, RELATIVE_SPECIFIER_PATTERN, extractRelativeImports = (code) => Array.from(new Set(Array.from(code.matchAll(RELATIVE_SPECIFIER_PATTERN), (match) => match.groups?.spec).filter((spec) => spec !== undefined))), resolveFromSource = (spec, sourcePath) => {
2493
+ try {
2494
+ return Bun.resolveSync(spec, dirname4(sourcePath));
2495
+ } catch {
2496
+ return null;
2497
+ }
2498
+ }, compileVueServerModule = async (sourcePath) => {
2490
2499
  syncIslandGeneration2();
2491
2500
  const cachedModulePath = compiledModuleCache3.get(sourcePath);
2492
2501
  if (cachedModulePath)
@@ -2519,10 +2528,10 @@ var serverCacheRoot3, compiledModuleCache3, syncIslandGeneration2, transpiler2,
2519
2528
  ssr: true,
2520
2529
  ssrCssVars: descriptor.cssVars
2521
2530
  }).code : "const ssrRender = () => {};";
2522
- const childImportPaths = extractRelativeVueImports(compiledScript.content);
2523
- const compiledChildren = await Promise.all(childImportPaths.map(async (relativeImport) => ({
2524
- compiledPath: await compileVueServerModule(resolve5(dirname4(sourcePath), relativeImport)),
2525
- spec: relativeImport
2531
+ const relativeImports = extractRelativeImports(compiledScript.content);
2532
+ const compiledChildren = await Promise.all(relativeImports.filter((spec) => spec.endsWith(".vue")).map(async (spec) => ({
2533
+ compiledPath: await compileVueServerModule(resolve5(dirname4(sourcePath), spec)),
2534
+ spec
2526
2535
  })));
2527
2536
  const strippedScript = stripExports(compiledScript.content);
2528
2537
  const transpiledScript = transpiler2.transformSync(strippedScript);
@@ -2534,10 +2543,22 @@ var serverCacheRoot3, compiledModuleCache3, syncIslandGeneration2, transpiler2,
2534
2543
  ].join(`
2535
2544
  `));
2536
2545
  const compiledModulePath = getCachedModulePath3(sourcePath);
2537
- let rewritten = assembled;
2546
+ const rewrittenSpecifiers = new Map;
2538
2547
  for (const child of compiledChildren) {
2539
- rewritten = rewritten.replaceAll(child.spec, ensureRelativeImportPath2(compiledModulePath, child.compiledPath));
2548
+ rewrittenSpecifiers.set(child.spec, ensureRelativeImportPath2(compiledModulePath, child.compiledPath));
2540
2549
  }
2550
+ for (const spec of extractRelativeImports(assembled)) {
2551
+ if (rewrittenSpecifiers.has(spec))
2552
+ continue;
2553
+ const resolvedImport = resolveFromSource(spec, sourcePath);
2554
+ if (!resolvedImport)
2555
+ continue;
2556
+ rewrittenSpecifiers.set(spec, ensureRelativeImportPath2(compiledModulePath, resolvedImport));
2557
+ }
2558
+ const rewritten = assembled.replace(RELATIVE_SPECIFIER_PATTERN, (match, prefix, quote, spec) => {
2559
+ const target = rewrittenSpecifiers.get(spec);
2560
+ return target ? `${prefix}${quote}${target}${quote}` : match;
2561
+ });
2541
2562
  await mkdir3(dirname4(compiledModulePath), { recursive: true });
2542
2563
  await writeIfChanged2(compiledModulePath, rewritten);
2543
2564
  compiledModuleCache3.set(sourcePath, compiledModulePath);
@@ -2551,6 +2572,7 @@ var init_vueServerModule = __esm(() => {
2551
2572
  compiledModuleCache3.clear();
2552
2573
  });
2553
2574
  transpiler2 = new Transpiler({ loader: "ts", target: "browser" });
2575
+ RELATIVE_SPECIFIER_PATTERN = /(\bfrom\s*|\bimport\s*\(\s*|\bimport\s+)(['"])(?<spec>\.{1,2}\/[^'"]*)\2/g;
2554
2576
  });
2555
2577
 
2556
2578
  // src/core/islandMarkupAttributes.ts
@@ -2831,5 +2853,5 @@ export {
2831
2853
  renderIslandMarkup
2832
2854
  };
2833
2855
 
2834
- //# debugId=05077611E3C00F5664756E2164756E21
2856
+ //# debugId=33FE6E9626DB36C864756E2164756E21
2835
2857
  //# sourceMappingURL=index.js.map