@mokup/server 1.1.6 → 1.2.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.
@@ -141,6 +141,12 @@ interface RouteDirectoryConfig {
141
141
  * @default undefined
142
142
  */
143
143
  middleware?: MiddlewareHandler | MiddlewareHandler[];
144
+ /**
145
+ * Error handling policy for defineConfig hooks.
146
+ *
147
+ * @default "warn"
148
+ */
149
+ hookError?: HookErrorPolicy;
144
150
  }
145
151
  /**
146
152
  * Middleware execution position.
@@ -151,6 +157,10 @@ interface RouteDirectoryConfig {
151
157
  * const position: MiddlewarePosition = 'pre'
152
158
  */
153
159
  type MiddlewarePosition = 'pre' | 'normal' | 'post';
160
+ /**
161
+ * Error handling policy for config hooks.
162
+ */
163
+ type HookErrorPolicy = 'throw' | 'warn' | 'silent';
154
164
  /**
155
165
  * Middleware registry used by defineConfig.
156
166
  *
@@ -211,4 +221,4 @@ interface ResolvedRoute {
211
221
  }
212
222
  type RouteTable = ResolvedRoute[];
213
223
 
214
- export type { MiddlewareRegistry as M, RouteDirectoryConfig as R, MiddlewarePosition as a, ResolvedMiddleware as b, RouteRule as c, RouteTable as d };
224
+ export type { HookErrorPolicy as H, MiddlewarePosition as M, RouteDirectoryConfig as R, MiddlewareRegistry as a, ResolvedMiddleware as b, RouteRule as c, RouteTable as d };
@@ -141,6 +141,12 @@ interface RouteDirectoryConfig {
141
141
  * @default undefined
142
142
  */
143
143
  middleware?: MiddlewareHandler | MiddlewareHandler[];
144
+ /**
145
+ * Error handling policy for defineConfig hooks.
146
+ *
147
+ * @default "warn"
148
+ */
149
+ hookError?: HookErrorPolicy;
144
150
  }
145
151
  /**
146
152
  * Middleware execution position.
@@ -151,6 +157,10 @@ interface RouteDirectoryConfig {
151
157
  * const position: MiddlewarePosition = 'pre'
152
158
  */
153
159
  type MiddlewarePosition = 'pre' | 'normal' | 'post';
160
+ /**
161
+ * Error handling policy for config hooks.
162
+ */
163
+ type HookErrorPolicy = 'throw' | 'warn' | 'silent';
154
164
  /**
155
165
  * Middleware registry used by defineConfig.
156
166
  *
@@ -211,4 +221,4 @@ interface ResolvedRoute {
211
221
  }
212
222
  type RouteTable = ResolvedRoute[];
213
223
 
214
- export type { MiddlewareRegistry as M, RouteDirectoryConfig as R, MiddlewarePosition as a, ResolvedMiddleware as b, RouteRule as c, RouteTable as d };
224
+ export type { HookErrorPolicy as H, MiddlewarePosition as M, RouteDirectoryConfig as R, MiddlewareRegistry as a, ResolvedMiddleware as b, RouteRule as c, RouteTable as d };
@@ -1,9 +1,18 @@
1
1
  'use strict';
2
2
 
3
+ const node_path = require('node:path');
4
+ const node_url = require('node:url');
3
5
  const fetch = require('./fetch.cjs');
4
6
  require('@mokup/runtime');
5
7
  require('./shared/server.aaygIV2Q.cjs');
6
8
 
9
+ function ensureTrailingSlash(value) {
10
+ return value.endsWith("/") ? value : `${value}/`;
11
+ }
12
+ function resolveModuleBase(dir) {
13
+ const absolute = node_path.resolve(dir);
14
+ return ensureTrailingSlash(node_url.pathToFileURL(absolute).href);
15
+ }
7
16
  function isManifest(value) {
8
17
  return typeof value === "object" && value !== null && !Array.isArray(value) && "version" in value && "routes" in value;
9
18
  }
@@ -27,23 +36,21 @@ async function loadBundleFromDir(dir) {
27
36
  throw new TypeError("createMokupWorker(dir) is only supported in Node runtimes.");
28
37
  }
29
38
  const { readFile, access } = await import('node:fs/promises');
30
- const { resolve, join } = await import('node:path');
31
- const { pathToFileURL } = await import('node:url');
32
- const manifestPath = resolve(dir, "mokup.manifest.json");
39
+ const manifestPath = node_path.resolve(dir, "mokup.manifest.json");
33
40
  const manifestRaw = await readFile(manifestPath, "utf8");
34
41
  const manifest = JSON.parse(manifestRaw);
35
- const handlersIndexPath = resolve(dir, "mokup-handlers", "index.mjs");
42
+ const handlersIndexPath = node_path.resolve(dir, "mokup-handlers", "index.mjs");
36
43
  let moduleMap;
37
44
  try {
38
45
  await access(handlersIndexPath);
39
- const module = await import(pathToFileURL(handlersIndexPath).href);
46
+ const module = await import(node_url.pathToFileURL(handlersIndexPath).href);
40
47
  moduleMap = module.mokupModuleMap;
41
48
  } catch {
42
49
  moduleMap = void 0;
43
50
  }
44
51
  const bundle = {
45
52
  manifest,
46
- moduleBase: join(dir, "/")
53
+ moduleBase: resolveModuleBase(dir)
47
54
  };
48
55
  if (typeof moduleMap !== "undefined") {
49
56
  bundle.moduleMap = moduleMap;
@@ -72,3 +79,4 @@ function createMokupWorker(input) {
72
79
  }
73
80
 
74
81
  exports.createMokupWorker = createMokupWorker;
82
+ exports.resolveModuleBase = resolveModuleBase;
@@ -22,6 +22,7 @@ interface FetchWorker {
22
22
  * const input: NodeWorkerInput = '.mokup'
23
23
  */
24
24
  type NodeWorkerInput = string | WorkerInput;
25
+ declare function resolveModuleBase(dir: string): string;
25
26
  /**
26
27
  * Create a Worker-compatible fetch handler for Node.
27
28
  *
@@ -36,5 +37,5 @@ type NodeWorkerInput = string | WorkerInput;
36
37
  declare function createMokupWorker(input: string): Promise<FetchWorker>;
37
38
  declare function createMokupWorker(input: WorkerInput): FetchWorker;
38
39
 
39
- export { createMokupWorker };
40
+ export { createMokupWorker, resolveModuleBase };
40
41
  export type { FetchWorker, NodeWorkerInput };
@@ -22,6 +22,7 @@ interface FetchWorker {
22
22
  * const input: NodeWorkerInput = '.mokup'
23
23
  */
24
24
  type NodeWorkerInput = string | WorkerInput;
25
+ declare function resolveModuleBase(dir: string): string;
25
26
  /**
26
27
  * Create a Worker-compatible fetch handler for Node.
27
28
  *
@@ -36,5 +37,5 @@ type NodeWorkerInput = string | WorkerInput;
36
37
  declare function createMokupWorker(input: string): Promise<FetchWorker>;
37
38
  declare function createMokupWorker(input: WorkerInput): FetchWorker;
38
39
 
39
- export { createMokupWorker };
40
+ export { createMokupWorker, resolveModuleBase };
40
41
  export type { FetchWorker, NodeWorkerInput };
@@ -22,6 +22,7 @@ interface FetchWorker {
22
22
  * const input: NodeWorkerInput = '.mokup'
23
23
  */
24
24
  type NodeWorkerInput = string | WorkerInput;
25
+ declare function resolveModuleBase(dir: string): string;
25
26
  /**
26
27
  * Create a Worker-compatible fetch handler for Node.
27
28
  *
@@ -36,5 +37,5 @@ type NodeWorkerInput = string | WorkerInput;
36
37
  declare function createMokupWorker(input: string): Promise<FetchWorker>;
37
38
  declare function createMokupWorker(input: WorkerInput): FetchWorker;
38
39
 
39
- export { createMokupWorker };
40
+ export { createMokupWorker, resolveModuleBase };
40
41
  export type { FetchWorker, NodeWorkerInput };
@@ -1,7 +1,16 @@
1
+ import { resolve } from 'node:path';
2
+ import { pathToFileURL } from 'node:url';
1
3
  import { createFetchHandler } from './fetch.mjs';
2
4
  import '@mokup/runtime';
3
5
  import './shared/server.LbftO9Jh.mjs';
4
6
 
7
+ function ensureTrailingSlash(value) {
8
+ return value.endsWith("/") ? value : `${value}/`;
9
+ }
10
+ function resolveModuleBase(dir) {
11
+ const absolute = resolve(dir);
12
+ return ensureTrailingSlash(pathToFileURL(absolute).href);
13
+ }
5
14
  function isManifest(value) {
6
15
  return typeof value === "object" && value !== null && !Array.isArray(value) && "version" in value && "routes" in value;
7
16
  }
@@ -25,8 +34,6 @@ async function loadBundleFromDir(dir) {
25
34
  throw new TypeError("createMokupWorker(dir) is only supported in Node runtimes.");
26
35
  }
27
36
  const { readFile, access } = await import('node:fs/promises');
28
- const { resolve, join } = await import('node:path');
29
- const { pathToFileURL } = await import('node:url');
30
37
  const manifestPath = resolve(dir, "mokup.manifest.json");
31
38
  const manifestRaw = await readFile(manifestPath, "utf8");
32
39
  const manifest = JSON.parse(manifestRaw);
@@ -41,7 +48,7 @@ async function loadBundleFromDir(dir) {
41
48
  }
42
49
  const bundle = {
43
50
  manifest,
44
- moduleBase: join(dir, "/")
51
+ moduleBase: resolveModuleBase(dir)
45
52
  };
46
53
  if (typeof moduleMap !== "undefined") {
47
54
  bundle.moduleMap = moduleMap;
@@ -69,4 +76,4 @@ function createMokupWorker(input) {
69
76
  return createWorker(normalizeWorkerOptions(input));
70
77
  }
71
78
 
72
- export { createMokupWorker };
79
+ export { createMokupWorker, resolveModuleBase };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mokup/server",
3
3
  "type": "module",
4
- "version": "1.1.6",
4
+ "version": "1.2.0",
5
5
  "description": "Server adapters for @mokup/runtime.",
6
6
  "license": "MIT",
7
7
  "homepage": "https://mokup.icebreaker.top",
@@ -80,9 +80,9 @@
80
80
  "@hono/node-server": "^1.19.9",
81
81
  "@hono/node-ws": "^1.1.1",
82
82
  "tsx": "^4.21.0",
83
- "@mokup/runtime": "1.0.5",
84
- "@mokup/shared": "1.1.0",
85
- "@mokup/playground": "0.0.13"
83
+ "@mokup/shared": "1.1.1",
84
+ "@mokup/playground": "0.0.15",
85
+ "@mokup/runtime": "1.0.6"
86
86
  },
87
87
  "devDependencies": {
88
88
  "@types/node": "^25.0.10",