@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/README.md +59 -1
- package/dist/cli.cjs +123 -4
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +123 -4
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +131 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +131 -15
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9871,7 +9871,7 @@ var require_built3 = __commonJS({
|
|
|
9871
9871
|
});
|
|
9872
9872
|
|
|
9873
9873
|
// src/server.ts
|
|
9874
|
-
import
|
|
9874
|
+
import fs17 from "fs";
|
|
9875
9875
|
import path23 from "path";
|
|
9876
9876
|
|
|
9877
9877
|
// modules/server/utils/server-dir.ts
|
|
@@ -9913,6 +9913,7 @@ async function runInitIfExists(projectRoot, serverData) {
|
|
|
9913
9913
|
// modules/server/setup.ts
|
|
9914
9914
|
import express from "express";
|
|
9915
9915
|
import path17 from "path";
|
|
9916
|
+
import fs15 from "fs";
|
|
9916
9917
|
|
|
9917
9918
|
// modules/router/loader-pages.ts
|
|
9918
9919
|
import fs4 from "fs";
|
|
@@ -14003,8 +14004,22 @@ function getStaticDir(projectRoot, config) {
|
|
|
14003
14004
|
}
|
|
14004
14005
|
|
|
14005
14006
|
// modules/server/setup.ts
|
|
14007
|
+
function setupStaticFiles(app, projectRoot, config) {
|
|
14008
|
+
if (!config) return;
|
|
14009
|
+
const staticDir = getStaticDir(projectRoot, config);
|
|
14010
|
+
if (fs15.existsSync(staticDir)) {
|
|
14011
|
+
app.use(
|
|
14012
|
+
express.static(staticDir, {
|
|
14013
|
+
// In production, add caching headers for better performance
|
|
14014
|
+
maxAge: process.env.NODE_ENV === "production" ? "1y" : 0,
|
|
14015
|
+
immutable: process.env.NODE_ENV === "production"
|
|
14016
|
+
})
|
|
14017
|
+
);
|
|
14018
|
+
}
|
|
14019
|
+
}
|
|
14006
14020
|
function setupServer(app, options) {
|
|
14007
14021
|
const { projectRoot, appDir, isDev, config } = options;
|
|
14022
|
+
setupStaticFiles(app, projectRoot, config);
|
|
14008
14023
|
const routeLoader = isDev ? new FilesystemRouteLoader(appDir, projectRoot) : new ManifestRouteLoader(projectRoot);
|
|
14009
14024
|
if (isDev) {
|
|
14010
14025
|
let getRoutes2 = function() {
|
|
@@ -15108,7 +15123,7 @@ function handleNotFound(res, urlPath) {
|
|
|
15108
15123
|
}
|
|
15109
15124
|
|
|
15110
15125
|
// modules/server/handlers/ssg.ts
|
|
15111
|
-
import
|
|
15126
|
+
import fs16 from "fs";
|
|
15112
15127
|
import path20 from "path";
|
|
15113
15128
|
var logger3 = createModuleLogger("ssg");
|
|
15114
15129
|
function getSsgDirForPath(baseDir, urlPath) {
|
|
@@ -15125,7 +15140,7 @@ function getSsgDataPath(baseDir, urlPath) {
|
|
|
15125
15140
|
}
|
|
15126
15141
|
function tryServeSsgHtml(res, ssgOutDir, urlPath) {
|
|
15127
15142
|
const ssgHtmlPath = getSsgHtmlPath(ssgOutDir, urlPath);
|
|
15128
|
-
if (!
|
|
15143
|
+
if (!fs16.existsSync(ssgHtmlPath)) {
|
|
15129
15144
|
return false;
|
|
15130
15145
|
}
|
|
15131
15146
|
logger3.info("Serving SSG HTML", { urlPath, ssgHtmlPath });
|
|
@@ -15135,17 +15150,17 @@ function tryServeSsgHtml(res, ssgOutDir, urlPath) {
|
|
|
15135
15150
|
);
|
|
15136
15151
|
res.statusCode = 200;
|
|
15137
15152
|
res.setHeader("Content-Type", "text/html; charset=utf-8");
|
|
15138
|
-
const stream =
|
|
15153
|
+
const stream = fs16.createReadStream(ssgHtmlPath, { encoding: "utf-8" });
|
|
15139
15154
|
stream.pipe(res);
|
|
15140
15155
|
return true;
|
|
15141
15156
|
}
|
|
15142
15157
|
function tryServeSsgData(res, ssgOutDir, urlPath) {
|
|
15143
15158
|
const ssgDataPath = getSsgDataPath(ssgOutDir, urlPath);
|
|
15144
|
-
if (!
|
|
15159
|
+
if (!fs16.existsSync(ssgDataPath)) {
|
|
15145
15160
|
return false;
|
|
15146
15161
|
}
|
|
15147
15162
|
try {
|
|
15148
|
-
const raw =
|
|
15163
|
+
const raw = fs16.readFileSync(ssgDataPath, "utf-8");
|
|
15149
15164
|
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
15150
15165
|
res.status(200).end(raw);
|
|
15151
15166
|
return true;
|
|
@@ -17161,7 +17176,7 @@ var setupApplication = async ({
|
|
|
17161
17176
|
// src/server.ts
|
|
17162
17177
|
import dotenv2 from "dotenv";
|
|
17163
17178
|
var envPath = path23.join(process.cwd(), ".env");
|
|
17164
|
-
if (
|
|
17179
|
+
if (fs17.existsSync(envPath)) {
|
|
17165
17180
|
dotenv2.config({ path: envPath });
|
|
17166
17181
|
} else {
|
|
17167
17182
|
dotenv2.config();
|
|
@@ -17183,7 +17198,7 @@ async function startServer(options = {}) {
|
|
|
17183
17198
|
const port = options.port ?? (process.env.PORT ? parseInt(process.env.PORT, 10) : void 0) ?? config.server.port;
|
|
17184
17199
|
const host = process.env.HOST ?? (!isDev ? "0.0.0.0" : void 0) ?? config.server.host;
|
|
17185
17200
|
const appDir = options.appDir ?? (isDev ? getAppDir(projectRoot, config) : path23.join(getBuildDir(projectRoot, config), "server"));
|
|
17186
|
-
if (!isDev && !
|
|
17201
|
+
if (!isDev && !fs17.existsSync(appDir)) {
|
|
17187
17202
|
logger4.error("Compiled directory not found", void 0, {
|
|
17188
17203
|
buildDir: config.directories.build,
|
|
17189
17204
|
appDir,
|
|
@@ -17290,7 +17305,7 @@ function pathToOutDir(baseDir, urlPath) {
|
|
|
17290
17305
|
}
|
|
17291
17306
|
|
|
17292
17307
|
// modules/build/ssg/renderer.ts
|
|
17293
|
-
import
|
|
17308
|
+
import fs18 from "fs";
|
|
17294
17309
|
import path25 from "path";
|
|
17295
17310
|
import { renderToString } from "react-dom/server";
|
|
17296
17311
|
init_globals();
|
|
@@ -17414,8 +17429,8 @@ async function renderStaticRoute(projectRoot, ssgOutDir, route, urlPath, params)
|
|
|
17414
17429
|
ensureDir(dir);
|
|
17415
17430
|
const htmlFile = path25.join(dir, "index.html");
|
|
17416
17431
|
const dataFile = path25.join(dir, "data.json");
|
|
17417
|
-
|
|
17418
|
-
|
|
17432
|
+
fs18.writeFileSync(htmlFile, html, "utf-8");
|
|
17433
|
+
fs18.writeFileSync(dataFile, JSON.stringify(initialData, null, 2), "utf-8");
|
|
17419
17434
|
}
|
|
17420
17435
|
|
|
17421
17436
|
// modules/build/ssg/builder.ts
|
|
@@ -17477,14 +17492,113 @@ async function buildStaticPages(projectRoot, routes) {
|
|
|
17477
17492
|
|
|
17478
17493
|
// modules/build/bundler/server.ts
|
|
17479
17494
|
import path27 from "path";
|
|
17480
|
-
import
|
|
17495
|
+
import fs19 from "fs";
|
|
17481
17496
|
import esbuild from "esbuild";
|
|
17482
17497
|
init_globals();
|
|
17483
17498
|
var SERVER_FILES = [INIT_FILE_NAME, CONFIG_FILE_NAME];
|
|
17499
|
+
function createPathAliasPlugin(projectRoot, outDir) {
|
|
17500
|
+
const aliases = loadAliasesFromTsconfig(projectRoot);
|
|
17501
|
+
const tsconfigPath = path27.join(projectRoot, "tsconfig.json");
|
|
17502
|
+
let baseUrl = ".";
|
|
17503
|
+
if (fs19.existsSync(tsconfigPath)) {
|
|
17504
|
+
try {
|
|
17505
|
+
const tsconfig = JSON.parse(fs19.readFileSync(tsconfigPath, "utf-8"));
|
|
17506
|
+
baseUrl = tsconfig.compilerOptions?.baseUrl ?? ".";
|
|
17507
|
+
} catch {
|
|
17508
|
+
}
|
|
17509
|
+
}
|
|
17510
|
+
function resolveAliasToRelative(importPath, sourceFile) {
|
|
17511
|
+
if (importPath.startsWith(".") || importPath.startsWith("/") || path27.isAbsolute(importPath) || importPath.includes("node_modules")) {
|
|
17512
|
+
return null;
|
|
17513
|
+
}
|
|
17514
|
+
for (const [aliasKey, aliasPath] of Object.entries(aliases)) {
|
|
17515
|
+
if (importPath.startsWith(aliasKey + "/") || importPath === aliasKey) {
|
|
17516
|
+
const restPath = importPath.startsWith(aliasKey + "/") ? importPath.slice(aliasKey.length + 1) : "";
|
|
17517
|
+
const resolvedPath = restPath ? path27.join(aliasPath, restPath) : aliasPath;
|
|
17518
|
+
let actualPath = null;
|
|
17519
|
+
const extensions = [".ts", ".tsx", ".js", ".jsx", ".json"];
|
|
17520
|
+
if (fs19.existsSync(resolvedPath) && fs19.statSync(resolvedPath).isDirectory()) {
|
|
17521
|
+
for (const ext of extensions) {
|
|
17522
|
+
const indexPath = path27.join(resolvedPath, `index${ext}`);
|
|
17523
|
+
if (fs19.existsSync(indexPath)) {
|
|
17524
|
+
actualPath = indexPath;
|
|
17525
|
+
break;
|
|
17526
|
+
}
|
|
17527
|
+
}
|
|
17528
|
+
} else {
|
|
17529
|
+
for (const ext of extensions) {
|
|
17530
|
+
const filePath = resolvedPath + ext;
|
|
17531
|
+
if (fs19.existsSync(filePath)) {
|
|
17532
|
+
actualPath = filePath;
|
|
17533
|
+
break;
|
|
17534
|
+
}
|
|
17535
|
+
}
|
|
17536
|
+
if (!actualPath && fs19.existsSync(resolvedPath)) {
|
|
17537
|
+
actualPath = resolvedPath;
|
|
17538
|
+
}
|
|
17539
|
+
}
|
|
17540
|
+
if (actualPath) {
|
|
17541
|
+
const relativePath = path27.relative(outDir, actualPath);
|
|
17542
|
+
const normalizedPath = relativePath.replace(/\\/g, "/");
|
|
17543
|
+
const finalPath = normalizedPath.startsWith(".") ? normalizedPath : `./${normalizedPath}`;
|
|
17544
|
+
const ext = path27.extname(finalPath);
|
|
17545
|
+
const pathWithoutExt = ext === ".json" ? finalPath : finalPath.slice(0, -ext.length);
|
|
17546
|
+
return pathWithoutExt;
|
|
17547
|
+
}
|
|
17548
|
+
}
|
|
17549
|
+
}
|
|
17550
|
+
return null;
|
|
17551
|
+
}
|
|
17552
|
+
return {
|
|
17553
|
+
name: "path-alias-resolver",
|
|
17554
|
+
setup(build) {
|
|
17555
|
+
build.onLoad({ filter: /\.(ts|tsx|js|jsx)$/ }, (args) => {
|
|
17556
|
+
const fileName = path27.basename(args.path);
|
|
17557
|
+
const isServerFile = SERVER_FILES.some((f) => fileName === `${f}.ts` || fileName === `${f}.tsx` || fileName === `${f}.js` || fileName === `${f}.jsx`);
|
|
17558
|
+
const isInProjectRoot = path27.dirname(args.path) === projectRoot;
|
|
17559
|
+
if (!isServerFile || !isInProjectRoot) {
|
|
17560
|
+
return null;
|
|
17561
|
+
}
|
|
17562
|
+
const contents = fs19.readFileSync(args.path, "utf-8");
|
|
17563
|
+
let transformed = contents;
|
|
17564
|
+
const aliasPatterns = Object.keys(aliases).sort((a, b) => b.length - a.length);
|
|
17565
|
+
for (const aliasKey of aliasPatterns) {
|
|
17566
|
+
const escapedAlias = aliasKey.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
17567
|
+
const aliasInQuotesPattern = new RegExp(
|
|
17568
|
+
`(['"\`])${escapedAlias}(/[^'"\`\\s]*)?(['"\`])`,
|
|
17569
|
+
"g"
|
|
17570
|
+
);
|
|
17571
|
+
transformed = transformed.replace(aliasInQuotesPattern, (match, quote1, rest, quote2) => {
|
|
17572
|
+
const fullPath = aliasKey + (rest || "");
|
|
17573
|
+
const resolved = resolveAliasToRelative(fullPath, args.path);
|
|
17574
|
+
if (resolved) {
|
|
17575
|
+
return `${quote1}${resolved}${quote2}`;
|
|
17576
|
+
}
|
|
17577
|
+
return match;
|
|
17578
|
+
});
|
|
17579
|
+
}
|
|
17580
|
+
return {
|
|
17581
|
+
contents: transformed,
|
|
17582
|
+
loader: path27.extname(args.path).slice(1)
|
|
17583
|
+
};
|
|
17584
|
+
});
|
|
17585
|
+
build.onResolve({ filter: /.*/ }, (args) => {
|
|
17586
|
+
const resolved = resolveAliasToRelative(args.path, args.importer || "");
|
|
17587
|
+
if (resolved) {
|
|
17588
|
+
return {
|
|
17589
|
+
path: resolved,
|
|
17590
|
+
namespace: "file"
|
|
17591
|
+
};
|
|
17592
|
+
}
|
|
17593
|
+
return null;
|
|
17594
|
+
});
|
|
17595
|
+
}
|
|
17596
|
+
};
|
|
17597
|
+
}
|
|
17484
17598
|
function collectAppSources(appDir) {
|
|
17485
17599
|
const entries = [];
|
|
17486
17600
|
function walk(dir) {
|
|
17487
|
-
const items =
|
|
17601
|
+
const items = fs19.readdirSync(dir, { withFileTypes: true });
|
|
17488
17602
|
for (const item of items) {
|
|
17489
17603
|
const full = path27.join(dir, item.name);
|
|
17490
17604
|
if (item.isDirectory()) {
|
|
@@ -17524,10 +17638,11 @@ async function buildServerApp(projectRoot, appDir) {
|
|
|
17524
17638
|
tsconfig: path27.join(projectRoot, "tsconfig.json"),
|
|
17525
17639
|
packages: "external"
|
|
17526
17640
|
});
|
|
17641
|
+
const pathAliasPlugin = createPathAliasPlugin(projectRoot, outDir);
|
|
17527
17642
|
for (const fileName of SERVER_FILES) {
|
|
17528
17643
|
const initTS = path27.join(projectRoot, `${fileName}.ts`);
|
|
17529
17644
|
const initJS = path27.join(outDir, `${fileName}.js`);
|
|
17530
|
-
if (
|
|
17645
|
+
if (fs19.existsSync(initTS)) {
|
|
17531
17646
|
await esbuild.build({
|
|
17532
17647
|
entryPoints: [initTS],
|
|
17533
17648
|
outfile: initJS,
|
|
@@ -17538,7 +17653,8 @@ async function buildServerApp(projectRoot, appDir) {
|
|
|
17538
17653
|
sourcemap: true,
|
|
17539
17654
|
bundle: false,
|
|
17540
17655
|
logLevel: "info",
|
|
17541
|
-
tsconfig: path27.join(projectRoot, "tsconfig.json")
|
|
17656
|
+
tsconfig: path27.join(projectRoot, "tsconfig.json"),
|
|
17657
|
+
plugins: [pathAliasPlugin]
|
|
17542
17658
|
});
|
|
17543
17659
|
}
|
|
17544
17660
|
}
|