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

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
@@ -43311,6 +43311,37 @@ var computeConfigHash = () => {
43311
43311
  } catch {
43312
43312
  return "";
43313
43313
  }
43314
+ }, readTsconfigPathAliases = () => {
43315
+ try {
43316
+ const configPath2 = resolve16(process.cwd(), "tsconfig.json");
43317
+ const config = ts2.readConfigFile(configPath2, ts2.sys.readFile).config;
43318
+ const compilerOptions = config?.compilerOptions ?? {};
43319
+ const baseUrl = resolve16(process.cwd(), compilerOptions.baseUrl ?? ".");
43320
+ const aliases = Object.entries(compilerOptions.paths ?? {}).map(([pattern, replacements]) => ({ pattern, replacements }));
43321
+ return { aliases, baseUrl };
43322
+ } catch {
43323
+ return { aliases: [], baseUrl: process.cwd() };
43324
+ }
43325
+ }, matchTsconfigAlias = (specifier, aliases, baseUrl, resolveSourceFile) => {
43326
+ for (const alias of aliases) {
43327
+ const wildcardIndex = alias.pattern.indexOf("*");
43328
+ const exactMatch = wildcardIndex === -1;
43329
+ if (exactMatch && specifier !== alias.pattern)
43330
+ continue;
43331
+ const prefix = exactMatch ? alias.pattern : alias.pattern.slice(0, wildcardIndex);
43332
+ const suffix = exactMatch ? "" : alias.pattern.slice(wildcardIndex + 1);
43333
+ if (!exactMatch && (!specifier.startsWith(prefix) || !specifier.endsWith(suffix))) {
43334
+ continue;
43335
+ }
43336
+ const wildcardValue = exactMatch ? "" : specifier.slice(prefix.length, specifier.length - suffix.length);
43337
+ for (const replacement of alias.replacements) {
43338
+ const candidate = replacement.replace("*", wildcardValue);
43339
+ const resolved = resolveSourceFile(resolve16(baseUrl, candidate));
43340
+ if (resolved)
43341
+ return resolved;
43342
+ }
43343
+ }
43344
+ return;
43314
43345
  }, resolveDevClientDir4 = () => {
43315
43346
  const projectRoot = process.cwd();
43316
43347
  const fromSource = resolve16(import.meta.dir, "../dev/client");
@@ -43789,9 +43820,52 @@ ${fields}
43789
43820
  }
43790
43821
  })
43791
43822
  });
43792
- const transpileAndRewrite = (sourceCode, relativeDir, actualPath) => {
43823
+ const tsconfigAliases = readTsconfigPathAliases();
43824
+ const resolveSourceFile = (candidate) => {
43825
+ const candidates = candidate.match(/\.[cm]?[tj]sx?$/) ? [candidate] : [
43826
+ `${candidate}.ts`,
43827
+ `${candidate}.tsx`,
43828
+ `${candidate}.js`,
43829
+ `${candidate}.jsx`,
43830
+ join15(candidate, "index.ts"),
43831
+ join15(candidate, "index.tsx"),
43832
+ join15(candidate, "index.js"),
43833
+ join15(candidate, "index.jsx")
43834
+ ];
43835
+ return candidates.find((file3) => existsSync16(file3));
43836
+ };
43837
+ const resolveLocalImport = (specifier, fromDir) => {
43838
+ if (specifier.startsWith(".") || specifier.startsWith("/")) {
43839
+ return resolveSourceFile(resolve16(fromDir, specifier));
43840
+ }
43841
+ const aliased = matchTsconfigAlias(specifier, tsconfigAliases.aliases, tsconfigAliases.baseUrl, resolveSourceFile);
43842
+ if (aliased)
43843
+ return aliased;
43844
+ try {
43845
+ const resolved = Bun.resolveSync(specifier, fromDir);
43846
+ if (resolved.includes("/node_modules/"))
43847
+ return;
43848
+ const absolute = resolve16(resolved);
43849
+ if (!absolute.startsWith(baseDir))
43850
+ return;
43851
+ return resolveSourceFile(absolute);
43852
+ } catch {
43853
+ return;
43854
+ }
43855
+ };
43856
+ const toOutputPath = (sourcePath) => {
43857
+ const inputDir = dirname10(sourcePath);
43858
+ const relativeDir = inputDir.startsWith(baseDir) ? inputDir.substring(baseDir.length + 1) : inputDir;
43859
+ const fileBase = basename6(sourcePath).replace(/\.[cm]?[tj]sx?$/, ".js");
43860
+ return join15(outDir, relativeDir, fileBase);
43861
+ };
43862
+ const transpileAndRewrite = (sourceCode, relativeDir, actualPath, importRewrites) => {
43793
43863
  let processedContent = angularTranspiler.transformSync(sourceCode);
43794
43864
  const rewriteBareImport = (prefix, specifier, suffix) => {
43865
+ const rewritten = importRewrites.get(specifier);
43866
+ if (rewritten) {
43867
+ return `${prefix}${rewritten}${suffix}`;
43868
+ }
43795
43869
  if (specifier.startsWith(".") || specifier.startsWith("/")) {
43796
43870
  return `${prefix}${specifier}${suffix}`;
43797
43871
  }
@@ -43836,12 +43910,13 @@ ${fields}
43836
43910
  sourceCode = inlineTemplateAndLowerDeferSync(inlined.source, dirname10(actualPath)).source;
43837
43911
  const inputDir = dirname10(actualPath);
43838
43912
  const relativeDir = inputDir.startsWith(baseDir) ? inputDir.substring(baseDir.length + 1) : inputDir;
43839
- const fileBase = basename6(actualPath).replace(/\.ts$/, ".js");
43913
+ const fileBase = basename6(actualPath).replace(/\.[cm]?[tj]sx?$/, ".js");
43840
43914
  const targetDir = join15(outDir, relativeDir);
43841
- const targetPath = join15(targetDir, fileBase);
43915
+ const targetPath = toOutputPath(actualPath);
43842
43916
  const localImports = [];
43843
- const fromRegex = /(?:from|import)\s+['"](\.\.?\/[^'"]+)['"]/g;
43844
- const dynamicImportRegex = /import\(\s*['"](\.\.?\/[^'"]+)['"]\s*\)/g;
43917
+ const importRewrites = new Map;
43918
+ const fromRegex = /(?:from|import)\s+['"]([^'".][^'"]*|\.\.?\/[^'"]+)['"]/g;
43919
+ const dynamicImportRegex = /import\(\s*['"]([^'".][^'"]*|\.\.?\/[^'"]+)['"]\s*\)/g;
43845
43920
  let importMatch;
43846
43921
  while ((importMatch = fromRegex.exec(sourceCode)) !== null) {
43847
43922
  if (importMatch[1])
@@ -43851,22 +43926,26 @@ ${fields}
43851
43926
  if (importMatch[1])
43852
43927
  localImports.push(importMatch[1]);
43853
43928
  }
43929
+ const localImportPaths = localImports.map((specifier) => {
43930
+ const resolved2 = resolveLocalImport(specifier, inputDir);
43931
+ if (!resolved2)
43932
+ return null;
43933
+ const relativeImport = relative9(targetDir, toOutputPath(resolved2)).replace(/\\/g, "/").replace(/\.js$/, "");
43934
+ importRewrites.set(specifier, relativeImport.startsWith(".") ? relativeImport : `./${relativeImport}`);
43935
+ return resolved2;
43936
+ }).filter((path2) => Boolean(path2));
43854
43937
  const contentHash = Bun.hash(sourceCode).toString(BASE_36_RADIX);
43855
43938
  const cacheKey2 = actualPath;
43856
43939
  if (jitContentCache.get(cacheKey2) === contentHash && existsSync16(targetPath)) {
43857
43940
  allOutputs.push(targetPath);
43858
43941
  } else {
43859
- const processedContent = transpileAndRewrite(sourceCode, relativeDir, actualPath);
43942
+ const processedContent = transpileAndRewrite(sourceCode, relativeDir, actualPath, importRewrites);
43860
43943
  await fs2.mkdir(targetDir, { recursive: true });
43861
43944
  await fs2.writeFile(targetPath, processedContent, "utf-8");
43862
43945
  allOutputs.push(targetPath);
43863
43946
  jitContentCache.set(cacheKey2, contentHash);
43864
43947
  }
43865
- const inputDirForResolve = dirname10(actualPath);
43866
- await Promise.all(localImports.map((imp) => {
43867
- const importPath = resolve16(inputDirForResolve, imp);
43868
- return transpileFile(importPath);
43869
- }));
43948
+ await Promise.all(localImportPaths.map((importPath) => transpileFile(importPath)));
43870
43949
  };
43871
43950
  await transpileFile(inputPath);
43872
43951
  return allOutputs;
@@ -49370,5 +49449,5 @@ export {
49370
49449
  build
49371
49450
  };
49372
49451
 
49373
- //# debugId=1EF9044D35D4419E64756E2164756E21
49452
+ //# debugId=2CC1930DF5B9DFEC64756E2164756E21
49374
49453
  //# sourceMappingURL=build.js.map