mokup 1.0.4 → 2.0.1
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 +14 -8
- package/dist/index.d.mts +14 -8
- package/dist/index.d.ts +14 -8
- package/dist/shared/{mokup.C7VW7pSP.cjs → mokup.B-yfMz5B.cjs} +104 -36
- package/dist/shared/{mokup.Da2mv7KS.mjs → mokup.jeVwRMia.mjs} +101 -33
- package/dist/vite.cjs +131 -27
- package/dist/vite.d.cts +4 -4
- package/dist/vite.d.mts +4 -4
- package/dist/vite.d.ts +4 -4
- package/dist/vite.mjs +131 -27
- package/dist/webpack.cjs +53 -13
- package/dist/webpack.d.cts +4 -4
- package/dist/webpack.d.mts +4 -4
- package/dist/webpack.d.ts +4 -4
- package/dist/webpack.mjs +53 -13
- package/package.json +7 -5
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.
|
|
8
|
+
const sw = require('./shared/mokup.B-yfMz5B.cjs');
|
|
8
9
|
require('node:buffer');
|
|
9
10
|
require('@mokup/shared/hono');
|
|
10
11
|
require('node:module');
|
|
@@ -18,7 +19,7 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
18
19
|
|
|
19
20
|
const chokidar__default = /*#__PURE__*/_interopDefaultCompat(chokidar);
|
|
20
21
|
|
|
21
|
-
function buildRouteSignature(routes, disabledRoutes) {
|
|
22
|
+
function buildRouteSignature(routes, disabledRoutes, ignoredRoutes, configFiles, disabledConfigFiles) {
|
|
22
23
|
return routes.map(
|
|
23
24
|
(route) => [
|
|
24
25
|
route.method,
|
|
@@ -37,22 +38,57 @@ function buildRouteSignature(routes, disabledRoutes) {
|
|
|
37
38
|
route.url ?? ""
|
|
38
39
|
].join("|")
|
|
39
40
|
)
|
|
41
|
+
).concat(
|
|
42
|
+
ignoredRoutes.map(
|
|
43
|
+
(route) => [
|
|
44
|
+
route.reason,
|
|
45
|
+
route.file
|
|
46
|
+
].join("|")
|
|
47
|
+
)
|
|
48
|
+
).concat(
|
|
49
|
+
configFiles.map((route) => route.file)
|
|
50
|
+
).concat(
|
|
51
|
+
disabledConfigFiles.map((route) => route.file)
|
|
40
52
|
).join("\n");
|
|
41
53
|
}
|
|
42
54
|
function isViteDevServer(server) {
|
|
43
55
|
return !!server && "ws" in server;
|
|
44
56
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
57
|
+
const legacyEntryKeys = [
|
|
58
|
+
"dir",
|
|
59
|
+
"prefix",
|
|
60
|
+
"include",
|
|
61
|
+
"exclude",
|
|
62
|
+
"ignorePrefix",
|
|
63
|
+
"watch",
|
|
64
|
+
"log",
|
|
65
|
+
"mode",
|
|
66
|
+
"sw"
|
|
67
|
+
];
|
|
68
|
+
function isLegacyEntryOptions(value) {
|
|
69
|
+
return legacyEntryKeys.some((key) => key in value);
|
|
48
70
|
}
|
|
49
|
-
function
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
71
|
+
function normalizeMokupOptions(options) {
|
|
72
|
+
if (!options) {
|
|
73
|
+
return {};
|
|
74
|
+
}
|
|
75
|
+
if (Array.isArray(options)) {
|
|
76
|
+
throw new TypeError("[mokup] Invalid config: use mokup({ entries: [...] }) instead of mokup([...]).");
|
|
77
|
+
}
|
|
78
|
+
if (typeof options !== "object") {
|
|
79
|
+
return {};
|
|
80
|
+
}
|
|
81
|
+
if (isLegacyEntryOptions(options)) {
|
|
82
|
+
throw new Error(
|
|
83
|
+
"[mokup] Invalid config: use mokup({ entries: { ... } }) instead of mokup({ dir, prefix, ... })."
|
|
84
|
+
);
|
|
54
85
|
}
|
|
55
|
-
return
|
|
86
|
+
return options;
|
|
87
|
+
}
|
|
88
|
+
function normalizeOptions(options) {
|
|
89
|
+
const entries = options.entries;
|
|
90
|
+
const list = Array.isArray(entries) ? entries : entries ? [entries] : [{}];
|
|
91
|
+
return list.length > 0 ? list : [{}];
|
|
56
92
|
}
|
|
57
93
|
function normalizeBase(base) {
|
|
58
94
|
if (!base) {
|
|
@@ -115,6 +151,24 @@ function addMiddlewareFirst(server, middleware) {
|
|
|
115
151
|
}
|
|
116
152
|
server.middlewares.use(middleware);
|
|
117
153
|
}
|
|
154
|
+
function normalizeWatcherFile(file, rootDir) {
|
|
155
|
+
if (!file) {
|
|
156
|
+
return file;
|
|
157
|
+
}
|
|
158
|
+
if (node_path.isAbsolute(file)) {
|
|
159
|
+
return file;
|
|
160
|
+
}
|
|
161
|
+
return node_path.resolve(rootDir, file);
|
|
162
|
+
}
|
|
163
|
+
function normalizeRawWatcherPath(rawPath) {
|
|
164
|
+
if (typeof rawPath === "string") {
|
|
165
|
+
return rawPath;
|
|
166
|
+
}
|
|
167
|
+
if (rawPath && typeof rawPath.toString === "function") {
|
|
168
|
+
return rawPath.toString();
|
|
169
|
+
}
|
|
170
|
+
return "";
|
|
171
|
+
}
|
|
118
172
|
function createMokupPlugin(options = {}) {
|
|
119
173
|
let root = process.cwd();
|
|
120
174
|
let base = "/";
|
|
@@ -124,14 +178,18 @@ function createMokupPlugin(options = {}) {
|
|
|
124
178
|
let serverRoutes = [];
|
|
125
179
|
let swRoutes = [];
|
|
126
180
|
let disabledRoutes = [];
|
|
181
|
+
let ignoredRoutes = [];
|
|
182
|
+
let configFiles = [];
|
|
183
|
+
let disabledConfigFiles = [];
|
|
127
184
|
let app = null;
|
|
128
185
|
let previewWatcher = null;
|
|
129
186
|
let currentServer = null;
|
|
130
187
|
let lastSignature = null;
|
|
131
|
-
const
|
|
188
|
+
const normalizedOptions = normalizeMokupOptions(options);
|
|
189
|
+
const optionList = normalizeOptions(normalizedOptions);
|
|
132
190
|
const logEnabled = optionList.every((entry) => entry.log !== false);
|
|
133
191
|
const watchEnabled = optionList.every((entry) => entry.watch !== false);
|
|
134
|
-
const playgroundConfig = sw.resolvePlaygroundOptions(
|
|
192
|
+
const playgroundConfig = sw.resolvePlaygroundOptions(normalizedOptions.playground);
|
|
135
193
|
const logger = sw.createLogger(logEnabled);
|
|
136
194
|
const hasSwEntries = optionList.some((entry) => entry.mode === "sw");
|
|
137
195
|
const swConfig = sw.resolveSwConfig(optionList, logger);
|
|
@@ -220,6 +278,9 @@ function createMokupPlugin(options = {}) {
|
|
|
220
278
|
const playgroundMiddleware = sw.createPlaygroundMiddleware({
|
|
221
279
|
getRoutes: () => routes,
|
|
222
280
|
getDisabledRoutes: () => disabledRoutes,
|
|
281
|
+
getIgnoredRoutes: () => ignoredRoutes,
|
|
282
|
+
getConfigFiles: () => configFiles,
|
|
283
|
+
getDisabledConfigFiles: () => disabledConfigFiles,
|
|
223
284
|
config: playgroundConfig,
|
|
224
285
|
logger,
|
|
225
286
|
getServer: () => currentServer,
|
|
@@ -231,13 +292,17 @@ function createMokupPlugin(options = {}) {
|
|
|
231
292
|
const collectedServer = [];
|
|
232
293
|
const collectedSw = [];
|
|
233
294
|
const collectedDisabled = [];
|
|
295
|
+
const collectedIgnored = [];
|
|
296
|
+
const collectedConfigs = [];
|
|
234
297
|
for (const entry of optionList) {
|
|
235
298
|
const dirs = sw.resolveDirs(entry.dir, root);
|
|
236
299
|
const scanParams = {
|
|
237
300
|
dirs,
|
|
238
301
|
prefix: entry.prefix ?? "",
|
|
239
302
|
logger,
|
|
240
|
-
onSkip: (info) => collectedDisabled.push(info)
|
|
303
|
+
onSkip: (info) => collectedDisabled.push(info),
|
|
304
|
+
onIgnore: (info) => collectedIgnored.push(info),
|
|
305
|
+
onConfig: (info) => collectedConfigs.push(info)
|
|
241
306
|
};
|
|
242
307
|
if (entry.include) {
|
|
243
308
|
scanParams.include = entry.include;
|
|
@@ -266,8 +331,19 @@ function createMokupPlugin(options = {}) {
|
|
|
266
331
|
serverRoutes = sw.sortRoutes(collectedServer);
|
|
267
332
|
swRoutes = sw.sortRoutes(collectedSw);
|
|
268
333
|
disabledRoutes = collectedDisabled;
|
|
334
|
+
ignoredRoutes = collectedIgnored;
|
|
335
|
+
const configMap = new Map(collectedConfigs.map((entry) => [entry.file, entry]));
|
|
336
|
+
const resolvedConfigs = Array.from(configMap.values());
|
|
337
|
+
configFiles = resolvedConfigs.filter((entry) => entry.enabled);
|
|
338
|
+
disabledConfigFiles = resolvedConfigs.filter((entry) => !entry.enabled);
|
|
269
339
|
app = serverRoutes.length > 0 ? sw.createHonoApp(serverRoutes) : null;
|
|
270
|
-
const signature = buildRouteSignature(
|
|
340
|
+
const signature = buildRouteSignature(
|
|
341
|
+
routes,
|
|
342
|
+
disabledRoutes,
|
|
343
|
+
ignoredRoutes,
|
|
344
|
+
configFiles,
|
|
345
|
+
disabledConfigFiles
|
|
346
|
+
);
|
|
271
347
|
if (isViteDevServer(server) && server.ws) {
|
|
272
348
|
if (lastSignature && signature !== lastSignature) {
|
|
273
349
|
server.ws.send({
|
|
@@ -425,18 +501,26 @@ function createMokupPlugin(options = {}) {
|
|
|
425
501
|
const dirs = resolveAllDirs();
|
|
426
502
|
server.watcher.add(dirs);
|
|
427
503
|
const scheduleRefresh = sw.createDebouncer(80, () => refreshRoutes(server));
|
|
428
|
-
|
|
429
|
-
|
|
504
|
+
const handleWatchedFile = (file) => {
|
|
505
|
+
const resolvedFile = normalizeWatcherFile(file, server.config.root ?? root);
|
|
506
|
+
if (sw.isInDirs(resolvedFile, dirs)) {
|
|
430
507
|
scheduleRefresh();
|
|
431
508
|
}
|
|
432
|
-
}
|
|
433
|
-
server.watcher.on("
|
|
434
|
-
|
|
435
|
-
|
|
509
|
+
};
|
|
510
|
+
server.watcher.on("add", handleWatchedFile);
|
|
511
|
+
server.watcher.on("change", handleWatchedFile);
|
|
512
|
+
server.watcher.on("unlink", handleWatchedFile);
|
|
513
|
+
server.watcher.on("raw", (eventName, rawPath, details) => {
|
|
514
|
+
if (eventName !== "rename") {
|
|
515
|
+
return;
|
|
436
516
|
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
517
|
+
const candidate = normalizeRawWatcherPath(rawPath);
|
|
518
|
+
if (!candidate) {
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
521
|
+
const baseDir = typeof details === "object" && details && "watchedPath" in details ? details.watchedPath ?? (server.config.root ?? root) : server.config.root ?? root;
|
|
522
|
+
const resolvedFile = normalizeWatcherFile(candidate, baseDir);
|
|
523
|
+
if (sw.isInDirs(resolvedFile, dirs)) {
|
|
440
524
|
scheduleRefresh();
|
|
441
525
|
}
|
|
442
526
|
});
|
|
@@ -481,9 +565,29 @@ function createMokupPlugin(options = {}) {
|
|
|
481
565
|
const watcher = chokidar__default.watch(dirs, { ignoreInitial: true });
|
|
482
566
|
previewWatcher = watcher;
|
|
483
567
|
const scheduleRefresh = sw.createDebouncer(80, () => refreshRoutes(server));
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
568
|
+
const handleWatchedFile = (file) => {
|
|
569
|
+
const resolvedFile = normalizeWatcherFile(file, server.config.root ?? root);
|
|
570
|
+
if (sw.isInDirs(resolvedFile, dirs)) {
|
|
571
|
+
scheduleRefresh();
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
watcher.on("add", handleWatchedFile);
|
|
575
|
+
watcher.on("change", handleWatchedFile);
|
|
576
|
+
watcher.on("unlink", handleWatchedFile);
|
|
577
|
+
watcher.on("raw", (eventName, rawPath, details) => {
|
|
578
|
+
if (eventName !== "rename") {
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
const candidate = normalizeRawWatcherPath(rawPath);
|
|
582
|
+
if (!candidate) {
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
const baseDir = typeof details === "object" && details && "watchedPath" in details ? details.watchedPath ?? (server.config.root ?? root) : server.config.root ?? root;
|
|
586
|
+
const resolvedFile = normalizeWatcherFile(candidate, baseDir);
|
|
587
|
+
if (sw.isInDirs(resolvedFile, dirs)) {
|
|
588
|
+
scheduleRefresh();
|
|
589
|
+
}
|
|
590
|
+
});
|
|
487
591
|
server.httpServer?.once("close", () => {
|
|
488
592
|
previewWatcher?.close();
|
|
489
593
|
previewWatcher = null;
|
package/dist/vite.d.cts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
|
-
import {
|
|
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?:
|
|
6
|
+
declare function createMokupPlugin(options?: MokupPluginOptions): Plugin;
|
|
7
7
|
|
|
8
8
|
// @ts-ignore
|
|
9
9
|
export = createMokupPlugin;
|
|
10
|
-
export {
|
|
10
|
+
export { MokupPluginOptions };
|
package/dist/vite.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
|
-
import {
|
|
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?:
|
|
6
|
+
declare function createMokupPlugin(options?: MokupPluginOptions): Plugin;
|
|
7
7
|
|
|
8
|
-
export {
|
|
8
|
+
export { MokupPluginOptions, createMokupPlugin as default };
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
|
-
import {
|
|
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?:
|
|
6
|
+
declare function createMokupPlugin(options?: MokupPluginOptions): Plugin;
|
|
7
7
|
|
|
8
8
|
// @ts-ignore
|
|
9
9
|
export = createMokupPlugin;
|
|
10
|
-
export {
|
|
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,
|
|
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.jeVwRMia.mjs';
|
|
6
7
|
import 'node:buffer';
|
|
7
8
|
import '@mokup/shared/hono';
|
|
8
9
|
import 'node:module';
|
|
@@ -11,7 +12,7 @@ import '@mokup/shared/esbuild';
|
|
|
11
12
|
import '@mokup/shared/jsonc-parser';
|
|
12
13
|
import '@mokup/runtime';
|
|
13
14
|
|
|
14
|
-
function buildRouteSignature(routes, disabledRoutes) {
|
|
15
|
+
function buildRouteSignature(routes, disabledRoutes, ignoredRoutes, configFiles, disabledConfigFiles) {
|
|
15
16
|
return routes.map(
|
|
16
17
|
(route) => [
|
|
17
18
|
route.method,
|
|
@@ -30,22 +31,57 @@ function buildRouteSignature(routes, disabledRoutes) {
|
|
|
30
31
|
route.url ?? ""
|
|
31
32
|
].join("|")
|
|
32
33
|
)
|
|
34
|
+
).concat(
|
|
35
|
+
ignoredRoutes.map(
|
|
36
|
+
(route) => [
|
|
37
|
+
route.reason,
|
|
38
|
+
route.file
|
|
39
|
+
].join("|")
|
|
40
|
+
)
|
|
41
|
+
).concat(
|
|
42
|
+
configFiles.map((route) => route.file)
|
|
43
|
+
).concat(
|
|
44
|
+
disabledConfigFiles.map((route) => route.file)
|
|
33
45
|
).join("\n");
|
|
34
46
|
}
|
|
35
47
|
function isViteDevServer(server) {
|
|
36
48
|
return !!server && "ws" in server;
|
|
37
49
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
50
|
+
const legacyEntryKeys = [
|
|
51
|
+
"dir",
|
|
52
|
+
"prefix",
|
|
53
|
+
"include",
|
|
54
|
+
"exclude",
|
|
55
|
+
"ignorePrefix",
|
|
56
|
+
"watch",
|
|
57
|
+
"log",
|
|
58
|
+
"mode",
|
|
59
|
+
"sw"
|
|
60
|
+
];
|
|
61
|
+
function isLegacyEntryOptions(value) {
|
|
62
|
+
return legacyEntryKeys.some((key) => key in value);
|
|
41
63
|
}
|
|
42
|
-
function
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
64
|
+
function normalizeMokupOptions(options) {
|
|
65
|
+
if (!options) {
|
|
66
|
+
return {};
|
|
67
|
+
}
|
|
68
|
+
if (Array.isArray(options)) {
|
|
69
|
+
throw new TypeError("[mokup] Invalid config: use mokup({ entries: [...] }) instead of mokup([...]).");
|
|
70
|
+
}
|
|
71
|
+
if (typeof options !== "object") {
|
|
72
|
+
return {};
|
|
73
|
+
}
|
|
74
|
+
if (isLegacyEntryOptions(options)) {
|
|
75
|
+
throw new Error(
|
|
76
|
+
"[mokup] Invalid config: use mokup({ entries: { ... } }) instead of mokup({ dir, prefix, ... })."
|
|
77
|
+
);
|
|
47
78
|
}
|
|
48
|
-
return
|
|
79
|
+
return options;
|
|
80
|
+
}
|
|
81
|
+
function normalizeOptions(options) {
|
|
82
|
+
const entries = options.entries;
|
|
83
|
+
const list = Array.isArray(entries) ? entries : entries ? [entries] : [{}];
|
|
84
|
+
return list.length > 0 ? list : [{}];
|
|
49
85
|
}
|
|
50
86
|
function normalizeBase(base) {
|
|
51
87
|
if (!base) {
|
|
@@ -108,6 +144,24 @@ function addMiddlewareFirst(server, middleware) {
|
|
|
108
144
|
}
|
|
109
145
|
server.middlewares.use(middleware);
|
|
110
146
|
}
|
|
147
|
+
function normalizeWatcherFile(file, rootDir) {
|
|
148
|
+
if (!file) {
|
|
149
|
+
return file;
|
|
150
|
+
}
|
|
151
|
+
if (isAbsolute(file)) {
|
|
152
|
+
return file;
|
|
153
|
+
}
|
|
154
|
+
return resolve(rootDir, file);
|
|
155
|
+
}
|
|
156
|
+
function normalizeRawWatcherPath(rawPath) {
|
|
157
|
+
if (typeof rawPath === "string") {
|
|
158
|
+
return rawPath;
|
|
159
|
+
}
|
|
160
|
+
if (rawPath && typeof rawPath.toString === "function") {
|
|
161
|
+
return rawPath.toString();
|
|
162
|
+
}
|
|
163
|
+
return "";
|
|
164
|
+
}
|
|
111
165
|
function createMokupPlugin(options = {}) {
|
|
112
166
|
let root = cwd();
|
|
113
167
|
let base = "/";
|
|
@@ -117,14 +171,18 @@ function createMokupPlugin(options = {}) {
|
|
|
117
171
|
let serverRoutes = [];
|
|
118
172
|
let swRoutes = [];
|
|
119
173
|
let disabledRoutes = [];
|
|
174
|
+
let ignoredRoutes = [];
|
|
175
|
+
let configFiles = [];
|
|
176
|
+
let disabledConfigFiles = [];
|
|
120
177
|
let app = null;
|
|
121
178
|
let previewWatcher = null;
|
|
122
179
|
let currentServer = null;
|
|
123
180
|
let lastSignature = null;
|
|
124
|
-
const
|
|
181
|
+
const normalizedOptions = normalizeMokupOptions(options);
|
|
182
|
+
const optionList = normalizeOptions(normalizedOptions);
|
|
125
183
|
const logEnabled = optionList.every((entry) => entry.log !== false);
|
|
126
184
|
const watchEnabled = optionList.every((entry) => entry.watch !== false);
|
|
127
|
-
const playgroundConfig = resolvePlaygroundOptions(
|
|
185
|
+
const playgroundConfig = resolvePlaygroundOptions(normalizedOptions.playground);
|
|
128
186
|
const logger = createLogger(logEnabled);
|
|
129
187
|
const hasSwEntries = optionList.some((entry) => entry.mode === "sw");
|
|
130
188
|
const swConfig = resolveSwConfig(optionList, logger);
|
|
@@ -213,6 +271,9 @@ function createMokupPlugin(options = {}) {
|
|
|
213
271
|
const playgroundMiddleware = createPlaygroundMiddleware({
|
|
214
272
|
getRoutes: () => routes,
|
|
215
273
|
getDisabledRoutes: () => disabledRoutes,
|
|
274
|
+
getIgnoredRoutes: () => ignoredRoutes,
|
|
275
|
+
getConfigFiles: () => configFiles,
|
|
276
|
+
getDisabledConfigFiles: () => disabledConfigFiles,
|
|
216
277
|
config: playgroundConfig,
|
|
217
278
|
logger,
|
|
218
279
|
getServer: () => currentServer,
|
|
@@ -224,13 +285,17 @@ function createMokupPlugin(options = {}) {
|
|
|
224
285
|
const collectedServer = [];
|
|
225
286
|
const collectedSw = [];
|
|
226
287
|
const collectedDisabled = [];
|
|
288
|
+
const collectedIgnored = [];
|
|
289
|
+
const collectedConfigs = [];
|
|
227
290
|
for (const entry of optionList) {
|
|
228
291
|
const dirs = resolveDirs(entry.dir, root);
|
|
229
292
|
const scanParams = {
|
|
230
293
|
dirs,
|
|
231
294
|
prefix: entry.prefix ?? "",
|
|
232
295
|
logger,
|
|
233
|
-
onSkip: (info) => collectedDisabled.push(info)
|
|
296
|
+
onSkip: (info) => collectedDisabled.push(info),
|
|
297
|
+
onIgnore: (info) => collectedIgnored.push(info),
|
|
298
|
+
onConfig: (info) => collectedConfigs.push(info)
|
|
234
299
|
};
|
|
235
300
|
if (entry.include) {
|
|
236
301
|
scanParams.include = entry.include;
|
|
@@ -259,8 +324,19 @@ function createMokupPlugin(options = {}) {
|
|
|
259
324
|
serverRoutes = sortRoutes(collectedServer);
|
|
260
325
|
swRoutes = sortRoutes(collectedSw);
|
|
261
326
|
disabledRoutes = collectedDisabled;
|
|
327
|
+
ignoredRoutes = collectedIgnored;
|
|
328
|
+
const configMap = new Map(collectedConfigs.map((entry) => [entry.file, entry]));
|
|
329
|
+
const resolvedConfigs = Array.from(configMap.values());
|
|
330
|
+
configFiles = resolvedConfigs.filter((entry) => entry.enabled);
|
|
331
|
+
disabledConfigFiles = resolvedConfigs.filter((entry) => !entry.enabled);
|
|
262
332
|
app = serverRoutes.length > 0 ? createHonoApp(serverRoutes) : null;
|
|
263
|
-
const signature = buildRouteSignature(
|
|
333
|
+
const signature = buildRouteSignature(
|
|
334
|
+
routes,
|
|
335
|
+
disabledRoutes,
|
|
336
|
+
ignoredRoutes,
|
|
337
|
+
configFiles,
|
|
338
|
+
disabledConfigFiles
|
|
339
|
+
);
|
|
264
340
|
if (isViteDevServer(server) && server.ws) {
|
|
265
341
|
if (lastSignature && signature !== lastSignature) {
|
|
266
342
|
server.ws.send({
|
|
@@ -418,18 +494,26 @@ function createMokupPlugin(options = {}) {
|
|
|
418
494
|
const dirs = resolveAllDirs();
|
|
419
495
|
server.watcher.add(dirs);
|
|
420
496
|
const scheduleRefresh = createDebouncer(80, () => refreshRoutes(server));
|
|
421
|
-
|
|
422
|
-
|
|
497
|
+
const handleWatchedFile = (file) => {
|
|
498
|
+
const resolvedFile = normalizeWatcherFile(file, server.config.root ?? root);
|
|
499
|
+
if (isInDirs(resolvedFile, dirs)) {
|
|
423
500
|
scheduleRefresh();
|
|
424
501
|
}
|
|
425
|
-
}
|
|
426
|
-
server.watcher.on("
|
|
427
|
-
|
|
428
|
-
|
|
502
|
+
};
|
|
503
|
+
server.watcher.on("add", handleWatchedFile);
|
|
504
|
+
server.watcher.on("change", handleWatchedFile);
|
|
505
|
+
server.watcher.on("unlink", handleWatchedFile);
|
|
506
|
+
server.watcher.on("raw", (eventName, rawPath, details) => {
|
|
507
|
+
if (eventName !== "rename") {
|
|
508
|
+
return;
|
|
429
509
|
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
510
|
+
const candidate = normalizeRawWatcherPath(rawPath);
|
|
511
|
+
if (!candidate) {
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
const baseDir = typeof details === "object" && details && "watchedPath" in details ? details.watchedPath ?? (server.config.root ?? root) : server.config.root ?? root;
|
|
515
|
+
const resolvedFile = normalizeWatcherFile(candidate, baseDir);
|
|
516
|
+
if (isInDirs(resolvedFile, dirs)) {
|
|
433
517
|
scheduleRefresh();
|
|
434
518
|
}
|
|
435
519
|
});
|
|
@@ -474,9 +558,29 @@ function createMokupPlugin(options = {}) {
|
|
|
474
558
|
const watcher = chokidar.watch(dirs, { ignoreInitial: true });
|
|
475
559
|
previewWatcher = watcher;
|
|
476
560
|
const scheduleRefresh = createDebouncer(80, () => refreshRoutes(server));
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
561
|
+
const handleWatchedFile = (file) => {
|
|
562
|
+
const resolvedFile = normalizeWatcherFile(file, server.config.root ?? root);
|
|
563
|
+
if (isInDirs(resolvedFile, dirs)) {
|
|
564
|
+
scheduleRefresh();
|
|
565
|
+
}
|
|
566
|
+
};
|
|
567
|
+
watcher.on("add", handleWatchedFile);
|
|
568
|
+
watcher.on("change", handleWatchedFile);
|
|
569
|
+
watcher.on("unlink", handleWatchedFile);
|
|
570
|
+
watcher.on("raw", (eventName, rawPath, details) => {
|
|
571
|
+
if (eventName !== "rename") {
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
574
|
+
const candidate = normalizeRawWatcherPath(rawPath);
|
|
575
|
+
if (!candidate) {
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
578
|
+
const baseDir = typeof details === "object" && details && "watchedPath" in details ? details.watchedPath ?? (server.config.root ?? root) : server.config.root ?? root;
|
|
579
|
+
const resolvedFile = normalizeWatcherFile(candidate, baseDir);
|
|
580
|
+
if (isInDirs(resolvedFile, dirs)) {
|
|
581
|
+
scheduleRefresh();
|
|
582
|
+
}
|
|
583
|
+
});
|
|
480
584
|
server.httpServer?.once("close", () => {
|
|
481
585
|
previewWatcher?.close();
|
|
482
586
|
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.
|
|
10
|
+
const sw = require('./shared/mokup.B-yfMz5B.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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
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
|
|
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(
|
|
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);
|
|
@@ -180,6 +205,9 @@ function createMokupWebpackPlugin(options = {}) {
|
|
|
180
205
|
let serverRoutes = [];
|
|
181
206
|
let swRoutes = [];
|
|
182
207
|
let disabledRoutes = [];
|
|
208
|
+
let ignoredRoutes = [];
|
|
209
|
+
let configFiles = [];
|
|
210
|
+
let disabledConfigFiles = [];
|
|
183
211
|
let app = null;
|
|
184
212
|
let watcher = null;
|
|
185
213
|
let watchingCompiler = null;
|
|
@@ -208,13 +236,17 @@ function createMokupWebpackPlugin(options = {}) {
|
|
|
208
236
|
const collectedServer = [];
|
|
209
237
|
const collectedSw = [];
|
|
210
238
|
const collectedDisabled = [];
|
|
239
|
+
const collectedIgnored = [];
|
|
240
|
+
const collectedConfigs = [];
|
|
211
241
|
for (const entry of optionList) {
|
|
212
242
|
const dirs = sw.resolveDirs(entry.dir, root);
|
|
213
243
|
const scanParams = {
|
|
214
244
|
dirs,
|
|
215
245
|
prefix: entry.prefix ?? "",
|
|
216
246
|
logger,
|
|
217
|
-
onSkip: (info) => collectedDisabled.push(info)
|
|
247
|
+
onSkip: (info) => collectedDisabled.push(info),
|
|
248
|
+
onIgnore: (info) => collectedIgnored.push(info),
|
|
249
|
+
onConfig: (info) => collectedConfigs.push(info)
|
|
218
250
|
};
|
|
219
251
|
if (entry.include) {
|
|
220
252
|
scanParams.include = entry.include;
|
|
@@ -240,6 +272,11 @@ function createMokupWebpackPlugin(options = {}) {
|
|
|
240
272
|
serverRoutes = sw.sortRoutes(collectedServer);
|
|
241
273
|
swRoutes = sw.sortRoutes(collectedSw);
|
|
242
274
|
disabledRoutes = collectedDisabled;
|
|
275
|
+
ignoredRoutes = collectedIgnored;
|
|
276
|
+
const configMap = new Map(collectedConfigs.map((entry) => [entry.file, entry]));
|
|
277
|
+
const resolvedConfigs = Array.from(configMap.values());
|
|
278
|
+
configFiles = resolvedConfigs.filter((entry) => entry.enabled);
|
|
279
|
+
disabledConfigFiles = resolvedConfigs.filter((entry) => !entry.enabled);
|
|
243
280
|
app = serverRoutes.length > 0 ? sw.createHonoApp(serverRoutes) : null;
|
|
244
281
|
};
|
|
245
282
|
const rebuildBundles = async () => {
|
|
@@ -289,6 +326,9 @@ function createMokupWebpackPlugin(options = {}) {
|
|
|
289
326
|
const playgroundMiddleware = sw.createPlaygroundMiddleware({
|
|
290
327
|
getRoutes: () => routes,
|
|
291
328
|
getDisabledRoutes: () => disabledRoutes,
|
|
329
|
+
getIgnoredRoutes: () => ignoredRoutes,
|
|
330
|
+
getConfigFiles: () => configFiles,
|
|
331
|
+
getDisabledConfigFiles: () => disabledConfigFiles,
|
|
292
332
|
config: playgroundConfig,
|
|
293
333
|
logger,
|
|
294
334
|
getDirs: () => resolveAllDirs(),
|