vite-plugin-mock-dev-server
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -68,2 +68,9 @@ import { Connect, Plugin, ResolvedConfig } from 'vite'; | ||
reload?: boolean; | ||
/** | ||
* Configure to `cors` | ||
* | ||
* 配置 `cors` | ||
* @default true | ||
* @see [cors](https://github.com/expressjs/cors#configuration-options) | ||
*/ | ||
cors?: boolean | CorsOptions; | ||
@@ -70,0 +77,0 @@ /** |
@@ -1,2 +0,2 @@ | ||
import qe from"node:fs";import Z from"node:fs/promises";import U from"node:path";import{build as ze}from"esbuild";import Ge from"fast-glob";import Qe from"is-core-module";import{createFilter as Ve,normalizePath as Ke}from"vite";var ue="vite-plugin-mock-dev-server",me="1.2.0";import ne from"picocolors";import te from"node:fs";import oe from"node:path";import{parse as Ie}from"node:querystring";import{URL as $e,fileURLToPath as Te}from"node:url";import Fe from"debug";import{match as Ne}from"path-to-regexp";import de from"picocolors";var v=t=>Array.isArray(t),W=t=>typeof t=="function",N=t=>Object.prototype.toString.call(t)==="[object Object]",re=t=>N(t)&&Object.keys(t).length===0,He=t=>t!==null&&typeof t=="object"&&typeof t.pipe=="function",fe=t=>He(t)&&t.readable!==!1&&typeof t._read=="function"&&typeof t._readableState=="object";function ke(t){return new Promise(o=>setTimeout(o,t))}function ge(t){return oe.dirname(Te(t))}var D=Fe("vite:plugin-mock-dev-server"),S=t=>v(t)?t:t==null?[]:[t],P={info(...t){console.info(de.cyan("mock-dev-server: "),...t)},error(...t){console.error(` | ||
import qe from"node:fs";import Z from"node:fs/promises";import U from"node:path";import{build as ze}from"esbuild";import Ge from"fast-glob";import Qe from"is-core-module";import{createFilter as Ve,normalizePath as Ke}from"vite";var ue="vite-plugin-mock-dev-server",me="1.2.1";import ne from"picocolors";import te from"node:fs";import oe from"node:path";import{parse as Ie}from"node:querystring";import{URL as $e,fileURLToPath as Te}from"node:url";import Fe from"debug";import{match as Ne}from"path-to-regexp";import de from"picocolors";var v=t=>Array.isArray(t),W=t=>typeof t=="function",N=t=>Object.prototype.toString.call(t)==="[object Object]",re=t=>N(t)&&Object.keys(t).length===0,He=t=>t!==null&&typeof t=="object"&&typeof t.pipe=="function",fe=t=>He(t)&&t.readable!==!1&&typeof t._read=="function"&&typeof t._readableState=="object";function ke(t){return new Promise(o=>setTimeout(o,t))}function ge(t){return oe.dirname(Te(t))}var D=Fe("vite:plugin-mock-dev-server"),S=t=>v(t)?t:t==null?[]:[t],P={info(...t){console.info(de.cyan("mock-dev-server: "),...t)},error(...t){console.error(` | ||
`,de.cyan("mock-dev-server: "),...t,` | ||
@@ -3,0 +3,0 @@ `)}};function B(t,o,e){for(let n of o){let s=oe.join(t,n);if(te.existsSync(s)&&te.statSync(s).isFile()){let i=e!=null&&e.pathOnly?s:te.readFileSync(s,"utf-8");if(!(e!=null&&e.predicate)||e.predicate(i))return i}}let r=oe.dirname(t);if(r!==t&&(!(e!=null&&e.rootDir)||r.startsWith(e==null?void 0:e.rootDir)))return B(r,o,e)}var G=(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 H(t,o){return t[0]==="^"&&new RegExp(t).test(o)||o.startsWith(t)}function J(t,o){return(Ne(t,{decode:decodeURIComponent})(o)||{params:{}}).params||{}}function j(t){let o=new $e(t,"http://example.com"),e=decodeURIComponent(o.pathname),r=Ie(o.search.replace(/^\?/,""));return{pathname:e,query:r}}var Ue=/import\.meta\.env\.(.+)/;function Q(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={},s=[];for(let a in t.define){let p=t.define[a];if(typeof p=="string")try{JSON.parse(p),r[a]=p}catch{s.push(a)}else r[a]=JSON.stringify(p);let f=a.match(Ue);f&&r[a]&&(n[f[1]]=`__vite__define__${r[a]}`)}s.length&&P.error(`${ne.yellow("[warn]")} The following keys: ${ne.yellow(ne.underline(s.join(", ")))} declared in 'define' cannot be parsed as regular code snippets.`);let i={},c={};i["import.meta.hot"]="undefined";for(let a in t.env)i[`import.meta.env.${a}`]=JSON.stringify(t.env[a]);return Object.assign(c,{"import.meta.env":JSON.stringify({...t.env,...n}).replace(/"__vite__define__(.+?)"([,}])/g,(a,p,f)=>`${p.replace(/(^\\")|(\\"$)/g,'"')}${f}`)}),{...i,...r,...c,...o}}import ye from"node:fs/promises";import Ae from"node:path";import Be from"json5";var V={name:"externalize-deps",setup(t){t.onResolve({filter:/.*/},({path:o})=>{if(o[0]!=="."&&!Ae.isAbsolute(o))return{external:!0}})}},K={name:"json5-loader",setup(t){t.onLoad({filter:/\.json5$/},async({path:o})=>{let e=await ye.readFile(o,"utf-8");return{contents:`export default ${JSON.stringify(Be.parse(e))}`,loader:"js"}})}},X={name:"json-loader",setup(t){t.onLoad({filter:/\.json$/},async({path:o})=>({contents:`export default ${await ye.readFile(o,"utf-8")}`,loader:"js"}))}},Y=t=>({name:"alias-plugin",setup(o){o.onResolve({filter:/.*/},async({path:e})=>{let r=t.find(({find:c})=>Je(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 Je(t,o){return t instanceof RegExp?t.test(o):o.length<t.length?!1:o===t?!0:o.startsWith(`${t}/`)}async function he(t,o,e){let r=S(e.include),n=S(e.exclude),s=Q(o),{httpProxies:i}=G(o.server.proxy||{});i.push(...S(e.prefix));let c=S(e.wsPrefix),a={};try{let m=B(o.root,["package.json"]);m&&(a=JSON.parse(m))}catch{}let p=e.build.dist,f=await et(process.cwd(),r,n),M=U.join(o.root,`mock-data-${Date.now()}.js`);await Z.writeFile(M,f,"utf-8");let{code:O,deps:L}=await tt(M,s,o.resolve.alias),l=Xe(L);await Z.unlink(M);let u=[{filename:U.join(p,"mock-data.js"),source:O},{filename:U.join(p,"index.js"),source:Ze(i,c,e.cookiesOptions,e.build.serverPort)},{filename:U.join(p,"package.json"),source:Ye(a,l)}];try{if(U.isAbsolute(p)){await Z.rm(p,{recursive:!0}),qe.mkdirSync(p,{recursive:!0});for(let{filename:m,source:d}of u)await Z.writeFile(m,d,"utf-8")}else for(let{filename:m,source:d}of u)t.emitFile({type:"asset",fileName:m,source:d})}catch{}}function Xe(t){let o=new Set,e=[ue,"connect","cors"];return Object.keys(t).forEach(r=>{t[r].imports.filter(s=>s.external&&!s.path.startsWith("<define:")).map(s=>s.path).forEach(s=>{!e.includes(s)&&!Qe(s)&&o.add(s)})}),Array.from(o)}function Ye(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":`^${me}`,cors:"^2.8.5"},pnpm:{peerDependencyRules:{ignoreMissing:["vite"]}}};return o.forEach(i=>{s.dependencies[i]=n[i]||"latest"}),JSON.stringify(s,null,2)}function Ze(t,o,e={},r=8080){return`import { createServer } from 'node:http'; |
{ | ||
"name": "vite-plugin-mock-dev-server", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"keywords": [ | ||
@@ -43,3 +43,3 @@ "vite", | ||
"fast-glob": "^3.2.12", | ||
"formidable": "^3.4.0", | ||
"formidable": "^2.1.1", | ||
"http-status": "^1.6.2", | ||
@@ -46,0 +46,0 @@ "is-core-module": "^2.12.1", |
@@ -177,3 +177,11 @@ # vite-plugin-mock-dev-server | ||
- `options.cors` | ||
**Type:** `boolean | CorsOptions` | ||
Enable by default. | ||
Configure to `cors`, see [cors](https://github.com/expressjs/cors#configuration-options) | ||
**Default:** `false` | ||
@@ -180,0 +188,0 @@ |
@@ -176,2 +176,10 @@ # vite-plugin-mock-dev-server | ||
- `options.cors` | ||
**Type:** `boolean | CorsOptions` | ||
默认启用. | ||
配置 `cors`, 查看 [cors](https://github.com/expressjs/cors#configuration-options) | ||
- `options.formidableOptions` | ||
@@ -178,0 +186,0 @@ |
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
108302
766
806
+ Addedformidable@2.1.2(transitive)
+ Addedhexoid@1.0.0(transitive)
- Removedformidable@3.5.2(transitive)
- Removedhexoid@2.0.0(transitive)
Updatedformidable@^2.1.1