@lolyjs/core 0.2.0-alpha.20 → 0.2.0-alpha.21

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/index.js CHANGED
@@ -17481,6 +17481,68 @@ import fs18 from "fs";
17481
17481
  import esbuild from "esbuild";
17482
17482
  init_globals();
17483
17483
  var SERVER_FILES = [INIT_FILE_NAME, CONFIG_FILE_NAME];
17484
+ function createPathAliasPlugin(projectRoot, outDir) {
17485
+ const aliases = loadAliasesFromTsconfig(projectRoot);
17486
+ const tsconfigPath = path27.join(projectRoot, "tsconfig.json");
17487
+ let baseUrl = ".";
17488
+ if (fs18.existsSync(tsconfigPath)) {
17489
+ try {
17490
+ const tsconfig = JSON.parse(fs18.readFileSync(tsconfigPath, "utf-8"));
17491
+ baseUrl = tsconfig.compilerOptions?.baseUrl ?? ".";
17492
+ } catch {
17493
+ }
17494
+ }
17495
+ return {
17496
+ name: "path-alias-resolver",
17497
+ setup(build) {
17498
+ build.onResolve({ filter: /.*/ }, (args) => {
17499
+ if (args.path.startsWith(".") || args.path.startsWith("/") || path27.isAbsolute(args.path) || args.path.includes("node_modules")) {
17500
+ return null;
17501
+ }
17502
+ for (const [aliasKey, aliasPath] of Object.entries(aliases)) {
17503
+ if (args.path.startsWith(aliasKey + "/") || args.path === aliasKey) {
17504
+ const restPath = args.path.startsWith(aliasKey + "/") ? args.path.slice(aliasKey.length + 1) : "";
17505
+ const resolvedPath = restPath ? path27.join(aliasPath, restPath) : aliasPath;
17506
+ let actualPath = null;
17507
+ const extensions = [".ts", ".tsx", ".js", ".jsx", ".json"];
17508
+ if (fs18.existsSync(resolvedPath) && fs18.statSync(resolvedPath).isDirectory()) {
17509
+ for (const ext of extensions) {
17510
+ const indexPath = path27.join(resolvedPath, `index${ext}`);
17511
+ if (fs18.existsSync(indexPath)) {
17512
+ actualPath = indexPath;
17513
+ break;
17514
+ }
17515
+ }
17516
+ } else {
17517
+ for (const ext of extensions) {
17518
+ const filePath = resolvedPath + ext;
17519
+ if (fs18.existsSync(filePath)) {
17520
+ actualPath = filePath;
17521
+ break;
17522
+ }
17523
+ }
17524
+ if (!actualPath && fs18.existsSync(resolvedPath)) {
17525
+ actualPath = resolvedPath;
17526
+ }
17527
+ }
17528
+ if (actualPath) {
17529
+ const relativePath = path27.relative(outDir, actualPath);
17530
+ const normalizedPath = relativePath.replace(/\\/g, "/");
17531
+ const finalPath = normalizedPath.startsWith(".") ? normalizedPath : `./${normalizedPath}`;
17532
+ const ext = path27.extname(finalPath);
17533
+ const pathWithoutExt = ext === ".json" ? finalPath : finalPath.slice(0, -ext.length);
17534
+ return {
17535
+ path: pathWithoutExt,
17536
+ namespace: "file"
17537
+ };
17538
+ }
17539
+ }
17540
+ }
17541
+ return null;
17542
+ });
17543
+ }
17544
+ };
17545
+ }
17484
17546
  function collectAppSources(appDir) {
17485
17547
  const entries = [];
17486
17548
  function walk(dir) {
@@ -17524,6 +17586,7 @@ async function buildServerApp(projectRoot, appDir) {
17524
17586
  tsconfig: path27.join(projectRoot, "tsconfig.json"),
17525
17587
  packages: "external"
17526
17588
  });
17589
+ const pathAliasPlugin = createPathAliasPlugin(projectRoot, outDir);
17527
17590
  for (const fileName of SERVER_FILES) {
17528
17591
  const initTS = path27.join(projectRoot, `${fileName}.ts`);
17529
17592
  const initJS = path27.join(outDir, `${fileName}.js`);
@@ -17538,7 +17601,8 @@ async function buildServerApp(projectRoot, appDir) {
17538
17601
  sourcemap: true,
17539
17602
  bundle: false,
17540
17603
  logLevel: "info",
17541
- tsconfig: path27.join(projectRoot, "tsconfig.json")
17604
+ tsconfig: path27.join(projectRoot, "tsconfig.json"),
17605
+ plugins: [pathAliasPlugin]
17542
17606
  });
17543
17607
  }
17544
17608
  }