Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vite-plugin-mock-dev-server

Package Overview
Dependencies
Maintainers
1
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-mock-dev-server - npm Package Compare versions

Comparing version 1.1.10 to 1.1.11

4

dist/index.js

@@ -1,2 +0,2 @@

import Ae from"fs";import Y from"fs/promises";import T from"path";import{build as Ne}from"esbuild";import Ue from"fast-glob";import qe from"is-core-module";import{createFilter as Be,normalizePath as Je}from"vite";var ie="vite-plugin-mock-dev-server",ce="1.1.10";import ae from"fs/promises";import Ee from"path";import Ie from"json5";var B={name:"externalize-deps",setup(t){t.onResolve({filter:/.*/},({path:o})=>{if(o[0]!=="."&&!Ee.isAbsolute(o))return{external:!0}})}},J={name:"json5-loader",setup(t){t.onLoad({filter:/\.json5$/},async({path:o})=>{let e=await ae.readFile(o,"utf-8");return{contents:`export default ${JSON.stringify(Ie.parse(e))}`,loader:"js"}})}},z={name:"json-loader",setup(t){t.onLoad({filter:/\.json$/},async({path:o})=>({contents:`export default ${await ae.readFile(o,"utf-8")}`,loader:"js"}))}},G=t=>({name:"alias-plugin",setup(o){o.onResolve({filter:/.*/},async({path:e})=>{let r=t.find(({find:c})=>Le(c,e));if(!r)return null;let{find:n,replacement:s}=r;return{path:(await o.resolve(e.replace(n,s),{kind:"import-statement",resolveDir:s,namespace:"file"})).path,external:!1}})}});function Le(t,o){return t instanceof RegExp?t.test(o):o.length<t.length?!1:o===t?!0:o.startsWith(`${t}/`)}import V from"fs";import Z from"path";import{fileURLToPath as _e}from"url";import $e from"debug";import{match as Fe}from"path-to-regexp";import pe from"picocolors";var w=t=>Array.isArray(t),P=t=>typeof t=="function",Te=t=>Object.prototype.toString.call(t)==="[object Object]",le=t=>Te(t)&&Object.keys(t).length===0,He=t=>t!==null&&typeof t=="object"&&typeof t.pipe=="function",ue=t=>He(t)&&t.readable!==!1&&typeof t._read=="function"&&typeof t._readableState=="object";function me(t){return new Promise(o=>setTimeout(o,t))}function de(t){return Z.dirname(_e(t))}var j=$e("vite:plugin-mock-dev-server"),O=t=>w(t)?t:t==null?[]:[t],R={info(...t){console.info(pe.cyan("mock-dev-server: "),...t)},error(...t){console.error(`
import Ae from"fs";import Y from"fs/promises";import T from"path";import{build as Ne}from"esbuild";import Ue from"fast-glob";import qe from"is-core-module";import{createFilter as Be,normalizePath as Je}from"vite";var ie="vite-plugin-mock-dev-server",ce="1.1.11";import ae from"fs/promises";import Ee from"path";import Ie from"json5";var B={name:"externalize-deps",setup(t){t.onResolve({filter:/.*/},({path:o})=>{if(o[0]!=="."&&!Ee.isAbsolute(o))return{external:!0}})}},J={name:"json5-loader",setup(t){t.onLoad({filter:/\.json5$/},async({path:o})=>{let e=await ae.readFile(o,"utf-8");return{contents:`export default ${JSON.stringify(Ie.parse(e))}`,loader:"js"}})}},z={name:"json-loader",setup(t){t.onLoad({filter:/\.json$/},async({path:o})=>({contents:`export default ${await ae.readFile(o,"utf-8")}`,loader:"js"}))}},G=t=>({name:"alias-plugin",setup(o){o.onResolve({filter:/.*/},async({path:e})=>{let r=t.find(({find:c})=>Le(c,e));if(!r)return null;let{find:n,replacement:s}=r;return{path:(await o.resolve(e.replace(n,s),{kind:"import-statement",resolveDir:s,namespace:"file"})).path,external:!1}})}});function Le(t,o){return t instanceof RegExp?t.test(o):o.length<t.length?!1:o===t?!0:o.startsWith(`${t}/`)}import V from"fs";import Z from"path";import{fileURLToPath as _e}from"url";import $e from"debug";import{match as Fe}from"path-to-regexp";import pe from"picocolors";var w=t=>Array.isArray(t),P=t=>typeof t=="function",Te=t=>Object.prototype.toString.call(t)==="[object Object]",le=t=>Te(t)&&Object.keys(t).length===0,He=t=>t!==null&&typeof t=="object"&&typeof t.pipe=="function",ue=t=>He(t)&&t.readable!==!1&&typeof t._read=="function"&&typeof t._readableState=="object";function me(t){return new Promise(o=>setTimeout(o,t))}function de(t){return Z.dirname(_e(t))}var j=$e("vite:plugin-mock-dev-server"),O=t=>w(t)?t:t==null?[]:[t],R={info(...t){console.info(pe.cyan("mock-dev-server: "),...t)},error(...t){console.error(`
`,pe.cyan("mock-dev-server: "),...t,`

@@ -50,3 +50,3 @@ `)}};function A(t,o,e){for(let n of o){let s=Z.join(t,n);if(V.existsSync(s)&&V.statSync(s).isFile()){let i=e!=null&&e.pathOnly?s:V.readFileSync(s,"utf-8");if(!(e!=null&&e.predicate)||e.predicate(i))return i}}let r=Z.dirname(t);if(r!==t&&(!(e!=null&&e.rootDir)||r.startsWith(e==null?void 0:e.rootDir)))return A(r,o,e)}var Q=(t={})=>{let o=[],e=[];return Object.keys(t).forEach(r=>{var s,i;let n=t[r];typeof n=="string"||!n.ws&&!((s=n.target)!=null&&s.toString().startsWith("ws:"))&&!((i=n.target)!=null&&i.toString().startsWith("wss:"))?o.push(r):e.push(r)}),{httpProxies:o,wsProxies:e}};function X(t,o){return t[0]==="^"&&new RegExp(t).test(o)||o.startsWith(t)}function N(t,o){return(Fe(t,{decode:decodeURIComponent})(o)||{params:{}}).params||{}}async function fe(t,o,e){let r=O(e.include),n=O(e.exclude),s={};if(o.define)for(let p in o.define){let m=o.define[p];s[p]=typeof m=="string"?m:JSON.stringify(m)}let{httpProxies:i}=Q(o.server.proxy||{});i.push(...O(e.prefix));let c=O(e.wsPrefix),u={};try{let p=A(o.root,["package.json"]);p&&(u=JSON.parse(p))}catch{}let d=e.build.dist,v=await Xe(process.cwd(),r,n),h=T.join(o.root,`mock-data-${Date.now()}.js`);await Y.writeFile(h,v,"utf-8");let{code:F,deps:D}=await Ye(h,s,o.resolve.alias),a=ze(D);await Y.unlink(h);let l=[{filename:T.join(d,"mock-data.js"),source:F},{filename:T.join(d,"index.js"),source:Qe(i,c,e.cookiesOptions,e.build.serverPort)},{filename:T.join(d,"package.json"),source:Ge(u,a)}];try{if(T.isAbsolute(d)){await Y.rm(d,{recursive:!0}),Ae.mkdirSync(d,{recursive:!0});for(let{filename:p,source:m}of l)await Y.writeFile(p,m,"utf-8")}else for(let{filename:p,source:m}of l)t.emitFile({type:"asset",fileName:p,source:m})}catch{}}function ze(t){let o=new Set,e=[ie,"connect","cors"];return Object.keys(t).forEach(r=>{t[r].imports.filter(s=>s.external).map(s=>s.path).forEach(s=>{!e.includes(s)&&!qe(s)&&o.add(s)})}),Array.from(o)}function Ge(t,o){let{dependencies:e={},devDependencies:r={}}=t,n={...e,...r},s={name:"mock-server",type:"module",scripts:{start:"node index.js"},dependencies:{connect:"^3.7.0","vite-plugin-mock-dev-server":`^${ce}`,cors:"^2.8.5"},pnpm:{peerDependencyRules:{ignoreMissing:["vite"]}}};return o.forEach(i=>{s.dependencies[i]=n[i]||"latest"}),JSON.stringify(s,null,2)}function Qe(t,o,e={},r=8080){return`import { createServer } from 'node:http';

`,s)}}async function st(t,o,{cookies:e}){if(e)try{let r=P(e)?await e(t):e;Object.keys(r).forEach(n=>{let s=r[n];if(w(s)){let[i,c]=s;o.setCookie(n,i,c)}else o.setCookie(n,s)})}catch(r){R.error(`${W.red("[cookies error]")} ${t.url}
`,r)}}function it(t,o,e){if(ue(o))o.pipe(t);else if(ye.isBuffer(o))t.end(e==="text"||e==="json"?o.toString("utf-8"):o);else{let r=typeof o=="string"?o:JSON.stringify(o);t.end(e==="buffer"?ye.from(r):r)}}async function ve(t,o){if(!o||o<=0)return;let e=Date.now()-t,r=o-e;r>0&&await me(r)}function ct(t){return et[t]||"Unknown"}import ut from"events";import oe from"fs";import{createRequire as mt}from"module";import we from"path";import{pathToFileURL as dt}from"url";import Se from"chokidar";import{build as ft}from"esbuild";import kt from"fast-glob";import{createFilter as gt,normalizePath as q}from"vite";import{parse as at}from"url";import pt from"lodash.sortby";function xe(t){let o=[];for(let[,r]of t.entries())r&&(w(r)?o.push(...r):o.push(r));let e={};return o.filter(r=>(r.enabled||typeof r.enabled>"u")&&r.url).forEach(r=>{let{pathname:n,query:s}=at(r.url,!0),i=e[n]??(e[n]=[]),c={...r,url:n};if(c.ws!==!0){let u=c.validator;le(s)||(P(u)?c.validator=function(d){return _(d.query,s)&&u(d)}:u?(c.validator={...u},c.validator.query=c.validator.query?{...s,...c.validator.query}:s):c.validator={query:s})}i.push(c)}),Object.keys(e).forEach(r=>{e[r]=pt(e[r],n=>{if(n.ws===!0)return 0;let{validator:s}=n;return s?P(s)?0:1/Object.keys(s).reduce((c,u)=>c+lt(s[u]),0):1})}),e}function lt(t){return t?Object.keys(t).length:0}var yt=de(import.meta.url),$=mt(yt),K=class extends ut{constructor(e){super();this.options=e;this.moduleCache=new Map;this.moduleDeps=new Map;this.moduleType="cjs";this._mockData={};this.cwd=e.cwd||process.cwd();try{let r=A(this.cwd,["package.json"]);this.moduleType=r&&JSON.parse(r).type==="module"?"esm":"cjs"}catch{}}get mockData(){return this._mockData}load(){let{include:e,exclude:r}=this.options,n=gt(e,r,{resolve:!1});kt(e,{cwd:this.cwd}).then(i=>Promise.all(i.filter(n).map(c=>this.loadMock(c)))).then(()=>this.updateMockList()),this.watchMockEntry(),this.watchDeps();let s=null;this.on("mock:update",async i=>{n(i)&&(await this.loadMock(i),s&&clearImmediate(s),s=setImmediate(()=>{this.updateMockList(),this.emit("mock:update-end",i),s=null}))}),this.on("mock:unlink",async i=>{n(i)&&(this.moduleCache.delete(i),this.updateMockList(),this.emit("mock:update-end",i))})}watchMockEntry(){let{include:e}=this.options,[r,...n]=e,s=Se.watch(r,{ignoreInitial:!0,cwd:this.cwd});n.length>0&&n.forEach(i=>s.add(i)),s.on("add",async i=>{i=q(i),this.emit("mock:update",i),j("watcher:add",i)}),s.on("change",async i=>{i=q(i),this.emit("mock:update",i),j("watcher:change",i)}),s.on("unlink",async i=>{i=q(i),this.emit("mock:unlink",i),j("watcher:unlink",i)}),this.mockWatcher=s}watchDeps(){let e=[];this.depsWatcher=Se.watch([],{ignoreInitial:!0,cwd:this.cwd}),this.depsWatcher.on("change",r=>{r=q(r);let n=this.moduleDeps.get(r);n&&n.forEach(s=>{this.emit("mock:update",s)})}),this.depsWatcher.on("unlink",r=>{r=q(r),this.moduleDeps.delete(r)}),this.on("update:deps",()=>{let r=[];for(let[s]of this.moduleDeps.entries())r.push(s);let n=r.filter(s=>!e.includes(s));n.length>0&&this.depsWatcher.add(n)})}close(){var e,r;(e=this.mockWatcher)==null||e.close(),(r=this.depsWatcher)==null||r.close()}updateMockList(){this._mockData=xe(this.moduleCache)}updateModuleDeps(e,r){Object.keys(r).forEach(n=>{r[n].imports.map(i=>i.path).forEach(i=>{this.moduleDeps.has(i)||this.moduleDeps.set(i,new Set),this.moduleDeps.get(i).add(e)})}),this.emit("update:deps")}async loadMock(e){if(!e)return;let r=!1;/\.m[jt]s$/.test(e)?r=!0:/\.c[jt]s$/.test(e)?r=!1:r=this.moduleType==="esm";let{code:n,deps:s}=await this.transformWithEsbuild(e,r);try{let i=await this.loadFromCode(e,n,r)||{},c;i.default?c=i.default:(c=[],Object.keys(i).forEach(u=>{w(i[u])?c.push(...i[u]):c.push(i[u])})),w(c)?c.forEach(u=>u.__filepath__=e):c.__filepath__=e,this.moduleCache.set(e,c),this.updateModuleDeps(e,s)}catch(i){console.error(i)}}async loadFromCode(e,r,n){if(n){let s=`${e}.timestamp-${Date.now()}`,i=`${s}.mjs`,c=`${dt(s)}.mjs`;await oe.promises.writeFile(i,r,"utf8");try{return await import(c)}finally{try{oe.unlinkSync(i)}catch{}}}else{e=we.resolve(this.cwd,e);let s=we.extname(e),i=oe.realpathSync(e),c=s in $.extensions?s:".js",u=$.extensions[c];$.extensions[c]=(v,h)=>{h===i?v._compile(r,h):u(v,h)},delete $.cache[$.resolve(e)];let d=$(e);return $.extensions[c]=u,d.__esModule?d:{default:d}}}async transformWithEsbuild(e,r){var n;try{let s=await ft({entryPoints:[e],outfile:"out.js",write:!1,target:["node14.18","node16"],platform:"node",bundle:!0,metafile:!0,format:r?"esm":"cjs",define:this.options.define,plugins:[G(this.options.alias),B,z,J]});return{code:s.outputFiles[0].text,deps:((n=s.metafile)==null?void 0:n.inputs)||{}}}catch(s){console.error(s)}return{code:"",deps:{}}}};import{parse as Oe}from"url";import ht from"cookies";import{pathToRegexp as Ce}from"path-to-regexp";import vt from"picocolors";import{WebSocketServer as Mt}from"ws";function je(t,o,e,r){var D;let n=new Map,s=new Map,i=new WeakMap,c=a=>{let l=s.get(a);return!l&&s.set(a,l=new Map),l},u=(a,l)=>{let p=a.get(l);return!p&&a.set(l,p=new Mt({noServer:!0})),p},d=(a,l)=>{let p=n.get(a);!p&&n.set(a,p=new Set),p.add(l)},v=(a,l,p,m,f,k)=>{var g;try{(g=p.setup)==null||g.call(p,l,m),l.on("close",()=>{a.delete(f)})}catch(S){R.error(`${vt.red("[websocket server error]")} ${k}
`,r)}}function it(t,o,e){if(ue(o))o.pipe(t);else if(ye.isBuffer(o))t.end(e==="text"||e==="json"?o.toString("utf-8"):o);else{let r=typeof o=="string"?o:JSON.stringify(o);t.end(e==="buffer"?ye.from(r):r)}}async function ve(t,o){if(!o||o<=0)return;let e=Date.now()-t,r=o-e;r>0&&await me(r)}function ct(t){return et[t]||"Unknown"}import ut from"events";import oe from"fs";import{createRequire as mt}from"module";import we from"path";import{pathToFileURL as dt}from"url";import Se from"chokidar";import{build as ft}from"esbuild";import kt from"fast-glob";import{createFilter as gt,normalizePath as q}from"vite";import{parse as at}from"url";import pt from"lodash.sortby";function xe(t){let o=[];for(let[,r]of t.entries())r&&(w(r)?o.push(...r):o.push(r));let e={};return o.filter(r=>(r.enabled||typeof r.enabled>"u")&&r.url).forEach(r=>{let{pathname:n,query:s}=at(r.url,!0),i=e[n]??(e[n]=[]),c={...r,url:n};if(c.ws!==!0){let u=c.validator;le(s)||(P(u)?c.validator=function(d){return _(d.query,s)&&u(d)}:u?(c.validator={...u},c.validator.query=c.validator.query?{...s,...c.validator.query}:s):c.validator={query:s})}i.push(c)}),Object.keys(e).forEach(r=>{e[r]=pt(e[r],n=>{if(n.ws===!0)return 0;let{validator:s}=n;return s?P(s)?0:1/Object.keys(s).reduce((c,u)=>c+lt(s[u]),0):2})}),e}function lt(t){return t?Object.keys(t).length:0}var yt=de(import.meta.url),$=mt(yt),K=class extends ut{constructor(e){super();this.options=e;this.moduleCache=new Map;this.moduleDeps=new Map;this.moduleType="cjs";this._mockData={};this.cwd=e.cwd||process.cwd();try{let r=A(this.cwd,["package.json"]);this.moduleType=r&&JSON.parse(r).type==="module"?"esm":"cjs"}catch{}}get mockData(){return this._mockData}load(){let{include:e,exclude:r}=this.options,n=gt(e,r,{resolve:!1});kt(e,{cwd:this.cwd}).then(i=>Promise.all(i.filter(n).map(c=>this.loadMock(c)))).then(()=>this.updateMockList()),this.watchMockEntry(),this.watchDeps();let s=null;this.on("mock:update",async i=>{n(i)&&(await this.loadMock(i),s&&clearImmediate(s),s=setImmediate(()=>{this.updateMockList(),this.emit("mock:update-end",i),s=null}))}),this.on("mock:unlink",async i=>{n(i)&&(this.moduleCache.delete(i),this.updateMockList(),this.emit("mock:update-end",i))})}watchMockEntry(){let{include:e}=this.options,[r,...n]=e,s=Se.watch(r,{ignoreInitial:!0,cwd:this.cwd});n.length>0&&n.forEach(i=>s.add(i)),s.on("add",async i=>{i=q(i),this.emit("mock:update",i),j("watcher:add",i)}),s.on("change",async i=>{i=q(i),this.emit("mock:update",i),j("watcher:change",i)}),s.on("unlink",async i=>{i=q(i),this.emit("mock:unlink",i),j("watcher:unlink",i)}),this.mockWatcher=s}watchDeps(){let e=[];this.depsWatcher=Se.watch([],{ignoreInitial:!0,cwd:this.cwd}),this.depsWatcher.on("change",r=>{r=q(r);let n=this.moduleDeps.get(r);n&&n.forEach(s=>{this.emit("mock:update",s)})}),this.depsWatcher.on("unlink",r=>{r=q(r),this.moduleDeps.delete(r)}),this.on("update:deps",()=>{let r=[];for(let[s]of this.moduleDeps.entries())r.push(s);let n=r.filter(s=>!e.includes(s));n.length>0&&this.depsWatcher.add(n)})}close(){var e,r;(e=this.mockWatcher)==null||e.close(),(r=this.depsWatcher)==null||r.close()}updateMockList(){this._mockData=xe(this.moduleCache)}updateModuleDeps(e,r){Object.keys(r).forEach(n=>{r[n].imports.map(i=>i.path).forEach(i=>{this.moduleDeps.has(i)||this.moduleDeps.set(i,new Set),this.moduleDeps.get(i).add(e)})}),this.emit("update:deps")}async loadMock(e){if(!e)return;let r=!1;/\.m[jt]s$/.test(e)?r=!0:/\.c[jt]s$/.test(e)?r=!1:r=this.moduleType==="esm";let{code:n,deps:s}=await this.transformWithEsbuild(e,r);try{let i=await this.loadFromCode(e,n,r)||{},c;i.default?c=i.default:(c=[],Object.keys(i).forEach(u=>{w(i[u])?c.push(...i[u]):c.push(i[u])})),w(c)?c.forEach(u=>u.__filepath__=e):c.__filepath__=e,this.moduleCache.set(e,c),this.updateModuleDeps(e,s)}catch(i){console.error(i)}}async loadFromCode(e,r,n){if(n){let s=`${e}.timestamp-${Date.now()}`,i=`${s}.mjs`,c=`${dt(s)}.mjs`;await oe.promises.writeFile(i,r,"utf8");try{return await import(c)}finally{try{oe.unlinkSync(i)}catch{}}}else{e=we.resolve(this.cwd,e);let s=we.extname(e),i=oe.realpathSync(e),c=s in $.extensions?s:".js",u=$.extensions[c];$.extensions[c]=(v,h)=>{h===i?v._compile(r,h):u(v,h)},delete $.cache[$.resolve(e)];let d=$(e);return $.extensions[c]=u,d.__esModule?d:{default:d}}}async transformWithEsbuild(e,r){var n;try{let s=await ft({entryPoints:[e],outfile:"out.js",write:!1,target:["node14.18","node16"],platform:"node",bundle:!0,metafile:!0,format:r?"esm":"cjs",define:this.options.define,plugins:[G(this.options.alias),B,z,J]});return{code:s.outputFiles[0].text,deps:((n=s.metafile)==null?void 0:n.inputs)||{}}}catch(s){console.error(s)}return{code:"",deps:{}}}};import{parse as Oe}from"url";import ht from"cookies";import{pathToRegexp as Ce}from"path-to-regexp";import vt from"picocolors";import{WebSocketServer as Mt}from"ws";function je(t,o,e,r){var D;let n=new Map,s=new Map,i=new WeakMap,c=a=>{let l=s.get(a);return!l&&s.set(a,l=new Map),l},u=(a,l)=>{let p=a.get(l);return!p&&a.set(l,p=new Mt({noServer:!0})),p},d=(a,l)=>{let p=n.get(a);!p&&n.set(a,p=new Set),p.add(l)},v=(a,l,p,m,f,k)=>{var g;try{(g=p.setup)==null||g.call(p,l,m),l.on("close",()=>{a.delete(f)})}catch(S){R.error(`${vt.red("[websocket server error]")} ${k}
`,S)}},h=(a,l,p,m)=>{a.emit("connection",l,p),l.on("close",()=>{let f=m.findIndex(k=>k.ws===l);f!==-1&&m.splice(f,1)})},F=(a,l,p,m,f)=>{let{cleanupList:k,connectionList:g,context:S}=i.get(l);Pe(k),g.forEach(({ws:C})=>C.removeAllListeners()),l.removeAllListeners(),v(a,l,p,S,m,f),g.forEach(({ws:C,req:E})=>h(l,C,E,g))};(D=t.on)==null||D.call(t,"mock:update-end",a=>{if(!n.has(a))return;let l=n.get(a);if(l)for(let p of l.values())for(let m of t.mockData[p]){if(!m.ws||m.__filepath__!==a)return;let f=c(p);for(let[k,g]of f.entries())F(f,g,m,k,a)}}),o==null||o.on("upgrade",(a,l,p)=>{let{pathname:m,query:f}=Oe(a.url,!0);if(!m||e.length===0||!e.some(M=>X(M,a.url)))return;let k=t.mockData,g=Object.keys(k).find(M=>Ce(M).test(m));if(!g)return;let S=k[g].find(M=>M.url&&M.ws&&Ce(M.url).test(m));if(!S)return;let C=S.__filepath__;d(C,g);let E=c(g),I=u(E,m),L=i.get(I);if(!L){let M=[],ne={onCleanup:De=>M.push(De)};L={cleanupList:M,context:ne,connectionList:[]},i.set(I,L),v(E,I,S,ne,m,C)}let y=a,H=new ht(a,a,r),{query:We}=Oe(a.headers.referer||"",!0);y.query=f,y.refererQuery=We,y.params=N(g,m),y.getCookie=H.get.bind(H),I.handleUpgrade(y,l,p,M=>{j(`websocket-mock: ${a.url} connected`),L.connectionList.push({req:y,ws:M}),h(I,M,y,L.connectionList)})}),o==null||o.on("close",()=>{for(let a of s.values()){for(let l of a.values()){let p=i.get(l);Pe(p.cleanupList),l.close()}a.clear()}s.clear(),n.clear()})}function Pe(t){let o;for(;o=t.shift();)o==null||o()}async function re(t,o,e,r){let n=O(o.include),s=O(o.exclude),i={};if(t.define)for(let v in t.define){let h=t.define[v];i[v]=typeof h=="string"?h:JSON.stringify(h)}let c=new K({include:n,exclude:s,define:i,alias:t.resolve.alias});c.load(),c.on("mock:update-end",()=>{o.reload&&(r==null||r.send({type:"full-reload"}))}),e==null||e.on("close",()=>c.close());let{httpProxies:u}=Q(t.server.proxy||{}),d=O(o.prefix);return je(c,e,O(o.wsPrefix),o.cookiesOptions),be(c,{formidableOptions:o.formidableOptions,proxies:[...d,...u],cookiesOptions:o.cookiesOptions})}function Re({prefix:t=[],wsPrefix:o=[],include:e=["mock/**/*.mock.{js,ts,cjs,mjs,json,json5}"],exclude:r=["**/node_modules/**","**/.vscode/**","**/.git/**"],reload:n=!1,formidableOptions:s={},build:i=!1,cookiesOptions:c={}}={}){let u={prefix:t,wsPrefix:o,include:e,exclude:r,reload:n,cookiesOptions:c,formidableOptions:{multiples:!0,...s},build:i?Object.assign({serverPort:8080,dist:"mockServer"},typeof i=="object"?i:{}):!1},d=[xt(u)];return u.build&&d.push(bt(u)),d}function bt(t){let o={};return{name:"vite-plugin-mock-dev-server-generator",enforce:"post",apply:"build",configResolved(e){o=e,e.logger.warn("")},async buildEnd(e){e||o.command==="build"&&await fe(this,o,t)}}}function xt(t){let o={};return{name:"vite-plugin-mock-dev-server",enforce:"pre",apply:"serve",configResolved(e){o=e,e.logger.warn("")},async configureServer({middlewares:e,config:r,httpServer:n,ws:s}){let i=await re(r,t,n,s);e.use(i)},async configurePreviewServer({middlewares:e,httpServer:r}){let n=await re(o,t,r);e.use(n)}}}function Zo(t){return t}function er(t){return e=>(w(e)?e=e.map(r=>t(r)||r):e=t(e)||e,e)}var nr=Re;export{be as baseMiddleware,er as createDefineMock,nr as default,Zo as defineMock,Re as mockDevServerPlugin,je as mockWebSocket,xe as transformMockData};
{
"name": "vite-plugin-mock-dev-server",
"version": "1.1.10",
"version": "1.1.11",
"keywords": [

@@ -5,0 +5,0 @@ "vite",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc