vite-plugin-mock-dev-server 1.8.0 → 1.8.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.
@@ -165,7 +165,7 @@ import bodyParser from "co-body";
165
165
  import formidable from "formidable";
166
166
  async function parseReqBody(req, formidableOptions, bodyParserOptions = {}) {
167
167
  const method = req.method.toUpperCase();
168
- if (["GET", "DELETE", "HEAD"].includes(method))
168
+ if (["HEAD", "OPTIONS"].includes(method))
169
169
  return void 0;
170
170
  const type = req.headers["content-type"]?.toLocaleLowerCase() || "";
171
171
  const { limit, formLimit, jsonLimit, textLimit, ...rest } = bodyParserOptions;
@@ -165,7 +165,7 @@ var _cobody = require('co-body'); var _cobody2 = _interopRequireDefault(_cobody)
165
165
  var _formidable = require('formidable'); var _formidable2 = _interopRequireDefault(_formidable);
166
166
  async function parseReqBody(req, formidableOptions, bodyParserOptions = {}) {
167
167
  const method = req.method.toUpperCase();
168
- if (["GET", "DELETE", "HEAD"].includes(method))
168
+ if (["HEAD", "OPTIONS"].includes(method))
169
169
  return void 0;
170
170
  const type = _optionalChain([req, 'access', _ => _.headers, 'access', _2 => _2["content-type"], 'optionalAccess', _3 => _3.toLocaleLowerCase, 'call', _4 => _4()]) || "";
171
171
  const { limit, formLimit, jsonLimit, textLimit, ...rest } = bodyParserOptions;
package/dist/index.cjs CHANGED
@@ -19,7 +19,7 @@ var _chunkJNSDHVCKcjs = require('./chunk-JNSDHVCK.cjs');
19
19
 
20
20
 
21
21
 
22
- var _chunkJP6LPDGGcjs = require('./chunk-JP6LPDGG.cjs');
22
+ var _chunkGWNR3FAVcjs = require('./chunk-GWNR3FAV.cjs');
23
23
 
24
24
  // src/plugin.ts
25
25
  var _utils = require('@pengzhanbo/utils');
@@ -182,7 +182,7 @@ async function generateMockServer(ctx, options) {
182
182
  const cwd = options.cwd || _process2.default.cwd();
183
183
  let pkg = {};
184
184
  try {
185
- const pkgStr = _chunkJP6LPDGGcjs.lookupFile.call(void 0, options.context, ["package.json"]);
185
+ const pkgStr = _chunkGWNR3FAVcjs.lookupFile.call(void 0, options.context, ["package.json"]);
186
186
  if (pkgStr)
187
187
  pkg = JSON.parse(pkgStr);
188
188
  } catch (e3) {
@@ -268,7 +268,7 @@ function generatePackageJson(pkg, mockDeps) {
268
268
  },
269
269
  dependencies: {
270
270
  connect: "^3.7.0",
271
- ["vite-plugin-mock-dev-server"]: `^${"1.7.3"}`,
271
+ ["vite-plugin-mock-dev-server"]: `^${"1.8.0"}`,
272
272
  cors: "^2.8.5"
273
273
  },
274
274
  pnpm: { peerDependencyRules: { ignoreMissing: ["vite"] } }
@@ -329,7 +329,7 @@ async function generateMockEntryCode(cwd, include, exclude) {
329
329
  let importers = "";
330
330
  const exporters = [];
331
331
  mockFiles.forEach((filepath, index) => {
332
- const file = _chunkJP6LPDGGcjs.normalizePath.call(void 0, _path2.default.join(cwd, filepath));
332
+ const file = _chunkGWNR3FAVcjs.normalizePath.call(void 0, _path2.default.join(cwd, filepath));
333
333
  importers += `import * as m${index} from '${file}';
334
334
  `;
335
335
  exporters.push(`[m${index}, '${filepath}']`);
@@ -366,7 +366,7 @@ var MockCompiler = (_class = class extends _events2.default {
366
366
  this.options = options;
367
367
  this.cwd = options.cwd || _process2.default.cwd();
368
368
  try {
369
- const pkg = _chunkJP6LPDGGcjs.lookupFile.call(void 0, this.cwd, ["package.json"]);
369
+ const pkg = _chunkGWNR3FAVcjs.lookupFile.call(void 0, this.cwd, ["package.json"]);
370
370
  this.moduleType = !!pkg && JSON.parse(pkg).type === "module" ? "esm" : "cjs";
371
371
  } catch (e4) {
372
372
  }
@@ -420,19 +420,19 @@ var MockCompiler = (_class = class extends _events2.default {
420
420
  if (otherGlob.length > 0)
421
421
  otherGlob.forEach((glob) => watcher.add(glob));
422
422
  watcher.on("add", async (filepath) => {
423
- filepath = _chunkJP6LPDGGcjs.normalizePath.call(void 0, filepath);
423
+ filepath = _chunkGWNR3FAVcjs.normalizePath.call(void 0, filepath);
424
424
  this.emit("mock:update", filepath);
425
- _chunkJP6LPDGGcjs.debug.call(void 0, "watcher:add", filepath);
425
+ _chunkGWNR3FAVcjs.debug.call(void 0, "watcher:add", filepath);
426
426
  });
427
427
  watcher.on("change", async (filepath) => {
428
- filepath = _chunkJP6LPDGGcjs.normalizePath.call(void 0, filepath);
428
+ filepath = _chunkGWNR3FAVcjs.normalizePath.call(void 0, filepath);
429
429
  this.emit("mock:update", filepath);
430
- _chunkJP6LPDGGcjs.debug.call(void 0, "watcher:change", filepath);
430
+ _chunkGWNR3FAVcjs.debug.call(void 0, "watcher:change", filepath);
431
431
  });
432
432
  watcher.on("unlink", async (filepath) => {
433
- filepath = _chunkJP6LPDGGcjs.normalizePath.call(void 0, filepath);
433
+ filepath = _chunkGWNR3FAVcjs.normalizePath.call(void 0, filepath);
434
434
  this.emit("mock:unlink", filepath);
435
- _chunkJP6LPDGGcjs.debug.call(void 0, "watcher:unlink", filepath);
435
+ _chunkGWNR3FAVcjs.debug.call(void 0, "watcher:unlink", filepath);
436
436
  });
437
437
  }
438
438
  /**
@@ -446,14 +446,14 @@ var MockCompiler = (_class = class extends _events2.default {
446
446
  cwd: this.cwd
447
447
  });
448
448
  this.depsWatcher.on("change", (filepath) => {
449
- filepath = _chunkJP6LPDGGcjs.normalizePath.call(void 0, filepath);
449
+ filepath = _chunkGWNR3FAVcjs.normalizePath.call(void 0, filepath);
450
450
  const mockFiles = this.moduleDeps.get(filepath);
451
451
  _optionalChain([mockFiles, 'optionalAccess', _4 => _4.forEach, 'call', _5 => _5((file) => {
452
452
  this.emit("mock:update", file);
453
453
  })]);
454
454
  });
455
455
  this.depsWatcher.on("unlink", (filepath) => {
456
- filepath = _chunkJP6LPDGGcjs.normalizePath.call(void 0, filepath);
456
+ filepath = _chunkGWNR3FAVcjs.normalizePath.call(void 0, filepath);
457
457
  this.moduleDeps.delete(filepath);
458
458
  });
459
459
  this.on("update:deps", () => {
@@ -470,7 +470,7 @@ var MockCompiler = (_class = class extends _events2.default {
470
470
  _optionalChain([this, 'access', _9 => _9.depsWatcher, 'optionalAccess', _10 => _10.close, 'call', _11 => _11()]);
471
471
  }
472
472
  updateMockList() {
473
- this._mockData = _chunkJP6LPDGGcjs.transformMockData.call(void 0, this.moduleCache);
473
+ this._mockData = _chunkGWNR3FAVcjs.transformMockData.call(void 0, this.moduleCache);
474
474
  }
475
475
  updateModuleDeps(filepath, deps) {
476
476
  Object.keys(deps).forEach((mPath) => {
@@ -501,7 +501,7 @@ var MockCompiler = (_class = class extends _events2.default {
501
501
  );
502
502
  try {
503
503
  const raw = await loadFromCode({ filepath, code, isESM, cwd: this.cwd }) || {};
504
- this.moduleCache.set(filepath, _chunkJP6LPDGGcjs.transformRawData.call(void 0, raw, filepath));
504
+ this.moduleCache.set(filepath, _chunkGWNR3FAVcjs.transformRawData.call(void 0, raw, filepath));
505
505
  this.updateModuleDeps(filepath, deps);
506
506
  } catch (e) {
507
507
  console.error(e);
@@ -518,7 +518,7 @@ function mockServerMiddleware(options, server, ws) {
518
518
  _optionalChain([ws, 'optionalAccess', _12 => _12.send, 'call', _13 => _13({ type: "full-reload" })]);
519
519
  });
520
520
  _optionalChain([server, 'optionalAccess', _14 => _14.on, 'call', _15 => _15("close", () => compiler.close())]);
521
- _chunkJP6LPDGGcjs.mockWebSocket.call(void 0, compiler, server, options);
521
+ _chunkGWNR3FAVcjs.mockWebSocket.call(void 0, compiler, server, options);
522
522
  const middlewares = [];
523
523
  middlewares.push(
524
524
  /**
@@ -533,14 +533,14 @@ function mockServerMiddleware(options, server, ws) {
533
533
  * 而用户的配置也仅对 mock 的接口生效。
534
534
  */
535
535
  corsMiddleware(compiler, options),
536
- _chunkJP6LPDGGcjs.baseMiddleware.call(void 0, compiler, options)
536
+ _chunkGWNR3FAVcjs.baseMiddleware.call(void 0, compiler, options)
537
537
  );
538
538
  return middlewares.filter(Boolean);
539
539
  }
540
540
  function corsMiddleware(compiler, { proxies, cors: corsOptions }) {
541
541
  return !corsOptions ? void 0 : function(req, res, next) {
542
- const { pathname } = _chunkJP6LPDGGcjs.urlParse.call(void 0, req.url);
543
- if (!pathname || proxies.length === 0 || !proxies.some((context) => _chunkJP6LPDGGcjs.doesProxyContextMatchUrl.call(void 0, context, req.url))) {
542
+ const { pathname } = _chunkGWNR3FAVcjs.urlParse.call(void 0, req.url);
543
+ if (!pathname || proxies.length === 0 || !proxies.some((context) => _chunkGWNR3FAVcjs.doesProxyContextMatchUrl.call(void 0, context, req.url))) {
544
544
  return next();
545
545
  }
546
546
  const mockData = compiler.mockData;
@@ -653,8 +653,8 @@ function resolvePluginOptions({
653
653
  bodyParserOptions = {},
654
654
  priority = {}
655
655
  }, config) {
656
- const logger = _chunkJP6LPDGGcjs.createLogger.call(void 0, "vite:mock", _utils.isBoolean.call(void 0, log) ? log ? "info" : "error" : log);
657
- const { httpProxies } = _chunkJP6LPDGGcjs.ensureProxies.call(void 0, config.server.proxy || {});
656
+ const logger = _chunkGWNR3FAVcjs.createLogger.call(void 0, "vite:mock", _utils.isBoolean.call(void 0, log) ? log ? "info" : "error" : log);
657
+ const { httpProxies } = _chunkGWNR3FAVcjs.ensureProxies.call(void 0, config.server.proxy || {});
658
658
  const proxies = _utils.uniq.call(void 0, [..._utils.toArray.call(void 0, prefix), ...httpProxies]);
659
659
  const wsProxies = _utils.toArray.call(void 0, wsPrefix);
660
660
  if (!proxies.length && !wsProxies.length)
@@ -755,7 +755,7 @@ function serverPlugin(options) {
755
755
  });
756
756
  config.server.proxy = proxy;
757
757
  }
758
- _chunkJP6LPDGGcjs.recoverRequest.call(void 0, config);
758
+ _chunkGWNR3FAVcjs.recoverRequest.call(void 0, config);
759
759
  },
760
760
  configResolved(config) {
761
761
  resolvedOptions = resolvePluginOptions(options, config);
@@ -788,4 +788,4 @@ var src_default = mockDevServerPlugin;
788
788
 
789
789
 
790
790
 
791
- exports.baseMiddleware = _chunkJP6LPDGGcjs.baseMiddleware; exports.createDefineMock = _chunkJNSDHVCKcjs.createDefineMock; exports.createLogger = _chunkJP6LPDGGcjs.createLogger; exports.createSSEStream = _chunkJNSDHVCKcjs.createSSEStream; exports.default = src_default; exports.defineMock = _chunkJNSDHVCKcjs.defineMock; exports.defineMockData = _chunkJNSDHVCKcjs.defineMockData; exports.logLevels = _chunkJP6LPDGGcjs.logLevels; exports.mockDevServerPlugin = mockDevServerPlugin; exports.mockWebSocket = _chunkJP6LPDGGcjs.mockWebSocket; exports.sortByValidator = _chunkJP6LPDGGcjs.sortByValidator; exports.transformMockData = _chunkJP6LPDGGcjs.transformMockData; exports.transformRawData = _chunkJP6LPDGGcjs.transformRawData;
791
+ exports.baseMiddleware = _chunkGWNR3FAVcjs.baseMiddleware; exports.createDefineMock = _chunkJNSDHVCKcjs.createDefineMock; exports.createLogger = _chunkGWNR3FAVcjs.createLogger; exports.createSSEStream = _chunkJNSDHVCKcjs.createSSEStream; exports.default = src_default; exports.defineMock = _chunkJNSDHVCKcjs.defineMock; exports.defineMockData = _chunkJNSDHVCKcjs.defineMockData; exports.logLevels = _chunkGWNR3FAVcjs.logLevels; exports.mockDevServerPlugin = mockDevServerPlugin; exports.mockWebSocket = _chunkGWNR3FAVcjs.mockWebSocket; exports.sortByValidator = _chunkGWNR3FAVcjs.sortByValidator; exports.transformMockData = _chunkGWNR3FAVcjs.transformMockData; exports.transformRawData = _chunkGWNR3FAVcjs.transformRawData;
package/dist/index.js CHANGED
@@ -19,7 +19,7 @@ import {
19
19
  transformMockData,
20
20
  transformRawData,
21
21
  urlParse
22
- } from "./chunk-FUNGHLD3.js";
22
+ } from "./chunk-2IAQM65M.js";
23
23
 
24
24
  // src/plugin.ts
25
25
  import { toArray as toArray4 } from "@pengzhanbo/utils";
@@ -268,7 +268,7 @@ function generatePackageJson(pkg, mockDeps) {
268
268
  },
269
269
  dependencies: {
270
270
  connect: "^3.7.0",
271
- ["vite-plugin-mock-dev-server"]: `^${"1.7.3"}`,
271
+ ["vite-plugin-mock-dev-server"]: `^${"1.8.0"}`,
272
272
  cors: "^2.8.5"
273
273
  },
274
274
  pnpm: { peerDependencyRules: { ignoreMissing: ["vite"] } }
package/dist/server.cjs CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
 
8
8
 
9
- var _chunkJP6LPDGGcjs = require('./chunk-JP6LPDGG.cjs');
9
+ var _chunkGWNR3FAVcjs = require('./chunk-GWNR3FAV.cjs');
10
10
 
11
11
 
12
12
 
@@ -15,4 +15,4 @@ var _chunkJP6LPDGGcjs = require('./chunk-JP6LPDGG.cjs');
15
15
 
16
16
 
17
17
 
18
- exports.baseMiddleware = _chunkJP6LPDGGcjs.baseMiddleware; exports.createLogger = _chunkJP6LPDGGcjs.createLogger; exports.logLevels = _chunkJP6LPDGGcjs.logLevels; exports.mockWebSocket = _chunkJP6LPDGGcjs.mockWebSocket; exports.sortByValidator = _chunkJP6LPDGGcjs.sortByValidator; exports.transformMockData = _chunkJP6LPDGGcjs.transformMockData; exports.transformRawData = _chunkJP6LPDGGcjs.transformRawData;
18
+ exports.baseMiddleware = _chunkGWNR3FAVcjs.baseMiddleware; exports.createLogger = _chunkGWNR3FAVcjs.createLogger; exports.logLevels = _chunkGWNR3FAVcjs.logLevels; exports.mockWebSocket = _chunkGWNR3FAVcjs.mockWebSocket; exports.sortByValidator = _chunkGWNR3FAVcjs.sortByValidator; exports.transformMockData = _chunkGWNR3FAVcjs.transformMockData; exports.transformRawData = _chunkGWNR3FAVcjs.transformRawData;
package/dist/server.js CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  sortByValidator,
7
7
  transformMockData,
8
8
  transformRawData
9
- } from "./chunk-FUNGHLD3.js";
9
+ } from "./chunk-2IAQM65M.js";
10
10
  export {
11
11
  baseMiddleware,
12
12
  createLogger,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-plugin-mock-dev-server",
3
3
  "type": "module",
4
- "version": "1.8.0",
4
+ "version": "1.8.1",
5
5
  "author": "pengzhanbo <q942450674@outlook.com> (https://github.com/pengzhanbo)",
6
6
  "license": "MIT",
7
7
  "homepage": "https://vite-plugin-mock-dev-server.netlify.app",
@@ -56,7 +56,7 @@
56
56
  "dist"
57
57
  ],
58
58
  "engines": {
59
- "node": "^18 || >= 20"
59
+ "node": "^18 || ^20 || >=22"
60
60
  },
61
61
  "peerDependencies": {
62
62
  "esbuild": ">=0.21.0",
@@ -69,7 +69,7 @@
69
69
  },
70
70
  "dependencies": {
71
71
  "@pengzhanbo/utils": "^1.1.2",
72
- "@rollup/pluginutils": "^5.1.2",
72
+ "@rollup/pluginutils": "^5.1.3",
73
73
  "chokidar": "3.6.0",
74
74
  "co-body": "^6.2.0",
75
75
  "cookies": "^0.9.1",
@@ -77,17 +77,17 @@
77
77
  "debug": "^4.3.7",
78
78
  "fast-glob": "^3.3.2",
79
79
  "formidable": "2.1.2",
80
- "http-status": "^1.7.4",
80
+ "http-status": "^2.0.0",
81
81
  "is-core-module": "^2.15.1",
82
82
  "json5": "^2.2.3",
83
83
  "mime-types": "^2.1.35",
84
84
  "path-to-regexp": "6.2.2",
85
- "picocolors": "^1.1.0",
85
+ "picocolors": "^1.1.1",
86
86
  "ws": "^8.18.0"
87
87
  },
88
88
  "devDependencies": {
89
89
  "esbuild": "^0.24.0",
90
- "vite": "^5.4.8"
90
+ "vite": "^6.0.3"
91
91
  },
92
92
  "publishConfig": {
93
93
  "access": "public"