mokup 2.2.1 → 2.3.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.
@@ -1,4 +1,6 @@
1
- import { resolve, isAbsolute, relative } from '@mokup/shared/pathe';
1
+ import { isAbsolute, resolve, relative } from '@mokup/shared/pathe';
2
+ import { toPosix } from '@mokup/shared/path-utils';
3
+ import '@mokup/shared/timing';
2
4
 
3
5
  const methodSet = /* @__PURE__ */ new Set([
4
6
  "GET",
@@ -22,71 +24,6 @@ const supportedExtensions = /* @__PURE__ */ new Set([
22
24
  ]);
23
25
  const configExtensions = [".ts", ".js", ".mjs", ".cjs"];
24
26
 
25
- function normalizeMethod(method) {
26
- if (!method) {
27
- return void 0;
28
- }
29
- const normalized = method.toUpperCase();
30
- if (methodSet.has(normalized)) {
31
- return normalized;
32
- }
33
- return void 0;
34
- }
35
- function normalizePrefix(prefix) {
36
- if (!prefix) {
37
- return "";
38
- }
39
- const normalized = prefix.startsWith("/") ? prefix : `/${prefix}`;
40
- return normalized.endsWith("/") ? normalized.slice(0, -1) : normalized;
41
- }
42
- function resolveDirs(dir, root) {
43
- const raw = typeof dir === "function" ? dir(root) : dir;
44
- const resolved = Array.isArray(raw) ? raw : raw ? [raw] : ["mock"];
45
- const normalized = resolved.map(
46
- (entry) => isAbsolute(entry) ? entry : resolve(root, entry)
47
- );
48
- return Array.from(new Set(normalized));
49
- }
50
- function createDebouncer(delayMs, fn) {
51
- let timer = null;
52
- return () => {
53
- if (timer) {
54
- clearTimeout(timer);
55
- }
56
- timer = setTimeout(() => {
57
- timer = null;
58
- fn();
59
- }, delayMs);
60
- };
61
- }
62
- function toPosix(value) {
63
- return value.replace(/\\/g, "/");
64
- }
65
- function isInDirs(file, dirs) {
66
- const normalized = toPosix(file);
67
- return dirs.some((dir) => {
68
- const normalizedDir = toPosix(dir).replace(/\/$/, "");
69
- return normalized === normalizedDir || normalized.startsWith(`${normalizedDir}/`);
70
- });
71
- }
72
- function normalizeIgnorePrefix(value, fallback = ["."]) {
73
- const list = typeof value === "undefined" ? fallback : Array.isArray(value) ? value : [value];
74
- return list.filter((entry) => typeof entry === "string" && entry.length > 0);
75
- }
76
- function hasIgnoredPrefix(file, rootDir, prefixes) {
77
- if (prefixes.length === 0) {
78
- return false;
79
- }
80
- const relativePath = toPosix(relative(rootDir, file));
81
- const segments = relativePath.split("/");
82
- return segments.some(
83
- (segment) => prefixes.some((prefix) => segment.startsWith(prefix))
84
- );
85
- }
86
- function delay(ms) {
87
- return new Promise((resolve2) => setTimeout(resolve2, ms));
88
- }
89
-
90
27
  function toViteImportPath(file, root) {
91
28
  const absolute = isAbsolute(file) ? file : resolve(root, file);
92
29
  const rel = relative(root, absolute);
@@ -234,4 +171,4 @@ function buildManifestData(params) {
234
171
  };
235
172
  }
236
173
 
237
- export { toViteImportPath as a, buildManifestData as b, createDebouncer as c, normalizeMethod as d, delay as e, configExtensions as f, normalizeIgnorePrefix as g, hasIgnoredPrefix as h, isInDirs as i, methodSuffixSet as m, normalizePrefix as n, resolveDirs as r, supportedExtensions as s, toPosix as t };
174
+ export { methodSuffixSet as a, buildManifestData as b, configExtensions as c, methodSet as m, supportedExtensions as s, toViteImportPath as t };
package/dist/vite.cjs CHANGED
@@ -1,15 +1,18 @@
1
1
  'use strict';
2
2
 
3
3
  const process = require('node:process');
4
- const bundle = require('./shared/mokup.zkaN1ADs.cjs');
4
+ const bundle = require('./shared/mokup.BXPIIxtS.cjs');
5
5
  const node_fs = require('node:fs');
6
6
  const pathe = require('@mokup/shared/pathe');
7
- const scanner = require('./shared/mokup.DLUSS6KF.cjs');
7
+ const scanner = require('./shared/mokup.DXCs9518.cjs');
8
+ const playgroundGrouping = require('@mokup/shared/playground-grouping');
8
9
  const logger = require('@mokup/shared/logger');
9
- const manifest = require('./shared/mokup.C7-7PDF7.cjs');
10
10
  const pc = require('picocolors');
11
11
  const node_path = require('node:path');
12
12
  const chokidar = require('@mokup/shared/chokidar');
13
+ require('./shared/mokup.Dy9VDphS.cjs');
14
+ const pathUtils = require('@mokup/shared/path-utils');
15
+ const timing = require('@mokup/shared/timing');
13
16
  const node_url = require('node:url');
14
17
  require('node:module');
15
18
  require('node:buffer');
@@ -36,8 +39,8 @@ function stripSwLifecycle(html) {
36
39
  );
37
40
  }
38
41
  async function writeRoutesPayload(params, targetDir) {
39
- const baseRoot = scanner.resolveGroupRoot(params.dirs, params.root);
40
- const groups = scanner.resolveGroups(params.dirs, baseRoot);
42
+ const baseRoot = playgroundGrouping.resolveGroupRoot(params.dirs, params.root);
43
+ const groups = playgroundGrouping.resolveGroups(params.dirs, baseRoot);
41
44
  const basePath = scanner.resolvePlaygroundRequestPath(params.base, params.playgroundPath);
42
45
  const payload = {
43
46
  basePath,
@@ -228,8 +231,8 @@ function isViteDevServer(server) {
228
231
  }
229
232
 
230
233
  function createRouteRefresher(params) {
231
- const { state, optionList, root, logger, enableViteMiddleware } = params;
232
- return async (server) => {
234
+ const { state, optionList, root, logger, enableViteMiddleware, virtualModuleIds } = params;
235
+ return async (server, options) => {
233
236
  const collected = [];
234
237
  const collectedServer = [];
235
238
  const collectedSw = [];
@@ -237,7 +240,7 @@ function createRouteRefresher(params) {
237
240
  const collectedIgnored = [];
238
241
  const collectedConfigs = [];
239
242
  for (const entry of optionList) {
240
- const dirs = manifest.resolveDirs(entry.dir, root());
243
+ const dirs = scanner.resolveDirs(entry.dir, root());
241
244
  const scanParams = {
242
245
  dirs,
243
246
  prefix: entry.prefix ?? "",
@@ -287,12 +290,21 @@ function createRouteRefresher(params) {
287
290
  state.disabledConfigFiles
288
291
  );
289
292
  if (isViteDevServer(server) && server.ws) {
290
- if (state.lastSignature && signature !== state.lastSignature) {
293
+ const shouldNotify = !options?.silent && state.lastSignature && (signature !== state.lastSignature || options?.force);
294
+ if (shouldNotify) {
291
295
  server.ws.send({
292
296
  type: "custom",
293
297
  event: "mokup:routes-changed",
294
298
  data: { ts: Date.now() }
295
299
  });
300
+ if (virtualModuleIds && virtualModuleIds.length > 0) {
301
+ for (const id of virtualModuleIds) {
302
+ const moduleNode = server.moduleGraph.getModuleById(id);
303
+ if (moduleNode) {
304
+ server.moduleGraph.invalidateModule(moduleNode);
305
+ }
306
+ }
307
+ }
296
308
  }
297
309
  }
298
310
  state.lastSignature = signature;
@@ -304,7 +316,7 @@ function createDirResolver(optionList, root) {
304
316
  const dirs = [];
305
317
  const seen = /* @__PURE__ */ new Set();
306
318
  for (const entry of optionList) {
307
- for (const dir of manifest.resolveDirs(entry.dir, root())) {
319
+ for (const dir of scanner.resolveDirs(entry.dir, root())) {
308
320
  if (seen.has(dir)) {
309
321
  continue;
310
322
  }
@@ -461,12 +473,12 @@ function normalizeRawWatcherPath(rawPath) {
461
473
  return "";
462
474
  }
463
475
  function setupViteWatchers(params) {
464
- const scheduleRefresh = manifest.createDebouncer(80, () => {
465
- void params.refresh();
476
+ const scheduleRefresh = timing.createDebouncer(80, () => {
477
+ void params.refresh({ force: true });
466
478
  });
467
479
  const handleWatchedFile = (file) => {
468
480
  const resolvedFile = normalizeWatcherFile(file, params.server.config.root ?? params.root);
469
- if (manifest.isInDirs(resolvedFile, params.dirs)) {
481
+ if (pathUtils.isInDirs(resolvedFile, params.dirs)) {
470
482
  scheduleRefresh();
471
483
  }
472
484
  };
@@ -484,19 +496,19 @@ function setupViteWatchers(params) {
484
496
  }
485
497
  const baseDir = typeof details === "object" && details && "watchedPath" in details ? details.watchedPath ?? (params.server.config.root ?? params.root) : params.server.config.root ?? params.root;
486
498
  const resolvedFile = normalizeWatcherFile(candidate, baseDir);
487
- if (manifest.isInDirs(resolvedFile, params.dirs)) {
499
+ if (pathUtils.isInDirs(resolvedFile, params.dirs)) {
488
500
  scheduleRefresh();
489
501
  }
490
502
  });
491
503
  }
492
504
  function setupPreviewWatchers(params) {
493
505
  const watcher = chokidar__default.watch(params.dirs, { ignoreInitial: true });
494
- const scheduleRefresh = manifest.createDebouncer(80, () => {
495
- void params.refresh();
506
+ const scheduleRefresh = timing.createDebouncer(80, () => {
507
+ void params.refresh({ force: true });
496
508
  });
497
509
  const handleWatchedFile = (file) => {
498
510
  const resolvedFile = normalizeWatcherFile(file, params.server.config.root ?? params.root);
499
- if (manifest.isInDirs(resolvedFile, params.dirs)) {
511
+ if (pathUtils.isInDirs(resolvedFile, params.dirs)) {
500
512
  scheduleRefresh();
501
513
  }
502
514
  };
@@ -513,7 +525,7 @@ function setupPreviewWatchers(params) {
513
525
  }
514
526
  const baseDir = typeof details === "object" && details && "watchedPath" in details ? details.watchedPath ?? (params.server.config.root ?? params.root) : params.server.config.root ?? params.root;
515
527
  const resolvedFile = normalizeWatcherFile(candidate, baseDir);
516
- if (manifest.isInDirs(resolvedFile, params.dirs)) {
528
+ if (pathUtils.isInDirs(resolvedFile, params.dirs)) {
517
529
  scheduleRefresh();
518
530
  }
519
531
  });
@@ -584,7 +596,7 @@ async function configureDevServer(params) {
584
596
  server,
585
597
  root,
586
598
  dirs,
587
- refresh: () => refreshRoutes(server)
599
+ refresh: (options) => refreshRoutes(server, options)
588
600
  });
589
601
  }
590
602
  async function configurePreviewServer(params) {
@@ -641,7 +653,7 @@ async function configurePreviewServer(params) {
641
653
  server,
642
654
  root,
643
655
  dirs,
644
- refresh: () => refreshRoutes(server)
656
+ refresh: (options) => refreshRoutes(server, options)
645
657
  });
646
658
  return watcher;
647
659
  }
@@ -889,7 +901,8 @@ function createMokupPlugin(options = {}) {
889
901
  optionList,
890
902
  root: () => root,
891
903
  logger: logger$1,
892
- enableViteMiddleware
904
+ enableViteMiddleware,
905
+ virtualModuleIds: [resolvedBundleVirtualId]
893
906
  });
894
907
  return {
895
908
  name: "mokup:vite",
@@ -908,8 +921,9 @@ function createMokupPlugin(options = {}) {
908
921
  },
909
922
  async load(id) {
910
923
  if (id === resolvedBundleVirtualId) {
911
- if (!state.lastSignature) {
912
- await refreshRoutes(currentServer ?? void 0);
924
+ const shouldRefresh = command !== "build" || !state.lastSignature;
925
+ if (shouldRefresh) {
926
+ await refreshRoutes(currentServer ?? void 0, { silent: true });
913
927
  }
914
928
  const dirs = resolveAllDirs();
915
929
  for (const dir of dirs) {
package/dist/vite.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { M as MokupPluginOptions } from './shared/mokup.DeotZ0g8.cjs';
2
- export { H as HttpMethod, b as MiddlewarePosition, c as MiddlewareRegistry, d as RequestHandler, e as RouteDirectoryConfig, f as RouteResponse, g as RouteRule, h as RuntimeMode, S as ServiceWorkerOptions, V as VitePluginOptions, i as VitePluginOptionsInput, j as ViteRuntime } from './shared/mokup.DeotZ0g8.cjs';
1
+ import { M as MokupPluginOptions } from './shared/mokup.Dkqu10Hk.cjs';
2
+ export { H as HttpMethod, b as MiddlewarePosition, c as MiddlewareRegistry, d as RequestHandler, e as RouteDirectoryConfig, f as RouteResponse, g as RouteRule, h as RuntimeMode, S as ServiceWorkerOptions, V as VitePluginOptions, i as VitePluginOptionsInput, j as ViteRuntime } from './shared/mokup.Dkqu10Hk.cjs';
3
3
  import { Plugin } from 'vite';
4
4
  export { Context, MiddlewareHandler } from '@mokup/shared/hono';
5
5
  export { PlaygroundOptionsInput } from '@mokup/shared';
package/dist/vite.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { M as MokupPluginOptions } from './shared/mokup.DeotZ0g8.mjs';
2
- export { H as HttpMethod, b as MiddlewarePosition, c as MiddlewareRegistry, d as RequestHandler, e as RouteDirectoryConfig, f as RouteResponse, g as RouteRule, h as RuntimeMode, S as ServiceWorkerOptions, V as VitePluginOptions, i as VitePluginOptionsInput, j as ViteRuntime } from './shared/mokup.DeotZ0g8.mjs';
1
+ import { M as MokupPluginOptions } from './shared/mokup.Dkqu10Hk.mjs';
2
+ export { H as HttpMethod, b as MiddlewarePosition, c as MiddlewareRegistry, d as RequestHandler, e as RouteDirectoryConfig, f as RouteResponse, g as RouteRule, h as RuntimeMode, S as ServiceWorkerOptions, V as VitePluginOptions, i as VitePluginOptionsInput, j as ViteRuntime } from './shared/mokup.Dkqu10Hk.mjs';
3
3
  import { Plugin } from 'vite';
4
4
  export { Context, MiddlewareHandler } from '@mokup/shared/hono';
5
5
  export { PlaygroundOptionsInput } from '@mokup/shared';
package/dist/vite.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /// <reference path="./types/virtual.d.ts" />
2
2
 
3
- import { M as MokupPluginOptions } from './shared/mokup.DeotZ0g8.js';
4
- export { H as HttpMethod, b as MiddlewarePosition, c as MiddlewareRegistry, d as RequestHandler, e as RouteDirectoryConfig, f as RouteResponse, g as RouteRule, h as RuntimeMode, S as ServiceWorkerOptions, V as VitePluginOptions, i as VitePluginOptionsInput, j as ViteRuntime } from './shared/mokup.DeotZ0g8.js';
3
+ import { M as MokupPluginOptions } from './shared/mokup.Dkqu10Hk.js';
4
+ export { H as HttpMethod, b as MiddlewarePosition, c as MiddlewareRegistry, d as RequestHandler, e as RouteDirectoryConfig, f as RouteResponse, g as RouteRule, h as RuntimeMode, S as ServiceWorkerOptions, V as VitePluginOptions, i as VitePluginOptionsInput, j as ViteRuntime } from './shared/mokup.Dkqu10Hk.js';
5
5
  import { Plugin } from 'vite';
6
6
  export { Context, MiddlewareHandler } from '@mokup/shared/hono';
7
7
  export { PlaygroundOptionsInput } from '@mokup/shared';
package/dist/vite.mjs CHANGED
@@ -1,13 +1,16 @@
1
1
  import { cwd } from 'node:process';
2
- import { b as buildBundleModule } from './shared/mokup.vAap-D_L.mjs';
2
+ import { b as buildBundleModule } from './shared/mokup.CsBTglhs.mjs';
3
3
  import { promises, existsSync } from 'node:fs';
4
4
  import { join, normalize } from '@mokup/shared/pathe';
5
- import { h as resolvePlaygroundDist, n as normalizePlaygroundPath, i as injectPlaygroundSw, j as resolveGroupRoot, k as resolveGroups, l as resolvePlaygroundRequestPath, t as toPlaygroundConfigFile, m as toPlaygroundIgnoredRoute, o as toPlaygroundDisabledRoute, p as toPlaygroundRoute, s as scanRoutes, a as sortRoutes, c as createHonoApp, b as buildSwScript, g as createMiddleware, r as resolvePlaygroundOptions, d as resolveSwConfig, e as resolveSwUnregisterConfig, f as createPlaygroundMiddleware } from './shared/mokup.CtSctWaa.mjs';
5
+ import { i as resolvePlaygroundDist, n as normalizePlaygroundPath, j as injectPlaygroundSw, k as resolvePlaygroundRequestPath, t as toPlaygroundConfigFile, l as toPlaygroundIgnoredRoute, m as toPlaygroundDisabledRoute, o as toPlaygroundRoute, r as resolveDirs, s as scanRoutes, a as sortRoutes, c as createHonoApp, b as buildSwScript, h as createMiddleware, d as resolvePlaygroundOptions, e as resolveSwConfig, f as resolveSwUnregisterConfig, g as createPlaygroundMiddleware } from './shared/mokup.C-hwskJ_.mjs';
6
+ import { resolveGroupRoot, resolveGroups } from '@mokup/shared/playground-grouping';
6
7
  import { createLogger } from '@mokup/shared/logger';
7
- import { r as resolveDirs, i as isInDirs, c as createDebouncer } from './shared/mokup.JBCzv4xR.mjs';
8
8
  import pc from 'picocolors';
9
9
  import { isAbsolute, resolve, dirname } from 'node:path';
10
10
  import chokidar from '@mokup/shared/chokidar';
11
+ import './shared/mokup.Iqw32OxC.mjs';
12
+ import { isInDirs } from '@mokup/shared/path-utils';
13
+ import { createDebouncer } from '@mokup/shared/timing';
11
14
  import { fileURLToPath } from 'node:url';
12
15
  import 'node:module';
13
16
  import 'node:buffer';
@@ -220,8 +223,8 @@ function isViteDevServer(server) {
220
223
  }
221
224
 
222
225
  function createRouteRefresher(params) {
223
- const { state, optionList, root, logger, enableViteMiddleware } = params;
224
- return async (server) => {
226
+ const { state, optionList, root, logger, enableViteMiddleware, virtualModuleIds } = params;
227
+ return async (server, options) => {
225
228
  const collected = [];
226
229
  const collectedServer = [];
227
230
  const collectedSw = [];
@@ -279,12 +282,21 @@ function createRouteRefresher(params) {
279
282
  state.disabledConfigFiles
280
283
  );
281
284
  if (isViteDevServer(server) && server.ws) {
282
- if (state.lastSignature && signature !== state.lastSignature) {
285
+ const shouldNotify = !options?.silent && state.lastSignature && (signature !== state.lastSignature || options?.force);
286
+ if (shouldNotify) {
283
287
  server.ws.send({
284
288
  type: "custom",
285
289
  event: "mokup:routes-changed",
286
290
  data: { ts: Date.now() }
287
291
  });
292
+ if (virtualModuleIds && virtualModuleIds.length > 0) {
293
+ for (const id of virtualModuleIds) {
294
+ const moduleNode = server.moduleGraph.getModuleById(id);
295
+ if (moduleNode) {
296
+ server.moduleGraph.invalidateModule(moduleNode);
297
+ }
298
+ }
299
+ }
288
300
  }
289
301
  }
290
302
  state.lastSignature = signature;
@@ -454,7 +466,7 @@ function normalizeRawWatcherPath(rawPath) {
454
466
  }
455
467
  function setupViteWatchers(params) {
456
468
  const scheduleRefresh = createDebouncer(80, () => {
457
- void params.refresh();
469
+ void params.refresh({ force: true });
458
470
  });
459
471
  const handleWatchedFile = (file) => {
460
472
  const resolvedFile = normalizeWatcherFile(file, params.server.config.root ?? params.root);
@@ -484,7 +496,7 @@ function setupViteWatchers(params) {
484
496
  function setupPreviewWatchers(params) {
485
497
  const watcher = chokidar.watch(params.dirs, { ignoreInitial: true });
486
498
  const scheduleRefresh = createDebouncer(80, () => {
487
- void params.refresh();
499
+ void params.refresh({ force: true });
488
500
  });
489
501
  const handleWatchedFile = (file) => {
490
502
  const resolvedFile = normalizeWatcherFile(file, params.server.config.root ?? params.root);
@@ -576,7 +588,7 @@ async function configureDevServer(params) {
576
588
  server,
577
589
  root,
578
590
  dirs,
579
- refresh: () => refreshRoutes(server)
591
+ refresh: (options) => refreshRoutes(server, options)
580
592
  });
581
593
  }
582
594
  async function configurePreviewServer(params) {
@@ -633,7 +645,7 @@ async function configurePreviewServer(params) {
633
645
  server,
634
646
  root,
635
647
  dirs,
636
- refresh: () => refreshRoutes(server)
648
+ refresh: (options) => refreshRoutes(server, options)
637
649
  });
638
650
  return watcher;
639
651
  }
@@ -881,7 +893,8 @@ function createMokupPlugin(options = {}) {
881
893
  optionList,
882
894
  root: () => root,
883
895
  logger,
884
- enableViteMiddleware
896
+ enableViteMiddleware,
897
+ virtualModuleIds: [resolvedBundleVirtualId]
885
898
  });
886
899
  return {
887
900
  name: "mokup:vite",
@@ -900,8 +913,9 @@ function createMokupPlugin(options = {}) {
900
913
  },
901
914
  async load(id) {
902
915
  if (id === resolvedBundleVirtualId) {
903
- if (!state.lastSignature) {
904
- await refreshRoutes(currentServer ?? void 0);
916
+ const shouldRefresh = command !== "build" || !state.lastSignature;
917
+ if (shouldRefresh) {
918
+ await refreshRoutes(currentServer ?? void 0, { silent: true });
905
919
  }
906
920
  const dirs = resolveAllDirs();
907
921
  for (const dir of dirs) {
package/dist/webpack.cjs CHANGED
@@ -1,13 +1,16 @@
1
1
  'use strict';
2
2
 
3
3
  const process = require('node:process');
4
- const scanner = require('./shared/mokup.DLUSS6KF.cjs');
4
+ const scanner = require('./shared/mokup.DXCs9518.cjs');
5
5
  require('node:fs');
6
6
  const pathe = require('@mokup/shared/pathe');
7
+ require('@mokup/shared/playground-grouping');
7
8
  const logger = require('@mokup/shared/logger');
8
- const manifest = require('./shared/mokup.C7-7PDF7.cjs');
9
9
  const esbuild = require('@mokup/shared/esbuild');
10
10
  const node_module = require('node:module');
11
+ require('./shared/mokup.Dy9VDphS.cjs');
12
+ const pathUtils = require('@mokup/shared/path-utils');
13
+ const timing = require('@mokup/shared/timing');
11
14
  const chokidar = require('@mokup/shared/chokidar');
12
15
  require('node:buffer');
13
16
  require('@mokup/shared/hono');
@@ -256,7 +259,7 @@ function joinPublicPath(publicPath, fileName) {
256
259
  }
257
260
  function resolveModuleFilePath(file, root) {
258
261
  const absolute = pathe.isAbsolute(file) ? file : pathe.resolve(root, file);
259
- const normalized = manifest.toPosix(absolute);
262
+ const normalized = pathUtils.toPosix(absolute);
260
263
  if (/^[a-z]:\//i.test(normalized)) {
261
264
  return `file:///${normalized}`;
262
265
  }
@@ -274,7 +277,7 @@ function createRouteRefresher(params) {
274
277
  const collectedConfigs = [];
275
278
  for (const entry of optionList) {
276
279
  const scanParams = {
277
- dirs: manifest.resolveDirs(entry.dir, root()),
280
+ dirs: scanner.resolveDirs(entry.dir, root()),
278
281
  prefix: entry.prefix ?? "",
279
282
  logger,
280
283
  onSkip: (info) => collectedDisabled.push(info),
@@ -319,21 +322,21 @@ function createWebpackWatcher(params) {
319
322
  return null;
320
323
  }
321
324
  const watcher = chokidar__default.watch(params.dirs, { ignoreInitial: true });
322
- const scheduleRefresh = manifest.createDebouncer(80, () => {
325
+ const scheduleRefresh = timing.createDebouncer(80, () => {
323
326
  void params.onRefresh();
324
327
  });
325
328
  watcher.on("add", (file) => {
326
- if (manifest.isInDirs(file, params.dirs)) {
329
+ if (pathUtils.isInDirs(file, params.dirs)) {
327
330
  scheduleRefresh();
328
331
  }
329
332
  });
330
333
  watcher.on("change", (file) => {
331
- if (manifest.isInDirs(file, params.dirs)) {
334
+ if (pathUtils.isInDirs(file, params.dirs)) {
332
335
  scheduleRefresh();
333
336
  }
334
337
  });
335
338
  watcher.on("unlink", (file) => {
336
- if (manifest.isInDirs(file, params.dirs)) {
339
+ if (pathUtils.isInDirs(file, params.dirs)) {
337
340
  scheduleRefresh();
338
341
  }
339
342
  });
@@ -377,7 +380,7 @@ function createMokupWebpackPlugin(options = {}) {
377
380
  const dirs = [];
378
381
  const seen = /* @__PURE__ */ new Set();
379
382
  for (const entry of optionList) {
380
- for (const dir of manifest.resolveDirs(entry.dir, root)) {
383
+ for (const dir of scanner.resolveDirs(entry.dir, root)) {
381
384
  if (seen.has(dir)) {
382
385
  continue;
383
386
  }
@@ -571,4 +574,36 @@ function createMokupWebpackPlugin(options = {}) {
571
574
  };
572
575
  }
573
576
 
577
+ function mokupWebpack(options = {}) {
578
+ const plugin = createMokupWebpackPlugin(options);
579
+ const applyConfig = (config = {}) => {
580
+ const plugins = Array.isArray(config.plugins) ? config.plugins : [];
581
+ const devServer = config.devServer && typeof config.devServer === "object" ? { ...config.devServer } : {};
582
+ return {
583
+ ...config,
584
+ plugins: [...plugins, plugin],
585
+ devServer
586
+ };
587
+ };
588
+ const applyInput = (input) => {
589
+ if (typeof input === "function") {
590
+ const wrapped = async (...args) => {
591
+ const resolved = await input(...args);
592
+ if (Array.isArray(resolved)) {
593
+ return resolved.map((item) => applyConfig(item));
594
+ }
595
+ return applyConfig(resolved ?? {});
596
+ };
597
+ return wrapped;
598
+ }
599
+ if (Array.isArray(input)) {
600
+ return input.map((item) => applyConfig(item));
601
+ }
602
+ return applyConfig(input ?? {});
603
+ };
604
+ return applyInput;
605
+ }
606
+
574
607
  exports.createMokupWebpackPlugin = createMokupWebpackPlugin;
608
+ exports.createWebpackPlugin = createMokupWebpackPlugin;
609
+ exports.mokupWebpack = mokupWebpack;
@@ -1,5 +1,6 @@
1
- import { M as MokupPluginOptions } from './shared/mokup.DeotZ0g8.cjs';
2
- export { H as HttpMethod, b as MiddlewarePosition, c as MiddlewareRegistry, d as RequestHandler, e as RouteDirectoryConfig, f as RouteResponse, g as RouteRule, h as RuntimeMode, S as ServiceWorkerOptions, V as VitePluginOptions, i as VitePluginOptionsInput } from './shared/mokup.DeotZ0g8.cjs';
1
+ import { Configuration } from 'webpack';
2
+ import { M as MokupPluginOptions } from './shared/mokup.Dkqu10Hk.cjs';
3
+ export { H as HttpMethod, b as MiddlewarePosition, c as MiddlewareRegistry, d as RequestHandler, e as RouteDirectoryConfig, f as RouteResponse, g as RouteRule, h as RuntimeMode, S as ServiceWorkerOptions, V as VitePluginOptions, i as VitePluginOptionsInput } from './shared/mokup.Dkqu10Hk.cjs';
3
4
  import { IncomingMessage, ServerResponse } from 'node:http';
4
5
  export { Context, MiddlewareHandler } from '@mokup/shared/hono';
5
6
  export { PlaygroundOptionsInput } from '@mokup/shared';
@@ -91,10 +92,10 @@ interface WebpackCompiler {
91
92
  * @returns Webpack plugin instance.
92
93
  *
93
94
  * @example
94
- * import { createMokupWebpackPlugin } from 'mokup/webpack'
95
+ * import { createWebpackPlugin } from 'mokup/webpack'
95
96
  *
96
97
  * export default {
97
- * plugins: [createMokupWebpackPlugin({ entries: { dir: 'mock' } })],
98
+ * plugins: [createWebpackPlugin({ entries: { dir: 'mock' } })],
98
99
  * }
99
100
  */
100
101
  declare function createMokupWebpackPlugin(options?: MokupPluginOptions): WebpackPluginInstance;
@@ -118,5 +119,23 @@ type WebpackPluginOptions = MokupPluginOptions;
118
119
  */
119
120
  type WebpackPluginOptionsInput = MokupPluginOptions;
120
121
 
121
- export { MokupPluginOptions, createMokupWebpackPlugin };
122
- export type { WebpackPluginOptions, WebpackPluginOptionsInput };
122
+ type WebpackConfig = Configuration;
123
+ type WebpackConfigFactory = (...args: unknown[]) => WebpackConfig | WebpackConfig[] | Promise<WebpackConfig | WebpackConfig[]>;
124
+ type WebpackConfigInput = WebpackConfig | WebpackConfig[] | WebpackConfigFactory;
125
+ type WithMokup<T> = T extends (...args: infer A) => infer R ? (...args: A) => Promise<WithMokup<Awaited<R>>> : T extends Array<infer U> ? Array<WithMokup<U>> : T extends WebpackConfig ? T : WebpackConfig;
126
+ /**
127
+ * Create a webpack config wrapper for Mokup.
128
+ *
129
+ * @example
130
+ * import { mokupWebpack } from 'mokup/webpack'
131
+ *
132
+ * const withMokup = mokupWebpack({ entries: { dir: 'mock' } })
133
+ *
134
+ * export default withMokup({
135
+ * devServer: {},
136
+ * })
137
+ */
138
+ declare function mokupWebpack(options?: WebpackPluginOptionsInput): <T extends WebpackConfigInput>(input: T) => WithMokup<T>;
139
+
140
+ export { MokupPluginOptions, createMokupWebpackPlugin, createMokupWebpackPlugin as createWebpackPlugin, mokupWebpack };
141
+ export type { WebpackConfig, WebpackConfigInput, WebpackPluginOptions, WebpackPluginOptionsInput };
@@ -1,5 +1,6 @@
1
- import { M as MokupPluginOptions } from './shared/mokup.DeotZ0g8.mjs';
2
- export { H as HttpMethod, b as MiddlewarePosition, c as MiddlewareRegistry, d as RequestHandler, e as RouteDirectoryConfig, f as RouteResponse, g as RouteRule, h as RuntimeMode, S as ServiceWorkerOptions, V as VitePluginOptions, i as VitePluginOptionsInput } from './shared/mokup.DeotZ0g8.mjs';
1
+ import { Configuration } from 'webpack';
2
+ import { M as MokupPluginOptions } from './shared/mokup.Dkqu10Hk.mjs';
3
+ export { H as HttpMethod, b as MiddlewarePosition, c as MiddlewareRegistry, d as RequestHandler, e as RouteDirectoryConfig, f as RouteResponse, g as RouteRule, h as RuntimeMode, S as ServiceWorkerOptions, V as VitePluginOptions, i as VitePluginOptionsInput } from './shared/mokup.Dkqu10Hk.mjs';
3
4
  import { IncomingMessage, ServerResponse } from 'node:http';
4
5
  export { Context, MiddlewareHandler } from '@mokup/shared/hono';
5
6
  export { PlaygroundOptionsInput } from '@mokup/shared';
@@ -91,10 +92,10 @@ interface WebpackCompiler {
91
92
  * @returns Webpack plugin instance.
92
93
  *
93
94
  * @example
94
- * import { createMokupWebpackPlugin } from 'mokup/webpack'
95
+ * import { createWebpackPlugin } from 'mokup/webpack'
95
96
  *
96
97
  * export default {
97
- * plugins: [createMokupWebpackPlugin({ entries: { dir: 'mock' } })],
98
+ * plugins: [createWebpackPlugin({ entries: { dir: 'mock' } })],
98
99
  * }
99
100
  */
100
101
  declare function createMokupWebpackPlugin(options?: MokupPluginOptions): WebpackPluginInstance;
@@ -118,5 +119,23 @@ type WebpackPluginOptions = MokupPluginOptions;
118
119
  */
119
120
  type WebpackPluginOptionsInput = MokupPluginOptions;
120
121
 
121
- export { MokupPluginOptions, createMokupWebpackPlugin };
122
- export type { WebpackPluginOptions, WebpackPluginOptionsInput };
122
+ type WebpackConfig = Configuration;
123
+ type WebpackConfigFactory = (...args: unknown[]) => WebpackConfig | WebpackConfig[] | Promise<WebpackConfig | WebpackConfig[]>;
124
+ type WebpackConfigInput = WebpackConfig | WebpackConfig[] | WebpackConfigFactory;
125
+ type WithMokup<T> = T extends (...args: infer A) => infer R ? (...args: A) => Promise<WithMokup<Awaited<R>>> : T extends Array<infer U> ? Array<WithMokup<U>> : T extends WebpackConfig ? T : WebpackConfig;
126
+ /**
127
+ * Create a webpack config wrapper for Mokup.
128
+ *
129
+ * @example
130
+ * import { mokupWebpack } from 'mokup/webpack'
131
+ *
132
+ * const withMokup = mokupWebpack({ entries: { dir: 'mock' } })
133
+ *
134
+ * export default withMokup({
135
+ * devServer: {},
136
+ * })
137
+ */
138
+ declare function mokupWebpack(options?: WebpackPluginOptionsInput): <T extends WebpackConfigInput>(input: T) => WithMokup<T>;
139
+
140
+ export { MokupPluginOptions, createMokupWebpackPlugin, createMokupWebpackPlugin as createWebpackPlugin, mokupWebpack };
141
+ export type { WebpackConfig, WebpackConfigInput, WebpackPluginOptions, WebpackPluginOptionsInput };
package/dist/webpack.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { M as MokupPluginOptions } from './shared/mokup.DeotZ0g8.js';
2
- export { H as HttpMethod, b as MiddlewarePosition, c as MiddlewareRegistry, d as RequestHandler, e as RouteDirectoryConfig, f as RouteResponse, g as RouteRule, h as RuntimeMode, S as ServiceWorkerOptions, V as VitePluginOptions, i as VitePluginOptionsInput } from './shared/mokup.DeotZ0g8.js';
1
+ import { Configuration } from 'webpack';
2
+ import { M as MokupPluginOptions } from './shared/mokup.Dkqu10Hk.js';
3
+ export { H as HttpMethod, b as MiddlewarePosition, c as MiddlewareRegistry, d as RequestHandler, e as RouteDirectoryConfig, f as RouteResponse, g as RouteRule, h as RuntimeMode, S as ServiceWorkerOptions, V as VitePluginOptions, i as VitePluginOptionsInput } from './shared/mokup.Dkqu10Hk.js';
3
4
  import { IncomingMessage, ServerResponse } from 'node:http';
4
5
  export { Context, MiddlewareHandler } from '@mokup/shared/hono';
5
6
  export { PlaygroundOptionsInput } from '@mokup/shared';
@@ -91,10 +92,10 @@ interface WebpackCompiler {
91
92
  * @returns Webpack plugin instance.
92
93
  *
93
94
  * @example
94
- * import { createMokupWebpackPlugin } from 'mokup/webpack'
95
+ * import { createWebpackPlugin } from 'mokup/webpack'
95
96
  *
96
97
  * export default {
97
- * plugins: [createMokupWebpackPlugin({ entries: { dir: 'mock' } })],
98
+ * plugins: [createWebpackPlugin({ entries: { dir: 'mock' } })],
98
99
  * }
99
100
  */
100
101
  declare function createMokupWebpackPlugin(options?: MokupPluginOptions): WebpackPluginInstance;
@@ -118,5 +119,23 @@ type WebpackPluginOptions = MokupPluginOptions;
118
119
  */
119
120
  type WebpackPluginOptionsInput = MokupPluginOptions;
120
121
 
121
- export { MokupPluginOptions, createMokupWebpackPlugin };
122
- export type { WebpackPluginOptions, WebpackPluginOptionsInput };
122
+ type WebpackConfig = Configuration;
123
+ type WebpackConfigFactory = (...args: unknown[]) => WebpackConfig | WebpackConfig[] | Promise<WebpackConfig | WebpackConfig[]>;
124
+ type WebpackConfigInput = WebpackConfig | WebpackConfig[] | WebpackConfigFactory;
125
+ type WithMokup<T> = T extends (...args: infer A) => infer R ? (...args: A) => Promise<WithMokup<Awaited<R>>> : T extends Array<infer U> ? Array<WithMokup<U>> : T extends WebpackConfig ? T : WebpackConfig;
126
+ /**
127
+ * Create a webpack config wrapper for Mokup.
128
+ *
129
+ * @example
130
+ * import { mokupWebpack } from 'mokup/webpack'
131
+ *
132
+ * const withMokup = mokupWebpack({ entries: { dir: 'mock' } })
133
+ *
134
+ * export default withMokup({
135
+ * devServer: {},
136
+ * })
137
+ */
138
+ declare function mokupWebpack(options?: WebpackPluginOptionsInput): <T extends WebpackConfigInput>(input: T) => WithMokup<T>;
139
+
140
+ export { MokupPluginOptions, createMokupWebpackPlugin, createMokupWebpackPlugin as createWebpackPlugin, mokupWebpack };
141
+ export type { WebpackConfig, WebpackConfigInput, WebpackPluginOptions, WebpackPluginOptionsInput };