mokup 2.2.3 → 2.3.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/bundle.cjs +2 -6
- package/dist/bundle.d.cts +1 -27
- package/dist/bundle.d.mts +1 -27
- package/dist/bundle.d.ts +1 -27
- package/dist/bundle.mjs +1 -5
- package/dist/cli-bin.d.cts +1 -0
- package/dist/cli-bin.d.mts +1 -0
- package/dist/cli-bin.d.ts +1 -0
- package/dist/index.cjs +10 -32
- package/dist/index.d.cts +7 -39
- package/dist/index.d.mts +7 -39
- package/dist/index.d.ts +7 -39
- package/dist/index.mjs +9 -33
- package/dist/shared/mokup.BZpTBIrj.mjs +10 -0
- package/dist/shared/mokup.CO9HhGox.cjs +13 -0
- package/dist/vite.cjs +72 -161
- package/dist/vite.d.cts +2 -7
- package/dist/vite.d.mts +3 -6
- package/dist/vite.d.ts +2 -7
- package/dist/vite.mjs +41 -130
- package/dist/webpack.cjs +61 -38
- package/dist/webpack.d.cts +25 -9
- package/dist/webpack.d.mts +25 -9
- package/dist/webpack.d.ts +25 -9
- package/dist/webpack.mjs +36 -15
- package/package.json +7 -13
- package/dist/shared/mokup.BXPIIxtS.cjs +0 -47
- package/dist/shared/mokup.Cn9uLpN8.cjs +0 -1791
- package/dist/shared/mokup.CsBTglhs.mjs +0 -45
- package/dist/shared/mokup.DJ2QlqTp.mjs +0 -1771
- package/dist/shared/mokup.DeotZ0g8.d.cts +0 -369
- package/dist/shared/mokup.DeotZ0g8.d.mts +0 -369
- package/dist/shared/mokup.DeotZ0g8.d.ts +0 -369
- package/dist/shared/mokup.Dy9VDphS.cjs +0 -181
- package/dist/shared/mokup.Iqw32OxC.mjs +0 -174
package/dist/vite.cjs
CHANGED
|
@@ -1,25 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const process = require('node:process');
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const pathe = require('@mokup/shared/pathe');
|
|
7
|
-
const scanner = require('./shared/mokup.Cn9uLpN8.cjs');
|
|
8
|
-
const playgroundGrouping = require('@mokup/shared/playground-grouping');
|
|
9
|
-
const logger = require('@mokup/shared/logger');
|
|
4
|
+
const core = require('@mokup/core');
|
|
5
|
+
const assets = require('./shared/mokup.CO9HhGox.cjs');
|
|
10
6
|
const pc = require('picocolors');
|
|
11
7
|
const node_path = require('node:path');
|
|
12
8
|
const chokidar = require('@mokup/shared/chokidar');
|
|
13
|
-
require('
|
|
14
|
-
const pathUtils = require('@mokup/shared/path-utils');
|
|
15
|
-
const timing = require('@mokup/shared/timing');
|
|
9
|
+
const node_fs = require('node:fs');
|
|
16
10
|
const node_url = require('node:url');
|
|
17
11
|
require('node:module');
|
|
18
|
-
require('
|
|
19
|
-
require('@mokup/shared/hono');
|
|
20
|
-
require('@mokup/shared/esbuild');
|
|
21
|
-
require('@mokup/shared/jsonc-parser');
|
|
22
|
-
require('@mokup/runtime');
|
|
12
|
+
require('@mokup/shared/pathe');
|
|
23
13
|
|
|
24
14
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
25
15
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
@@ -27,79 +17,6 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
27
17
|
const pc__default = /*#__PURE__*/_interopDefaultCompat(pc);
|
|
28
18
|
const chokidar__default = /*#__PURE__*/_interopDefaultCompat(chokidar);
|
|
29
19
|
|
|
30
|
-
function resolvePlaygroundOutDir(outDir, playgroundPath) {
|
|
31
|
-
const normalized = scanner.normalizePlaygroundPath(playgroundPath);
|
|
32
|
-
const trimmed = normalized.replace(/^\/+/, "");
|
|
33
|
-
return trimmed ? pathe.join(outDir, pathe.normalize(trimmed)) : outDir;
|
|
34
|
-
}
|
|
35
|
-
function stripSwLifecycle(html) {
|
|
36
|
-
return html.replace(
|
|
37
|
-
/<script[^>]*mokup-sw-lifecycle\.js[^>]*><\/script>\s*/gi,
|
|
38
|
-
""
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
async function writeRoutesPayload(params, targetDir) {
|
|
42
|
-
const baseRoot = playgroundGrouping.resolveGroupRoot(params.dirs, params.root);
|
|
43
|
-
const groups = playgroundGrouping.resolveGroups(params.dirs, baseRoot);
|
|
44
|
-
const basePath = scanner.resolvePlaygroundRequestPath(params.base, params.playgroundPath);
|
|
45
|
-
const payload = {
|
|
46
|
-
basePath,
|
|
47
|
-
root: baseRoot,
|
|
48
|
-
count: params.routes.length,
|
|
49
|
-
groups: groups.map((group) => ({ key: group.key, label: group.label })),
|
|
50
|
-
routes: params.routes.map((route) => scanner.toPlaygroundRoute(route, baseRoot, groups)),
|
|
51
|
-
disabled: params.disabledRoutes.map(
|
|
52
|
-
(route) => scanner.toPlaygroundDisabledRoute(route, baseRoot, groups)
|
|
53
|
-
),
|
|
54
|
-
ignored: params.ignoredRoutes.map(
|
|
55
|
-
(route) => scanner.toPlaygroundIgnoredRoute(route, baseRoot, groups)
|
|
56
|
-
),
|
|
57
|
-
configs: params.configFiles.map((entry) => scanner.toPlaygroundConfigFile(entry, baseRoot, groups)),
|
|
58
|
-
disabledConfigs: params.disabledConfigFiles.map(
|
|
59
|
-
(entry) => scanner.toPlaygroundConfigFile(entry, baseRoot, groups)
|
|
60
|
-
)
|
|
61
|
-
};
|
|
62
|
-
await node_fs.promises.writeFile(
|
|
63
|
-
pathe.join(targetDir, "routes"),
|
|
64
|
-
JSON.stringify(payload, null, 2),
|
|
65
|
-
"utf8"
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
async function updateIndexHtml(targetDir, swScript) {
|
|
69
|
-
const indexPath = pathe.join(targetDir, "index.html");
|
|
70
|
-
const html = await node_fs.promises.readFile(indexPath, "utf8");
|
|
71
|
-
const cleaned = stripSwLifecycle(html);
|
|
72
|
-
const output = swScript ? scanner.injectPlaygroundSw(cleaned, swScript) : cleaned;
|
|
73
|
-
await node_fs.promises.writeFile(indexPath, output, "utf8");
|
|
74
|
-
}
|
|
75
|
-
async function removeLegacySwAsset(targetDir) {
|
|
76
|
-
const legacyFiles = [
|
|
77
|
-
pathe.join(targetDir, "assets", "mokup-sw-lifecycle.js"),
|
|
78
|
-
pathe.join(targetDir, "assets", "mokup-sw-lifecycle.js.map")
|
|
79
|
-
];
|
|
80
|
-
await Promise.all(legacyFiles.map((file) => node_fs.promises.rm(file, { force: true })));
|
|
81
|
-
}
|
|
82
|
-
async function writePlaygroundBuild(params) {
|
|
83
|
-
const distDir = scanner.resolvePlaygroundDist();
|
|
84
|
-
const targetDir = resolvePlaygroundOutDir(params.outDir, params.playgroundPath);
|
|
85
|
-
if (targetDir === params.outDir) {
|
|
86
|
-
params.logger.error("Playground build path resolves to the Vite outDir. Aborting output.");
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
try {
|
|
90
|
-
await node_fs.promises.stat(distDir);
|
|
91
|
-
} catch (error) {
|
|
92
|
-
params.logger.error("Failed to locate playground assets:", error);
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
await node_fs.promises.rm(targetDir, { recursive: true, force: true });
|
|
96
|
-
await node_fs.promises.mkdir(params.outDir, { recursive: true });
|
|
97
|
-
await node_fs.promises.cp(distDir, targetDir, { recursive: true });
|
|
98
|
-
await removeLegacySwAsset(targetDir);
|
|
99
|
-
await updateIndexHtml(targetDir, params.swScript);
|
|
100
|
-
await writeRoutesPayload(params, targetDir);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
20
|
const legacyEntryKeys = [
|
|
104
21
|
"dir",
|
|
105
22
|
"prefix",
|
|
@@ -231,8 +148,16 @@ function isViteDevServer(server) {
|
|
|
231
148
|
}
|
|
232
149
|
|
|
233
150
|
function createRouteRefresher(params) {
|
|
234
|
-
const {
|
|
235
|
-
|
|
151
|
+
const {
|
|
152
|
+
state,
|
|
153
|
+
optionList,
|
|
154
|
+
root,
|
|
155
|
+
logger,
|
|
156
|
+
enableViteMiddleware,
|
|
157
|
+
virtualModuleIds,
|
|
158
|
+
reloadOnChange = false
|
|
159
|
+
} = params;
|
|
160
|
+
return async (server, options) => {
|
|
236
161
|
const collected = [];
|
|
237
162
|
const collectedServer = [];
|
|
238
163
|
const collectedSw = [];
|
|
@@ -240,7 +165,7 @@ function createRouteRefresher(params) {
|
|
|
240
165
|
const collectedIgnored = [];
|
|
241
166
|
const collectedConfigs = [];
|
|
242
167
|
for (const entry of optionList) {
|
|
243
|
-
const dirs =
|
|
168
|
+
const dirs = core.resolveDirs(entry.dir, root());
|
|
244
169
|
const scanParams = {
|
|
245
170
|
dirs,
|
|
246
171
|
prefix: entry.prefix ?? "",
|
|
@@ -261,7 +186,7 @@ function createRouteRefresher(params) {
|
|
|
261
186
|
if (server) {
|
|
262
187
|
scanParams.server = server;
|
|
263
188
|
}
|
|
264
|
-
const scanned = await
|
|
189
|
+
const scanned = await core.scanRoutes(scanParams);
|
|
265
190
|
collected.push(...scanned);
|
|
266
191
|
if (entry.mode === "sw") {
|
|
267
192
|
collectedSw.push(...scanned);
|
|
@@ -272,16 +197,16 @@ function createRouteRefresher(params) {
|
|
|
272
197
|
collectedServer.push(...scanned);
|
|
273
198
|
}
|
|
274
199
|
}
|
|
275
|
-
state.routes =
|
|
276
|
-
state.serverRoutes =
|
|
277
|
-
state.swRoutes =
|
|
200
|
+
state.routes = core.sortRoutes(collected);
|
|
201
|
+
state.serverRoutes = core.sortRoutes(collectedServer);
|
|
202
|
+
state.swRoutes = core.sortRoutes(collectedSw);
|
|
278
203
|
state.disabledRoutes = collectedDisabled;
|
|
279
204
|
state.ignoredRoutes = collectedIgnored;
|
|
280
205
|
const configMap = new Map(collectedConfigs.map((entry) => [entry.file, entry]));
|
|
281
206
|
const resolvedConfigs = Array.from(configMap.values());
|
|
282
207
|
state.configFiles = resolvedConfigs.filter((entry) => entry.enabled);
|
|
283
208
|
state.disabledConfigFiles = resolvedConfigs.filter((entry) => !entry.enabled);
|
|
284
|
-
state.app = enableViteMiddleware && state.serverRoutes.length > 0 ?
|
|
209
|
+
state.app = enableViteMiddleware && state.serverRoutes.length > 0 ? core.createHonoApp(state.serverRoutes) : null;
|
|
285
210
|
const signature = buildRouteSignature(
|
|
286
211
|
state.routes,
|
|
287
212
|
state.disabledRoutes,
|
|
@@ -290,12 +215,24 @@ function createRouteRefresher(params) {
|
|
|
290
215
|
state.disabledConfigFiles
|
|
291
216
|
);
|
|
292
217
|
if (isViteDevServer(server) && server.ws) {
|
|
293
|
-
|
|
218
|
+
const shouldNotify = !options?.silent && state.lastSignature && (signature !== state.lastSignature || options?.force);
|
|
219
|
+
if (shouldNotify) {
|
|
294
220
|
server.ws.send({
|
|
295
221
|
type: "custom",
|
|
296
222
|
event: "mokup:routes-changed",
|
|
297
223
|
data: { ts: Date.now() }
|
|
298
224
|
});
|
|
225
|
+
if (virtualModuleIds && virtualModuleIds.length > 0) {
|
|
226
|
+
for (const id of virtualModuleIds) {
|
|
227
|
+
const moduleNode = server.moduleGraph.getModuleById(id);
|
|
228
|
+
if (moduleNode) {
|
|
229
|
+
server.moduleGraph.invalidateModule(moduleNode);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (reloadOnChange) {
|
|
234
|
+
server.ws.send({ type: "full-reload", path: "*" });
|
|
235
|
+
}
|
|
299
236
|
}
|
|
300
237
|
}
|
|
301
238
|
state.lastSignature = signature;
|
|
@@ -307,7 +244,7 @@ function createDirResolver(optionList, root) {
|
|
|
307
244
|
const dirs = [];
|
|
308
245
|
const seen = /* @__PURE__ */ new Set();
|
|
309
246
|
for (const entry of optionList) {
|
|
310
|
-
for (const dir of
|
|
247
|
+
for (const dir of core.resolveDirs(entry.dir, root())) {
|
|
311
248
|
if (seen.has(dir)) {
|
|
312
249
|
continue;
|
|
313
250
|
}
|
|
@@ -356,37 +293,6 @@ function addMiddlewareFirst(server, middleware) {
|
|
|
356
293
|
server.middlewares.use(middleware);
|
|
357
294
|
}
|
|
358
295
|
|
|
359
|
-
const portPattern = /:(?<port>\d{2,5})/g;
|
|
360
|
-
const escapeCode = 27;
|
|
361
|
-
function stripAnsi(value) {
|
|
362
|
-
let output = "";
|
|
363
|
-
for (let index = 0; index < value.length; index += 1) {
|
|
364
|
-
const code = value.charCodeAt(index);
|
|
365
|
-
if (code === escapeCode && value[index + 1] === "[") {
|
|
366
|
-
index += 1;
|
|
367
|
-
while (index < value.length && value[index] !== "m") {
|
|
368
|
-
index += 1;
|
|
369
|
-
}
|
|
370
|
-
continue;
|
|
371
|
-
}
|
|
372
|
-
output += value[index];
|
|
373
|
-
}
|
|
374
|
-
return output;
|
|
375
|
-
}
|
|
376
|
-
function formatOutputLine(line, options) {
|
|
377
|
-
const { arrowToken, formattedArrow, labels, formatLabel, formatPort } = options;
|
|
378
|
-
let output = formattedArrow ? line.replaceAll(arrowToken, formattedArrow) : line;
|
|
379
|
-
if (labels && formatLabel) {
|
|
380
|
-
for (const label of labels) {
|
|
381
|
-
output = output.replaceAll(label, formatLabel(label));
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
if (formatPort) {
|
|
385
|
-
output = output.replace(portPattern, (_match, port) => `:${formatPort(port)}`);
|
|
386
|
-
}
|
|
387
|
-
return output;
|
|
388
|
-
}
|
|
389
|
-
|
|
390
296
|
const arrowToken = "\u279C";
|
|
391
297
|
const playgroundLabel = "Mokup Playground";
|
|
392
298
|
const coloredArrow = pc__default.green(arrowToken);
|
|
@@ -423,7 +329,7 @@ function patchPlaygroundPrintUrls(server, playgroundPath) {
|
|
|
423
329
|
const coloredUrl = pc__default.magenta(outputUrl);
|
|
424
330
|
const playgroundLine = ` ${arrowToken} ${playgroundLabel}: ${coloredUrl}`;
|
|
425
331
|
const arrowPrefix = ` ${arrowToken} `;
|
|
426
|
-
const findIndex = (needle) => lines.findIndex((args) => stripAnsi(args[0]).includes(needle));
|
|
332
|
+
const findIndex = (needle) => lines.findIndex((args) => core.stripAnsi(args[0]).includes(needle));
|
|
427
333
|
const networkIndex = findIndex(`${arrowPrefix}Network:`);
|
|
428
334
|
const localIndex = findIndex(`${arrowPrefix}Local:`);
|
|
429
335
|
const insertIndex = networkIndex >= 0 ? networkIndex + 1 : localIndex >= 0 ? localIndex + 1 : lines.length;
|
|
@@ -432,7 +338,7 @@ function patchPlaygroundPrintUrls(server, playgroundPath) {
|
|
|
432
338
|
for (const args of outputLines) {
|
|
433
339
|
if (typeof args[0] === "string") {
|
|
434
340
|
const nextArgs = args.slice();
|
|
435
|
-
nextArgs[0] = formatOutputLine(nextArgs[0], formatOptions);
|
|
341
|
+
nextArgs[0] = core.formatOutputLine(nextArgs[0], formatOptions);
|
|
436
342
|
originalInfo(...nextArgs);
|
|
437
343
|
} else {
|
|
438
344
|
originalInfo(...args);
|
|
@@ -464,12 +370,12 @@ function normalizeRawWatcherPath(rawPath) {
|
|
|
464
370
|
return "";
|
|
465
371
|
}
|
|
466
372
|
function setupViteWatchers(params) {
|
|
467
|
-
const scheduleRefresh =
|
|
468
|
-
void params.refresh();
|
|
373
|
+
const scheduleRefresh = core.createDebouncer(80, () => {
|
|
374
|
+
void params.refresh({ force: true });
|
|
469
375
|
});
|
|
470
376
|
const handleWatchedFile = (file) => {
|
|
471
377
|
const resolvedFile = normalizeWatcherFile(file, params.server.config.root ?? params.root);
|
|
472
|
-
if (
|
|
378
|
+
if (core.isInDirs(resolvedFile, params.dirs)) {
|
|
473
379
|
scheduleRefresh();
|
|
474
380
|
}
|
|
475
381
|
};
|
|
@@ -487,19 +393,19 @@ function setupViteWatchers(params) {
|
|
|
487
393
|
}
|
|
488
394
|
const baseDir = typeof details === "object" && details && "watchedPath" in details ? details.watchedPath ?? (params.server.config.root ?? params.root) : params.server.config.root ?? params.root;
|
|
489
395
|
const resolvedFile = normalizeWatcherFile(candidate, baseDir);
|
|
490
|
-
if (
|
|
396
|
+
if (core.isInDirs(resolvedFile, params.dirs)) {
|
|
491
397
|
scheduleRefresh();
|
|
492
398
|
}
|
|
493
399
|
});
|
|
494
400
|
}
|
|
495
401
|
function setupPreviewWatchers(params) {
|
|
496
402
|
const watcher = chokidar__default.watch(params.dirs, { ignoreInitial: true });
|
|
497
|
-
const scheduleRefresh =
|
|
498
|
-
void params.refresh();
|
|
403
|
+
const scheduleRefresh = core.createDebouncer(80, () => {
|
|
404
|
+
void params.refresh({ force: true });
|
|
499
405
|
});
|
|
500
406
|
const handleWatchedFile = (file) => {
|
|
501
407
|
const resolvedFile = normalizeWatcherFile(file, params.server.config.root ?? params.root);
|
|
502
|
-
if (
|
|
408
|
+
if (core.isInDirs(resolvedFile, params.dirs)) {
|
|
503
409
|
scheduleRefresh();
|
|
504
410
|
}
|
|
505
411
|
};
|
|
@@ -516,7 +422,7 @@ function setupPreviewWatchers(params) {
|
|
|
516
422
|
}
|
|
517
423
|
const baseDir = typeof details === "object" && details && "watchedPath" in details ? details.watchedPath ?? (params.server.config.root ?? params.root) : params.server.config.root ?? params.root;
|
|
518
424
|
const resolvedFile = normalizeWatcherFile(candidate, baseDir);
|
|
519
|
-
if (
|
|
425
|
+
if (core.isInDirs(resolvedFile, params.dirs)) {
|
|
520
426
|
scheduleRefresh();
|
|
521
427
|
}
|
|
522
428
|
});
|
|
@@ -557,7 +463,7 @@ async function configureDevServer(params) {
|
|
|
557
463
|
return next();
|
|
558
464
|
}
|
|
559
465
|
try {
|
|
560
|
-
const code =
|
|
466
|
+
const code = core.buildSwScript({
|
|
561
467
|
routes: state.swRoutes,
|
|
562
468
|
root,
|
|
563
469
|
runtimeImportPath: resolveSwRuntimeImportPath(base),
|
|
@@ -577,7 +483,7 @@ async function configureDevServer(params) {
|
|
|
577
483
|
});
|
|
578
484
|
}
|
|
579
485
|
if (enableViteMiddleware && state.serverRoutes.length > 0) {
|
|
580
|
-
server.middlewares.use(
|
|
486
|
+
server.middlewares.use(core.createMiddleware(() => state.app, logger));
|
|
581
487
|
}
|
|
582
488
|
if (!watchEnabled) {
|
|
583
489
|
return;
|
|
@@ -587,7 +493,7 @@ async function configureDevServer(params) {
|
|
|
587
493
|
server,
|
|
588
494
|
root,
|
|
589
495
|
dirs,
|
|
590
|
-
refresh: () => refreshRoutes(server)
|
|
496
|
+
refresh: (options) => refreshRoutes(server, options)
|
|
591
497
|
});
|
|
592
498
|
}
|
|
593
499
|
async function configurePreviewServer(params) {
|
|
@@ -616,7 +522,7 @@ async function configurePreviewServer(params) {
|
|
|
616
522
|
return next();
|
|
617
523
|
}
|
|
618
524
|
try {
|
|
619
|
-
const code =
|
|
525
|
+
const code = core.buildSwScript({
|
|
620
526
|
routes: state.swRoutes,
|
|
621
527
|
root,
|
|
622
528
|
basePaths: swConfig?.basePaths ?? []
|
|
@@ -634,7 +540,7 @@ async function configurePreviewServer(params) {
|
|
|
634
540
|
});
|
|
635
541
|
}
|
|
636
542
|
if (enableViteMiddleware && state.serverRoutes.length > 0) {
|
|
637
|
-
server.middlewares.use(
|
|
543
|
+
server.middlewares.use(core.createMiddleware(() => state.app, logger));
|
|
638
544
|
}
|
|
639
545
|
if (!watchEnabled) {
|
|
640
546
|
return null;
|
|
@@ -644,7 +550,7 @@ async function configurePreviewServer(params) {
|
|
|
644
550
|
server,
|
|
645
551
|
root,
|
|
646
552
|
dirs,
|
|
647
|
-
refresh: () => refreshRoutes(server)
|
|
553
|
+
refresh: (options) => refreshRoutes(server, options)
|
|
648
554
|
});
|
|
649
555
|
return watcher;
|
|
650
556
|
}
|
|
@@ -847,11 +753,11 @@ function createMokupPlugin(options = {}) {
|
|
|
847
753
|
const optionList = normalizeOptions(normalizedOptions);
|
|
848
754
|
const logEnabled = optionList.every((entry) => entry.log !== false);
|
|
849
755
|
const watchEnabled = optionList.every((entry) => entry.watch !== false);
|
|
850
|
-
const playgroundConfig =
|
|
851
|
-
const logger
|
|
756
|
+
const playgroundConfig = core.resolvePlaygroundOptions(normalizedOptions.playground);
|
|
757
|
+
const logger = core.createLogger(logEnabled);
|
|
852
758
|
const hasSwEntries = optionList.some((entry) => entry.mode === "sw");
|
|
853
|
-
const swConfig =
|
|
854
|
-
const unregisterConfig =
|
|
759
|
+
const swConfig = core.resolveSwConfig(optionList, logger);
|
|
760
|
+
const unregisterConfig = core.resolveSwUnregisterConfig(optionList, logger);
|
|
855
761
|
const resolveAllDirs = createDirResolver(optionList, () => root);
|
|
856
762
|
const hasSwRoutes = () => !!swConfig && state.swRoutes.length > 0;
|
|
857
763
|
const { resolveSwRequestPath, resolveSwRegisterScope } = createSwPathResolver(() => base);
|
|
@@ -867,14 +773,14 @@ function createMokupPlugin(options = {}) {
|
|
|
867
773
|
const resolvedBundleVirtualId = `\0${bundleVirtualId}`;
|
|
868
774
|
let swLifecycleFileName = null;
|
|
869
775
|
let swLifecycleScript = null;
|
|
870
|
-
const playgroundMiddleware =
|
|
776
|
+
const playgroundMiddleware = core.createPlaygroundMiddleware({
|
|
871
777
|
getRoutes: () => state.routes,
|
|
872
778
|
getDisabledRoutes: () => state.disabledRoutes,
|
|
873
779
|
getIgnoredRoutes: () => state.ignoredRoutes,
|
|
874
780
|
getConfigFiles: () => state.configFiles,
|
|
875
781
|
getDisabledConfigFiles: () => state.disabledConfigFiles,
|
|
876
782
|
config: playgroundConfig,
|
|
877
|
-
logger
|
|
783
|
+
logger,
|
|
878
784
|
getServer: () => currentServer,
|
|
879
785
|
getDirs: () => resolveAllDirs(),
|
|
880
786
|
getSwScript: () => buildSwLifecycleScript({
|
|
@@ -885,14 +791,17 @@ function createMokupPlugin(options = {}) {
|
|
|
885
791
|
hasSwRoutes: hasSwRoutes(),
|
|
886
792
|
resolveRequestPath: resolveSwRequestPath,
|
|
887
793
|
resolveRegisterScope: resolveSwRegisterScope
|
|
888
|
-
})
|
|
794
|
+
}),
|
|
795
|
+
resolvePlaygroundDist: assets.resolvePlaygroundDist
|
|
889
796
|
});
|
|
890
797
|
const refreshRoutes = createRouteRefresher({
|
|
891
798
|
state,
|
|
892
799
|
optionList,
|
|
893
800
|
root: () => root,
|
|
894
|
-
logger
|
|
895
|
-
enableViteMiddleware
|
|
801
|
+
logger,
|
|
802
|
+
enableViteMiddleware,
|
|
803
|
+
virtualModuleIds: [resolvedBundleVirtualId],
|
|
804
|
+
reloadOnChange: runtime === "worker"
|
|
896
805
|
});
|
|
897
806
|
return {
|
|
898
807
|
name: "mokup:vite",
|
|
@@ -911,8 +820,9 @@ function createMokupPlugin(options = {}) {
|
|
|
911
820
|
},
|
|
912
821
|
async load(id) {
|
|
913
822
|
if (id === resolvedBundleVirtualId) {
|
|
914
|
-
|
|
915
|
-
|
|
823
|
+
const shouldRefresh = command !== "build" || !state.lastSignature;
|
|
824
|
+
if (shouldRefresh) {
|
|
825
|
+
await refreshRoutes(currentServer ?? void 0, { silent: true });
|
|
916
826
|
}
|
|
917
827
|
const dirs = resolveAllDirs();
|
|
918
828
|
for (const dir of dirs) {
|
|
@@ -930,7 +840,7 @@ function createMokupPlugin(options = {}) {
|
|
|
930
840
|
for (const config of state.disabledConfigFiles) {
|
|
931
841
|
this.addWatchFile(config.file);
|
|
932
842
|
}
|
|
933
|
-
return
|
|
843
|
+
return core.buildBundleModule({ routes: state.serverRoutes, root });
|
|
934
844
|
}
|
|
935
845
|
if (id !== resolvedSwVirtualId) {
|
|
936
846
|
if (id !== resolvedSwLifecycleVirtualId) {
|
|
@@ -956,7 +866,7 @@ function createMokupPlugin(options = {}) {
|
|
|
956
866
|
if (state.swRoutes.length === 0) {
|
|
957
867
|
await refreshRoutes();
|
|
958
868
|
}
|
|
959
|
-
return
|
|
869
|
+
return core.buildSwScript({
|
|
960
870
|
routes: state.swRoutes,
|
|
961
871
|
root,
|
|
962
872
|
basePaths: swConfig?.basePaths ?? []
|
|
@@ -1056,7 +966,7 @@ function createMokupPlugin(options = {}) {
|
|
|
1056
966
|
state,
|
|
1057
967
|
root,
|
|
1058
968
|
base,
|
|
1059
|
-
logger
|
|
969
|
+
logger,
|
|
1060
970
|
playgroundConfig,
|
|
1061
971
|
playgroundMiddleware,
|
|
1062
972
|
swConfig,
|
|
@@ -1074,7 +984,7 @@ function createMokupPlugin(options = {}) {
|
|
|
1074
984
|
state,
|
|
1075
985
|
root,
|
|
1076
986
|
base,
|
|
1077
|
-
logger
|
|
987
|
+
logger,
|
|
1078
988
|
playgroundMiddleware,
|
|
1079
989
|
swConfig,
|
|
1080
990
|
hasSwRoutes,
|
|
@@ -1102,7 +1012,7 @@ function createMokupPlugin(options = {}) {
|
|
|
1102
1012
|
resolveRequestPath: resolveSwRequestPath,
|
|
1103
1013
|
resolveRegisterScope: resolveSwRegisterScope
|
|
1104
1014
|
});
|
|
1105
|
-
await writePlaygroundBuild({
|
|
1015
|
+
await core.writePlaygroundBuild({
|
|
1106
1016
|
outDir,
|
|
1107
1017
|
base,
|
|
1108
1018
|
playgroundPath: playgroundConfig.path,
|
|
@@ -1114,7 +1024,8 @@ function createMokupPlugin(options = {}) {
|
|
|
1114
1024
|
disabledConfigFiles: state.disabledConfigFiles,
|
|
1115
1025
|
dirs: resolveAllDirs(),
|
|
1116
1026
|
swScript,
|
|
1117
|
-
logger
|
|
1027
|
+
logger,
|
|
1028
|
+
resolvePlaygroundDist: assets.resolvePlaygroundDist
|
|
1118
1029
|
});
|
|
1119
1030
|
}
|
|
1120
1031
|
};
|
package/dist/vite.d.cts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { MokupPluginOptions } from '@mokup/core';
|
|
2
|
+
export { Context, HttpMethod, MiddlewareHandler, MiddlewarePosition, MiddlewareRegistry, MokupPluginOptions, PlaygroundOptionsInput, RequestHandler, RouteDirectoryConfig, RouteResponse, RouteRule, RuntimeMode, ServiceWorkerOptions, VitePluginOptions, VitePluginOptionsInput, ViteRuntime } from '@mokup/core';
|
|
3
3
|
import { Plugin } from 'vite';
|
|
4
|
-
export { Context, MiddlewareHandler } from '@mokup/shared/hono';
|
|
5
|
-
export { PlaygroundOptionsInput } from '@mokup/shared';
|
|
6
|
-
import '@mokup/runtime';
|
|
7
4
|
|
|
8
5
|
/**
|
|
9
6
|
* Create the mokup Vite plugin.
|
|
@@ -25,6 +22,4 @@ import '@mokup/runtime';
|
|
|
25
22
|
*/
|
|
26
23
|
declare function createMokupPlugin(options?: MokupPluginOptions): Plugin;
|
|
27
24
|
|
|
28
|
-
// @ts-ignore
|
|
29
25
|
export = createMokupPlugin;
|
|
30
|
-
export { MokupPluginOptions };
|
package/dist/vite.d.mts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { MokupPluginOptions } from '@mokup/core';
|
|
2
|
+
export { Context, HttpMethod, MiddlewareHandler, MiddlewarePosition, MiddlewareRegistry, MokupPluginOptions, PlaygroundOptionsInput, RequestHandler, RouteDirectoryConfig, RouteResponse, RouteRule, RuntimeMode, ServiceWorkerOptions, VitePluginOptions, VitePluginOptionsInput, ViteRuntime } from '@mokup/core';
|
|
3
3
|
import { Plugin } from 'vite';
|
|
4
|
-
export { Context, MiddlewareHandler } from '@mokup/shared/hono';
|
|
5
|
-
export { PlaygroundOptionsInput } from '@mokup/shared';
|
|
6
|
-
import '@mokup/runtime';
|
|
7
4
|
|
|
8
5
|
/**
|
|
9
6
|
* Create the mokup Vite plugin.
|
|
@@ -25,4 +22,4 @@ import '@mokup/runtime';
|
|
|
25
22
|
*/
|
|
26
23
|
declare function createMokupPlugin(options?: MokupPluginOptions): Plugin;
|
|
27
24
|
|
|
28
|
-
export {
|
|
25
|
+
export { createMokupPlugin as default };
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
/// <reference path="./types/virtual.d.ts" />
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
export {
|
|
3
|
+
import { MokupPluginOptions } from '@mokup/core';
|
|
4
|
+
export { Context, HttpMethod, MiddlewareHandler, MiddlewarePosition, MiddlewareRegistry, MokupPluginOptions, PlaygroundOptionsInput, RequestHandler, RouteDirectoryConfig, RouteResponse, RouteRule, RuntimeMode, ServiceWorkerOptions, VitePluginOptions, VitePluginOptionsInput, ViteRuntime } from '@mokup/core';
|
|
5
5
|
import { Plugin } from 'vite';
|
|
6
|
-
export { Context, MiddlewareHandler } from '@mokup/shared/hono';
|
|
7
|
-
export { PlaygroundOptionsInput } from '@mokup/shared';
|
|
8
|
-
import '@mokup/runtime';
|
|
9
6
|
|
|
10
7
|
/**
|
|
11
8
|
* Create the mokup Vite plugin.
|
|
@@ -27,6 +24,4 @@ import '@mokup/runtime';
|
|
|
27
24
|
*/
|
|
28
25
|
declare function createMokupPlugin(options?: MokupPluginOptions): Plugin;
|
|
29
26
|
|
|
30
|
-
// @ts-ignore
|
|
31
27
|
export = createMokupPlugin;
|
|
32
|
-
export { MokupPluginOptions };
|