@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.cjs CHANGED
@@ -17514,6 +17514,68 @@ var import_fs20 = __toESM(require("fs"));
17514
17514
  var import_esbuild = __toESM(require("esbuild"));
17515
17515
  init_globals();
17516
17516
  var SERVER_FILES = [INIT_FILE_NAME, CONFIG_FILE_NAME];
17517
+ function createPathAliasPlugin(projectRoot, outDir) {
17518
+ const aliases = loadAliasesFromTsconfig(projectRoot);
17519
+ const tsconfigPath = import_path31.default.join(projectRoot, "tsconfig.json");
17520
+ let baseUrl = ".";
17521
+ if (import_fs20.default.existsSync(tsconfigPath)) {
17522
+ try {
17523
+ const tsconfig = JSON.parse(import_fs20.default.readFileSync(tsconfigPath, "utf-8"));
17524
+ baseUrl = tsconfig.compilerOptions?.baseUrl ?? ".";
17525
+ } catch {
17526
+ }
17527
+ }
17528
+ return {
17529
+ name: "path-alias-resolver",
17530
+ setup(build) {
17531
+ build.onResolve({ filter: /.*/ }, (args) => {
17532
+ if (args.path.startsWith(".") || args.path.startsWith("/") || import_path31.default.isAbsolute(args.path) || args.path.includes("node_modules")) {
17533
+ return null;
17534
+ }
17535
+ for (const [aliasKey, aliasPath] of Object.entries(aliases)) {
17536
+ if (args.path.startsWith(aliasKey + "/") || args.path === aliasKey) {
17537
+ const restPath = args.path.startsWith(aliasKey + "/") ? args.path.slice(aliasKey.length + 1) : "";
17538
+ const resolvedPath = restPath ? import_path31.default.join(aliasPath, restPath) : aliasPath;
17539
+ let actualPath = null;
17540
+ const extensions = [".ts", ".tsx", ".js", ".jsx", ".json"];
17541
+ if (import_fs20.default.existsSync(resolvedPath) && import_fs20.default.statSync(resolvedPath).isDirectory()) {
17542
+ for (const ext of extensions) {
17543
+ const indexPath = import_path31.default.join(resolvedPath, `index${ext}`);
17544
+ if (import_fs20.default.existsSync(indexPath)) {
17545
+ actualPath = indexPath;
17546
+ break;
17547
+ }
17548
+ }
17549
+ } else {
17550
+ for (const ext of extensions) {
17551
+ const filePath = resolvedPath + ext;
17552
+ if (import_fs20.default.existsSync(filePath)) {
17553
+ actualPath = filePath;
17554
+ break;
17555
+ }
17556
+ }
17557
+ if (!actualPath && import_fs20.default.existsSync(resolvedPath)) {
17558
+ actualPath = resolvedPath;
17559
+ }
17560
+ }
17561
+ if (actualPath) {
17562
+ const relativePath = import_path31.default.relative(outDir, actualPath);
17563
+ const normalizedPath = relativePath.replace(/\\/g, "/");
17564
+ const finalPath = normalizedPath.startsWith(".") ? normalizedPath : `./${normalizedPath}`;
17565
+ const ext = import_path31.default.extname(finalPath);
17566
+ const pathWithoutExt = ext === ".json" ? finalPath : finalPath.slice(0, -ext.length);
17567
+ return {
17568
+ path: pathWithoutExt,
17569
+ namespace: "file"
17570
+ };
17571
+ }
17572
+ }
17573
+ }
17574
+ return null;
17575
+ });
17576
+ }
17577
+ };
17578
+ }
17517
17579
  function collectAppSources(appDir) {
17518
17580
  const entries = [];
17519
17581
  function walk(dir) {
@@ -17557,6 +17619,7 @@ async function buildServerApp(projectRoot, appDir) {
17557
17619
  tsconfig: import_path31.default.join(projectRoot, "tsconfig.json"),
17558
17620
  packages: "external"
17559
17621
  });
17622
+ const pathAliasPlugin = createPathAliasPlugin(projectRoot, outDir);
17560
17623
  for (const fileName of SERVER_FILES) {
17561
17624
  const initTS = import_path31.default.join(projectRoot, `${fileName}.ts`);
17562
17625
  const initJS = import_path31.default.join(outDir, `${fileName}.js`);
@@ -17571,7 +17634,8 @@ async function buildServerApp(projectRoot, appDir) {
17571
17634
  sourcemap: true,
17572
17635
  bundle: false,
17573
17636
  logLevel: "info",
17574
- tsconfig: import_path31.default.join(projectRoot, "tsconfig.json")
17637
+ tsconfig: import_path31.default.join(projectRoot, "tsconfig.json"),
17638
+ plugins: [pathAliasPlugin]
17575
17639
  });
17576
17640
  }
17577
17641
  }