vite-plugin-mock-dev-server
Advanced tools
Comparing version 1.1.12 to 1.1.13
@@ -1,2 +0,2 @@ | ||
import Ue from"fs";import X from"fs/promises";import T from"path";import{build as qe}from"esbuild";import Be from"fast-glob";import Je from"is-core-module";import{createFilter as ze,normalizePath as Ge}from"vite";var ae="vite-plugin-mock-dev-server",pe="1.1.12";var Ee=/import\.meta\.env\.(.+)/;function B(t){let o={},e=process.env.NODE_ENV||t.mode;Object.assign(o,{"process.env.NODE_ENV":JSON.stringify(e),"global.process.env.NODE_ENV":JSON.stringify(e),"globalThis.process.env.NODE_ENV":JSON.stringify(e),__vite_process_env_NODE_ENV:JSON.stringify(e)});let r={},n={};for(let c in t.define){let a=t.define[c];r[c]=typeof a=="string"?a:JSON.stringify(a);let m=c.match(Ee);m&&(n[m[1]]=`__vite__define__${r[c]}`)}let s={},i={};s["import.meta.hot"]="undefined";for(let c in t.env)s[`import.meta.env.${c}`]=JSON.stringify(t.env[c]);return Object.assign(i,{"import.meta.env":JSON.stringify({...t.env,...n}).replace(/"__vite__define__(.+?)"([,}])/g,(c,a,m)=>`${a.replace(/(^\\")|(\\"$)/g,'"')}${m}`)}),{...s,...i,...o}}import le from"fs/promises";import Ie from"path";import Le from"json5";var J={name:"externalize-deps",setup(t){t.onResolve({filter:/.*/},({path:o})=>{if(o[0]!=="."&&!Ie.isAbsolute(o))return{external:!0}})}},z={name:"json5-loader",setup(t){t.onLoad({filter:/\.json5$/},async({path:o})=>{let e=await le.readFile(o,"utf-8");return{contents:`export default ${JSON.stringify(Le.parse(e))}`,loader:"js"}})}},G={name:"json-loader",setup(t){t.onLoad({filter:/\.json$/},async({path:o})=>({contents:`export default ${await le.readFile(o,"utf-8")}`,loader:"js"}))}},Q=t=>({name:"alias-plugin",setup(o){o.onResolve({filter:/.*/},async({path:e})=>{let r=t.find(({find:c})=>$e(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 $e(t,o){return t instanceof RegExp?t.test(o):o.length<t.length?!1:o===t?!0:o.startsWith(`${t}/`)}import Z from"fs";import ee from"path";import{fileURLToPath as Fe}from"url";import Te from"debug";import{match as Ne}from"path-to-regexp";import ue from"picocolors";var S=t=>Array.isArray(t),j=t=>typeof t=="function",He=t=>Object.prototype.toString.call(t)==="[object Object]",te=t=>He(t)&&Object.keys(t).length===0,Ae=t=>t!==null&&typeof t=="object"&&typeof t.pipe=="function",me=t=>Ae(t)&&t.readable!==!1&&typeof t._read=="function"&&typeof t._readableState=="object";function de(t){return new Promise(o=>setTimeout(o,t))}function fe(t){return ee.dirname(Fe(t))}var C=Te("vite:plugin-mock-dev-server"),w=t=>S(t)?t:t==null?[]:[t],R={info(...t){console.info(ue.cyan("mock-dev-server: "),...t)},error(...t){console.error(` | ||
import Ue from"fs";import X from"fs/promises";import T from"path";import{build as qe}from"esbuild";import Be from"fast-glob";import Je from"is-core-module";import{createFilter as ze,normalizePath as Ge}from"vite";var ae="vite-plugin-mock-dev-server",pe="1.1.13";var Ee=/import\.meta\.env\.(.+)/;function B(t){let o={},e=process.env.NODE_ENV||t.mode;Object.assign(o,{"process.env.NODE_ENV":JSON.stringify(e),"global.process.env.NODE_ENV":JSON.stringify(e),"globalThis.process.env.NODE_ENV":JSON.stringify(e),__vite_process_env_NODE_ENV:JSON.stringify(e)});let r={},n={};for(let c in t.define){let a=t.define[c];r[c]=typeof a=="string"?a:JSON.stringify(a);let m=c.match(Ee);m&&(n[m[1]]=`__vite__define__${r[c]}`)}let s={},i={};s["import.meta.hot"]="undefined";for(let c in t.env)s[`import.meta.env.${c}`]=JSON.stringify(t.env[c]);return Object.assign(i,{"import.meta.env":JSON.stringify({...t.env,...n}).replace(/"__vite__define__(.+?)"([,}])/g,(c,a,m)=>`${a.replace(/(^\\")|(\\"$)/g,'"')}${m}`)}),{...s,...r,...i,...o}}import le from"fs/promises";import Ie from"path";import Le from"json5";var J={name:"externalize-deps",setup(t){t.onResolve({filter:/.*/},({path:o})=>{if(o[0]!=="."&&!Ie.isAbsolute(o))return{external:!0}})}},z={name:"json5-loader",setup(t){t.onLoad({filter:/\.json5$/},async({path:o})=>{let e=await le.readFile(o,"utf-8");return{contents:`export default ${JSON.stringify(Le.parse(e))}`,loader:"js"}})}},G={name:"json-loader",setup(t){t.onLoad({filter:/\.json$/},async({path:o})=>({contents:`export default ${await le.readFile(o,"utf-8")}`,loader:"js"}))}},Q=t=>({name:"alias-plugin",setup(o){o.onResolve({filter:/.*/},async({path:e})=>{let r=t.find(({find:c})=>$e(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 $e(t,o){return t instanceof RegExp?t.test(o):o.length<t.length?!1:o===t?!0:o.startsWith(`${t}/`)}import Z from"fs";import ee from"path";import{fileURLToPath as Fe}from"url";import Te from"debug";import{match as Ne}from"path-to-regexp";import ue from"picocolors";var S=t=>Array.isArray(t),j=t=>typeof t=="function",He=t=>Object.prototype.toString.call(t)==="[object Object]",te=t=>He(t)&&Object.keys(t).length===0,Ae=t=>t!==null&&typeof t=="object"&&typeof t.pipe=="function",me=t=>Ae(t)&&t.readable!==!1&&typeof t._read=="function"&&typeof t._readableState=="object";function de(t){return new Promise(o=>setTimeout(o,t))}function fe(t){return ee.dirname(Fe(t))}var C=Te("vite:plugin-mock-dev-server"),w=t=>S(t)?t:t==null?[]:[t],R={info(...t){console.info(ue.cyan("mock-dev-server: "),...t)},error(...t){console.error(` | ||
`,ue.cyan("mock-dev-server: "),...t,` | ||
@@ -3,0 +3,0 @@ `)}};function H(t,o,e){for(let n of o){let s=ee.join(t,n);if(Z.existsSync(s)&&Z.statSync(s).isFile()){let i=e!=null&&e.pathOnly?s:Z.readFileSync(s,"utf-8");if(!(e!=null&&e.predicate)||e.predicate(i))return i}}let r=ee.dirname(t);if(r!==t&&(!(e!=null&&e.rootDir)||r.startsWith(e==null?void 0:e.rootDir)))return H(r,o,e)}var V=(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 K(t,o){return t[0]==="^"&&new RegExp(t).test(o)||o.startsWith(t)}function A(t,o){return(Ne(t,{decode:decodeURIComponent})(o)||{params:{}}).params||{}}async function ge(t,o,e){let r=w(e.include),n=w(e.exclude),s=B(o),{httpProxies:i}=V(o.server.proxy||{});i.push(...w(e.prefix));let c=w(e.wsPrefix),a={};try{let u=H(o.root,["package.json"]);u&&(a=JSON.parse(u))}catch{}let m=e.build.dist,x=await Xe(process.cwd(),r,n),v=T.join(o.root,`mock-data-${Date.now()}.js`);await X.writeFile(v,x,"utf-8");let{code:F,deps:D}=await Ye(v,s,o.resolve.alias),p=Qe(D);await X.unlink(v);let l=[{filename:T.join(m,"mock-data.js"),source:F},{filename:T.join(m,"index.js"),source:Ke(i,c,e.cookiesOptions,e.build.serverPort)},{filename:T.join(m,"package.json"),source:Ve(a,p)}];try{if(T.isAbsolute(m)){await X.rm(m,{recursive:!0}),Ue.mkdirSync(m,{recursive:!0});for(let{filename:u,source:d}of l)await X.writeFile(u,d,"utf-8")}else for(let{filename:u,source:d}of l)t.emitFile({type:"asset",fileName:u,source:d})}catch{}}function Qe(t){let o=new Set,e=[ae,"connect","cors"];return Object.keys(t).forEach(r=>{t[r].imports.filter(s=>s.external).map(s=>s.path).forEach(s=>{!e.includes(s)&&!Je(s)&&o.add(s)})}),Array.from(o)}function Ve(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":`^${pe}`,cors:"^2.8.5"},pnpm:{peerDependencyRules:{ignoreMissing:["vite"]}}};return o.forEach(i=>{s.dependencies[i]=n[i]||"latest"}),JSON.stringify(s,null,2)}function Ke(t,o,e={},r=8080){return`import { createServer } from 'node:http'; |
{ | ||
"name": "vite-plugin-mock-dev-server", | ||
"version": "1.1.12", | ||
"version": "1.1.13", | ||
"keywords": [ | ||
@@ -5,0 +5,0 @@ "vite", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
104409