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

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,105 @@ 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
+ function resolveAliasToRelative(importPath, sourceFile) {
13763
+ if (importPath.startsWith(".") || importPath.startsWith("/") || path21.isAbsolute(importPath) || importPath.includes("node_modules")) {
13764
+ return null;
13765
+ }
13766
+ for (const [aliasKey, aliasPath] of Object.entries(aliases)) {
13767
+ if (importPath.startsWith(aliasKey + "/") || importPath === aliasKey) {
13768
+ const restPath = importPath.startsWith(aliasKey + "/") ? importPath.slice(aliasKey.length + 1) : "";
13769
+ const resolvedPath = restPath ? path21.join(aliasPath, restPath) : aliasPath;
13770
+ let actualPath = null;
13771
+ const extensions = [".ts", ".tsx", ".js", ".jsx", ".json"];
13772
+ if (fs16.existsSync(resolvedPath) && fs16.statSync(resolvedPath).isDirectory()) {
13773
+ for (const ext of extensions) {
13774
+ const indexPath = path21.join(resolvedPath, `index${ext}`);
13775
+ if (fs16.existsSync(indexPath)) {
13776
+ actualPath = indexPath;
13777
+ break;
13778
+ }
13779
+ }
13780
+ } else {
13781
+ for (const ext of extensions) {
13782
+ const filePath = resolvedPath + ext;
13783
+ if (fs16.existsSync(filePath)) {
13784
+ actualPath = filePath;
13785
+ break;
13786
+ }
13787
+ }
13788
+ if (!actualPath && fs16.existsSync(resolvedPath)) {
13789
+ actualPath = resolvedPath;
13790
+ }
13791
+ }
13792
+ if (actualPath) {
13793
+ const relativePath = path21.relative(outDir, actualPath);
13794
+ const normalizedPath = relativePath.replace(/\\/g, "/");
13795
+ const finalPath = normalizedPath.startsWith(".") ? normalizedPath : `./${normalizedPath}`;
13796
+ const ext = path21.extname(finalPath);
13797
+ const pathWithoutExt = ext === ".json" ? finalPath : finalPath.slice(0, -ext.length);
13798
+ return pathWithoutExt;
13799
+ }
13800
+ }
13801
+ }
13802
+ return null;
13803
+ }
13804
+ return {
13805
+ name: "path-alias-resolver",
13806
+ setup(build) {
13807
+ build.onLoad({ filter: /\.(ts|tsx|js|jsx)$/ }, (args) => {
13808
+ const fileName = path21.basename(args.path);
13809
+ const isServerFile = SERVER_FILES.some((f) => fileName === `${f}.ts` || fileName === `${f}.tsx` || fileName === `${f}.js` || fileName === `${f}.jsx`);
13810
+ const isInProjectRoot = path21.dirname(args.path) === projectRoot;
13811
+ if (!isServerFile || !isInProjectRoot) {
13812
+ return null;
13813
+ }
13814
+ const contents = fs16.readFileSync(args.path, "utf-8");
13815
+ let transformed = contents;
13816
+ const aliasPatterns = Object.keys(aliases).sort((a, b) => b.length - a.length);
13817
+ for (const aliasKey of aliasPatterns) {
13818
+ const escapedAlias = aliasKey.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
13819
+ const aliasInQuotesPattern = new RegExp(
13820
+ `(['"\`])${escapedAlias}(/[^'"\`\\s]*)?(['"\`])`,
13821
+ "g"
13822
+ );
13823
+ transformed = transformed.replace(aliasInQuotesPattern, (match, quote1, rest, quote2) => {
13824
+ const fullPath = aliasKey + (rest || "");
13825
+ const resolved = resolveAliasToRelative(fullPath, args.path);
13826
+ if (resolved) {
13827
+ return `${quote1}${resolved}${quote2}`;
13828
+ }
13829
+ return match;
13830
+ });
13831
+ }
13832
+ return {
13833
+ contents: transformed,
13834
+ loader: path21.extname(args.path).slice(1)
13835
+ };
13836
+ });
13837
+ build.onResolve({ filter: /.*/ }, (args) => {
13838
+ const resolved = resolveAliasToRelative(args.path, args.importer || "");
13839
+ if (resolved) {
13840
+ return {
13841
+ path: resolved,
13842
+ namespace: "file"
13843
+ };
13844
+ }
13845
+ return null;
13846
+ });
13847
+ }
13848
+ };
13849
+ }
13751
13850
  function collectAppSources(appDir) {
13752
13851
  const entries = [];
13753
13852
  function walk(dir) {
@@ -13791,6 +13890,7 @@ async function buildServerApp(projectRoot, appDir) {
13791
13890
  tsconfig: path21.join(projectRoot, "tsconfig.json"),
13792
13891
  packages: "external"
13793
13892
  });
13893
+ const pathAliasPlugin = createPathAliasPlugin(projectRoot, outDir);
13794
13894
  for (const fileName of SERVER_FILES) {
13795
13895
  const initTS = path21.join(projectRoot, `${fileName}.ts`);
13796
13896
  const initJS = path21.join(outDir, `${fileName}.js`);
@@ -13805,7 +13905,8 @@ async function buildServerApp(projectRoot, appDir) {
13805
13905
  sourcemap: true,
13806
13906
  bundle: false,
13807
13907
  logLevel: "info",
13808
- tsconfig: path21.join(projectRoot, "tsconfig.json")
13908
+ tsconfig: path21.join(projectRoot, "tsconfig.json"),
13909
+ plugins: [pathAliasPlugin]
13809
13910
  });
13810
13911
  }
13811
13912
  }
@@ -14042,6 +14143,9 @@ function getAppDir(projectRoot, config) {
14042
14143
  function getBuildDir(projectRoot, config) {
14043
14144
  return path22.join(projectRoot, config.directories.build);
14044
14145
  }
14146
+ function getStaticDir(projectRoot, config) {
14147
+ return path22.resolve(projectRoot, config.directories.static);
14148
+ }
14045
14149
 
14046
14150
  // modules/build/index.ts
14047
14151
  async function buildApp(options = {}) {
@@ -14092,12 +14196,13 @@ async function buildApp(options = {}) {
14092
14196
  }
14093
14197
 
14094
14198
  // src/server.ts
14095
- import fs18 from "fs";
14199
+ import fs19 from "fs";
14096
14200
  import path27 from "path";
14097
14201
 
14098
14202
  // modules/server/setup.ts
14099
14203
  import express from "express";
14100
14204
  import path25 from "path";
14205
+ import fs18 from "fs";
14101
14206
 
14102
14207
  // ../../node_modules/.pnpm/chokidar@4.0.3/node_modules/chokidar/esm/index.js
14103
14208
  import { stat as statcb } from "fs";
@@ -15939,8 +16044,22 @@ function clearAppRequireCache(appDir) {
15939
16044
 
15940
16045
  // modules/server/setup.ts
15941
16046
  init_globals();
16047
+ function setupStaticFiles(app, projectRoot, config) {
16048
+ if (!config) return;
16049
+ const staticDir = getStaticDir(projectRoot, config);
16050
+ if (fs18.existsSync(staticDir)) {
16051
+ app.use(
16052
+ express.static(staticDir, {
16053
+ // In production, add caching headers for better performance
16054
+ maxAge: process.env.NODE_ENV === "production" ? "1y" : 0,
16055
+ immutable: process.env.NODE_ENV === "production"
16056
+ })
16057
+ );
16058
+ }
16059
+ }
15942
16060
  function setupServer(app, options) {
15943
16061
  const { projectRoot, appDir, isDev, config } = options;
16062
+ setupStaticFiles(app, projectRoot, config);
15944
16063
  const routeLoader = isDev ? new FilesystemRouteLoader(appDir, projectRoot) : new ManifestRouteLoader(projectRoot);
15945
16064
  if (isDev) {
15946
16065
  let getRoutes2 = function() {
@@ -17503,7 +17622,7 @@ var setupApplication = async ({
17503
17622
  // src/server.ts
17504
17623
  import dotenv2 from "dotenv";
17505
17624
  var envPath = path27.join(process.cwd(), ".env");
17506
- if (fs18.existsSync(envPath)) {
17625
+ if (fs19.existsSync(envPath)) {
17507
17626
  dotenv2.config({ path: envPath });
17508
17627
  } else {
17509
17628
  dotenv2.config();
@@ -17525,7 +17644,7 @@ async function startServer(options = {}) {
17525
17644
  const port = options.port ?? (process.env.PORT ? parseInt(process.env.PORT, 10) : void 0) ?? config.server.port;
17526
17645
  const host = process.env.HOST ?? (!isDev ? "0.0.0.0" : void 0) ?? config.server.host;
17527
17646
  const appDir = options.appDir ?? (isDev ? getAppDir(projectRoot, config) : path27.join(getBuildDir(projectRoot, config), "server"));
17528
- if (!isDev && !fs18.existsSync(appDir)) {
17647
+ if (!isDev && !fs19.existsSync(appDir)) {
17529
17648
  logger4.error("Compiled directory not found", void 0, {
17530
17649
  buildDir: config.directories.build,
17531
17650
  appDir,