mokup 1.0.4 → 2.0.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/dist/index.d.cts CHANGED
@@ -20,6 +20,10 @@ interface ServiceWorkerOptions {
20
20
  fallback?: boolean;
21
21
  basePath?: string | string[];
22
22
  }
23
+ type PlaygroundOptionsInput = boolean | {
24
+ path?: string;
25
+ enabled?: boolean;
26
+ } | undefined;
23
27
  interface RouteDirectoryConfig {
24
28
  headers?: Record<string, string>;
25
29
  status?: number;
@@ -40,11 +44,11 @@ interface VitePluginOptions {
40
44
  log?: boolean;
41
45
  mode?: RuntimeMode;
42
46
  sw?: ServiceWorkerOptions;
43
- playground?: boolean | {
44
- path?: string;
45
- enabled?: boolean;
46
- };
47
47
  }
48
- type VitePluginOptionsInput = VitePluginOptions | VitePluginOptions[];
48
+ interface MokupPluginOptions {
49
+ entries?: VitePluginOptions | VitePluginOptions[];
50
+ playground?: PlaygroundOptionsInput;
51
+ }
52
+ type VitePluginOptionsInput = MokupPluginOptions;
49
53
 
50
- export type { HttpMethod, RequestHandler, RouteDirectoryConfig, RouteResponse, RouteRule, RuntimeMode, ServiceWorkerOptions, VitePluginOptions, VitePluginOptionsInput };
54
+ export type { HttpMethod, MokupPluginOptions, PlaygroundOptionsInput, RequestHandler, RouteDirectoryConfig, RouteResponse, RouteRule, RuntimeMode, ServiceWorkerOptions, VitePluginOptions, VitePluginOptionsInput };
package/dist/index.d.mts CHANGED
@@ -20,6 +20,10 @@ interface ServiceWorkerOptions {
20
20
  fallback?: boolean;
21
21
  basePath?: string | string[];
22
22
  }
23
+ type PlaygroundOptionsInput = boolean | {
24
+ path?: string;
25
+ enabled?: boolean;
26
+ } | undefined;
23
27
  interface RouteDirectoryConfig {
24
28
  headers?: Record<string, string>;
25
29
  status?: number;
@@ -40,11 +44,11 @@ interface VitePluginOptions {
40
44
  log?: boolean;
41
45
  mode?: RuntimeMode;
42
46
  sw?: ServiceWorkerOptions;
43
- playground?: boolean | {
44
- path?: string;
45
- enabled?: boolean;
46
- };
47
47
  }
48
- type VitePluginOptionsInput = VitePluginOptions | VitePluginOptions[];
48
+ interface MokupPluginOptions {
49
+ entries?: VitePluginOptions | VitePluginOptions[];
50
+ playground?: PlaygroundOptionsInput;
51
+ }
52
+ type VitePluginOptionsInput = MokupPluginOptions;
49
53
 
50
- export type { HttpMethod, RequestHandler, RouteDirectoryConfig, RouteResponse, RouteRule, RuntimeMode, ServiceWorkerOptions, VitePluginOptions, VitePluginOptionsInput };
54
+ export type { HttpMethod, MokupPluginOptions, PlaygroundOptionsInput, RequestHandler, RouteDirectoryConfig, RouteResponse, RouteRule, RuntimeMode, ServiceWorkerOptions, VitePluginOptions, VitePluginOptionsInput };
package/dist/index.d.ts CHANGED
@@ -20,6 +20,10 @@ interface ServiceWorkerOptions {
20
20
  fallback?: boolean;
21
21
  basePath?: string | string[];
22
22
  }
23
+ type PlaygroundOptionsInput = boolean | {
24
+ path?: string;
25
+ enabled?: boolean;
26
+ } | undefined;
23
27
  interface RouteDirectoryConfig {
24
28
  headers?: Record<string, string>;
25
29
  status?: number;
@@ -40,11 +44,11 @@ interface VitePluginOptions {
40
44
  log?: boolean;
41
45
  mode?: RuntimeMode;
42
46
  sw?: ServiceWorkerOptions;
43
- playground?: boolean | {
44
- path?: string;
45
- enabled?: boolean;
46
- };
47
47
  }
48
- type VitePluginOptionsInput = VitePluginOptions | VitePluginOptions[];
48
+ interface MokupPluginOptions {
49
+ entries?: VitePluginOptions | VitePluginOptions[];
50
+ playground?: PlaygroundOptionsInput;
51
+ }
52
+ type VitePluginOptionsInput = MokupPluginOptions;
49
53
 
50
- export type { HttpMethod, RequestHandler, RouteDirectoryConfig, RouteResponse, RouteRule, RuntimeMode, ServiceWorkerOptions, VitePluginOptions, VitePluginOptionsInput };
54
+ export type { HttpMethod, MokupPluginOptions, PlaygroundOptionsInput, RequestHandler, RouteDirectoryConfig, RouteResponse, RouteRule, RuntimeMode, ServiceWorkerOptions, VitePluginOptions, VitePluginOptionsInput };
@@ -350,7 +350,7 @@ function createMiddleware(getApp, logger) {
350
350
  };
351
351
  }
352
352
 
353
- const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/mokup.C7VW7pSP.cjs', document.baseURI).href)));
353
+ const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/mokup.CvPjMpMJ.cjs', document.baseURI).href)));
354
354
  const mimeTypes = {
355
355
  ".html": "text/html; charset=utf-8",
356
356
  ".css": "text/css; charset=utf-8",
@@ -584,14 +584,21 @@ function toPlaygroundRoute(route, root, groups) {
584
584
  }
585
585
  function toPlaygroundDisabledRoute(route, root, groups) {
586
586
  const matchedGroup = resolveRouteGroup(route.file, groups);
587
- return {
587
+ const disabled = {
588
588
  file: formatRouteFile(route.file, root),
589
- reason: normalizeDisabledReason(route.reason),
590
- method: route.method,
591
- url: route.url,
592
- groupKey: matchedGroup?.key,
593
- group: matchedGroup?.label
589
+ reason: normalizeDisabledReason(route.reason)
594
590
  };
591
+ if (typeof route.method !== "undefined") {
592
+ disabled.method = route.method;
593
+ }
594
+ if (typeof route.url !== "undefined") {
595
+ disabled.url = route.url;
596
+ }
597
+ if (matchedGroup) {
598
+ disabled.groupKey = matchedGroup.key;
599
+ disabled.group = matchedGroup.label;
600
+ }
601
+ return disabled;
595
602
  }
596
603
  function createPlaygroundMiddleware(params) {
597
604
  const distDir = resolvePlaygroundDist();
@@ -795,7 +802,7 @@ const configExtensions = [".ts", ".js", ".mjs", ".cjs"];
795
802
  async function loadModule$1(file) {
796
803
  const ext = configExtensions.find((extension) => file.endsWith(extension));
797
804
  if (ext === ".cjs") {
798
- const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/mokup.C7VW7pSP.cjs', document.baseURI).href)));
805
+ const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/mokup.CvPjMpMJ.cjs', document.baseURI).href)));
799
806
  delete require$1.cache[file];
800
807
  return require$1(file);
801
808
  }
@@ -988,7 +995,7 @@ function isSupportedFile(file) {
988
995
  async function loadModule(file) {
989
996
  const ext = pathe.extname(file).toLowerCase();
990
997
  if (ext === ".cjs") {
991
- const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/mokup.C7VW7pSP.cjs', document.baseURI).href)));
998
+ const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/mokup.CvPjMpMJ.cjs', document.baseURI).href)));
992
999
  delete require$1.cache[file];
993
1000
  return require$1(file);
994
1001
  }
@@ -1103,6 +1110,14 @@ function resolveSkipRoute(params) {
1103
1110
  url: resolved.template
1104
1111
  };
1105
1112
  }
1113
+ function buildSkipInfo(file, reason, resolved) {
1114
+ const info = { file, reason };
1115
+ if (resolved) {
1116
+ info.method = resolved.method;
1117
+ info.url = resolved.url;
1118
+ }
1119
+ return info;
1120
+ }
1106
1121
  async function scanRoutes(params) {
1107
1122
  const routes = [];
1108
1123
  const seen = /* @__PURE__ */ new Set();
@@ -1130,12 +1145,7 @@ async function scanRoutes(params) {
1130
1145
  rootDir: fileInfo.rootDir,
1131
1146
  prefix: params.prefix
1132
1147
  });
1133
- params.onSkip?.({
1134
- file: fileInfo.file,
1135
- reason: "disabled-dir",
1136
- method: resolved?.method,
1137
- url: resolved?.url
1138
- });
1148
+ params.onSkip?.(buildSkipInfo(fileInfo.file, "disabled-dir", resolved));
1139
1149
  }
1140
1150
  continue;
1141
1151
  }
@@ -1147,12 +1157,7 @@ async function scanRoutes(params) {
1147
1157
  rootDir: fileInfo.rootDir,
1148
1158
  prefix: params.prefix
1149
1159
  });
1150
- params.onSkip?.({
1151
- file: fileInfo.file,
1152
- reason: "ignore-prefix",
1153
- method: resolved?.method,
1154
- url: resolved?.url
1155
- });
1160
+ params.onSkip?.(buildSkipInfo(fileInfo.file, "ignore-prefix", resolved));
1156
1161
  }
1157
1162
  continue;
1158
1163
  }
@@ -1169,12 +1174,7 @@ async function scanRoutes(params) {
1169
1174
  prefix: params.prefix
1170
1175
  });
1171
1176
  const reason = effectiveExclude && matchesFilter(fileInfo.file, void 0, effectiveExclude) ? "exclude" : "include";
1172
- params.onSkip?.({
1173
- file: fileInfo.file,
1174
- reason,
1175
- method: resolved?.method,
1176
- url: resolved?.url
1177
- });
1177
+ params.onSkip?.(buildSkipInfo(fileInfo.file, reason, resolved));
1178
1178
  }
1179
1179
  continue;
1180
1180
  }
@@ -1195,12 +1195,7 @@ async function scanRoutes(params) {
1195
1195
  prefix: params.prefix,
1196
1196
  derived
1197
1197
  });
1198
- params.onSkip?.({
1199
- file: fileInfo.file,
1200
- reason: "disabled",
1201
- method: resolved2?.method,
1202
- url: resolved2?.url
1203
- });
1198
+ params.onSkip?.(buildSkipInfo(fileInfo.file, "disabled", resolved2));
1204
1199
  }
1205
1200
  continue;
1206
1201
  }
@@ -581,14 +581,21 @@ function toPlaygroundRoute(route, root, groups) {
581
581
  }
582
582
  function toPlaygroundDisabledRoute(route, root, groups) {
583
583
  const matchedGroup = resolveRouteGroup(route.file, groups);
584
- return {
584
+ const disabled = {
585
585
  file: formatRouteFile(route.file, root),
586
- reason: normalizeDisabledReason(route.reason),
587
- method: route.method,
588
- url: route.url,
589
- groupKey: matchedGroup?.key,
590
- group: matchedGroup?.label
586
+ reason: normalizeDisabledReason(route.reason)
591
587
  };
588
+ if (typeof route.method !== "undefined") {
589
+ disabled.method = route.method;
590
+ }
591
+ if (typeof route.url !== "undefined") {
592
+ disabled.url = route.url;
593
+ }
594
+ if (matchedGroup) {
595
+ disabled.groupKey = matchedGroup.key;
596
+ disabled.group = matchedGroup.label;
597
+ }
598
+ return disabled;
592
599
  }
593
600
  function createPlaygroundMiddleware(params) {
594
601
  const distDir = resolvePlaygroundDist();
@@ -1100,6 +1107,14 @@ function resolveSkipRoute(params) {
1100
1107
  url: resolved.template
1101
1108
  };
1102
1109
  }
1110
+ function buildSkipInfo(file, reason, resolved) {
1111
+ const info = { file, reason };
1112
+ if (resolved) {
1113
+ info.method = resolved.method;
1114
+ info.url = resolved.url;
1115
+ }
1116
+ return info;
1117
+ }
1103
1118
  async function scanRoutes(params) {
1104
1119
  const routes = [];
1105
1120
  const seen = /* @__PURE__ */ new Set();
@@ -1127,12 +1142,7 @@ async function scanRoutes(params) {
1127
1142
  rootDir: fileInfo.rootDir,
1128
1143
  prefix: params.prefix
1129
1144
  });
1130
- params.onSkip?.({
1131
- file: fileInfo.file,
1132
- reason: "disabled-dir",
1133
- method: resolved?.method,
1134
- url: resolved?.url
1135
- });
1145
+ params.onSkip?.(buildSkipInfo(fileInfo.file, "disabled-dir", resolved));
1136
1146
  }
1137
1147
  continue;
1138
1148
  }
@@ -1144,12 +1154,7 @@ async function scanRoutes(params) {
1144
1154
  rootDir: fileInfo.rootDir,
1145
1155
  prefix: params.prefix
1146
1156
  });
1147
- params.onSkip?.({
1148
- file: fileInfo.file,
1149
- reason: "ignore-prefix",
1150
- method: resolved?.method,
1151
- url: resolved?.url
1152
- });
1157
+ params.onSkip?.(buildSkipInfo(fileInfo.file, "ignore-prefix", resolved));
1153
1158
  }
1154
1159
  continue;
1155
1160
  }
@@ -1166,12 +1171,7 @@ async function scanRoutes(params) {
1166
1171
  prefix: params.prefix
1167
1172
  });
1168
1173
  const reason = effectiveExclude && matchesFilter(fileInfo.file, void 0, effectiveExclude) ? "exclude" : "include";
1169
- params.onSkip?.({
1170
- file: fileInfo.file,
1171
- reason,
1172
- method: resolved?.method,
1173
- url: resolved?.url
1174
- });
1174
+ params.onSkip?.(buildSkipInfo(fileInfo.file, reason, resolved));
1175
1175
  }
1176
1176
  continue;
1177
1177
  }
@@ -1192,12 +1192,7 @@ async function scanRoutes(params) {
1192
1192
  prefix: params.prefix,
1193
1193
  derived
1194
1194
  });
1195
- params.onSkip?.({
1196
- file: fileInfo.file,
1197
- reason: "disabled",
1198
- method: resolved2?.method,
1199
- url: resolved2?.url
1200
- });
1195
+ params.onSkip?.(buildSkipInfo(fileInfo.file, "disabled", resolved2));
1201
1196
  }
1202
1197
  continue;
1203
1198
  }
package/dist/vite.cjs CHANGED
@@ -1,10 +1,11 @@
1
1
  'use strict';
2
2
 
3
3
  const node_fs = require('node:fs');
4
+ const node_path = require('node:path');
4
5
  const process = require('node:process');
5
6
  const node_url = require('node:url');
6
7
  const chokidar = require('@mokup/shared/chokidar');
7
- const sw = require('./shared/mokup.C7VW7pSP.cjs');
8
+ const sw = require('./shared/mokup.CvPjMpMJ.cjs');
8
9
  require('node:buffer');
9
10
  require('@mokup/shared/hono');
10
11
  require('node:module');
@@ -42,17 +43,41 @@ function buildRouteSignature(routes, disabledRoutes) {
42
43
  function isViteDevServer(server) {
43
44
  return !!server && "ws" in server;
44
45
  }
45
- function normalizeOptions(options) {
46
- const list = Array.isArray(options) ? options : [options];
47
- return list.length > 0 ? list : [{}];
46
+ const legacyEntryKeys = [
47
+ "dir",
48
+ "prefix",
49
+ "include",
50
+ "exclude",
51
+ "ignorePrefix",
52
+ "watch",
53
+ "log",
54
+ "mode",
55
+ "sw"
56
+ ];
57
+ function isLegacyEntryOptions(value) {
58
+ return legacyEntryKeys.some((key) => key in value);
48
59
  }
49
- function resolvePlaygroundInput(list) {
50
- for (const entry of list) {
51
- if (typeof entry.playground !== "undefined") {
52
- return entry.playground;
53
- }
60
+ function normalizeMokupOptions(options) {
61
+ if (!options) {
62
+ return {};
54
63
  }
55
- return void 0;
64
+ if (Array.isArray(options)) {
65
+ throw new TypeError("[mokup] Invalid config: use mokup({ entries: [...] }) instead of mokup([...]).");
66
+ }
67
+ if (typeof options !== "object") {
68
+ return {};
69
+ }
70
+ if (isLegacyEntryOptions(options)) {
71
+ throw new Error(
72
+ "[mokup] Invalid config: use mokup({ entries: { ... } }) instead of mokup({ dir, prefix, ... })."
73
+ );
74
+ }
75
+ return options;
76
+ }
77
+ function normalizeOptions(options) {
78
+ const entries = options.entries;
79
+ const list = Array.isArray(entries) ? entries : entries ? [entries] : [{}];
80
+ return list.length > 0 ? list : [{}];
56
81
  }
57
82
  function normalizeBase(base) {
58
83
  if (!base) {
@@ -115,6 +140,24 @@ function addMiddlewareFirst(server, middleware) {
115
140
  }
116
141
  server.middlewares.use(middleware);
117
142
  }
143
+ function normalizeWatcherFile(file, rootDir) {
144
+ if (!file) {
145
+ return file;
146
+ }
147
+ if (node_path.isAbsolute(file)) {
148
+ return file;
149
+ }
150
+ return node_path.resolve(rootDir, file);
151
+ }
152
+ function normalizeRawWatcherPath(rawPath) {
153
+ if (typeof rawPath === "string") {
154
+ return rawPath;
155
+ }
156
+ if (rawPath && typeof rawPath.toString === "function") {
157
+ return rawPath.toString();
158
+ }
159
+ return "";
160
+ }
118
161
  function createMokupPlugin(options = {}) {
119
162
  let root = process.cwd();
120
163
  let base = "/";
@@ -128,10 +171,11 @@ function createMokupPlugin(options = {}) {
128
171
  let previewWatcher = null;
129
172
  let currentServer = null;
130
173
  let lastSignature = null;
131
- const optionList = normalizeOptions(options);
174
+ const normalizedOptions = normalizeMokupOptions(options);
175
+ const optionList = normalizeOptions(normalizedOptions);
132
176
  const logEnabled = optionList.every((entry) => entry.log !== false);
133
177
  const watchEnabled = optionList.every((entry) => entry.watch !== false);
134
- const playgroundConfig = sw.resolvePlaygroundOptions(resolvePlaygroundInput(optionList));
178
+ const playgroundConfig = sw.resolvePlaygroundOptions(normalizedOptions.playground);
135
179
  const logger = sw.createLogger(logEnabled);
136
180
  const hasSwEntries = optionList.some((entry) => entry.mode === "sw");
137
181
  const swConfig = sw.resolveSwConfig(optionList, logger);
@@ -425,18 +469,26 @@ function createMokupPlugin(options = {}) {
425
469
  const dirs = resolveAllDirs();
426
470
  server.watcher.add(dirs);
427
471
  const scheduleRefresh = sw.createDebouncer(80, () => refreshRoutes(server));
428
- server.watcher.on("add", (file) => {
429
- if (sw.isInDirs(file, dirs)) {
472
+ const handleWatchedFile = (file) => {
473
+ const resolvedFile = normalizeWatcherFile(file, server.config.root ?? root);
474
+ if (sw.isInDirs(resolvedFile, dirs)) {
430
475
  scheduleRefresh();
431
476
  }
432
- });
433
- server.watcher.on("change", (file) => {
434
- if (sw.isInDirs(file, dirs)) {
435
- scheduleRefresh();
477
+ };
478
+ server.watcher.on("add", handleWatchedFile);
479
+ server.watcher.on("change", handleWatchedFile);
480
+ server.watcher.on("unlink", handleWatchedFile);
481
+ server.watcher.on("raw", (eventName, rawPath, details) => {
482
+ if (eventName !== "rename") {
483
+ return;
436
484
  }
437
- });
438
- server.watcher.on("unlink", (file) => {
439
- if (sw.isInDirs(file, dirs)) {
485
+ const candidate = normalizeRawWatcherPath(rawPath);
486
+ if (!candidate) {
487
+ return;
488
+ }
489
+ const baseDir = typeof details === "object" && details && "watchedPath" in details ? details.watchedPath ?? (server.config.root ?? root) : server.config.root ?? root;
490
+ const resolvedFile = normalizeWatcherFile(candidate, baseDir);
491
+ if (sw.isInDirs(resolvedFile, dirs)) {
440
492
  scheduleRefresh();
441
493
  }
442
494
  });
@@ -481,9 +533,29 @@ function createMokupPlugin(options = {}) {
481
533
  const watcher = chokidar__default.watch(dirs, { ignoreInitial: true });
482
534
  previewWatcher = watcher;
483
535
  const scheduleRefresh = sw.createDebouncer(80, () => refreshRoutes(server));
484
- watcher.on("add", scheduleRefresh);
485
- watcher.on("change", scheduleRefresh);
486
- watcher.on("unlink", scheduleRefresh);
536
+ const handleWatchedFile = (file) => {
537
+ const resolvedFile = normalizeWatcherFile(file, server.config.root ?? root);
538
+ if (sw.isInDirs(resolvedFile, dirs)) {
539
+ scheduleRefresh();
540
+ }
541
+ };
542
+ watcher.on("add", handleWatchedFile);
543
+ watcher.on("change", handleWatchedFile);
544
+ watcher.on("unlink", handleWatchedFile);
545
+ watcher.on("raw", (eventName, rawPath, details) => {
546
+ if (eventName !== "rename") {
547
+ return;
548
+ }
549
+ const candidate = normalizeRawWatcherPath(rawPath);
550
+ if (!candidate) {
551
+ return;
552
+ }
553
+ const baseDir = typeof details === "object" && details && "watchedPath" in details ? details.watchedPath ?? (server.config.root ?? root) : server.config.root ?? root;
554
+ const resolvedFile = normalizeWatcherFile(candidate, baseDir);
555
+ if (sw.isInDirs(resolvedFile, dirs)) {
556
+ scheduleRefresh();
557
+ }
558
+ });
487
559
  server.httpServer?.once("close", () => {
488
560
  previewWatcher?.close();
489
561
  previewWatcher = null;
package/dist/vite.d.cts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { Plugin } from 'vite';
2
- import { VitePluginOptionsInput } from './index.cjs';
3
- export { HttpMethod, RequestHandler, RouteDirectoryConfig, RouteResponse, RouteRule, RuntimeMode, ServiceWorkerOptions, VitePluginOptions } from './index.cjs';
2
+ import { MokupPluginOptions } from './index.cjs';
3
+ export { HttpMethod, PlaygroundOptionsInput, RequestHandler, RouteDirectoryConfig, RouteResponse, RouteRule, RuntimeMode, ServiceWorkerOptions, VitePluginOptions, VitePluginOptionsInput } from './index.cjs';
4
4
  export { Context, MiddlewareHandler } from '@mokup/shared/hono';
5
5
 
6
- declare function createMokupPlugin(options?: VitePluginOptionsInput): Plugin;
6
+ declare function createMokupPlugin(options?: MokupPluginOptions): Plugin;
7
7
 
8
8
  // @ts-ignore
9
9
  export = createMokupPlugin;
10
- export { VitePluginOptionsInput };
10
+ export { MokupPluginOptions };
package/dist/vite.d.mts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { Plugin } from 'vite';
2
- import { VitePluginOptionsInput } from './index.mjs';
3
- export { HttpMethod, RequestHandler, RouteDirectoryConfig, RouteResponse, RouteRule, RuntimeMode, ServiceWorkerOptions, VitePluginOptions } from './index.mjs';
2
+ import { MokupPluginOptions } from './index.mjs';
3
+ export { HttpMethod, PlaygroundOptionsInput, RequestHandler, RouteDirectoryConfig, RouteResponse, RouteRule, RuntimeMode, ServiceWorkerOptions, VitePluginOptions, VitePluginOptionsInput } from './index.mjs';
4
4
  export { Context, MiddlewareHandler } from '@mokup/shared/hono';
5
5
 
6
- declare function createMokupPlugin(options?: VitePluginOptionsInput): Plugin;
6
+ declare function createMokupPlugin(options?: MokupPluginOptions): Plugin;
7
7
 
8
- export { VitePluginOptionsInput, createMokupPlugin as default };
8
+ export { MokupPluginOptions, createMokupPlugin as default };
package/dist/vite.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { Plugin } from 'vite';
2
- import { VitePluginOptionsInput } from './index.js';
3
- export { HttpMethod, RequestHandler, RouteDirectoryConfig, RouteResponse, RouteRule, RuntimeMode, ServiceWorkerOptions, VitePluginOptions } from './index.js';
2
+ import { MokupPluginOptions } from './index.js';
3
+ export { HttpMethod, PlaygroundOptionsInput, RequestHandler, RouteDirectoryConfig, RouteResponse, RouteRule, RuntimeMode, ServiceWorkerOptions, VitePluginOptions, VitePluginOptionsInput } from './index.js';
4
4
  export { Context, MiddlewareHandler } from '@mokup/shared/hono';
5
5
 
6
- declare function createMokupPlugin(options?: VitePluginOptionsInput): Plugin;
6
+ declare function createMokupPlugin(options?: MokupPluginOptions): Plugin;
7
7
 
8
8
  // @ts-ignore
9
9
  export = createMokupPlugin;
10
- export { VitePluginOptionsInput };
10
+ export { MokupPluginOptions };
package/dist/vite.mjs CHANGED
@@ -1,8 +1,9 @@
1
1
  import { existsSync } from 'node:fs';
2
+ import { isAbsolute, resolve } from 'node:path';
2
3
  import { cwd } from 'node:process';
3
4
  import { fileURLToPath } from 'node:url';
4
5
  import chokidar from '@mokup/shared/chokidar';
5
- import { r as resolvePlaygroundOptions, a as resolveSwConfig, b as resolveSwUnregisterConfig, c as createPlaygroundMiddleware, d as buildSwScript, e as createLogger, f as createMiddleware, g as createDebouncer, i as isInDirs, h as resolveDirs, s as scanRoutes, j as sortRoutes, k as createHonoApp } from './shared/mokup.Da2mv7KS.mjs';
6
+ import { r as resolvePlaygroundOptions, a as resolveSwConfig, b as resolveSwUnregisterConfig, c as createPlaygroundMiddleware, d as buildSwScript, e as createLogger, f as createMiddleware, i as isInDirs, g as createDebouncer, h as resolveDirs, s as scanRoutes, j as sortRoutes, k as createHonoApp } from './shared/mokup.U2S5CHgY.mjs';
6
7
  import 'node:buffer';
7
8
  import '@mokup/shared/hono';
8
9
  import 'node:module';
@@ -35,17 +36,41 @@ function buildRouteSignature(routes, disabledRoutes) {
35
36
  function isViteDevServer(server) {
36
37
  return !!server && "ws" in server;
37
38
  }
38
- function normalizeOptions(options) {
39
- const list = Array.isArray(options) ? options : [options];
40
- return list.length > 0 ? list : [{}];
39
+ const legacyEntryKeys = [
40
+ "dir",
41
+ "prefix",
42
+ "include",
43
+ "exclude",
44
+ "ignorePrefix",
45
+ "watch",
46
+ "log",
47
+ "mode",
48
+ "sw"
49
+ ];
50
+ function isLegacyEntryOptions(value) {
51
+ return legacyEntryKeys.some((key) => key in value);
41
52
  }
42
- function resolvePlaygroundInput(list) {
43
- for (const entry of list) {
44
- if (typeof entry.playground !== "undefined") {
45
- return entry.playground;
46
- }
53
+ function normalizeMokupOptions(options) {
54
+ if (!options) {
55
+ return {};
47
56
  }
48
- return void 0;
57
+ if (Array.isArray(options)) {
58
+ throw new TypeError("[mokup] Invalid config: use mokup({ entries: [...] }) instead of mokup([...]).");
59
+ }
60
+ if (typeof options !== "object") {
61
+ return {};
62
+ }
63
+ if (isLegacyEntryOptions(options)) {
64
+ throw new Error(
65
+ "[mokup] Invalid config: use mokup({ entries: { ... } }) instead of mokup({ dir, prefix, ... })."
66
+ );
67
+ }
68
+ return options;
69
+ }
70
+ function normalizeOptions(options) {
71
+ const entries = options.entries;
72
+ const list = Array.isArray(entries) ? entries : entries ? [entries] : [{}];
73
+ return list.length > 0 ? list : [{}];
49
74
  }
50
75
  function normalizeBase(base) {
51
76
  if (!base) {
@@ -108,6 +133,24 @@ function addMiddlewareFirst(server, middleware) {
108
133
  }
109
134
  server.middlewares.use(middleware);
110
135
  }
136
+ function normalizeWatcherFile(file, rootDir) {
137
+ if (!file) {
138
+ return file;
139
+ }
140
+ if (isAbsolute(file)) {
141
+ return file;
142
+ }
143
+ return resolve(rootDir, file);
144
+ }
145
+ function normalizeRawWatcherPath(rawPath) {
146
+ if (typeof rawPath === "string") {
147
+ return rawPath;
148
+ }
149
+ if (rawPath && typeof rawPath.toString === "function") {
150
+ return rawPath.toString();
151
+ }
152
+ return "";
153
+ }
111
154
  function createMokupPlugin(options = {}) {
112
155
  let root = cwd();
113
156
  let base = "/";
@@ -121,10 +164,11 @@ function createMokupPlugin(options = {}) {
121
164
  let previewWatcher = null;
122
165
  let currentServer = null;
123
166
  let lastSignature = null;
124
- const optionList = normalizeOptions(options);
167
+ const normalizedOptions = normalizeMokupOptions(options);
168
+ const optionList = normalizeOptions(normalizedOptions);
125
169
  const logEnabled = optionList.every((entry) => entry.log !== false);
126
170
  const watchEnabled = optionList.every((entry) => entry.watch !== false);
127
- const playgroundConfig = resolvePlaygroundOptions(resolvePlaygroundInput(optionList));
171
+ const playgroundConfig = resolvePlaygroundOptions(normalizedOptions.playground);
128
172
  const logger = createLogger(logEnabled);
129
173
  const hasSwEntries = optionList.some((entry) => entry.mode === "sw");
130
174
  const swConfig = resolveSwConfig(optionList, logger);
@@ -418,18 +462,26 @@ function createMokupPlugin(options = {}) {
418
462
  const dirs = resolveAllDirs();
419
463
  server.watcher.add(dirs);
420
464
  const scheduleRefresh = createDebouncer(80, () => refreshRoutes(server));
421
- server.watcher.on("add", (file) => {
422
- if (isInDirs(file, dirs)) {
465
+ const handleWatchedFile = (file) => {
466
+ const resolvedFile = normalizeWatcherFile(file, server.config.root ?? root);
467
+ if (isInDirs(resolvedFile, dirs)) {
423
468
  scheduleRefresh();
424
469
  }
425
- });
426
- server.watcher.on("change", (file) => {
427
- if (isInDirs(file, dirs)) {
428
- scheduleRefresh();
470
+ };
471
+ server.watcher.on("add", handleWatchedFile);
472
+ server.watcher.on("change", handleWatchedFile);
473
+ server.watcher.on("unlink", handleWatchedFile);
474
+ server.watcher.on("raw", (eventName, rawPath, details) => {
475
+ if (eventName !== "rename") {
476
+ return;
429
477
  }
430
- });
431
- server.watcher.on("unlink", (file) => {
432
- if (isInDirs(file, dirs)) {
478
+ const candidate = normalizeRawWatcherPath(rawPath);
479
+ if (!candidate) {
480
+ return;
481
+ }
482
+ const baseDir = typeof details === "object" && details && "watchedPath" in details ? details.watchedPath ?? (server.config.root ?? root) : server.config.root ?? root;
483
+ const resolvedFile = normalizeWatcherFile(candidate, baseDir);
484
+ if (isInDirs(resolvedFile, dirs)) {
433
485
  scheduleRefresh();
434
486
  }
435
487
  });
@@ -474,9 +526,29 @@ function createMokupPlugin(options = {}) {
474
526
  const watcher = chokidar.watch(dirs, { ignoreInitial: true });
475
527
  previewWatcher = watcher;
476
528
  const scheduleRefresh = createDebouncer(80, () => refreshRoutes(server));
477
- watcher.on("add", scheduleRefresh);
478
- watcher.on("change", scheduleRefresh);
479
- watcher.on("unlink", scheduleRefresh);
529
+ const handleWatchedFile = (file) => {
530
+ const resolvedFile = normalizeWatcherFile(file, server.config.root ?? root);
531
+ if (isInDirs(resolvedFile, dirs)) {
532
+ scheduleRefresh();
533
+ }
534
+ };
535
+ watcher.on("add", handleWatchedFile);
536
+ watcher.on("change", handleWatchedFile);
537
+ watcher.on("unlink", handleWatchedFile);
538
+ watcher.on("raw", (eventName, rawPath, details) => {
539
+ if (eventName !== "rename") {
540
+ return;
541
+ }
542
+ const candidate = normalizeRawWatcherPath(rawPath);
543
+ if (!candidate) {
544
+ return;
545
+ }
546
+ const baseDir = typeof details === "object" && details && "watchedPath" in details ? details.watchedPath ?? (server.config.root ?? root) : server.config.root ?? root;
547
+ const resolvedFile = normalizeWatcherFile(candidate, baseDir);
548
+ if (isInDirs(resolvedFile, dirs)) {
549
+ scheduleRefresh();
550
+ }
551
+ });
480
552
  server.httpServer?.once("close", () => {
481
553
  previewWatcher?.close();
482
554
  previewWatcher = null;
package/dist/webpack.cjs CHANGED
@@ -7,7 +7,7 @@ const process = require('node:process');
7
7
  const chokidar = require('@mokup/shared/chokidar');
8
8
  const esbuild = require('@mokup/shared/esbuild');
9
9
  const pathe = require('@mokup/shared/pathe');
10
- const sw = require('./shared/mokup.C7VW7pSP.cjs');
10
+ const sw = require('./shared/mokup.CvPjMpMJ.cjs');
11
11
  require('node:buffer');
12
12
  require('@mokup/shared/hono');
13
13
  require('node:fs');
@@ -22,17 +22,41 @@ const chokidar__default = /*#__PURE__*/_interopDefaultCompat(chokidar);
22
22
 
23
23
  const pluginName = "mokup:webpack";
24
24
  const lifecycleBaseName = "mokup-sw-lifecycle.js";
25
- function normalizeOptions(options) {
26
- const list = Array.isArray(options) ? options : [options];
27
- return list.length > 0 ? list : [{}];
25
+ const legacyEntryKeys = [
26
+ "dir",
27
+ "prefix",
28
+ "include",
29
+ "exclude",
30
+ "ignorePrefix",
31
+ "watch",
32
+ "log",
33
+ "mode",
34
+ "sw"
35
+ ];
36
+ function isLegacyEntryOptions(value) {
37
+ return legacyEntryKeys.some((key) => key in value);
28
38
  }
29
- function resolvePlaygroundInput(list) {
30
- for (const entry of list) {
31
- if (typeof entry.playground !== "undefined") {
32
- return entry.playground;
33
- }
39
+ function normalizeMokupOptions(options) {
40
+ if (!options) {
41
+ return {};
42
+ }
43
+ if (Array.isArray(options)) {
44
+ throw new TypeError("[mokup] Invalid config: use mokup({ entries: [...] }) instead of mokup([...]).");
45
+ }
46
+ if (typeof options !== "object") {
47
+ return {};
34
48
  }
35
- return void 0;
49
+ if (isLegacyEntryOptions(options)) {
50
+ throw new Error(
51
+ "[mokup] Invalid config: use mokup({ entries: { ... } }) instead of mokup({ dir, prefix, ... })."
52
+ );
53
+ }
54
+ return options;
55
+ }
56
+ function normalizeOptions(options) {
57
+ const entries = options.entries;
58
+ const list = Array.isArray(entries) ? entries : entries ? [entries] : [{}];
59
+ return list.length > 0 ? list : [{}];
36
60
  }
37
61
  function normalizeBase(base) {
38
62
  if (!base) {
@@ -165,10 +189,11 @@ function resolveHtmlWebpackPlugin() {
165
189
  }
166
190
  }
167
191
  function createMokupWebpackPlugin(options = {}) {
168
- const optionList = normalizeOptions(options);
192
+ const normalizedOptions = normalizeMokupOptions(options);
193
+ const optionList = normalizeOptions(normalizedOptions);
169
194
  const logEnabled = optionList.every((entry) => entry.log !== false);
170
195
  const watchEnabled = optionList.every((entry) => entry.watch !== false);
171
- const playgroundConfig = sw.resolvePlaygroundOptions(resolvePlaygroundInput(optionList));
196
+ const playgroundConfig = sw.resolvePlaygroundOptions(normalizedOptions.playground);
172
197
  const logger = sw.createLogger(logEnabled);
173
198
  const hasSwEntries = optionList.some((entry) => entry.mode === "sw");
174
199
  const swConfig = sw.resolveSwConfig(optionList, logger);
@@ -1,5 +1,5 @@
1
- import { VitePluginOptionsInput } from './index.cjs';
2
- export { HttpMethod, RequestHandler, RouteDirectoryConfig, RouteResponse, RouteRule, RuntimeMode, ServiceWorkerOptions, VitePluginOptions } from './index.cjs';
1
+ import { MokupPluginOptions } from './index.cjs';
2
+ export { HttpMethod, PlaygroundOptionsInput, RequestHandler, RouteDirectoryConfig, RouteResponse, RouteRule, RuntimeMode, ServiceWorkerOptions, VitePluginOptions, VitePluginOptionsInput } from './index.cjs';
3
3
  import { IncomingMessage, ServerResponse } from 'node:http';
4
4
  export { Context, MiddlewareHandler } from '@mokup/shared/hono';
5
5
 
@@ -81,8 +81,8 @@ interface WebpackCompiler {
81
81
  };
82
82
  };
83
83
  }
84
- declare function createMokupWebpackPlugin(options?: VitePluginOptionsInput): WebpackPluginInstance;
84
+ declare function createMokupWebpackPlugin(options?: MokupPluginOptions): WebpackPluginInstance;
85
85
 
86
86
  // @ts-ignore
87
87
  export = createMokupWebpackPlugin;
88
- export { VitePluginOptionsInput, createMokupWebpackPlugin };
88
+ export { MokupPluginOptions, createMokupWebpackPlugin };
@@ -1,5 +1,5 @@
1
- import { VitePluginOptionsInput } from './index.mjs';
2
- export { HttpMethod, RequestHandler, RouteDirectoryConfig, RouteResponse, RouteRule, RuntimeMode, ServiceWorkerOptions, VitePluginOptions } from './index.mjs';
1
+ import { MokupPluginOptions } from './index.mjs';
2
+ export { HttpMethod, PlaygroundOptionsInput, RequestHandler, RouteDirectoryConfig, RouteResponse, RouteRule, RuntimeMode, ServiceWorkerOptions, VitePluginOptions, VitePluginOptionsInput } from './index.mjs';
3
3
  import { IncomingMessage, ServerResponse } from 'node:http';
4
4
  export { Context, MiddlewareHandler } from '@mokup/shared/hono';
5
5
 
@@ -81,6 +81,6 @@ interface WebpackCompiler {
81
81
  };
82
82
  };
83
83
  }
84
- declare function createMokupWebpackPlugin(options?: VitePluginOptionsInput): WebpackPluginInstance;
84
+ declare function createMokupWebpackPlugin(options?: MokupPluginOptions): WebpackPluginInstance;
85
85
 
86
- export { VitePluginOptionsInput, createMokupWebpackPlugin, createMokupWebpackPlugin as default };
86
+ export { MokupPluginOptions, createMokupWebpackPlugin, createMokupWebpackPlugin as default };
package/dist/webpack.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { VitePluginOptionsInput } from './index.js';
2
- export { HttpMethod, RequestHandler, RouteDirectoryConfig, RouteResponse, RouteRule, RuntimeMode, ServiceWorkerOptions, VitePluginOptions } from './index.js';
1
+ import { MokupPluginOptions } from './index.js';
2
+ export { HttpMethod, PlaygroundOptionsInput, RequestHandler, RouteDirectoryConfig, RouteResponse, RouteRule, RuntimeMode, ServiceWorkerOptions, VitePluginOptions, VitePluginOptionsInput } from './index.js';
3
3
  import { IncomingMessage, ServerResponse } from 'node:http';
4
4
  export { Context, MiddlewareHandler } from '@mokup/shared/hono';
5
5
 
@@ -81,8 +81,8 @@ interface WebpackCompiler {
81
81
  };
82
82
  };
83
83
  }
84
- declare function createMokupWebpackPlugin(options?: VitePluginOptionsInput): WebpackPluginInstance;
84
+ declare function createMokupWebpackPlugin(options?: MokupPluginOptions): WebpackPluginInstance;
85
85
 
86
86
  // @ts-ignore
87
87
  export = createMokupWebpackPlugin;
88
- export { VitePluginOptionsInput, createMokupWebpackPlugin };
88
+ export { MokupPluginOptions, createMokupWebpackPlugin };
package/dist/webpack.mjs CHANGED
@@ -3,7 +3,7 @@ import { cwd } from 'node:process';
3
3
  import chokidar from '@mokup/shared/chokidar';
4
4
  import { build } from '@mokup/shared/esbuild';
5
5
  import { isAbsolute, resolve } from '@mokup/shared/pathe';
6
- import { r as resolvePlaygroundOptions, a as resolveSwConfig, b as resolveSwUnregisterConfig, c as createPlaygroundMiddleware, e as createLogger, f as createMiddleware, i as isInDirs, g as createDebouncer, h as resolveDirs, s as scanRoutes, j as sortRoutes, k as createHonoApp, d as buildSwScript, t as toPosix } from './shared/mokup.Da2mv7KS.mjs';
6
+ import { r as resolvePlaygroundOptions, a as resolveSwConfig, b as resolveSwUnregisterConfig, c as createPlaygroundMiddleware, e as createLogger, f as createMiddleware, i as isInDirs, g as createDebouncer, h as resolveDirs, s as scanRoutes, j as sortRoutes, k as createHonoApp, d as buildSwScript, t as toPosix } from './shared/mokup.U2S5CHgY.mjs';
7
7
  import 'node:buffer';
8
8
  import '@mokup/shared/hono';
9
9
  import 'node:fs';
@@ -13,17 +13,41 @@ import '@mokup/runtime';
13
13
 
14
14
  const pluginName = "mokup:webpack";
15
15
  const lifecycleBaseName = "mokup-sw-lifecycle.js";
16
- function normalizeOptions(options) {
17
- const list = Array.isArray(options) ? options : [options];
18
- return list.length > 0 ? list : [{}];
16
+ const legacyEntryKeys = [
17
+ "dir",
18
+ "prefix",
19
+ "include",
20
+ "exclude",
21
+ "ignorePrefix",
22
+ "watch",
23
+ "log",
24
+ "mode",
25
+ "sw"
26
+ ];
27
+ function isLegacyEntryOptions(value) {
28
+ return legacyEntryKeys.some((key) => key in value);
19
29
  }
20
- function resolvePlaygroundInput(list) {
21
- for (const entry of list) {
22
- if (typeof entry.playground !== "undefined") {
23
- return entry.playground;
24
- }
30
+ function normalizeMokupOptions(options) {
31
+ if (!options) {
32
+ return {};
33
+ }
34
+ if (Array.isArray(options)) {
35
+ throw new TypeError("[mokup] Invalid config: use mokup({ entries: [...] }) instead of mokup([...]).");
36
+ }
37
+ if (typeof options !== "object") {
38
+ return {};
25
39
  }
26
- return void 0;
40
+ if (isLegacyEntryOptions(options)) {
41
+ throw new Error(
42
+ "[mokup] Invalid config: use mokup({ entries: { ... } }) instead of mokup({ dir, prefix, ... })."
43
+ );
44
+ }
45
+ return options;
46
+ }
47
+ function normalizeOptions(options) {
48
+ const entries = options.entries;
49
+ const list = Array.isArray(entries) ? entries : entries ? [entries] : [{}];
50
+ return list.length > 0 ? list : [{}];
27
51
  }
28
52
  function normalizeBase(base) {
29
53
  if (!base) {
@@ -156,10 +180,11 @@ function resolveHtmlWebpackPlugin() {
156
180
  }
157
181
  }
158
182
  function createMokupWebpackPlugin(options = {}) {
159
- const optionList = normalizeOptions(options);
183
+ const normalizedOptions = normalizeMokupOptions(options);
184
+ const optionList = normalizeOptions(normalizedOptions);
160
185
  const logEnabled = optionList.every((entry) => entry.log !== false);
161
186
  const watchEnabled = optionList.every((entry) => entry.watch !== false);
162
- const playgroundConfig = resolvePlaygroundOptions(resolvePlaygroundInput(optionList));
187
+ const playgroundConfig = resolvePlaygroundOptions(normalizedOptions.playground);
163
188
  const logger = createLogger(logEnabled);
164
189
  const hasSwEntries = optionList.some((entry) => entry.mode === "sw");
165
190
  const swConfig = resolveSwConfig(optionList, logger);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mokup",
3
3
  "type": "module",
4
- "version": "1.0.4",
4
+ "version": "2.0.0",
5
5
  "description": "Mock utilities and Vite plugin for mokup.",
6
6
  "license": "MIT",
7
7
  "homepage": "https://mokup.icebreaker.top",
@@ -81,10 +81,10 @@
81
81
  }
82
82
  },
83
83
  "dependencies": {
84
- "@mokup/cli": "1.0.2",
85
- "@mokup/playground": "0.0.8",
84
+ "@mokup/cli": "1.0.3",
85
+ "@mokup/playground": "0.0.9",
86
86
  "@mokup/runtime": "1.0.0",
87
- "@mokup/server": "1.0.4",
87
+ "@mokup/server": "1.1.0",
88
88
  "@mokup/shared": "1.0.0"
89
89
  },
90
90
  "devDependencies": {