@lolyjs/core 0.2.0-alpha.11 → 0.2.0-alpha.13
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 +3 -10
- package/dist/cli.cjs +47 -34
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +40 -27
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +45 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +38 -25
- package/dist/index.js.map +1 -1
- package/dist/react/hooks.cjs.map +1 -1
- package/dist/react/hooks.js.map +1 -1
- package/dist/react/sockets.cjs +10 -4
- package/dist/react/sockets.cjs.map +1 -1
- package/dist/react/sockets.js +10 -4
- package/dist/react/sockets.js.map +1 -1
- package/dist/runtime.cjs +1 -1
- package/dist/runtime.cjs.map +1 -1
- package/dist/runtime.js +1 -1
- package/dist/runtime.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -84,10 +84,7 @@ export const getServerSideProps: ServerLoader = async (ctx) => {
|
|
|
84
84
|
|
|
85
85
|
```tsx
|
|
86
86
|
// app/page.tsx
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
export default function Home() {
|
|
90
|
-
const { props } = usePageProps();
|
|
87
|
+
export default function Home({ props }) {
|
|
91
88
|
return <h1>{props.data}</h1>;
|
|
92
89
|
}
|
|
93
90
|
```
|
|
@@ -519,15 +516,12 @@ export const events = [
|
|
|
519
516
|
];
|
|
520
517
|
```
|
|
521
518
|
|
|
522
|
-
### Client
|
|
519
|
+
### Client Cache
|
|
523
520
|
|
|
524
521
|
```tsx
|
|
525
|
-
import { usePageProps } from "@lolyjs/core/hooks";
|
|
526
522
|
import { revalidate } from "@lolyjs/core/client-cache";
|
|
527
523
|
|
|
528
|
-
export default function Page() {
|
|
529
|
-
const { params, props } = usePageProps();
|
|
530
|
-
|
|
524
|
+
export default function Page({ props }) {
|
|
531
525
|
const handleRefresh = async () => {
|
|
532
526
|
await revalidate(); // Refresh current page data
|
|
533
527
|
};
|
|
@@ -730,7 +724,6 @@ import { logger, createModuleLogger, getRequestLogger } from "@lolyjs/core";
|
|
|
730
724
|
|
|
731
725
|
// Client
|
|
732
726
|
import { Link } from "@lolyjs/core/components";
|
|
733
|
-
import { usePageProps } from "@lolyjs/core/hooks";
|
|
734
727
|
import { lolySocket } from "@lolyjs/core/sockets";
|
|
735
728
|
import { revalidate, revalidatePath } from "@lolyjs/core/client-cache";
|
|
736
729
|
```
|
package/dist/cli.cjs
CHANGED
|
@@ -1113,6 +1113,7 @@ var import_core2 = require("@rspack/core");
|
|
|
1113
1113
|
|
|
1114
1114
|
// modules/build/config/client.ts
|
|
1115
1115
|
var import_path13 = __toESM(require("path"));
|
|
1116
|
+
var import_fs11 = __toESM(require("fs"));
|
|
1116
1117
|
var import_core = require("@rspack/core");
|
|
1117
1118
|
|
|
1118
1119
|
// modules/build/utils/index.ts
|
|
@@ -1256,15 +1257,21 @@ function createClientConfig(projectRoot, mode) {
|
|
|
1256
1257
|
const buildDir = import_path13.default.join(projectRoot, BUILD_FOLDER_NAME);
|
|
1257
1258
|
const clientEntry = import_path13.default.join(buildDir, "boostrap.ts");
|
|
1258
1259
|
const outDir = import_path13.default.join(buildDir, "client");
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1260
|
+
const envPath2 = import_path13.default.join(projectRoot, ".env");
|
|
1261
|
+
if (import_fs11.default.existsSync(envPath2)) {
|
|
1262
|
+
import_dotenv.default.config({
|
|
1263
|
+
path: envPath2
|
|
1264
|
+
});
|
|
1265
|
+
}
|
|
1262
1266
|
const publicEnv = {};
|
|
1263
1267
|
for (const [key, value] of Object.entries(process.env)) {
|
|
1264
1268
|
if (key.startsWith("PUBLIC_")) {
|
|
1265
1269
|
publicEnv[`process.env.${key}`] = JSON.stringify(value ?? "");
|
|
1266
1270
|
}
|
|
1267
1271
|
}
|
|
1272
|
+
if (!publicEnv["process.env.PUBLIC_WS_BASE_URL"]) {
|
|
1273
|
+
publicEnv["process.env.PUBLIC_WS_BASE_URL"] = JSON.stringify(void 0);
|
|
1274
|
+
}
|
|
1268
1275
|
const config = {
|
|
1269
1276
|
mode,
|
|
1270
1277
|
entry: {
|
|
@@ -1313,7 +1320,8 @@ function createClientConfig(projectRoot, mode) {
|
|
|
1313
1320
|
},
|
|
1314
1321
|
plugins: [
|
|
1315
1322
|
new import_core.rspack.DefinePlugin({
|
|
1316
|
-
|
|
1323
|
+
// Always define NODE_ENV, using mode as fallback if not set
|
|
1324
|
+
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || mode),
|
|
1317
1325
|
...publicEnv
|
|
1318
1326
|
}),
|
|
1319
1327
|
new import_core.rspack.CssExtractRspackPlugin({
|
|
@@ -1330,7 +1338,7 @@ function createClientConfig(projectRoot, mode) {
|
|
|
1330
1338
|
|
|
1331
1339
|
// modules/build/bundler/client.ts
|
|
1332
1340
|
var import_path14 = __toESM(require("path"));
|
|
1333
|
-
var
|
|
1341
|
+
var import_fs12 = __toESM(require("fs"));
|
|
1334
1342
|
init_globals();
|
|
1335
1343
|
function startClientBundler(projectRoot, mode = "development") {
|
|
1336
1344
|
const { config, outDir } = createClientConfig(projectRoot, mode);
|
|
@@ -1422,7 +1430,7 @@ function buildClientBundle(projectRoot) {
|
|
|
1422
1430
|
copyStaticAssets(projectRoot, outDir);
|
|
1423
1431
|
const assetManifest = generateAssetManifest(outDir);
|
|
1424
1432
|
const manifestPath = import_path14.default.join(projectRoot, BUILD_FOLDER_NAME, "asset-manifest.json");
|
|
1425
|
-
|
|
1433
|
+
import_fs12.default.writeFileSync(manifestPath, JSON.stringify(assetManifest, null, 2), "utf-8");
|
|
1426
1434
|
resolve3({ outDir });
|
|
1427
1435
|
});
|
|
1428
1436
|
});
|
|
@@ -1465,7 +1473,7 @@ function pathToOutDir(baseDir, urlPath) {
|
|
|
1465
1473
|
}
|
|
1466
1474
|
|
|
1467
1475
|
// modules/build/ssg/renderer.ts
|
|
1468
|
-
var
|
|
1476
|
+
var import_fs13 = __toESM(require("fs"));
|
|
1469
1477
|
var import_path16 = __toESM(require("path"));
|
|
1470
1478
|
var import_server = require("react-dom/server");
|
|
1471
1479
|
|
|
@@ -1688,8 +1696,8 @@ async function renderStaticRoute(projectRoot, ssgOutDir, route, urlPath, params)
|
|
|
1688
1696
|
ensureDir(dir);
|
|
1689
1697
|
const htmlFile = import_path16.default.join(dir, "index.html");
|
|
1690
1698
|
const dataFile = import_path16.default.join(dir, "data.json");
|
|
1691
|
-
|
|
1692
|
-
|
|
1699
|
+
import_fs13.default.writeFileSync(htmlFile, html, "utf-8");
|
|
1700
|
+
import_fs13.default.writeFileSync(dataFile, JSON.stringify(initialData, null, 2), "utf-8");
|
|
1693
1701
|
}
|
|
1694
1702
|
|
|
1695
1703
|
// modules/build/ssg/builder.ts
|
|
@@ -1744,11 +1752,11 @@ async function buildStaticPages(projectRoot, routes) {
|
|
|
1744
1752
|
|
|
1745
1753
|
// modules/build/bundler/server.ts
|
|
1746
1754
|
var import_path21 = __toESM(require("path"));
|
|
1747
|
-
var
|
|
1755
|
+
var import_fs15 = __toESM(require("fs"));
|
|
1748
1756
|
var import_esbuild = __toESM(require("esbuild"));
|
|
1749
1757
|
|
|
1750
1758
|
// modules/server/utils/server-dir.ts
|
|
1751
|
-
var
|
|
1759
|
+
var import_fs14 = __toESM(require("fs"));
|
|
1752
1760
|
var import_path20 = __toESM(require("path"));
|
|
1753
1761
|
init_globals();
|
|
1754
1762
|
var getServerFile = async (projectRoot, fileName) => {
|
|
@@ -1757,13 +1765,13 @@ var getServerFile = async (projectRoot, fileName) => {
|
|
|
1757
1765
|
const isDev = process.env.NODE_ENV === "development";
|
|
1758
1766
|
let mod = null;
|
|
1759
1767
|
if (isDev) {
|
|
1760
|
-
if (!
|
|
1768
|
+
if (!import_fs14.default.existsSync(fileTS)) {
|
|
1761
1769
|
return null;
|
|
1762
1770
|
}
|
|
1763
1771
|
require("tsx/cjs");
|
|
1764
1772
|
mod = require(fileTS);
|
|
1765
1773
|
} else {
|
|
1766
|
-
if (!
|
|
1774
|
+
if (!import_fs14.default.existsSync(fileJS)) {
|
|
1767
1775
|
return null;
|
|
1768
1776
|
}
|
|
1769
1777
|
mod = require(fileJS);
|
|
@@ -1856,7 +1864,7 @@ var SERVER_FILES = [INIT_FILE_NAME, CONFIG_FILE_NAME];
|
|
|
1856
1864
|
function collectAppSources(appDir) {
|
|
1857
1865
|
const entries = [];
|
|
1858
1866
|
function walk(dir) {
|
|
1859
|
-
const items =
|
|
1867
|
+
const items = import_fs15.default.readdirSync(dir, { withFileTypes: true });
|
|
1860
1868
|
for (const item of items) {
|
|
1861
1869
|
const full = import_path21.default.join(dir, item.name);
|
|
1862
1870
|
if (item.isDirectory()) {
|
|
@@ -1899,7 +1907,7 @@ async function buildServerApp(projectRoot, appDir) {
|
|
|
1899
1907
|
for (const fileName of SERVER_FILES) {
|
|
1900
1908
|
const initTS = import_path21.default.join(projectRoot, `${fileName}.ts`);
|
|
1901
1909
|
const initJS = import_path21.default.join(outDir, `${fileName}.js`);
|
|
1902
|
-
if (
|
|
1910
|
+
if (import_fs15.default.existsSync(initTS)) {
|
|
1903
1911
|
await import_esbuild.default.build({
|
|
1904
1912
|
entryPoints: [initTS],
|
|
1905
1913
|
outfile: initJS,
|
|
@@ -1922,7 +1930,7 @@ init_globals();
|
|
|
1922
1930
|
|
|
1923
1931
|
// src/config.ts
|
|
1924
1932
|
var import_path22 = __toESM(require("path"));
|
|
1925
|
-
var
|
|
1933
|
+
var import_fs16 = __toESM(require("fs"));
|
|
1926
1934
|
init_globals();
|
|
1927
1935
|
var DEFAULT_CONFIG2 = {
|
|
1928
1936
|
directories: {
|
|
@@ -1985,10 +1993,10 @@ function loadConfig(projectRoot) {
|
|
|
1985
1993
|
];
|
|
1986
1994
|
let userConfig = {};
|
|
1987
1995
|
for (const configFile of configFiles) {
|
|
1988
|
-
if (
|
|
1996
|
+
if (import_fs16.default.existsSync(configFile)) {
|
|
1989
1997
|
try {
|
|
1990
1998
|
if (configFile.endsWith(".json")) {
|
|
1991
|
-
const content =
|
|
1999
|
+
const content = import_fs16.default.readFileSync(configFile, "utf-8");
|
|
1992
2000
|
userConfig = JSON.parse(content);
|
|
1993
2001
|
} else {
|
|
1994
2002
|
if (process.env.NODE_ENV === "development") {
|
|
@@ -2005,7 +2013,7 @@ function loadConfig(projectRoot) {
|
|
|
2005
2013
|
}
|
|
2006
2014
|
const config = deepMerge(DEFAULT_CONFIG2, userConfig);
|
|
2007
2015
|
const appDir = import_path22.default.join(projectRoot, config.directories.app);
|
|
2008
|
-
if (!
|
|
2016
|
+
if (!import_fs16.default.existsSync(appDir) && process.env.NODE_ENV !== "test") {
|
|
2009
2017
|
console.warn(`[framework] App directory not found: ${appDir}`);
|
|
2010
2018
|
}
|
|
2011
2019
|
return config;
|
|
@@ -2066,7 +2074,7 @@ async function buildApp(options = {}) {
|
|
|
2066
2074
|
}
|
|
2067
2075
|
|
|
2068
2076
|
// src/server.ts
|
|
2069
|
-
var
|
|
2077
|
+
var import_fs20 = __toESM(require("fs"));
|
|
2070
2078
|
var import_path28 = __toESM(require("path"));
|
|
2071
2079
|
|
|
2072
2080
|
// modules/server/setup.ts
|
|
@@ -2074,7 +2082,7 @@ var import_express = __toESM(require("express"));
|
|
|
2074
2082
|
var import_path25 = __toESM(require("path"));
|
|
2075
2083
|
|
|
2076
2084
|
// ../../node_modules/.pnpm/chokidar@4.0.3/node_modules/chokidar/esm/index.js
|
|
2077
|
-
var
|
|
2085
|
+
var import_fs18 = require("fs");
|
|
2078
2086
|
var import_promises3 = require("fs/promises");
|
|
2079
2087
|
var import_events = require("events");
|
|
2080
2088
|
var sysPath2 = __toESM(require("path"), 1);
|
|
@@ -2299,7 +2307,7 @@ function readdirp(root, options = {}) {
|
|
|
2299
2307
|
}
|
|
2300
2308
|
|
|
2301
2309
|
// ../../node_modules/.pnpm/chokidar@4.0.3/node_modules/chokidar/esm/handler.js
|
|
2302
|
-
var
|
|
2310
|
+
var import_fs17 = require("fs");
|
|
2303
2311
|
var import_promises2 = require("fs/promises");
|
|
2304
2312
|
var sysPath = __toESM(require("path"), 1);
|
|
2305
2313
|
var import_os = require("os");
|
|
@@ -2637,7 +2645,7 @@ function createFsWatchInstance(path26, options, listener, errHandler, emitRaw) {
|
|
|
2637
2645
|
}
|
|
2638
2646
|
};
|
|
2639
2647
|
try {
|
|
2640
|
-
return (0,
|
|
2648
|
+
return (0, import_fs17.watch)(path26, {
|
|
2641
2649
|
persistent: options.persistent
|
|
2642
2650
|
}, handleEvent);
|
|
2643
2651
|
} catch (error) {
|
|
@@ -2720,7 +2728,7 @@ var setFsWatchFileListener = (path26, fullPath, options, handlers) => {
|
|
|
2720
2728
|
let cont = FsWatchFileInstances.get(fullPath);
|
|
2721
2729
|
const copts = cont && cont.options;
|
|
2722
2730
|
if (copts && (copts.persistent < options.persistent || copts.interval > options.interval)) {
|
|
2723
|
-
(0,
|
|
2731
|
+
(0, import_fs17.unwatchFile)(fullPath);
|
|
2724
2732
|
cont = void 0;
|
|
2725
2733
|
}
|
|
2726
2734
|
if (cont) {
|
|
@@ -2731,7 +2739,7 @@ var setFsWatchFileListener = (path26, fullPath, options, handlers) => {
|
|
|
2731
2739
|
listeners: listener,
|
|
2732
2740
|
rawEmitters: rawEmitter,
|
|
2733
2741
|
options,
|
|
2734
|
-
watcher: (0,
|
|
2742
|
+
watcher: (0, import_fs17.watchFile)(fullPath, options, (curr, prev) => {
|
|
2735
2743
|
foreach(cont.rawEmitters, (rawEmitter2) => {
|
|
2736
2744
|
rawEmitter2(EV.CHANGE, fullPath, { curr, prev });
|
|
2737
2745
|
});
|
|
@@ -2748,7 +2756,7 @@ var setFsWatchFileListener = (path26, fullPath, options, handlers) => {
|
|
|
2748
2756
|
delFromSet(cont, KEY_RAW, rawEmitter);
|
|
2749
2757
|
if (isEmptySet(cont.listeners)) {
|
|
2750
2758
|
FsWatchFileInstances.delete(fullPath);
|
|
2751
|
-
(0,
|
|
2759
|
+
(0, import_fs17.unwatchFile)(fullPath);
|
|
2752
2760
|
cont.options = cont.watcher = void 0;
|
|
2753
2761
|
Object.freeze(cont);
|
|
2754
2762
|
}
|
|
@@ -3591,7 +3599,7 @@ var FSWatcher = class extends import_events.EventEmitter {
|
|
|
3591
3599
|
const now = /* @__PURE__ */ new Date();
|
|
3592
3600
|
const writes = this._pendingWrites;
|
|
3593
3601
|
function awaitWriteFinishFn(prevStat) {
|
|
3594
|
-
(0,
|
|
3602
|
+
(0, import_fs18.stat)(fullPath, (err, curStat) => {
|
|
3595
3603
|
if (err || !writes.has(path26)) {
|
|
3596
3604
|
if (err && err.code !== "ENOENT")
|
|
3597
3605
|
awfEmit(err);
|
|
@@ -4374,7 +4382,7 @@ function handleNotFound(res, urlPath) {
|
|
|
4374
4382
|
}
|
|
4375
4383
|
|
|
4376
4384
|
// modules/server/handlers/ssg.ts
|
|
4377
|
-
var
|
|
4385
|
+
var import_fs19 = __toESM(require("fs"));
|
|
4378
4386
|
var import_path26 = __toESM(require("path"));
|
|
4379
4387
|
var logger2 = createModuleLogger("ssg");
|
|
4380
4388
|
function getSsgDirForPath(baseDir, urlPath) {
|
|
@@ -4391,7 +4399,7 @@ function getSsgDataPath(baseDir, urlPath) {
|
|
|
4391
4399
|
}
|
|
4392
4400
|
function tryServeSsgHtml(res, ssgOutDir, urlPath) {
|
|
4393
4401
|
const ssgHtmlPath = getSsgHtmlPath(ssgOutDir, urlPath);
|
|
4394
|
-
if (!
|
|
4402
|
+
if (!import_fs19.default.existsSync(ssgHtmlPath)) {
|
|
4395
4403
|
return false;
|
|
4396
4404
|
}
|
|
4397
4405
|
logger2.info("Serving SSG HTML", { urlPath, ssgHtmlPath });
|
|
@@ -4401,17 +4409,17 @@ function tryServeSsgHtml(res, ssgOutDir, urlPath) {
|
|
|
4401
4409
|
);
|
|
4402
4410
|
res.statusCode = 200;
|
|
4403
4411
|
res.setHeader("Content-Type", "text/html; charset=utf-8");
|
|
4404
|
-
const stream =
|
|
4412
|
+
const stream = import_fs19.default.createReadStream(ssgHtmlPath, { encoding: "utf-8" });
|
|
4405
4413
|
stream.pipe(res);
|
|
4406
4414
|
return true;
|
|
4407
4415
|
}
|
|
4408
4416
|
function tryServeSsgData(res, ssgOutDir, urlPath) {
|
|
4409
4417
|
const ssgDataPath = getSsgDataPath(ssgOutDir, urlPath);
|
|
4410
|
-
if (!
|
|
4418
|
+
if (!import_fs19.default.existsSync(ssgDataPath)) {
|
|
4411
4419
|
return false;
|
|
4412
4420
|
}
|
|
4413
4421
|
try {
|
|
4414
|
-
const raw =
|
|
4422
|
+
const raw = import_fs19.default.readFileSync(ssgDataPath, "utf-8");
|
|
4415
4423
|
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
4416
4424
|
res.status(200).end(raw);
|
|
4417
4425
|
return true;
|
|
@@ -5050,7 +5058,12 @@ var setupApplication = async ({
|
|
|
5050
5058
|
|
|
5051
5059
|
// src/server.ts
|
|
5052
5060
|
var import_dotenv2 = __toESM(require("dotenv"));
|
|
5053
|
-
|
|
5061
|
+
var envPath = import_path28.default.join(process.cwd(), ".env");
|
|
5062
|
+
if (import_fs20.default.existsSync(envPath)) {
|
|
5063
|
+
import_dotenv2.default.config({ path: envPath });
|
|
5064
|
+
} else {
|
|
5065
|
+
import_dotenv2.default.config();
|
|
5066
|
+
}
|
|
5054
5067
|
var logger3 = createModuleLogger("server");
|
|
5055
5068
|
async function startServer(options = {}) {
|
|
5056
5069
|
const isDev = options.isDev ?? process.env.NODE_ENV === "development";
|
|
@@ -5059,7 +5072,7 @@ async function startServer(options = {}) {
|
|
|
5059
5072
|
const port = options.port ?? (process.env.PORT ? parseInt(process.env.PORT, 10) : void 0) ?? config.server.port;
|
|
5060
5073
|
const host = process.env.HOST ?? (!isDev ? "0.0.0.0" : void 0) ?? config.server.host;
|
|
5061
5074
|
const appDir = options.appDir ?? (isDev ? getAppDir(projectRoot, config) : import_path28.default.join(getBuildDir(projectRoot, config), "server"));
|
|
5062
|
-
if (!isDev && !
|
|
5075
|
+
if (!isDev && !import_fs20.default.existsSync(appDir)) {
|
|
5063
5076
|
logger3.error("Compiled directory not found", void 0, {
|
|
5064
5077
|
buildDir: config.directories.build,
|
|
5065
5078
|
appDir,
|