@anaemia/core 0.3.7 → 0.5.0
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/LICENSE +1 -1
- package/README.md +1 -1
- package/dist/config.d.ts +8 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/plugins/lightningcss.js +4 -4
- package/dist/runtime/context.d.ts.map +1 -1
- package/dist/runtime/context.js +5 -4
- package/dist/runtime/entry-client.jsx +4 -5
- package/dist/runtime/entry-server.d.ts +1 -2
- package/dist/runtime/entry-server.d.ts.map +1 -1
- package/dist/runtime/entry-server.jsx +18 -321
- package/dist/runtime/resources.d.ts.map +1 -1
- package/dist/runtime/resources.js +2 -1
- package/dist/runtime/route-data.d.ts.map +1 -1
- package/dist/runtime/route-data.js +4 -3
- package/dist/runtime/route-request.d.ts.map +1 -1
- package/dist/runtime/route-request.js +3 -2
- package/dist/runtime/rpc-client.d.ts.map +1 -1
- package/dist/runtime/rpc-client.js +10 -9
- package/dist/runtime/server/app.d.ts +22 -0
- package/dist/runtime/server/app.d.ts.map +1 -0
- package/dist/runtime/server/app.js +21 -0
- package/dist/runtime/server/assets.d.ts +5 -0
- package/dist/runtime/server/assets.d.ts.map +1 -0
- package/dist/runtime/server/assets.js +48 -0
- package/dist/runtime/server/boot.d.ts +4 -0
- package/dist/runtime/server/boot.d.ts.map +1 -0
- package/dist/runtime/server/boot.js +6 -0
- package/dist/runtime/server/env.d.ts +3 -0
- package/dist/runtime/server/env.d.ts.map +1 -0
- package/dist/runtime/server/env.js +14 -0
- package/dist/runtime/server/guards.d.ts +29 -0
- package/dist/runtime/server/guards.d.ts.map +1 -0
- package/dist/runtime/server/guards.js +12 -0
- package/dist/runtime/server/html.d.ts +15 -0
- package/dist/runtime/server/html.d.ts.map +1 -0
- package/dist/runtime/server/html.js +62 -0
- package/dist/runtime/server/hydration.d.ts +3 -0
- package/dist/runtime/server/hydration.d.ts.map +1 -0
- package/dist/runtime/server/hydration.js +20 -0
- package/dist/runtime/server/manifest.d.ts +14 -0
- package/dist/runtime/server/manifest.d.ts.map +1 -0
- package/dist/runtime/server/manifest.js +59 -0
- package/dist/runtime/server/render-request.d.ts +21 -0
- package/dist/runtime/server/render-request.d.ts.map +1 -0
- package/dist/runtime/server/render-request.jsx +170 -0
- package/dist/runtime/server/route-match.d.ts +14 -0
- package/dist/runtime/server/route-match.d.ts.map +1 -0
- package/dist/runtime/server/route-match.js +35 -0
- package/dist/runtime/server/rpc.d.ts +3 -0
- package/dist/runtime/server/rpc.d.ts.map +1 -0
- package/dist/runtime/server/rpc.js +32 -0
- package/dist/runtime/server/types.d.ts +33 -0
- package/dist/runtime/server/types.d.ts.map +1 -0
- package/dist/runtime/server/types.js +1 -0
- package/dist/runtime/shared/constants.d.ts +8 -0
- package/dist/runtime/shared/constants.d.ts.map +1 -0
- package/dist/runtime/shared/constants.js +7 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +11 -7
- package/src/anaemia.d.ts +75 -0
- package/src/config.ts +9 -1
- package/src/index.ts +9 -1
- package/src/plugins/index.ts +1 -1
- package/src/plugins/lightningcss.ts +11 -11
- package/src/runtime/context.browser.ts +1 -1
- package/src/runtime/context.ts +6 -5
- package/src/runtime/entry-client.tsx +5 -8
- package/src/runtime/entry-server.tsx +19 -373
- package/src/runtime/resources.ts +3 -2
- package/src/runtime/route-data.ts +6 -5
- package/src/runtime/route-request.ts +4 -3
- package/src/runtime/rpc-client.ts +14 -13
- package/src/runtime/server/app.ts +44 -0
- package/src/runtime/server/assets.ts +69 -0
- package/src/runtime/server/boot.ts +9 -0
- package/src/runtime/server/env.ts +17 -0
- package/src/runtime/server/guards.ts +26 -0
- package/src/runtime/server/html.ts +84 -0
- package/src/runtime/server/hydration.ts +26 -0
- package/src/runtime/server/manifest.ts +69 -0
- package/src/runtime/server/render-request.tsx +230 -0
- package/src/runtime/server/route-match.ts +45 -0
- package/src/runtime/server/rpc.ts +34 -0
- package/src/runtime/server/types.ts +36 -0
- package/src/runtime/shared/constants.ts +7 -0
- package/src/runtime/webpack.d.ts +1 -1
- package/src/types.ts +18 -3
- package/test/integration/hmr.test.mjs +18 -5
- package/test/rpc-client.test.mjs +1 -1
- package/test/run-on-server.test.mjs +2 -6
- package/tsconfig.json +1 -1
package/src/types.ts
CHANGED
|
@@ -13,7 +13,9 @@ export interface LoaderArgs<Params extends Record<string, string> = Record<strin
|
|
|
13
13
|
/**
|
|
14
14
|
* represents an application page loader function.
|
|
15
15
|
*/
|
|
16
|
-
export type LoaderFunction<ResponseData = unknown, Params extends Record<string, string> = Record<string, string>> = (
|
|
16
|
+
export type LoaderFunction<ResponseData = unknown, Params extends Record<string, string> = Record<string, string>> = (
|
|
17
|
+
args: LoaderArgs<Params>,
|
|
18
|
+
) => Promise<ResponseData> | ResponseData;
|
|
17
19
|
|
|
18
20
|
/**
|
|
19
21
|
* extracts and unwraps the true data structure returned by a server function or loader.
|
|
@@ -27,9 +29,22 @@ export type GuardContext = {
|
|
|
27
29
|
url: string;
|
|
28
30
|
};
|
|
29
31
|
|
|
30
|
-
export type GuardResult =
|
|
32
|
+
export type GuardResult =
|
|
33
|
+
| void
|
|
34
|
+
| undefined
|
|
35
|
+
| { redirect: string; status?: 301 | 302 | 307 | 308 }
|
|
36
|
+
| { status: 401 | 403 | 404 | 500; body?: string };
|
|
31
37
|
|
|
32
|
-
export type GuardFn = (ctx: {
|
|
38
|
+
export type GuardFn = (ctx: {
|
|
39
|
+
params: Record<string, string>;
|
|
40
|
+
request: Request;
|
|
41
|
+
url: string;
|
|
42
|
+
}) =>
|
|
43
|
+
| void
|
|
44
|
+
| undefined
|
|
45
|
+
| { redirect: string; status?: RedirectStatusCode }
|
|
46
|
+
| { status: number; body?: string }
|
|
47
|
+
| Promise<void | undefined | { redirect: string; status?: RedirectStatusCode } | { status: number; body?: string }>;
|
|
33
48
|
|
|
34
49
|
export type ServerFunction<Args extends unknown[], Return> = ((...args: Args) => Promise<Return>) & {
|
|
35
50
|
id?: string;
|
|
@@ -28,7 +28,9 @@ async function resolveConfigPort() {
|
|
|
28
28
|
return userConfig.port;
|
|
29
29
|
}
|
|
30
30
|
} catch (err) {
|
|
31
|
-
console.warn(
|
|
31
|
+
console.warn(
|
|
32
|
+
`[HMR test warning]: failed parsing anaemia.config.ts, falling back to port 3000. Error: ${err.message}`,
|
|
33
|
+
);
|
|
32
34
|
}
|
|
33
35
|
}
|
|
34
36
|
|
|
@@ -119,11 +121,18 @@ test("integration - dev server HMR & hydration lifecycle", async (t) => {
|
|
|
119
121
|
|
|
120
122
|
const titleText = await page.textContent("h1");
|
|
121
123
|
assert.equal(titleText.trim(), "anaemia");
|
|
122
|
-
assert.equal(
|
|
124
|
+
assert.equal(
|
|
125
|
+
consoleErrors.length,
|
|
126
|
+
0,
|
|
127
|
+
`Errors during initial render: ${consoleErrors.map((e) => e.message).join(", ")}`,
|
|
128
|
+
);
|
|
123
129
|
});
|
|
124
130
|
|
|
125
131
|
await t.test("should push hot module updates to browser when files change", async () => {
|
|
126
|
-
const updatedContent = originalComponentContent.replace(
|
|
132
|
+
const updatedContent = originalComponentContent.replace(
|
|
133
|
+
`<h1 class={styles.title}>anaemia</h1>`,
|
|
134
|
+
`<h1 class={styles.title}>anaemia updated!</h1>`,
|
|
135
|
+
);
|
|
127
136
|
|
|
128
137
|
assert.notEqual(originalComponentContent, updatedContent, "Regex failed to modify component text.");
|
|
129
138
|
fs.writeFileSync(componentPath, updatedContent, "utf-8");
|
|
@@ -134,7 +143,7 @@ test("integration - dev server HMR & hydration lifecycle", async (t) => {
|
|
|
134
143
|
const h1 = document.querySelector("h1");
|
|
135
144
|
return h1 && h1.textContent.trim() === "anaemia updated!";
|
|
136
145
|
},
|
|
137
|
-
{ timeout: 10000 }
|
|
146
|
+
{ timeout: 10000 },
|
|
138
147
|
);
|
|
139
148
|
});
|
|
140
149
|
|
|
@@ -145,6 +154,10 @@ test("integration - dev server HMR & hydration lifecycle", async (t) => {
|
|
|
145
154
|
|
|
146
155
|
const titleText = await page.textContent("h1");
|
|
147
156
|
assert.equal(titleText.trim(), "anaemia updated!");
|
|
148
|
-
assert.equal(
|
|
157
|
+
assert.equal(
|
|
158
|
+
consoleErrors.length,
|
|
159
|
+
0,
|
|
160
|
+
`Errors detected after page refresh: ${consoleErrors.map((e) => e.message).join(", ")}`,
|
|
161
|
+
);
|
|
149
162
|
});
|
|
150
163
|
});
|
package/test/rpc-client.test.mjs
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import test from "node:test";
|
|
3
|
-
import {
|
|
4
|
-
runOnServer,
|
|
5
|
-
serverFunctionsRegistry,
|
|
6
|
-
ssrStorage,
|
|
7
|
-
} from "../dist/runtime/context.js";
|
|
3
|
+
import { runOnServer, serverFunctionsRegistry, ssrStorage } from "../dist/runtime/context.js";
|
|
8
4
|
import { createRouteRequest } from "../dist/runtime/route-request.js";
|
|
9
5
|
|
|
10
6
|
test("runOnServer returns a callable function and registers the original implementation", async () => {
|
|
@@ -26,7 +22,7 @@ test("runOnServer records SSR results by id and argument list for hydration", as
|
|
|
26
22
|
|
|
27
23
|
assert.deepEqual(store.get("__SERVER_FUNCTION_DATA__"), {
|
|
28
24
|
greet: {
|
|
29
|
-
|
|
25
|
+
'["Ada"]': "hello Ada",
|
|
30
26
|
},
|
|
31
27
|
});
|
|
32
28
|
});
|
package/tsconfig.json
CHANGED