@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/cli.js CHANGED
@@ -13748,6 +13748,68 @@ function validateRealtimeConfig(config) {
13748
13748
  // modules/build/bundler/server.ts
13749
13749
  init_globals();
13750
13750
  var SERVER_FILES = [INIT_FILE_NAME, CONFIG_FILE_NAME];
13751
+ function createPathAliasPlugin(projectRoot, outDir) {
13752
+ const aliases = loadAliasesFromTsconfig(projectRoot);
13753
+ const tsconfigPath = path21.join(projectRoot, "tsconfig.json");
13754
+ let baseUrl = ".";
13755
+ if (fs16.existsSync(tsconfigPath)) {
13756
+ try {
13757
+ const tsconfig = JSON.parse(fs16.readFileSync(tsconfigPath, "utf-8"));
13758
+ baseUrl = tsconfig.compilerOptions?.baseUrl ?? ".";
13759
+ } catch {
13760
+ }
13761
+ }
13762
+ return {
13763
+ name: "path-alias-resolver",
13764
+ setup(build) {
13765
+ build.onResolve({ filter: /.*/ }, (args) => {
13766
+ if (args.path.startsWith(".") || args.path.startsWith("/") || path21.isAbsolute(args.path) || args.path.includes("node_modules")) {
13767
+ return null;
13768
+ }
13769
+ for (const [aliasKey, aliasPath] of Object.entries(aliases)) {
13770
+ if (args.path.startsWith(aliasKey + "/") || args.path === aliasKey) {
13771
+ const restPath = args.path.startsWith(aliasKey + "/") ? args.path.slice(aliasKey.length + 1) : "";
13772
+ const resolvedPath = restPath ? path21.join(aliasPath, restPath) : aliasPath;
13773
+ let actualPath = null;
13774
+ const extensions = [".ts", ".tsx", ".js", ".jsx", ".json"];
13775
+ if (fs16.existsSync(resolvedPath) && fs16.statSync(resolvedPath).isDirectory()) {
13776
+ for (const ext of extensions) {
13777
+ const indexPath = path21.join(resolvedPath, `index${ext}`);
13778
+ if (fs16.existsSync(indexPath)) {
13779
+ actualPath = indexPath;
13780
+ break;
13781
+ }
13782
+ }
13783
+ } else {
13784
+ for (const ext of extensions) {
13785
+ const filePath = resolvedPath + ext;
13786
+ if (fs16.existsSync(filePath)) {
13787
+ actualPath = filePath;
13788
+ break;
13789
+ }
13790
+ }
13791
+ if (!actualPath && fs16.existsSync(resolvedPath)) {
13792
+ actualPath = resolvedPath;
13793
+ }
13794
+ }
13795
+ if (actualPath) {
13796
+ const relativePath = path21.relative(outDir, actualPath);
13797
+ const normalizedPath = relativePath.replace(/\\/g, "/");
13798
+ const finalPath = normalizedPath.startsWith(".") ? normalizedPath : `./${normalizedPath}`;
13799
+ const ext = path21.extname(finalPath);
13800
+ const pathWithoutExt = ext === ".json" ? finalPath : finalPath.slice(0, -ext.length);
13801
+ return {
13802
+ path: pathWithoutExt,
13803
+ namespace: "file"
13804
+ };
13805
+ }
13806
+ }
13807
+ }
13808
+ return null;
13809
+ });
13810
+ }
13811
+ };
13812
+ }
13751
13813
  function collectAppSources(appDir) {
13752
13814
  const entries = [];
13753
13815
  function walk(dir) {
@@ -13791,6 +13853,7 @@ async function buildServerApp(projectRoot, appDir) {
13791
13853
  tsconfig: path21.join(projectRoot, "tsconfig.json"),
13792
13854
  packages: "external"
13793
13855
  });
13856
+ const pathAliasPlugin = createPathAliasPlugin(projectRoot, outDir);
13794
13857
  for (const fileName of SERVER_FILES) {
13795
13858
  const initTS = path21.join(projectRoot, `${fileName}.ts`);
13796
13859
  const initJS = path21.join(outDir, `${fileName}.js`);
@@ -13805,7 +13868,8 @@ async function buildServerApp(projectRoot, appDir) {
13805
13868
  sourcemap: true,
13806
13869
  bundle: false,
13807
13870
  logLevel: "info",
13808
- tsconfig: path21.join(projectRoot, "tsconfig.json")
13871
+ tsconfig: path21.join(projectRoot, "tsconfig.json"),
13872
+ plugins: [pathAliasPlugin]
13809
13873
  });
13810
13874
  }
13811
13875
  }