@anaemia/core 0.0.1 → 0.1.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.
Files changed (42) hide show
  1. package/dist/config.d.ts +3 -2
  2. package/dist/config.d.ts.map +1 -1
  3. package/dist/index.d.ts +1 -5
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/plugins/lightningcss.d.ts.map +1 -1
  6. package/dist/plugins/lightningcss.js +1 -2
  7. package/dist/runtime/context.browser.d.ts.map +1 -1
  8. package/dist/runtime/context.browser.js +3 -1
  9. package/dist/runtime/context.d.ts +5 -4
  10. package/dist/runtime/context.d.ts.map +1 -1
  11. package/dist/runtime/entry-client.jsx +1 -1
  12. package/dist/runtime/entry-server.d.ts.map +1 -1
  13. package/dist/runtime/entry-server.jsx +18 -29
  14. package/dist/runtime/resources.d.ts +1 -1
  15. package/dist/runtime/resources.d.ts.map +1 -1
  16. package/dist/runtime/resources.js +5 -3
  17. package/dist/runtime/route-data.d.ts +7 -6
  18. package/dist/runtime/route-data.d.ts.map +1 -1
  19. package/dist/runtime/route-data.js +5 -8
  20. package/dist/runtime/route-request.d.ts +1 -1
  21. package/dist/runtime/route-request.d.ts.map +1 -1
  22. package/dist/runtime/route-request.js +2 -1
  23. package/dist/runtime/rpc-client.d.ts +2 -2
  24. package/dist/runtime/rpc-client.d.ts.map +1 -1
  25. package/dist/runtime/rpc-client.js +12 -11
  26. package/dist/types.d.ts +6 -2
  27. package/dist/types.d.ts.map +1 -1
  28. package/package.json +3 -1
  29. package/src/config.ts +3 -2
  30. package/src/index.ts +1 -6
  31. package/src/plugins/lightningcss.ts +7 -3
  32. package/src/runtime/context.browser.ts +3 -2
  33. package/src/runtime/context.ts +8 -13
  34. package/src/runtime/entry-client.tsx +1 -1
  35. package/src/runtime/entry-server.tsx +47 -47
  36. package/src/runtime/resources.ts +28 -16
  37. package/src/runtime/route-data.ts +24 -36
  38. package/src/runtime/route-request.ts +5 -4
  39. package/src/runtime/rpc-client.ts +44 -24
  40. package/src/runtime/webpack.d.ts +1 -1
  41. package/src/types.ts +7 -2
  42. package/test/integration/hmr.test.mjs +16 -22
package/src/types.ts CHANGED
@@ -13,13 +13,13 @@ 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 = any, Params extends Record<string, string> = Record<string, string>> = (args: LoaderArgs<Params>) => Promise<ResponseData> | ResponseData;
16
+ export type LoaderFunction<ResponseData = unknown, Params extends Record<string, string> = Record<string, string>> = (args: LoaderArgs<Params>) => Promise<ResponseData> | ResponseData;
17
17
 
18
18
  /**
19
19
  * extracts and unwraps the true data structure returned by a server function or loader.
20
20
  * essential for typing useRouteData() effortlessly in user-space.
21
21
  */
22
- export type InferServerData<T extends (...args: any[]) => any> = Awaited<ReturnType<T>>;
22
+ export type InferServerData<T extends (...args: unknown[]) => unknown> = Awaited<ReturnType<T>>;
23
23
 
24
24
  export type GuardContext = {
25
25
  params: Record<string, string>;
@@ -30,3 +30,8 @@ export type GuardContext = {
30
30
  export type GuardResult = void | undefined | { redirect: string; status?: 301 | 302 | 307 | 308 } | { status: 401 | 403 | 404 | 500; body?: string };
31
31
 
32
32
  export type GuardFn = (ctx: { params: Record<string, string>; request: Request; url: string }) => void | undefined | { redirect: string; status?: RedirectStatusCode } | { status: number; body?: string } | Promise<void | undefined | { redirect: string; status?: RedirectStatusCode } | { status: number; body?: string }>;
33
+
34
+ export type ServerFunction<Args extends unknown[], Return> = ((...args: Args) => Promise<Return>) & {
35
+ id?: string;
36
+ urlId?: string;
37
+ };
@@ -11,14 +11,14 @@ const require = createRequire(import.meta.url);
11
11
  const { createJiti } = require("jiti");
12
12
  const jiti = createJiti(import.meta.url);
13
13
 
14
- function resolveConfigPort() {
14
+ async function resolveConfigPort() {
15
15
  const configPath = path.resolve(projectRoot, "anaemia.config.ts");
16
-
16
+
17
17
  if (fs.existsSync(configPath)) {
18
18
  try {
19
- const userConfigModule = jiti(configPath);
19
+ const userConfigModule = await jiti.import(configPath);
20
20
  const userConfig = userConfigModule.default || userConfigModule;
21
-
21
+
22
22
  if (userConfig && typeof userConfig.port === "number") {
23
23
  return userConfig.port;
24
24
  }
@@ -50,9 +50,7 @@ test("integration - dev server HMR & hydration lifecycle", async (t) => {
50
50
  if (browser) await browser.close();
51
51
 
52
52
  if (devProcess && devProcess.pid) {
53
- try {
54
- process.kill(-devProcess.pid, "SIGKILL");
55
- } catch (e) {}
53
+ process.kill(-devProcess.pid, "SIGKILL");
56
54
  }
57
55
  });
58
56
 
@@ -76,15 +74,14 @@ test("integration - dev server HMR & hydration lifecycle", async (t) => {
76
74
 
77
75
  const checkPortReady = async () => {
78
76
  for (let i = 0; i < 20; i++) {
79
- try {
80
- // Dynamic URL Check
81
- const res = await fetch(BASE_URL);
82
- if (res.status === 200 || res.status === 404) {
83
- clearTimeout(timeout);
84
- resolve();
85
- return;
86
- }
87
- } catch (e) {}
77
+ // Dynamic URL Check
78
+ const res = await fetch(BASE_URL);
79
+ if (res.status === 200 || res.status === 404) {
80
+ clearTimeout(timeout);
81
+ resolve();
82
+ return;
83
+ }
84
+
88
85
  await new Promise((r) => setTimeout(r, 200));
89
86
  }
90
87
  reject(new Error(`Server process started but port ${TARGET_PORT} never responded to HTTP requests.`));
@@ -129,6 +126,7 @@ test("integration - dev server HMR & hydration lifecycle", async (t) => {
129
126
 
130
127
  await page.waitForFunction(
131
128
  () => {
129
+ // eslint-disable-next-line no-undef
132
130
  const h1 = document.querySelector("h1");
133
131
  return h1 && h1.textContent.trim() === "anaemia updated!";
134
132
  },
@@ -143,10 +141,6 @@ test("integration - dev server HMR & hydration lifecycle", async (t) => {
143
141
 
144
142
  const titleText = await page.textContent("h1");
145
143
  assert.equal(titleText.trim(), "anaemia updated!");
146
- assert.equal(
147
- consoleErrors.length,
148
- 0,
149
- `Errors detected after page refresh: ${consoleErrors.map(e => e.message).join(", ")}`
150
- );
144
+ assert.equal(consoleErrors.length, 0, `Errors detected after page refresh: ${consoleErrors.map((e) => e.message).join(", ")}`);
151
145
  });
152
- });
146
+ });