vite-plugin-mock-dev-server 1.8.1 → 1.8.3

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.
@@ -344,7 +344,7 @@ function isIncluded(source, target) {
344
344
  })
345
345
  );
346
346
  }
347
- if (_utils.isObject.call(void 0, source) && _utils.isObject.call(void 0, target))
347
+ if (_utils.isPlainObject.call(void 0, source) && _utils.isPlainObject.call(void 0, target))
348
348
  return isObjectSubset(source, target);
349
349
  return Object.is(source, target);
350
350
  }
@@ -688,7 +688,7 @@ function transformMockData(mockList) {
688
688
  list.push(..._utils.toArray.call(void 0, handle));
689
689
  }
690
690
  const mocks = {};
691
- list.filter((mock) => _utils.isObject.call(void 0, mock) && mock.enabled !== false && mock.url).forEach((mock) => {
691
+ list.filter((mock) => _utils.isPlainObject.call(void 0, mock) && mock.enabled !== false && mock.url).forEach((mock) => {
692
692
  const { pathname, query } = urlParse(mock.url);
693
693
  const list2 = mocks[pathname] ??= [];
694
694
  const current = { ...mock, url: pathname };
@@ -317,7 +317,7 @@ function normalizePath(id) {
317
317
  }
318
318
 
319
319
  // src/core/validator.ts
320
- import { isArray as isArray2, isObject } from "@pengzhanbo/utils";
320
+ import { isArray as isArray2, isPlainObject } from "@pengzhanbo/utils";
321
321
  function validate(request, validator) {
322
322
  return isObjectSubset(request.headers, validator.headers) && isObjectSubset(request.body, validator.body) && isObjectSubset(request.params, validator.params) && isObjectSubset(request.query, validator.query) && isObjectSubset(request.refererQuery, validator.refererQuery);
323
323
  }
@@ -344,7 +344,7 @@ function isIncluded(source, target) {
344
344
  })
345
345
  );
346
346
  }
347
- if (isObject(source) && isObject(target))
347
+ if (isPlainObject(source) && isPlainObject(target))
348
348
  return isObjectSubset(source, target);
349
349
  return Object.is(source, target);
350
350
  }
@@ -658,7 +658,7 @@ import {
658
658
  isArray as isArray4,
659
659
  isEmptyObject as isEmptyObject3,
660
660
  isFunction as isFunction2,
661
- isObject as isObject2,
661
+ isPlainObject as isPlainObject2,
662
662
  sortBy as sortBy2,
663
663
  toArray
664
664
  } from "@pengzhanbo/utils";
@@ -688,7 +688,7 @@ function transformMockData(mockList) {
688
688
  list.push(...toArray(handle));
689
689
  }
690
690
  const mocks = {};
691
- list.filter((mock) => isObject2(mock) && mock.enabled !== false && mock.url).forEach((mock) => {
691
+ list.filter((mock) => isPlainObject2(mock) && mock.enabled !== false && mock.url).forEach((mock) => {
692
692
  const { pathname, query } = urlParse(mock.url);
693
693
  const list2 = mocks[pathname] ??= [];
694
694
  const current = { ...mock, url: pathname };
package/dist/index.cjs CHANGED
@@ -19,7 +19,7 @@ var _chunkJNSDHVCKcjs = require('./chunk-JNSDHVCK.cjs');
19
19
 
20
20
 
21
21
 
22
- var _chunkGWNR3FAVcjs = require('./chunk-GWNR3FAV.cjs');
22
+ var _chunkFQYSVVSCcjs = require('./chunk-FQYSVVSC.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 = _chunkGWNR3FAVcjs.lookupFile.call(void 0, options.context, ["package.json"]);
185
+ const pkgStr = _chunkFQYSVVSCcjs.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.8.0"}`,
271
+ ["vite-plugin-mock-dev-server"]: `^${"1.8.2"}`,
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 = _chunkGWNR3FAVcjs.normalizePath.call(void 0, _path2.default.join(cwd, filepath));
332
+ const file = _chunkFQYSVVSCcjs.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 = _chunkGWNR3FAVcjs.lookupFile.call(void 0, this.cwd, ["package.json"]);
369
+ const pkg = _chunkFQYSVVSCcjs.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 = _chunkGWNR3FAVcjs.normalizePath.call(void 0, filepath);
423
+ filepath = _chunkFQYSVVSCcjs.normalizePath.call(void 0, filepath);
424
424
  this.emit("mock:update", filepath);
425
- _chunkGWNR3FAVcjs.debug.call(void 0, "watcher:add", filepath);
425
+ _chunkFQYSVVSCcjs.debug.call(void 0, "watcher:add", filepath);
426
426
  });
427
427
  watcher.on("change", async (filepath) => {
428
- filepath = _chunkGWNR3FAVcjs.normalizePath.call(void 0, filepath);
428
+ filepath = _chunkFQYSVVSCcjs.normalizePath.call(void 0, filepath);
429
429
  this.emit("mock:update", filepath);
430
- _chunkGWNR3FAVcjs.debug.call(void 0, "watcher:change", filepath);
430
+ _chunkFQYSVVSCcjs.debug.call(void 0, "watcher:change", filepath);
431
431
  });
432
432
  watcher.on("unlink", async (filepath) => {
433
- filepath = _chunkGWNR3FAVcjs.normalizePath.call(void 0, filepath);
433
+ filepath = _chunkFQYSVVSCcjs.normalizePath.call(void 0, filepath);
434
434
  this.emit("mock:unlink", filepath);
435
- _chunkGWNR3FAVcjs.debug.call(void 0, "watcher:unlink", filepath);
435
+ _chunkFQYSVVSCcjs.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 = _chunkGWNR3FAVcjs.normalizePath.call(void 0, filepath);
449
+ filepath = _chunkFQYSVVSCcjs.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 = _chunkGWNR3FAVcjs.normalizePath.call(void 0, filepath);
456
+ filepath = _chunkFQYSVVSCcjs.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 = _chunkGWNR3FAVcjs.transformMockData.call(void 0, this.moduleCache);
473
+ this._mockData = _chunkFQYSVVSCcjs.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, _chunkGWNR3FAVcjs.transformRawData.call(void 0, raw, filepath));
504
+ this.moduleCache.set(filepath, _chunkFQYSVVSCcjs.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
- _chunkGWNR3FAVcjs.mockWebSocket.call(void 0, compiler, server, options);
521
+ _chunkFQYSVVSCcjs.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
- _chunkGWNR3FAVcjs.baseMiddleware.call(void 0, compiler, options)
536
+ _chunkFQYSVVSCcjs.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 } = _chunkGWNR3FAVcjs.urlParse.call(void 0, req.url);
543
- if (!pathname || proxies.length === 0 || !proxies.some((context) => _chunkGWNR3FAVcjs.doesProxyContextMatchUrl.call(void 0, context, req.url))) {
542
+ const { pathname } = _chunkFQYSVVSCcjs.urlParse.call(void 0, req.url);
543
+ if (!pathname || proxies.length === 0 || !proxies.some((context) => _chunkFQYSVVSCcjs.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 = _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 || {});
656
+ const logger = _chunkFQYSVVSCcjs.createLogger.call(void 0, "vite:mock", _utils.isBoolean.call(void 0, log) ? log ? "info" : "error" : log);
657
+ const { httpProxies } = _chunkFQYSVVSCcjs.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
- _chunkGWNR3FAVcjs.recoverRequest.call(void 0, config);
758
+ _chunkFQYSVVSCcjs.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 = _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;
791
+ exports.baseMiddleware = _chunkFQYSVVSCcjs.baseMiddleware; exports.createDefineMock = _chunkJNSDHVCKcjs.createDefineMock; exports.createLogger = _chunkFQYSVVSCcjs.createLogger; exports.createSSEStream = _chunkJNSDHVCKcjs.createSSEStream; exports.default = src_default; exports.defineMock = _chunkJNSDHVCKcjs.defineMock; exports.defineMockData = _chunkJNSDHVCKcjs.defineMockData; exports.logLevels = _chunkFQYSVVSCcjs.logLevels; exports.mockDevServerPlugin = mockDevServerPlugin; exports.mockWebSocket = _chunkFQYSVVSCcjs.mockWebSocket; exports.sortByValidator = _chunkFQYSVVSCcjs.sortByValidator; exports.transformMockData = _chunkFQYSVVSCcjs.transformMockData; exports.transformRawData = _chunkFQYSVVSCcjs.transformRawData;
package/dist/index.js CHANGED
@@ -19,7 +19,7 @@ import {
19
19
  transformMockData,
20
20
  transformRawData,
21
21
  urlParse
22
- } from "./chunk-2IAQM65M.js";
22
+ } from "./chunk-YZXX2W2L.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.8.0"}`,
271
+ ["vite-plugin-mock-dev-server"]: `^${"1.8.2"}`,
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 _chunkGWNR3FAVcjs = require('./chunk-GWNR3FAV.cjs');
9
+ var _chunkFQYSVVSCcjs = require('./chunk-FQYSVVSC.cjs');
10
10
 
11
11
 
12
12
 
@@ -15,4 +15,4 @@ var _chunkGWNR3FAVcjs = require('./chunk-GWNR3FAV.cjs');
15
15
 
16
16
 
17
17
 
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;
18
+ exports.baseMiddleware = _chunkFQYSVVSCcjs.baseMiddleware; exports.createLogger = _chunkFQYSVVSCcjs.createLogger; exports.logLevels = _chunkFQYSVVSCcjs.logLevels; exports.mockWebSocket = _chunkFQYSVVSCcjs.mockWebSocket; exports.sortByValidator = _chunkFQYSVVSCcjs.sortByValidator; exports.transformMockData = _chunkFQYSVVSCcjs.transformMockData; exports.transformRawData = _chunkFQYSVVSCcjs.transformRawData;
package/dist/server.js CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  sortByValidator,
7
7
  transformMockData,
8
8
  transformRawData
9
- } from "./chunk-2IAQM65M.js";
9
+ } from "./chunk-YZXX2W2L.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.1",
4
+ "version": "1.8.3",
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",
@@ -68,20 +68,20 @@
68
68
  }
69
69
  },
70
70
  "dependencies": {
71
- "@pengzhanbo/utils": "^1.1.2",
72
- "@rollup/pluginutils": "^5.1.3",
71
+ "@pengzhanbo/utils": "^1.2.0",
72
+ "@rollup/pluginutils": "^5.1.4",
73
73
  "chokidar": "3.6.0",
74
74
  "co-body": "^6.2.0",
75
75
  "cookies": "^0.9.1",
76
76
  "cors": "^2.8.5",
77
- "debug": "^4.3.7",
77
+ "debug": "^4.4.0",
78
78
  "fast-glob": "^3.3.2",
79
79
  "formidable": "2.1.2",
80
80
  "http-status": "^2.0.0",
81
- "is-core-module": "^2.15.1",
81
+ "is-core-module": "^2.16.0",
82
82
  "json5": "^2.2.3",
83
83
  "mime-types": "^2.1.35",
84
- "path-to-regexp": "6.2.2",
84
+ "path-to-regexp": "6.3.0",
85
85
  "picocolors": "^1.1.1",
86
86
  "ws": "^8.18.0"
87
87
  },