@lolyjs/core 0.2.0-alpha.21 → 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/README.md +59 -1
- package/dist/cli.cjs +97 -42
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +97 -42
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +107 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +107 -55
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -13759,51 +13759,88 @@ function createPathAliasPlugin(projectRoot, outDir) {
|
|
|
13759
13759
|
} catch {
|
|
13760
13760
|
}
|
|
13761
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
|
+
}
|
|
13762
13804
|
return {
|
|
13763
13805
|
name: "path-alias-resolver",
|
|
13764
13806
|
setup(build) {
|
|
13765
|
-
build.
|
|
13766
|
-
|
|
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) {
|
|
13767
13812
|
return null;
|
|
13768
13813
|
}
|
|
13769
|
-
|
|
13770
|
-
|
|
13771
|
-
|
|
13772
|
-
|
|
13773
|
-
|
|
13774
|
-
|
|
13775
|
-
|
|
13776
|
-
|
|
13777
|
-
|
|
13778
|
-
|
|
13779
|
-
|
|
13780
|
-
|
|
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
|
-
};
|
|
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}`;
|
|
13805
13828
|
}
|
|
13806
|
-
|
|
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
|
+
};
|
|
13807
13844
|
}
|
|
13808
13845
|
return null;
|
|
13809
13846
|
});
|
|
@@ -14106,6 +14143,9 @@ function getAppDir(projectRoot, config) {
|
|
|
14106
14143
|
function getBuildDir(projectRoot, config) {
|
|
14107
14144
|
return path22.join(projectRoot, config.directories.build);
|
|
14108
14145
|
}
|
|
14146
|
+
function getStaticDir(projectRoot, config) {
|
|
14147
|
+
return path22.resolve(projectRoot, config.directories.static);
|
|
14148
|
+
}
|
|
14109
14149
|
|
|
14110
14150
|
// modules/build/index.ts
|
|
14111
14151
|
async function buildApp(options = {}) {
|
|
@@ -14156,12 +14196,13 @@ async function buildApp(options = {}) {
|
|
|
14156
14196
|
}
|
|
14157
14197
|
|
|
14158
14198
|
// src/server.ts
|
|
14159
|
-
import
|
|
14199
|
+
import fs19 from "fs";
|
|
14160
14200
|
import path27 from "path";
|
|
14161
14201
|
|
|
14162
14202
|
// modules/server/setup.ts
|
|
14163
14203
|
import express from "express";
|
|
14164
14204
|
import path25 from "path";
|
|
14205
|
+
import fs18 from "fs";
|
|
14165
14206
|
|
|
14166
14207
|
// ../../node_modules/.pnpm/chokidar@4.0.3/node_modules/chokidar/esm/index.js
|
|
14167
14208
|
import { stat as statcb } from "fs";
|
|
@@ -16003,8 +16044,22 @@ function clearAppRequireCache(appDir) {
|
|
|
16003
16044
|
|
|
16004
16045
|
// modules/server/setup.ts
|
|
16005
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
|
+
}
|
|
16006
16060
|
function setupServer(app, options) {
|
|
16007
16061
|
const { projectRoot, appDir, isDev, config } = options;
|
|
16062
|
+
setupStaticFiles(app, projectRoot, config);
|
|
16008
16063
|
const routeLoader = isDev ? new FilesystemRouteLoader(appDir, projectRoot) : new ManifestRouteLoader(projectRoot);
|
|
16009
16064
|
if (isDev) {
|
|
16010
16065
|
let getRoutes2 = function() {
|
|
@@ -17567,7 +17622,7 @@ var setupApplication = async ({
|
|
|
17567
17622
|
// src/server.ts
|
|
17568
17623
|
import dotenv2 from "dotenv";
|
|
17569
17624
|
var envPath = path27.join(process.cwd(), ".env");
|
|
17570
|
-
if (
|
|
17625
|
+
if (fs19.existsSync(envPath)) {
|
|
17571
17626
|
dotenv2.config({ path: envPath });
|
|
17572
17627
|
} else {
|
|
17573
17628
|
dotenv2.config();
|
|
@@ -17589,7 +17644,7 @@ async function startServer(options = {}) {
|
|
|
17589
17644
|
const port = options.port ?? (process.env.PORT ? parseInt(process.env.PORT, 10) : void 0) ?? config.server.port;
|
|
17590
17645
|
const host = process.env.HOST ?? (!isDev ? "0.0.0.0" : void 0) ?? config.server.host;
|
|
17591
17646
|
const appDir = options.appDir ?? (isDev ? getAppDir(projectRoot, config) : path27.join(getBuildDir(projectRoot, config), "server"));
|
|
17592
|
-
if (!isDev && !
|
|
17647
|
+
if (!isDev && !fs19.existsSync(appDir)) {
|
|
17593
17648
|
logger4.error("Compiled directory not found", void 0, {
|
|
17594
17649
|
buildDir: config.directories.build,
|
|
17595
17650
|
appDir,
|