@absolutejs/absolute 0.19.0-beta.697 → 0.19.0-beta.699

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.
@@ -3106,6 +3106,37 @@ var computeConfigHash = () => {
3106
3106
  } catch {
3107
3107
  return "";
3108
3108
  }
3109
+ }, readTsconfigPathAliases = () => {
3110
+ try {
3111
+ const configPath = resolve6(process.cwd(), "tsconfig.json");
3112
+ const config = ts.readConfigFile(configPath, ts.sys.readFile).config;
3113
+ const compilerOptions = config?.compilerOptions ?? {};
3114
+ const baseUrl = resolve6(process.cwd(), compilerOptions.baseUrl ?? ".");
3115
+ const aliases = Object.entries(compilerOptions.paths ?? {}).map(([pattern, replacements]) => ({ pattern, replacements }));
3116
+ return { aliases, baseUrl };
3117
+ } catch {
3118
+ return { aliases: [], baseUrl: process.cwd() };
3119
+ }
3120
+ }, matchTsconfigAlias = (specifier, aliases, baseUrl, resolveSourceFile) => {
3121
+ for (const alias of aliases) {
3122
+ const wildcardIndex = alias.pattern.indexOf("*");
3123
+ const exactMatch = wildcardIndex === -1;
3124
+ if (exactMatch && specifier !== alias.pattern)
3125
+ continue;
3126
+ const prefix = exactMatch ? alias.pattern : alias.pattern.slice(0, wildcardIndex);
3127
+ const suffix = exactMatch ? "" : alias.pattern.slice(wildcardIndex + 1);
3128
+ if (!exactMatch && (!specifier.startsWith(prefix) || !specifier.endsWith(suffix))) {
3129
+ continue;
3130
+ }
3131
+ const wildcardValue = exactMatch ? "" : specifier.slice(prefix.length, specifier.length - suffix.length);
3132
+ for (const replacement of alias.replacements) {
3133
+ const candidate = replacement.replace("*", wildcardValue);
3134
+ const resolved = resolveSourceFile(resolve6(baseUrl, candidate));
3135
+ if (resolved)
3136
+ return resolved;
3137
+ }
3138
+ }
3139
+ return;
3109
3140
  }, resolveDevClientDir = () => {
3110
3141
  const projectRoot = process.cwd();
3111
3142
  const fromSource = resolve6(import.meta.dir, "../dev/client");
@@ -3471,8 +3502,9 @@ ${slot.resolvedBindings.map((binding) => ` "${binding.key}": this.__absoluteDef
3471
3502
  ${fields}
3472
3503
  `);
3473
3504
  }, readAndEscapeFile = async (filePath, stylePreprocessors) => {
3474
- if (!existsSync5(filePath))
3475
- return null;
3505
+ if (!existsSync5(filePath)) {
3506
+ throw new Error(`Unable to inline Angular style resource: file not found at ${filePath}`);
3507
+ }
3476
3508
  const content = await compileStyleFileIfNeeded(filePath, stylePreprocessors);
3477
3509
  return escapeTemplateContent(content);
3478
3510
  }, inlineTemplateAndLowerDefer = async (source, fileDir) => {
@@ -3480,7 +3512,7 @@ ${fields}
3480
3512
  if (templateUrlMatch?.[1]) {
3481
3513
  const templatePath = join5(fileDir, templateUrlMatch[1]);
3482
3514
  if (!existsSync5(templatePath)) {
3483
- return { deferSlots: [], source };
3515
+ throw new Error(`Unable to inline Angular templateUrl "${templateUrlMatch[1]}": file not found at ${templatePath}`);
3484
3516
  }
3485
3517
  const templateRaw2 = await fs.readFile(templatePath, "utf-8");
3486
3518
  const lowered2 = lowerAngularDeferSyntax(templateRaw2);
@@ -3511,7 +3543,7 @@ ${fields}
3511
3543
  if (templateUrlMatch?.[1]) {
3512
3544
  const templatePath = join5(fileDir, templateUrlMatch[1]);
3513
3545
  if (!existsSync5(templatePath)) {
3514
- return { deferSlots: [], source };
3546
+ throw new Error(`Unable to inline Angular templateUrl "${templateUrlMatch[1]}": file not found at ${templatePath}`);
3515
3547
  }
3516
3548
  const templateRaw2 = readFileSync4(templatePath, "utf-8");
3517
3549
  const lowered2 = lowerAngularDeferSyntax(templateRaw2);
@@ -3584,9 +3616,52 @@ ${fields}
3584
3616
  }
3585
3617
  })
3586
3618
  });
3587
- const transpileAndRewrite = (sourceCode, relativeDir, actualPath) => {
3619
+ const tsconfigAliases = readTsconfigPathAliases();
3620
+ const resolveSourceFile = (candidate) => {
3621
+ const candidates = candidate.match(/\.[cm]?[tj]sx?$/) ? [candidate] : [
3622
+ `${candidate}.ts`,
3623
+ `${candidate}.tsx`,
3624
+ `${candidate}.js`,
3625
+ `${candidate}.jsx`,
3626
+ join5(candidate, "index.ts"),
3627
+ join5(candidate, "index.tsx"),
3628
+ join5(candidate, "index.js"),
3629
+ join5(candidate, "index.jsx")
3630
+ ];
3631
+ return candidates.find((file) => existsSync5(file));
3632
+ };
3633
+ const resolveLocalImport = (specifier, fromDir) => {
3634
+ if (specifier.startsWith(".") || specifier.startsWith("/")) {
3635
+ return resolveSourceFile(resolve6(fromDir, specifier));
3636
+ }
3637
+ const aliased = matchTsconfigAlias(specifier, tsconfigAliases.aliases, tsconfigAliases.baseUrl, resolveSourceFile);
3638
+ if (aliased)
3639
+ return aliased;
3640
+ try {
3641
+ const resolved = Bun.resolveSync(specifier, fromDir);
3642
+ if (resolved.includes("/node_modules/"))
3643
+ return;
3644
+ const absolute = resolve6(resolved);
3645
+ if (!absolute.startsWith(baseDir))
3646
+ return;
3647
+ return resolveSourceFile(absolute);
3648
+ } catch {
3649
+ return;
3650
+ }
3651
+ };
3652
+ const toOutputPath = (sourcePath) => {
3653
+ const inputDir = dirname4(sourcePath);
3654
+ const relativeDir = inputDir.startsWith(baseDir) ? inputDir.substring(baseDir.length + 1) : inputDir;
3655
+ const fileBase = basename3(sourcePath).replace(/\.[cm]?[tj]sx?$/, ".js");
3656
+ return join5(outDir, relativeDir, fileBase);
3657
+ };
3658
+ const transpileAndRewrite = (sourceCode, relativeDir, actualPath, importRewrites) => {
3588
3659
  let processedContent = angularTranspiler.transformSync(sourceCode);
3589
3660
  const rewriteBareImport = (prefix, specifier, suffix) => {
3661
+ const rewritten = importRewrites.get(specifier);
3662
+ if (rewritten) {
3663
+ return `${prefix}${rewritten}${suffix}`;
3664
+ }
3590
3665
  if (specifier.startsWith(".") || specifier.startsWith("/")) {
3591
3666
  return `${prefix}${specifier}${suffix}`;
3592
3667
  }
@@ -3631,12 +3706,13 @@ ${fields}
3631
3706
  sourceCode = inlineTemplateAndLowerDeferSync(inlined.source, dirname4(actualPath)).source;
3632
3707
  const inputDir = dirname4(actualPath);
3633
3708
  const relativeDir = inputDir.startsWith(baseDir) ? inputDir.substring(baseDir.length + 1) : inputDir;
3634
- const fileBase = basename3(actualPath).replace(/\.ts$/, ".js");
3709
+ const fileBase = basename3(actualPath).replace(/\.[cm]?[tj]sx?$/, ".js");
3635
3710
  const targetDir = join5(outDir, relativeDir);
3636
- const targetPath = join5(targetDir, fileBase);
3711
+ const targetPath = toOutputPath(actualPath);
3637
3712
  const localImports = [];
3638
- const fromRegex = /(?:from|import)\s+['"](\.\.?\/[^'"]+)['"]/g;
3639
- const dynamicImportRegex = /import\(\s*['"](\.\.?\/[^'"]+)['"]\s*\)/g;
3713
+ const importRewrites = new Map;
3714
+ const fromRegex = /(?:from|import)\s+['"]([^'".][^'"]*|\.\.?\/[^'"]+)['"]/g;
3715
+ const dynamicImportRegex = /import\(\s*['"]([^'".][^'"]*|\.\.?\/[^'"]+)['"]\s*\)/g;
3640
3716
  let importMatch;
3641
3717
  while ((importMatch = fromRegex.exec(sourceCode)) !== null) {
3642
3718
  if (importMatch[1])
@@ -3646,22 +3722,26 @@ ${fields}
3646
3722
  if (importMatch[1])
3647
3723
  localImports.push(importMatch[1]);
3648
3724
  }
3725
+ const localImportPaths = localImports.map((specifier) => {
3726
+ const resolved2 = resolveLocalImport(specifier, inputDir);
3727
+ if (!resolved2)
3728
+ return null;
3729
+ const relativeImport = relative3(targetDir, toOutputPath(resolved2)).replace(/\\/g, "/").replace(/\.js$/, "");
3730
+ importRewrites.set(specifier, relativeImport.startsWith(".") ? relativeImport : `./${relativeImport}`);
3731
+ return resolved2;
3732
+ }).filter((path) => Boolean(path));
3649
3733
  const contentHash = Bun.hash(sourceCode).toString(BASE_36_RADIX);
3650
3734
  const cacheKey = actualPath;
3651
3735
  if (jitContentCache.get(cacheKey) === contentHash && existsSync5(targetPath)) {
3652
3736
  allOutputs.push(targetPath);
3653
3737
  } else {
3654
- const processedContent = transpileAndRewrite(sourceCode, relativeDir, actualPath);
3738
+ const processedContent = transpileAndRewrite(sourceCode, relativeDir, actualPath, importRewrites);
3655
3739
  await fs.mkdir(targetDir, { recursive: true });
3656
3740
  await fs.writeFile(targetPath, processedContent, "utf-8");
3657
3741
  allOutputs.push(targetPath);
3658
3742
  jitContentCache.set(cacheKey, contentHash);
3659
3743
  }
3660
- const inputDirForResolve = dirname4(actualPath);
3661
- await Promise.all(localImports.map((imp) => {
3662
- const importPath = resolve6(inputDirForResolve, imp);
3663
- return transpileFile(importPath);
3664
- }));
3744
+ await Promise.all(localImportPaths.map((importPath) => transpileFile(importPath)));
3665
3745
  };
3666
3746
  await transpileFile(inputPath);
3667
3747
  return allOutputs;
@@ -4894,5 +4974,5 @@ export {
4894
4974
  handleAngularPageRequest
4895
4975
  };
4896
4976
 
4897
- //# debugId=4F6B5E16C1BC6DAC64756E2164756E21
4977
+ //# debugId=6DAA1F30AA9E65E864756E2164756E21
4898
4978
  //# sourceMappingURL=server.js.map