@anaemia/core 0.1.2 → 0.3.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/runtime/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,KAAK,KAAK,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;AAE7C,eAAO,MAAM,uBAAuB,oBAA2B,CAAC;AAChE,eAAO,MAAM,UAAU,yCAAgD,CAAC;AAGxE,wBAAgB,WAAW,CAAC,CAAC,SAAS,KAAK,EAAE,SAAS,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,CAAC,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/runtime/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,KAAK,KAAK,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;AAE7C,eAAO,MAAM,uBAAuB,oBAA2B,CAAC;AAChE,eAAO,MAAM,UAAU,yCAAgD,CAAC;AAGxE,wBAAgB,WAAW,CAAC,CAAC,SAAS,KAAK,EAAE,SAAS,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,CAAC,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAsB1F"}
|
package/dist/runtime/context.js
CHANGED
|
@@ -4,6 +4,7 @@ export const ssrStorage = new AsyncLocalStorage();
|
|
|
4
4
|
globalThis.__ANAEMIA_SERVER_STORAGE__ = ssrStorage;
|
|
5
5
|
export function runOnServer(backendFn, id) {
|
|
6
6
|
const hashId = id || "";
|
|
7
|
+
serverFunctionsRegistry.set(hashId, backendFn);
|
|
7
8
|
const rpcProxy = async function (...args) {
|
|
8
9
|
const result = await backendFn(...args);
|
|
9
10
|
const store = ssrStorage.getStore();
|
package/package.json
CHANGED
package/src/runtime/context.ts
CHANGED
|
@@ -8,6 +8,8 @@ export const ssrStorage = new AsyncLocalStorage<Map<string, unknown>>();
|
|
|
8
8
|
|
|
9
9
|
export function runOnServer<T extends AnyFn>(backendFn: T, id?: string): T & { id: string } {
|
|
10
10
|
const hashId = id || "";
|
|
11
|
+
serverFunctionsRegistry.set(hashId, backendFn);
|
|
12
|
+
|
|
11
13
|
const rpcProxy = async function (...args: unknown[]) {
|
|
12
14
|
const result = await backendFn(...args);
|
|
13
15
|
const store = ssrStorage.getStore();
|
|
@@ -7,10 +7,15 @@ import { fileURLToPath } from "node:url";
|
|
|
7
7
|
import { chromium } from "playwright";
|
|
8
8
|
import { createRequire } from "node:module";
|
|
9
9
|
|
|
10
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
11
|
+
const __dirname = path.dirname(__filename);
|
|
12
|
+
|
|
10
13
|
const require = createRequire(import.meta.url);
|
|
11
14
|
const { createJiti } = require("jiti");
|
|
12
15
|
const jiti = createJiti(import.meta.url);
|
|
13
16
|
|
|
17
|
+
const projectRoot = path.resolve(__dirname, "../../../../templates/base-app");
|
|
18
|
+
|
|
14
19
|
async function resolveConfigPort() {
|
|
15
20
|
const configPath = path.resolve(projectRoot, "anaemia.config.ts");
|
|
16
21
|
|
|
@@ -30,12 +35,8 @@ async function resolveConfigPort() {
|
|
|
30
35
|
return 3000;
|
|
31
36
|
}
|
|
32
37
|
|
|
33
|
-
const TARGET_PORT = resolveConfigPort();
|
|
38
|
+
const TARGET_PORT = await resolveConfigPort();
|
|
34
39
|
const BASE_URL = `http://localhost:${TARGET_PORT}`;
|
|
35
|
-
|
|
36
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
37
|
-
const __dirname = path.dirname(__filename);
|
|
38
|
-
const projectRoot = path.resolve(__dirname, "../../../../templates/base-app");
|
|
39
40
|
const componentPath = path.resolve(projectRoot, "src/features/welcome-hero/components/WelcomeHero.tsx");
|
|
40
41
|
|
|
41
42
|
test("integration - dev server HMR & hydration lifecycle", async (t) => {
|
|
@@ -70,19 +71,22 @@ test("integration - dev server HMR & hydration lifecycle", async (t) => {
|
|
|
70
71
|
|
|
71
72
|
const timeout = setTimeout(() => {
|
|
72
73
|
reject(new Error(`Dev server startup timed out. Current output:\n${output}`));
|
|
73
|
-
},
|
|
74
|
+
}, 30_000);
|
|
74
75
|
|
|
75
76
|
const checkPortReady = async () => {
|
|
76
77
|
for (let i = 0; i < 20; i++) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
78
|
+
try {
|
|
79
|
+
const res = await fetch(BASE_URL);
|
|
80
|
+
if (res.status === 200 || res.status === 404) {
|
|
81
|
+
clearTimeout(timeout);
|
|
82
|
+
resolve();
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
} catch {
|
|
86
|
+
// server not up yet, keep polling
|
|
83
87
|
}
|
|
84
88
|
|
|
85
|
-
await new Promise((r) => setTimeout(r,
|
|
89
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
86
90
|
}
|
|
87
91
|
reject(new Error(`Server process started but port ${TARGET_PORT} never responded to HTTP requests.`));
|
|
88
92
|
};
|
|
@@ -12,7 +12,6 @@ test("runOnServer returns a callable function and registers the original impleme
|
|
|
12
12
|
|
|
13
13
|
assert.equal(typeof add, "function");
|
|
14
14
|
assert.equal(add.id, "add");
|
|
15
|
-
assert.equal(add.urlId, "add");
|
|
16
15
|
assert.equal(await add(2, 3), 5);
|
|
17
16
|
assert.equal(await serverFunctionsRegistry.get("add")(4, 6), 10);
|
|
18
17
|
});
|