mokup 2.3.3 → 2.3.5

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/vite.cjs CHANGED
@@ -46,6 +46,11 @@ function normalizeMokupOptions(options) {
46
46
  "[mokup] Invalid config: use mokup({ entries: { ... } }) instead of mokup({ dir, prefix, ... })."
47
47
  );
48
48
  }
49
+ if (options.runtime === "vite") {
50
+ throw new Error(
51
+ '[mokup] Invalid config: runtime "vite" is no longer supported. Use "node" or "worker".'
52
+ );
53
+ }
49
54
  return options;
50
55
  }
51
56
  function normalizeOptions(options) {
@@ -214,8 +219,12 @@ function createRouteRefresher(params) {
214
219
  state.configFiles,
215
220
  state.disabledConfigFiles
216
221
  );
222
+ const changed = signature !== state.lastSignature || options?.force;
223
+ if (changed && state.swRoutes.length > 0) {
224
+ state.swModuleVersion = (state.swModuleVersion ?? 0) + 1;
225
+ }
217
226
  if (isViteDevServer(server) && server.ws) {
218
- const shouldNotify = !options?.silent && state.lastSignature && (signature !== state.lastSignature || options?.force);
227
+ const shouldNotify = !options?.silent && state.lastSignature && changed;
219
228
  if (shouldNotify) {
220
229
  server.ws.send({
221
230
  type: "custom",
@@ -471,7 +480,8 @@ async function configureDevServer(params) {
471
480
  root,
472
481
  runtimeImportPath: resolveSwRuntimeImportPath(base),
473
482
  loggerImportPath: resolveSwLoggerImportPath(base),
474
- basePaths: swConfig?.basePaths ?? []
483
+ basePaths: swConfig?.basePaths ?? [],
484
+ moduleVersion: state.swModuleVersion
475
485
  });
476
486
  res.statusCode = 200;
477
487
  res.setHeader("Content-Type", "application/javascript; charset=utf-8");
@@ -528,7 +538,8 @@ async function configurePreviewServer(params) {
528
538
  const code = core.buildSwScript({
529
539
  routes: state.swRoutes,
530
540
  root,
531
- basePaths: swConfig?.basePaths ?? []
541
+ basePaths: swConfig?.basePaths ?? [],
542
+ moduleVersion: state.swModuleVersion
532
543
  });
533
544
  res.statusCode = 200;
534
545
  res.setHeader("Content-Type", "application/javascript; charset=utf-8");
@@ -741,12 +752,13 @@ function createMokupPlugin(options = {}) {
741
752
  configFiles: [],
742
753
  disabledConfigFiles: [],
743
754
  app: null,
744
- lastSignature: null
755
+ lastSignature: null,
756
+ swModuleVersion: 0
745
757
  };
746
758
  let previewWatcher = null;
747
759
  let currentServer = null;
748
760
  const normalizedOptions = normalizeMokupOptions(options);
749
- const runtime = normalizedOptions.runtime ?? "vite";
761
+ const runtime = normalizedOptions.runtime ?? "node";
750
762
  const enableViteMiddleware = runtime !== "worker";
751
763
  const optionList = normalizeOptions(normalizedOptions);
752
764
  const logEnabled = optionList.every((entry) => entry.log !== false);
@@ -865,7 +877,8 @@ function createMokupPlugin(options = {}) {
865
877
  return core.buildSwScript({
866
878
  routes: state.swRoutes,
867
879
  root,
868
- basePaths: swConfig?.basePaths ?? []
880
+ basePaths: swConfig?.basePaths ?? [],
881
+ moduleVersion: state.swModuleVersion
869
882
  });
870
883
  },
871
884
  async buildStart() {
package/dist/vite.d.cts CHANGED
@@ -1,5 +1,5 @@
1
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';
2
+ export { Context, HttpMethod, MiddlewareHandler, MiddlewarePosition, MiddlewareRegistry, MokupPluginOptions, PlaygroundOptionsInput, RequestHandler, RouteDirectoryConfig, RouteResponse, RouteRule, RuntimeMode, RuntimeTarget, ServiceWorkerOptions, VitePluginOptions, VitePluginOptionsInput } from '@mokup/core';
3
3
  import { Plugin } from 'vite';
4
4
 
5
5
  /**
package/dist/vite.d.mts CHANGED
@@ -1,5 +1,5 @@
1
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';
2
+ export { Context, HttpMethod, MiddlewareHandler, MiddlewarePosition, MiddlewareRegistry, MokupPluginOptions, PlaygroundOptionsInput, RequestHandler, RouteDirectoryConfig, RouteResponse, RouteRule, RuntimeMode, RuntimeTarget, ServiceWorkerOptions, VitePluginOptions, VitePluginOptionsInput } from '@mokup/core';
3
3
  import { Plugin } from 'vite';
4
4
 
5
5
  /**
package/dist/vite.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /// <reference path="./types/virtual.d.ts" />
2
2
 
3
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';
4
+ export { Context, HttpMethod, MiddlewareHandler, MiddlewarePosition, MiddlewareRegistry, MokupPluginOptions, PlaygroundOptionsInput, RequestHandler, RouteDirectoryConfig, RouteResponse, RouteRule, RuntimeMode, RuntimeTarget, ServiceWorkerOptions, VitePluginOptions, VitePluginOptionsInput } from '@mokup/core';
5
5
  import { Plugin } from 'vite';
6
6
 
7
7
  /**
package/dist/vite.mjs CHANGED
@@ -38,6 +38,11 @@ function normalizeMokupOptions(options) {
38
38
  "[mokup] Invalid config: use mokup({ entries: { ... } }) instead of mokup({ dir, prefix, ... })."
39
39
  );
40
40
  }
41
+ if (options.runtime === "vite") {
42
+ throw new Error(
43
+ '[mokup] Invalid config: runtime "vite" is no longer supported. Use "node" or "worker".'
44
+ );
45
+ }
41
46
  return options;
42
47
  }
43
48
  function normalizeOptions(options) {
@@ -206,8 +211,12 @@ function createRouteRefresher(params) {
206
211
  state.configFiles,
207
212
  state.disabledConfigFiles
208
213
  );
214
+ const changed = signature !== state.lastSignature || options?.force;
215
+ if (changed && state.swRoutes.length > 0) {
216
+ state.swModuleVersion = (state.swModuleVersion ?? 0) + 1;
217
+ }
209
218
  if (isViteDevServer(server) && server.ws) {
210
- const shouldNotify = !options?.silent && state.lastSignature && (signature !== state.lastSignature || options?.force);
219
+ const shouldNotify = !options?.silent && state.lastSignature && changed;
211
220
  if (shouldNotify) {
212
221
  server.ws.send({
213
222
  type: "custom",
@@ -463,7 +472,8 @@ async function configureDevServer(params) {
463
472
  root,
464
473
  runtimeImportPath: resolveSwRuntimeImportPath(base),
465
474
  loggerImportPath: resolveSwLoggerImportPath(base),
466
- basePaths: swConfig?.basePaths ?? []
475
+ basePaths: swConfig?.basePaths ?? [],
476
+ moduleVersion: state.swModuleVersion
467
477
  });
468
478
  res.statusCode = 200;
469
479
  res.setHeader("Content-Type", "application/javascript; charset=utf-8");
@@ -520,7 +530,8 @@ async function configurePreviewServer(params) {
520
530
  const code = buildSwScript({
521
531
  routes: state.swRoutes,
522
532
  root,
523
- basePaths: swConfig?.basePaths ?? []
533
+ basePaths: swConfig?.basePaths ?? [],
534
+ moduleVersion: state.swModuleVersion
524
535
  });
525
536
  res.statusCode = 200;
526
537
  res.setHeader("Content-Type", "application/javascript; charset=utf-8");
@@ -733,12 +744,13 @@ function createMokupPlugin(options = {}) {
733
744
  configFiles: [],
734
745
  disabledConfigFiles: [],
735
746
  app: null,
736
- lastSignature: null
747
+ lastSignature: null,
748
+ swModuleVersion: 0
737
749
  };
738
750
  let previewWatcher = null;
739
751
  let currentServer = null;
740
752
  const normalizedOptions = normalizeMokupOptions(options);
741
- const runtime = normalizedOptions.runtime ?? "vite";
753
+ const runtime = normalizedOptions.runtime ?? "node";
742
754
  const enableViteMiddleware = runtime !== "worker";
743
755
  const optionList = normalizeOptions(normalizedOptions);
744
756
  const logEnabled = optionList.every((entry) => entry.log !== false);
@@ -857,7 +869,8 @@ function createMokupPlugin(options = {}) {
857
869
  return buildSwScript({
858
870
  routes: state.swRoutes,
859
871
  root,
860
- basePaths: swConfig?.basePaths ?? []
872
+ basePaths: swConfig?.basePaths ?? [],
873
+ moduleVersion: state.swModuleVersion
861
874
  });
862
875
  },
863
876
  async buildStart() {
@@ -116,7 +116,9 @@ type WebpackPluginOptions = MokupPluginOptions;
116
116
  */
117
117
  type WebpackPluginOptionsInput = MokupPluginOptions;
118
118
 
119
- type WebpackConfig = Configuration;
119
+ type WebpackConfig = Configuration & {
120
+ devServer?: Record<string, unknown>;
121
+ };
120
122
  type WebpackConfigFactory = (...args: unknown[]) => WebpackConfig | WebpackConfig[] | Promise<WebpackConfig | WebpackConfig[]>;
121
123
  type WebpackConfigInput = WebpackConfig | WebpackConfig[] | WebpackConfigFactory;
122
124
  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;
@@ -116,7 +116,9 @@ type WebpackPluginOptions = MokupPluginOptions;
116
116
  */
117
117
  type WebpackPluginOptionsInput = MokupPluginOptions;
118
118
 
119
- type WebpackConfig = Configuration;
119
+ type WebpackConfig = Configuration & {
120
+ devServer?: Record<string, unknown>;
121
+ };
120
122
  type WebpackConfigFactory = (...args: unknown[]) => WebpackConfig | WebpackConfig[] | Promise<WebpackConfig | WebpackConfig[]>;
121
123
  type WebpackConfigInput = WebpackConfig | WebpackConfig[] | WebpackConfigFactory;
122
124
  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;
package/dist/webpack.d.ts CHANGED
@@ -116,7 +116,9 @@ type WebpackPluginOptions = MokupPluginOptions;
116
116
  */
117
117
  type WebpackPluginOptionsInput = MokupPluginOptions;
118
118
 
119
- type WebpackConfig = Configuration;
119
+ type WebpackConfig = Configuration & {
120
+ devServer?: Record<string, unknown>;
121
+ };
120
122
  type WebpackConfigFactory = (...args: unknown[]) => WebpackConfig | WebpackConfig[] | Promise<WebpackConfig | WebpackConfig[]>;
121
123
  type WebpackConfigInput = WebpackConfig | WebpackConfig[] | WebpackConfigFactory;
122
124
  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;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mokup",
3
3
  "type": "module",
4
- "version": "2.3.3",
4
+ "version": "2.3.5",
5
5
  "description": "Mock utilities and Vite plugin for mokup.",
6
6
  "license": "MIT",
7
7
  "homepage": "https://mokup.icebreaker.top",
@@ -164,12 +164,12 @@
164
164
  },
165
165
  "dependencies": {
166
166
  "picocolors": "^1.1.1",
167
- "@mokup/cli": "1.1.2",
168
- "@mokup/playground": "0.1.1",
169
- "@mokup/core": "1.1.1",
170
- "@mokup/runtime": "1.0.8",
171
- "@mokup/server": "1.2.2",
172
- "@mokup/shared": "1.1.3"
167
+ "@mokup/cli": "1.1.4",
168
+ "@mokup/core": "1.1.3",
169
+ "@mokup/playground": "0.2.1",
170
+ "@mokup/runtime": "1.0.9",
171
+ "@mokup/server": "1.2.4",
172
+ "@mokup/shared": "1.1.4"
173
173
  },
174
174
  "scripts": {
175
175
  "build": "unbuild",