hadars 0.1.35 → 0.1.37
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 +77 -0
- package/cli-lib.ts +90 -5
- package/dist/chunk-F7IIMM3J.js +1060 -0
- package/dist/chunk-UNQSQIOO.js +60 -0
- package/dist/cli.js +285 -261
- package/dist/hadars-B3b_6sj2.d.cts +188 -0
- package/dist/hadars-B3b_6sj2.d.ts +188 -0
- package/dist/index.cjs +11 -19
- package/dist/index.d.cts +105 -0
- package/dist/index.d.ts +4 -175
- package/dist/index.js +14 -42
- package/dist/{jsx-runtime-97ca74a5.d.ts → jsx-runtime-BOYrELJb.d.cts} +1 -1
- package/dist/jsx-runtime-BOYrELJb.d.ts +18 -0
- package/dist/lambda.cjs +1405 -0
- package/dist/lambda.d.cts +93 -0
- package/dist/lambda.d.ts +93 -0
- package/dist/lambda.js +499 -0
- package/dist/loader.cjs +22 -44
- package/dist/slim-react/index.cjs +29 -58
- package/dist/slim-react/index.d.cts +190 -0
- package/dist/slim-react/index.d.ts +3 -3
- package/dist/slim-react/index.js +34 -1043
- package/dist/slim-react/jsx-runtime.d.cts +1 -0
- package/dist/slim-react/jsx-runtime.d.ts +1 -1
- package/dist/ssr-render-worker.js +44 -78
- package/dist/ssr-watch.js +24 -7
- package/dist/utils/Head.tsx +2 -2
- package/package.json +11 -6
- package/src/build.ts +8 -166
- package/src/lambda.ts +287 -0
- package/src/types/hadars.ts +10 -0
- package/src/utils/Head.tsx +2 -2
- package/src/utils/rspack.ts +27 -0
- package/src/utils/ssrHandler.ts +185 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,180 +1,9 @@
|
|
|
1
1
|
import * as React$1 from 'react';
|
|
2
|
-
import React__default
|
|
2
|
+
import React__default from 'react';
|
|
3
|
+
import { A as AppContext } from './hadars-B3b_6sj2.js';
|
|
4
|
+
export { b as HadarsApp, H as HadarsEntryModule, c as HadarsGetAfterRenderProps, d as HadarsGetClientProps, e as HadarsGetFinalProps, f as HadarsGetInitialProps, a as HadarsOptions, g as HadarsProps, h as HadarsRequest } from './hadars-B3b_6sj2.js';
|
|
3
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
6
|
|
|
5
|
-
type HadarsGetInitialProps<T extends {}> = (req: HadarsRequest) => Promise<T> | T;
|
|
6
|
-
type HadarsGetClientProps<T extends {}> = (props: T) => Promise<T> | T;
|
|
7
|
-
type HadarsGetAfterRenderProps<T extends {}> = (props: HadarsProps<T>, html: string) => Promise<HadarsProps<T>> | HadarsProps<T>;
|
|
8
|
-
type HadarsGetFinalProps<T extends {}> = (props: HadarsProps<T>) => Promise<T> | T;
|
|
9
|
-
type HadarsApp<T extends {}> = React.FC<HadarsProps<T>>;
|
|
10
|
-
type HadarsEntryModule<T extends {}> = {
|
|
11
|
-
default: HadarsApp<T>;
|
|
12
|
-
getInitProps?: HadarsGetInitialProps<T>;
|
|
13
|
-
getAfterRenderProps?: HadarsGetAfterRenderProps<T>;
|
|
14
|
-
getFinalProps?: HadarsGetFinalProps<T>;
|
|
15
|
-
getClientProps?: HadarsGetClientProps<T>;
|
|
16
|
-
};
|
|
17
|
-
interface AppHead {
|
|
18
|
-
title: string;
|
|
19
|
-
status: number;
|
|
20
|
-
meta: Record<string, MetaProps>;
|
|
21
|
-
link: Record<string, LinkProps>;
|
|
22
|
-
style: Record<string, StyleProps>;
|
|
23
|
-
script: Record<string, ScriptProps>;
|
|
24
|
-
}
|
|
25
|
-
type UnsuspendEntry = {
|
|
26
|
-
status: 'pending';
|
|
27
|
-
promise: Promise<unknown>;
|
|
28
|
-
} | {
|
|
29
|
-
status: 'fulfilled';
|
|
30
|
-
value: unknown;
|
|
31
|
-
} | {
|
|
32
|
-
status: 'rejected';
|
|
33
|
-
reason: unknown;
|
|
34
|
-
};
|
|
35
|
-
/** @internal Populated by the framework's render loop — use useServerData() instead. */
|
|
36
|
-
interface AppUnsuspend {
|
|
37
|
-
cache: Map<string, UnsuspendEntry>;
|
|
38
|
-
}
|
|
39
|
-
interface AppContext {
|
|
40
|
-
path?: string;
|
|
41
|
-
head: AppHead;
|
|
42
|
-
/** @internal Framework use only — use the useServerData() hook instead. */
|
|
43
|
-
_unsuspend?: AppUnsuspend;
|
|
44
|
-
}
|
|
45
|
-
type HadarsEntryBase = {
|
|
46
|
-
location: string;
|
|
47
|
-
context: AppContext;
|
|
48
|
-
};
|
|
49
|
-
type HadarsProps<T extends {}> = T & HadarsEntryBase;
|
|
50
|
-
type MetaProps = MetaHTMLAttributes<HTMLMetaElement>;
|
|
51
|
-
type LinkProps = LinkHTMLAttributes<HTMLLinkElement>;
|
|
52
|
-
type StyleProps = StyleHTMLAttributes<HTMLStyleElement>;
|
|
53
|
-
type ScriptProps = ScriptHTMLAttributes<HTMLScriptElement>;
|
|
54
|
-
interface HadarsOptions {
|
|
55
|
-
port?: number;
|
|
56
|
-
entry: string;
|
|
57
|
-
baseURL?: string;
|
|
58
|
-
swcPlugins?: SwcPluginList;
|
|
59
|
-
proxy?: Record<string, string> | ((req: HadarsRequest) => Promise<Response | null> | Response | null);
|
|
60
|
-
proxyCORS?: boolean;
|
|
61
|
-
define?: Record<string, string>;
|
|
62
|
-
/**
|
|
63
|
-
* Bun WebSocket handler passed directly to `Bun.serve()`.
|
|
64
|
-
* Ignored on Node.js and Deno — use `fetch` + a third-party WS library there.
|
|
65
|
-
* Pass a `Bun.WebSocketHandler` instance here when running on Bun.
|
|
66
|
-
*/
|
|
67
|
-
websocket?: unknown;
|
|
68
|
-
fetch?: (req: HadarsRequest) => Promise<Response | undefined> | Response | undefined;
|
|
69
|
-
wsPath?: string;
|
|
70
|
-
hmrPort?: number;
|
|
71
|
-
/**
|
|
72
|
-
* Parallelism level for `run()` mode (production server). Defaults to 1.
|
|
73
|
-
* Has no effect in `dev()` mode.
|
|
74
|
-
*
|
|
75
|
-
* **Node.js** — forks this many worker processes via `node:cluster`, each
|
|
76
|
-
* binding to the same port via OS round-robin. Set to `os.cpus().length`
|
|
77
|
-
* to saturate all CPU cores.
|
|
78
|
-
*
|
|
79
|
-
* **Bun / Deno** — creates a `node:worker_threads` render pool of this size.
|
|
80
|
-
* Each thread handles the synchronous `renderToString` step, freeing the
|
|
81
|
-
* main event loop for I/O.
|
|
82
|
-
*/
|
|
83
|
-
workers?: number;
|
|
84
|
-
/**
|
|
85
|
-
* Override or extend rspack's `optimization` config for production client builds.
|
|
86
|
-
* Merged on top of hadars defaults (splitChunks vendor splitting, deterministic moduleIds).
|
|
87
|
-
* Has no effect on the SSR bundle or dev mode.
|
|
88
|
-
*/
|
|
89
|
-
optimization?: Record<string, unknown>;
|
|
90
|
-
/**
|
|
91
|
-
* Path to a custom HTML template file (relative to the project root).
|
|
92
|
-
* Replaces the built-in minimal template used to generate the HTML shell.
|
|
93
|
-
*
|
|
94
|
-
* The file must include two marker elements so hadars can inject the
|
|
95
|
-
* per-request head tags and the server-rendered body:
|
|
96
|
-
*
|
|
97
|
-
* ```html
|
|
98
|
-
* <meta name="HADARS_HEAD"> <!-- replaced with <title>, <meta>, <link>, <style> tags -->
|
|
99
|
-
* <meta name="HADARS_BODY"> <!-- replaced with the SSR-rendered React tree -->
|
|
100
|
-
* ```
|
|
101
|
-
*
|
|
102
|
-
* Any `<style>` blocks in the template are automatically processed through
|
|
103
|
-
* PostCSS (using the project's `postcss.config.js`) at build/dev startup time,
|
|
104
|
-
* so `@import "tailwindcss"` and other PostCSS directives work as expected.
|
|
105
|
-
* Note: inline styles are processed once at startup and are not live-reloaded.
|
|
106
|
-
*/
|
|
107
|
-
htmlTemplate?: string;
|
|
108
|
-
/**
|
|
109
|
-
* Force the React runtime mode independently of the build mode.
|
|
110
|
-
* Useful when you need production build optimizations (minification, tree-shaking)
|
|
111
|
-
* but want React's development build for debugging hydration mismatches or
|
|
112
|
-
* component stack traces.
|
|
113
|
-
*
|
|
114
|
-
* - `'development'` — forces `process.env.NODE_ENV = "development"` and enables
|
|
115
|
-
* JSX source info even in `hadars build`. React prints detailed hydration error
|
|
116
|
-
* messages and component stacks.
|
|
117
|
-
* - `'production'` — the default; React uses the optimised production bundle.
|
|
118
|
-
*
|
|
119
|
-
* Only affects the **client** bundle. The SSR bundle always uses slim-react.
|
|
120
|
-
*
|
|
121
|
-
* @example
|
|
122
|
-
* // hadars.config.ts — debug hydration errors in a production build
|
|
123
|
-
* reactMode: 'development'
|
|
124
|
-
*/
|
|
125
|
-
reactMode?: 'development' | 'production';
|
|
126
|
-
/**
|
|
127
|
-
* Additional rspack module rules appended to the built-in rule set.
|
|
128
|
-
* Applied to both the client and the SSR bundle.
|
|
129
|
-
*
|
|
130
|
-
* Useful for loaders not included by default, such as `@mdx-js/loader`,
|
|
131
|
-
* `less-loader`, `yaml-loader`, etc.
|
|
132
|
-
*
|
|
133
|
-
* @example
|
|
134
|
-
* moduleRules: [
|
|
135
|
-
* {
|
|
136
|
-
* test: /\.mdx?$/,
|
|
137
|
-
* use: [{ loader: '@mdx-js/loader' }],
|
|
138
|
-
* },
|
|
139
|
-
* ]
|
|
140
|
-
*/
|
|
141
|
-
moduleRules?: Record<string, any>[];
|
|
142
|
-
/**
|
|
143
|
-
* SSR response cache for `run()` mode. Has no effect in `dev()` mode.
|
|
144
|
-
*
|
|
145
|
-
* Receives the incoming request and should return `{ key, ttl? }` to cache
|
|
146
|
-
* the response, or `null`/`undefined` to skip caching for that request.
|
|
147
|
-
* `ttl` is the time-to-live in milliseconds; omit for entries that never expire.
|
|
148
|
-
* The function may be async.
|
|
149
|
-
*
|
|
150
|
-
* @example
|
|
151
|
-
* // Cache every page by pathname (no per-user personalisation):
|
|
152
|
-
* cache: (req) => ({ key: req.pathname })
|
|
153
|
-
*
|
|
154
|
-
* @example
|
|
155
|
-
* // Cache with a per-route TTL, skip authenticated requests:
|
|
156
|
-
* cache: (req) => req.cookies.session ? null : { key: req.pathname, ttl: 60_000 }
|
|
157
|
-
*/
|
|
158
|
-
cache?: (req: HadarsRequest) => {
|
|
159
|
-
key: string;
|
|
160
|
-
ttl?: number;
|
|
161
|
-
} | null | undefined | Promise<{
|
|
162
|
-
key: string;
|
|
163
|
-
ttl?: number;
|
|
164
|
-
} | null | undefined>;
|
|
165
|
-
}
|
|
166
|
-
type SwcPluginItem = string | [string, Record<string, unknown>] | {
|
|
167
|
-
path: string;
|
|
168
|
-
options?: Record<string, unknown>;
|
|
169
|
-
} | ((...args: any[]) => any);
|
|
170
|
-
type SwcPluginList = SwcPluginItem[];
|
|
171
|
-
interface HadarsRequest extends Request {
|
|
172
|
-
pathname: string;
|
|
173
|
-
search: string;
|
|
174
|
-
location: string;
|
|
175
|
-
cookies: Record<string, string>;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
7
|
/** Call this before hydrating to seed the client cache from the server's data.
|
|
179
8
|
* Invoked automatically by the hadars client bootstrap.
|
|
180
9
|
* Always clears the existing cache before populating — call with `{}` to just clear. */
|
|
@@ -273,4 +102,4 @@ declare const HadarsContext: React$1.FC<{
|
|
|
273
102
|
*/
|
|
274
103
|
declare function loadModule<T = any>(path: string): Promise<T>;
|
|
275
104
|
|
|
276
|
-
export { CacheSegment,
|
|
105
|
+
export { CacheSegment, HadarsContext, Head as HadarsHead, clearSegments, deleteSegment, initServerDataCache, loadModule, useServerData };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CACHE_TAG,
|
|
3
|
+
clearSegments,
|
|
4
|
+
deleteSegment,
|
|
5
|
+
getSegment
|
|
6
|
+
} from "./chunk-UNQSQIOO.js";
|
|
7
|
+
|
|
1
8
|
// src/utils/Head.tsx
|
|
2
9
|
import React from "react";
|
|
3
10
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -136,8 +143,7 @@ var fetchedPaths = /* @__PURE__ */ new Set();
|
|
|
136
143
|
var ssrInitialKeys = null;
|
|
137
144
|
var unclaimedKeyCheckScheduled = false;
|
|
138
145
|
function scheduleUnclaimedKeyCheck() {
|
|
139
|
-
if (unclaimedKeyCheckScheduled)
|
|
140
|
-
return;
|
|
146
|
+
if (unclaimedKeyCheckScheduled) return;
|
|
141
147
|
unclaimedKeyCheckScheduled = true;
|
|
142
148
|
setTimeout(() => {
|
|
143
149
|
unclaimedKeyCheckScheduled = false;
|
|
@@ -198,13 +204,10 @@ function useServerData(key, fn) {
|
|
|
198
204
|
throw pendingDataFetch.get(pathKey);
|
|
199
205
|
}
|
|
200
206
|
const unsuspend = globalThis.__hadarsUnsuspend;
|
|
201
|
-
if (!unsuspend)
|
|
202
|
-
return void 0;
|
|
207
|
+
if (!unsuspend) return void 0;
|
|
203
208
|
const _u = unsuspend;
|
|
204
|
-
if (!_u.seenThisPass)
|
|
205
|
-
|
|
206
|
-
if (!_u.seenLastPass)
|
|
207
|
-
_u.seenLastPass = /* @__PURE__ */ new Set();
|
|
209
|
+
if (!_u.seenThisPass) _u.seenThisPass = /* @__PURE__ */ new Set();
|
|
210
|
+
if (!_u.seenLastPass) _u.seenLastPass = /* @__PURE__ */ new Set();
|
|
208
211
|
if (_u.newPassStarting) {
|
|
209
212
|
_u.seenLastPass = new Set(_u.seenThisPass);
|
|
210
213
|
_u.seenThisPass.clear();
|
|
@@ -246,8 +249,7 @@ function useServerData(key, fn) {
|
|
|
246
249
|
_u.newPassStarting = true;
|
|
247
250
|
throw existing.promise;
|
|
248
251
|
}
|
|
249
|
-
if (existing.status === "rejected")
|
|
250
|
-
throw existing.reason;
|
|
252
|
+
if (existing.status === "rejected") throw existing.reason;
|
|
251
253
|
return existing.value;
|
|
252
254
|
}
|
|
253
255
|
var genRandomId = () => {
|
|
@@ -266,8 +268,7 @@ var Head = React.memo(({ children, status }) => {
|
|
|
266
268
|
setStatus(status);
|
|
267
269
|
}
|
|
268
270
|
React.Children.forEach(children, (child) => {
|
|
269
|
-
if (!React.isValidElement(child))
|
|
270
|
-
return;
|
|
271
|
+
if (!React.isValidElement(child)) return;
|
|
271
272
|
const childType = child.type;
|
|
272
273
|
const childProps = child.props;
|
|
273
274
|
const id = childProps["id"] || genRandomId();
|
|
@@ -303,34 +304,6 @@ var Head = React.memo(({ children, status }) => {
|
|
|
303
304
|
|
|
304
305
|
// src/components/CacheSegment.tsx
|
|
305
306
|
import React2 from "react";
|
|
306
|
-
|
|
307
|
-
// src/utils/segmentCache.ts
|
|
308
|
-
function getStore() {
|
|
309
|
-
const g = globalThis;
|
|
310
|
-
if (!g.__hadarsSegmentStore) {
|
|
311
|
-
g.__hadarsSegmentStore = /* @__PURE__ */ new Map();
|
|
312
|
-
}
|
|
313
|
-
return g.__hadarsSegmentStore;
|
|
314
|
-
}
|
|
315
|
-
function getSegment(key) {
|
|
316
|
-
const entry = getStore().get(key);
|
|
317
|
-
if (!entry)
|
|
318
|
-
return null;
|
|
319
|
-
if (entry.expiresAt !== null && Date.now() >= entry.expiresAt) {
|
|
320
|
-
getStore().delete(key);
|
|
321
|
-
return null;
|
|
322
|
-
}
|
|
323
|
-
return entry.html;
|
|
324
|
-
}
|
|
325
|
-
function deleteSegment(key) {
|
|
326
|
-
getStore().delete(key);
|
|
327
|
-
}
|
|
328
|
-
function clearSegments() {
|
|
329
|
-
getStore().clear();
|
|
330
|
-
}
|
|
331
|
-
var CACHE_TAG = "hadars-c";
|
|
332
|
-
|
|
333
|
-
// src/components/CacheSegment.tsx
|
|
334
307
|
import { Fragment, jsx as jsx2 } from "react/jsx-runtime";
|
|
335
308
|
function CacheSegment({ cacheKey, ttl, children }) {
|
|
336
309
|
if (typeof window !== "undefined") {
|
|
@@ -348,8 +321,7 @@ function CacheSegment({ cacheKey, ttl, children }) {
|
|
|
348
321
|
"data-key": cacheKey,
|
|
349
322
|
"data-cache": "miss"
|
|
350
323
|
};
|
|
351
|
-
if (ttl != null)
|
|
352
|
-
props["data-ttl"] = ttl;
|
|
324
|
+
if (ttl != null) props["data-ttl"] = ttl;
|
|
353
325
|
return React2.createElement(CACHE_TAG, props, children);
|
|
354
326
|
}
|
|
355
327
|
|
|
@@ -15,4 +15,4 @@ declare function jsx(type: string | ComponentFunction | symbol, props: Record<st
|
|
|
15
15
|
|
|
16
16
|
declare function createElement(type: string | ComponentFunction | symbol, props?: Record<string, any> | null, ...children: SlimNode[]): SlimElement;
|
|
17
17
|
|
|
18
|
-
export { ComponentFunction as C,
|
|
18
|
+
export { type ComponentFunction as C, FRAGMENT_TYPE as F, type SlimNode as S, type SlimElement as a, Fragment as b, createElement as c, SLIM_ELEMENT as d, SUSPENSE_TYPE as e, jsx as j };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
declare const SLIM_ELEMENT: unique symbol;
|
|
2
|
+
declare const FRAGMENT_TYPE: unique symbol;
|
|
3
|
+
declare const SUSPENSE_TYPE: unique symbol;
|
|
4
|
+
type ComponentFunction = (props: any) => SlimNode;
|
|
5
|
+
type SlimElement = {
|
|
6
|
+
$$typeof: typeof SLIM_ELEMENT;
|
|
7
|
+
type: string | ComponentFunction | symbol;
|
|
8
|
+
props: Record<string, any>;
|
|
9
|
+
key: string | number | null;
|
|
10
|
+
};
|
|
11
|
+
type SlimNode = SlimElement | string | number | boolean | null | undefined | SlimNode[];
|
|
12
|
+
|
|
13
|
+
declare const Fragment: symbol;
|
|
14
|
+
declare function jsx(type: string | ComponentFunction | symbol, props: Record<string, any>, key?: string | number | null): SlimElement;
|
|
15
|
+
|
|
16
|
+
declare function createElement(type: string | ComponentFunction | symbol, props?: Record<string, any> | null, ...children: SlimNode[]): SlimElement;
|
|
17
|
+
|
|
18
|
+
export { type ComponentFunction as C, FRAGMENT_TYPE as F, type SlimNode as S, type SlimElement as a, Fragment as b, createElement as c, SLIM_ELEMENT as d, SUSPENSE_TYPE as e, jsx as j };
|