@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/index.cjs
CHANGED
|
@@ -9904,7 +9904,7 @@ __export(src_exports, {
|
|
|
9904
9904
|
module.exports = __toCommonJS(src_exports);
|
|
9905
9905
|
|
|
9906
9906
|
// src/server.ts
|
|
9907
|
-
var
|
|
9907
|
+
var import_fs19 = __toESM(require("fs"));
|
|
9908
9908
|
var import_path25 = __toESM(require("path"));
|
|
9909
9909
|
|
|
9910
9910
|
// modules/server/utils/server-dir.ts
|
|
@@ -9946,6 +9946,7 @@ async function runInitIfExists(projectRoot, serverData) {
|
|
|
9946
9946
|
// modules/server/setup.ts
|
|
9947
9947
|
var import_express = __toESM(require("express"));
|
|
9948
9948
|
var import_path19 = __toESM(require("path"));
|
|
9949
|
+
var import_fs17 = __toESM(require("fs"));
|
|
9949
9950
|
|
|
9950
9951
|
// modules/router/loader-pages.ts
|
|
9951
9952
|
var import_fs4 = __toESM(require("fs"));
|
|
@@ -14036,8 +14037,22 @@ function getStaticDir(projectRoot, config) {
|
|
|
14036
14037
|
}
|
|
14037
14038
|
|
|
14038
14039
|
// modules/server/setup.ts
|
|
14040
|
+
function setupStaticFiles(app, projectRoot, config) {
|
|
14041
|
+
if (!config) return;
|
|
14042
|
+
const staticDir = getStaticDir(projectRoot, config);
|
|
14043
|
+
if (import_fs17.default.existsSync(staticDir)) {
|
|
14044
|
+
app.use(
|
|
14045
|
+
import_express.default.static(staticDir, {
|
|
14046
|
+
// In production, add caching headers for better performance
|
|
14047
|
+
maxAge: process.env.NODE_ENV === "production" ? "1y" : 0,
|
|
14048
|
+
immutable: process.env.NODE_ENV === "production"
|
|
14049
|
+
})
|
|
14050
|
+
);
|
|
14051
|
+
}
|
|
14052
|
+
}
|
|
14039
14053
|
function setupServer(app, options) {
|
|
14040
14054
|
const { projectRoot, appDir, isDev, config } = options;
|
|
14055
|
+
setupStaticFiles(app, projectRoot, config);
|
|
14041
14056
|
const routeLoader = isDev ? new FilesystemRouteLoader(appDir, projectRoot) : new ManifestRouteLoader(projectRoot);
|
|
14042
14057
|
if (isDev) {
|
|
14043
14058
|
let getRoutes2 = function() {
|
|
@@ -15141,7 +15156,7 @@ function handleNotFound(res, urlPath) {
|
|
|
15141
15156
|
}
|
|
15142
15157
|
|
|
15143
15158
|
// modules/server/handlers/ssg.ts
|
|
15144
|
-
var
|
|
15159
|
+
var import_fs18 = __toESM(require("fs"));
|
|
15145
15160
|
var import_path22 = __toESM(require("path"));
|
|
15146
15161
|
var logger3 = createModuleLogger("ssg");
|
|
15147
15162
|
function getSsgDirForPath(baseDir, urlPath) {
|
|
@@ -15158,7 +15173,7 @@ function getSsgDataPath(baseDir, urlPath) {
|
|
|
15158
15173
|
}
|
|
15159
15174
|
function tryServeSsgHtml(res, ssgOutDir, urlPath) {
|
|
15160
15175
|
const ssgHtmlPath = getSsgHtmlPath(ssgOutDir, urlPath);
|
|
15161
|
-
if (!
|
|
15176
|
+
if (!import_fs18.default.existsSync(ssgHtmlPath)) {
|
|
15162
15177
|
return false;
|
|
15163
15178
|
}
|
|
15164
15179
|
logger3.info("Serving SSG HTML", { urlPath, ssgHtmlPath });
|
|
@@ -15168,17 +15183,17 @@ function tryServeSsgHtml(res, ssgOutDir, urlPath) {
|
|
|
15168
15183
|
);
|
|
15169
15184
|
res.statusCode = 200;
|
|
15170
15185
|
res.setHeader("Content-Type", "text/html; charset=utf-8");
|
|
15171
|
-
const stream =
|
|
15186
|
+
const stream = import_fs18.default.createReadStream(ssgHtmlPath, { encoding: "utf-8" });
|
|
15172
15187
|
stream.pipe(res);
|
|
15173
15188
|
return true;
|
|
15174
15189
|
}
|
|
15175
15190
|
function tryServeSsgData(res, ssgOutDir, urlPath) {
|
|
15176
15191
|
const ssgDataPath = getSsgDataPath(ssgOutDir, urlPath);
|
|
15177
|
-
if (!
|
|
15192
|
+
if (!import_fs18.default.existsSync(ssgDataPath)) {
|
|
15178
15193
|
return false;
|
|
15179
15194
|
}
|
|
15180
15195
|
try {
|
|
15181
|
-
const raw =
|
|
15196
|
+
const raw = import_fs18.default.readFileSync(ssgDataPath, "utf-8");
|
|
15182
15197
|
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
15183
15198
|
res.status(200).end(raw);
|
|
15184
15199
|
return true;
|
|
@@ -17194,7 +17209,7 @@ var setupApplication = async ({
|
|
|
17194
17209
|
// src/server.ts
|
|
17195
17210
|
var import_dotenv2 = __toESM(require("dotenv"));
|
|
17196
17211
|
var envPath = import_path25.default.join(process.cwd(), ".env");
|
|
17197
|
-
if (
|
|
17212
|
+
if (import_fs19.default.existsSync(envPath)) {
|
|
17198
17213
|
import_dotenv2.default.config({ path: envPath });
|
|
17199
17214
|
} else {
|
|
17200
17215
|
import_dotenv2.default.config();
|
|
@@ -17216,7 +17231,7 @@ async function startServer(options = {}) {
|
|
|
17216
17231
|
const port = options.port ?? (process.env.PORT ? parseInt(process.env.PORT, 10) : void 0) ?? config.server.port;
|
|
17217
17232
|
const host = process.env.HOST ?? (!isDev ? "0.0.0.0" : void 0) ?? config.server.host;
|
|
17218
17233
|
const appDir = options.appDir ?? (isDev ? getAppDir(projectRoot, config) : import_path25.default.join(getBuildDir(projectRoot, config), "server"));
|
|
17219
|
-
if (!isDev && !
|
|
17234
|
+
if (!isDev && !import_fs19.default.existsSync(appDir)) {
|
|
17220
17235
|
logger4.error("Compiled directory not found", void 0, {
|
|
17221
17236
|
buildDir: config.directories.build,
|
|
17222
17237
|
appDir,
|
|
@@ -17323,7 +17338,7 @@ function pathToOutDir(baseDir, urlPath) {
|
|
|
17323
17338
|
}
|
|
17324
17339
|
|
|
17325
17340
|
// modules/build/ssg/renderer.ts
|
|
17326
|
-
var
|
|
17341
|
+
var import_fs20 = __toESM(require("fs"));
|
|
17327
17342
|
var import_path27 = __toESM(require("path"));
|
|
17328
17343
|
var import_server3 = require("react-dom/server");
|
|
17329
17344
|
init_globals();
|
|
@@ -17447,8 +17462,8 @@ async function renderStaticRoute(projectRoot, ssgOutDir, route, urlPath, params)
|
|
|
17447
17462
|
ensureDir(dir);
|
|
17448
17463
|
const htmlFile = import_path27.default.join(dir, "index.html");
|
|
17449
17464
|
const dataFile = import_path27.default.join(dir, "data.json");
|
|
17450
|
-
|
|
17451
|
-
|
|
17465
|
+
import_fs20.default.writeFileSync(htmlFile, html, "utf-8");
|
|
17466
|
+
import_fs20.default.writeFileSync(dataFile, JSON.stringify(initialData, null, 2), "utf-8");
|
|
17452
17467
|
}
|
|
17453
17468
|
|
|
17454
17469
|
// modules/build/ssg/builder.ts
|
|
@@ -17510,7 +17525,7 @@ async function buildStaticPages(projectRoot, routes) {
|
|
|
17510
17525
|
|
|
17511
17526
|
// modules/build/bundler/server.ts
|
|
17512
17527
|
var import_path31 = __toESM(require("path"));
|
|
17513
|
-
var
|
|
17528
|
+
var import_fs21 = __toESM(require("fs"));
|
|
17514
17529
|
var import_esbuild = __toESM(require("esbuild"));
|
|
17515
17530
|
init_globals();
|
|
17516
17531
|
var SERVER_FILES = [INIT_FILE_NAME, CONFIG_FILE_NAME];
|
|
@@ -17518,58 +17533,95 @@ function createPathAliasPlugin(projectRoot, outDir) {
|
|
|
17518
17533
|
const aliases = loadAliasesFromTsconfig(projectRoot);
|
|
17519
17534
|
const tsconfigPath = import_path31.default.join(projectRoot, "tsconfig.json");
|
|
17520
17535
|
let baseUrl = ".";
|
|
17521
|
-
if (
|
|
17536
|
+
if (import_fs21.default.existsSync(tsconfigPath)) {
|
|
17522
17537
|
try {
|
|
17523
|
-
const tsconfig = JSON.parse(
|
|
17538
|
+
const tsconfig = JSON.parse(import_fs21.default.readFileSync(tsconfigPath, "utf-8"));
|
|
17524
17539
|
baseUrl = tsconfig.compilerOptions?.baseUrl ?? ".";
|
|
17525
17540
|
} catch {
|
|
17526
17541
|
}
|
|
17527
17542
|
}
|
|
17543
|
+
function resolveAliasToRelative(importPath, sourceFile) {
|
|
17544
|
+
if (importPath.startsWith(".") || importPath.startsWith("/") || import_path31.default.isAbsolute(importPath) || importPath.includes("node_modules")) {
|
|
17545
|
+
return null;
|
|
17546
|
+
}
|
|
17547
|
+
for (const [aliasKey, aliasPath] of Object.entries(aliases)) {
|
|
17548
|
+
if (importPath.startsWith(aliasKey + "/") || importPath === aliasKey) {
|
|
17549
|
+
const restPath = importPath.startsWith(aliasKey + "/") ? importPath.slice(aliasKey.length + 1) : "";
|
|
17550
|
+
const resolvedPath = restPath ? import_path31.default.join(aliasPath, restPath) : aliasPath;
|
|
17551
|
+
let actualPath = null;
|
|
17552
|
+
const extensions = [".ts", ".tsx", ".js", ".jsx", ".json"];
|
|
17553
|
+
if (import_fs21.default.existsSync(resolvedPath) && import_fs21.default.statSync(resolvedPath).isDirectory()) {
|
|
17554
|
+
for (const ext of extensions) {
|
|
17555
|
+
const indexPath = import_path31.default.join(resolvedPath, `index${ext}`);
|
|
17556
|
+
if (import_fs21.default.existsSync(indexPath)) {
|
|
17557
|
+
actualPath = indexPath;
|
|
17558
|
+
break;
|
|
17559
|
+
}
|
|
17560
|
+
}
|
|
17561
|
+
} else {
|
|
17562
|
+
for (const ext of extensions) {
|
|
17563
|
+
const filePath = resolvedPath + ext;
|
|
17564
|
+
if (import_fs21.default.existsSync(filePath)) {
|
|
17565
|
+
actualPath = filePath;
|
|
17566
|
+
break;
|
|
17567
|
+
}
|
|
17568
|
+
}
|
|
17569
|
+
if (!actualPath && import_fs21.default.existsSync(resolvedPath)) {
|
|
17570
|
+
actualPath = resolvedPath;
|
|
17571
|
+
}
|
|
17572
|
+
}
|
|
17573
|
+
if (actualPath) {
|
|
17574
|
+
const relativePath = import_path31.default.relative(outDir, actualPath);
|
|
17575
|
+
const normalizedPath = relativePath.replace(/\\/g, "/");
|
|
17576
|
+
const finalPath = normalizedPath.startsWith(".") ? normalizedPath : `./${normalizedPath}`;
|
|
17577
|
+
const ext = import_path31.default.extname(finalPath);
|
|
17578
|
+
const pathWithoutExt = ext === ".json" ? finalPath : finalPath.slice(0, -ext.length);
|
|
17579
|
+
return pathWithoutExt;
|
|
17580
|
+
}
|
|
17581
|
+
}
|
|
17582
|
+
}
|
|
17583
|
+
return null;
|
|
17584
|
+
}
|
|
17528
17585
|
return {
|
|
17529
17586
|
name: "path-alias-resolver",
|
|
17530
17587
|
setup(build) {
|
|
17531
|
-
build.
|
|
17532
|
-
|
|
17588
|
+
build.onLoad({ filter: /\.(ts|tsx|js|jsx)$/ }, (args) => {
|
|
17589
|
+
const fileName = import_path31.default.basename(args.path);
|
|
17590
|
+
const isServerFile = SERVER_FILES.some((f) => fileName === `${f}.ts` || fileName === `${f}.tsx` || fileName === `${f}.js` || fileName === `${f}.jsx`);
|
|
17591
|
+
const isInProjectRoot = import_path31.default.dirname(args.path) === projectRoot;
|
|
17592
|
+
if (!isServerFile || !isInProjectRoot) {
|
|
17533
17593
|
return null;
|
|
17534
17594
|
}
|
|
17535
|
-
|
|
17536
|
-
|
|
17537
|
-
|
|
17538
|
-
|
|
17539
|
-
|
|
17540
|
-
|
|
17541
|
-
|
|
17542
|
-
|
|
17543
|
-
|
|
17544
|
-
|
|
17545
|
-
|
|
17546
|
-
|
|
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
|
-
};
|
|
17595
|
+
const contents = import_fs21.default.readFileSync(args.path, "utf-8");
|
|
17596
|
+
let transformed = contents;
|
|
17597
|
+
const aliasPatterns = Object.keys(aliases).sort((a, b) => b.length - a.length);
|
|
17598
|
+
for (const aliasKey of aliasPatterns) {
|
|
17599
|
+
const escapedAlias = aliasKey.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
17600
|
+
const aliasInQuotesPattern = new RegExp(
|
|
17601
|
+
`(['"\`])${escapedAlias}(/[^'"\`\\s]*)?(['"\`])`,
|
|
17602
|
+
"g"
|
|
17603
|
+
);
|
|
17604
|
+
transformed = transformed.replace(aliasInQuotesPattern, (match, quote1, rest, quote2) => {
|
|
17605
|
+
const fullPath = aliasKey + (rest || "");
|
|
17606
|
+
const resolved = resolveAliasToRelative(fullPath, args.path);
|
|
17607
|
+
if (resolved) {
|
|
17608
|
+
return `${quote1}${resolved}${quote2}`;
|
|
17571
17609
|
}
|
|
17572
|
-
|
|
17610
|
+
return match;
|
|
17611
|
+
});
|
|
17612
|
+
}
|
|
17613
|
+
return {
|
|
17614
|
+
contents: transformed,
|
|
17615
|
+
loader: import_path31.default.extname(args.path).slice(1)
|
|
17616
|
+
};
|
|
17617
|
+
});
|
|
17618
|
+
build.onResolve({ filter: /.*/ }, (args) => {
|
|
17619
|
+
const resolved = resolveAliasToRelative(args.path, args.importer || "");
|
|
17620
|
+
if (resolved) {
|
|
17621
|
+
return {
|
|
17622
|
+
path: resolved,
|
|
17623
|
+
namespace: "file"
|
|
17624
|
+
};
|
|
17573
17625
|
}
|
|
17574
17626
|
return null;
|
|
17575
17627
|
});
|
|
@@ -17579,7 +17631,7 @@ function createPathAliasPlugin(projectRoot, outDir) {
|
|
|
17579
17631
|
function collectAppSources(appDir) {
|
|
17580
17632
|
const entries = [];
|
|
17581
17633
|
function walk(dir) {
|
|
17582
|
-
const items =
|
|
17634
|
+
const items = import_fs21.default.readdirSync(dir, { withFileTypes: true });
|
|
17583
17635
|
for (const item of items) {
|
|
17584
17636
|
const full = import_path31.default.join(dir, item.name);
|
|
17585
17637
|
if (item.isDirectory()) {
|
|
@@ -17623,7 +17675,7 @@ async function buildServerApp(projectRoot, appDir) {
|
|
|
17623
17675
|
for (const fileName of SERVER_FILES) {
|
|
17624
17676
|
const initTS = import_path31.default.join(projectRoot, `${fileName}.ts`);
|
|
17625
17677
|
const initJS = import_path31.default.join(outDir, `${fileName}.js`);
|
|
17626
|
-
if (
|
|
17678
|
+
if (import_fs21.default.existsSync(initTS)) {
|
|
17627
17679
|
await import_esbuild.default.build({
|
|
17628
17680
|
entryPoints: [initTS],
|
|
17629
17681
|
outfile: initJS,
|