vite-plugin-mock-dev-server
Advanced tools
Comparing version 1.3.0-beta.0 to 1.3.0
@@ -1,2 +0,2 @@ | ||
import{toArray as Jt}from"@pengzhanbo/utils";import rt from"node:fs";import K from"node:fs/promises";import H from"node:path";import{toArray as X}from"@pengzhanbo/utils";import nt from"fast-glob";import st from"is-core-module";import{createFilter as it,normalizePath as ct}from"vite";var me="vite-plugin-mock-dev-server",ue="1.3.0-beta.0";import ge,{promises as se}from"node:fs";import{createRequire as Ae}from"node:module";import ne from"node:path";import{pathToFileURL as ze}from"node:url";import{build as Ge}from"esbuild";import Qe from"json5";import oe from"node:fs";import re from"node:path";import{parse as He}from"node:querystring";import{URL as Fe,fileURLToPath as qe}from"node:url";import Ue from"debug";import{match as Be}from"path-to-regexp";var Je=o=>o!==null&&typeof o=="object"&&typeof o.pipe=="function",de=o=>Je(o)&&o.readable!==!1&&typeof o._read=="function"&&typeof o._readableState=="object";function fe(o){return re.dirname(qe(o))}var A=Ue("vite:mock-dev-server");function q(o,t,e){for(let s of t){let r=re.join(o,s);if(oe.existsSync(r)&&oe.statSync(r).isFile()){let i=e!=null&&e.pathOnly?r:oe.readFileSync(r,"utf-8");if(!(e!=null&&e.predicate)||e.predicate(i))return i}}let n=re.dirname(o);if(n!==o&&(!(e!=null&&e.rootDir)||n.startsWith(e==null?void 0:e.rootDir)))return q(n,t,e)}var z=(o={})=>{let t=[],e=[];return Object.keys(o).forEach(n=>{var r,i;let s=o[n];typeof s=="string"||!s.ws&&!((r=s.target)!=null&&r.toString().startsWith("ws:"))&&!((i=s.target)!=null&&i.toString().startsWith("wss:"))?t.push(n):e.push(n)}),{httpProxies:t,wsProxies:e}};function N(o,t){return o[0]==="^"&&new RegExp(o).test(t)||t.startsWith(o)}function U(o,t){return(Be(o,{decode:decodeURIComponent})(t)||{params:{}}).params||{}}function R(o){let t=new Fe(o,"http://example.com"),e=decodeURIComponent(t.pathname),n=He(t.search.replace(/^\?/,""));return{pathname:e,query:n}}var Ve={name:"externalize-deps",setup(o){o.onResolve({filter:/.*/},({path:t})=>{if(t[0]!=="."&&!ne.isAbsolute(t))return{external:!0}})}},Ke={name:"json5-loader",setup(o){o.onLoad({filter:/\.json5$/},async({path:t})=>{let e=await se.readFile(t,"utf-8");return{contents:`export default ${JSON.stringify(Qe.parse(e))}`,loader:"js"}})}},Xe={name:"json-loader",setup(o){o.onLoad({filter:/\.json$/},async({path:t})=>({contents:`export default ${await se.readFile(t,"utf-8")}`,loader:"js"}))}},Ye=o=>({name:"alias-plugin",setup(t){t.onResolve({filter:/.*/},async({path:e})=>{let n=o.find(({find:c})=>Ze(c,e));if(!n)return null;let{find:s,replacement:r}=n;return{path:(await t.resolve(e.replace(s,r),{kind:"import-statement",resolveDir:r,namespace:"file"})).path,external:!1}})}});function Ze(o,t){return o instanceof RegExp?o.test(t):t.length<o.length?!1:t===o?!0:t.startsWith(`${o}/`)}async function G(o,t){var r;let{isESM:e=!0,define:n,alias:s}=t;try{let i=await Ge({entryPoints:[o],outfile:"out.js",write:!1,target:["node14.18","node16"],platform:"node",bundle:!0,metafile:!0,format:e?"esm":"cjs",define:n,plugins:[Ye(s),Ve,Xe,Ke]});return{code:i.outputFiles[0].text,deps:((r=i.metafile)==null?void 0:r.inputs)||{}}}catch(i){console.error(i)}return{code:"",deps:{}}}var et=fe(import.meta.url),_=Ae(et);async function ke(o,t,e,n){if(e){let s=`${o}.timestamp-${Date.now()}`,r=`${s}.mjs`,i=`${ze(s)}.mjs`;await se.writeFile(r,t,"utf8");try{return await import(i)}finally{try{ge.unlinkSync(r)}catch{}}}else{o=ne.resolve(n,o);let s=ne.extname(o),r=ge.realpathSync(o),i=s in _.extensions?s:".js",c=_.extensions[i];_.extensions[i]=(p,m)=>{m===r?p._compile(t,m):c(p,m)},delete _.cache[_.resolve(o)];let a=_(o);return _.extensions[i]=c,a.__esModule?a:{default:a}}}import he from"picocolors";import{isBoolean as tt}from"@pengzhanbo/utils";import I from"picocolors";var ye={silent:0,error:1,warn:2,info:3};function Q(o,t="info"){o=`[${o}]`;function e(s,r,i){if(i=tt(i)?i?t:"error":i,ye[i]>=ye[s]){let a=s==="info"?"log":s,p=s==="info"?I.cyan(I.bold(o)):s==="warn"?I.yellow(I.bold(o)):I.red(I.bold(o)),m=`${I.dim(new Date().toLocaleTimeString())} ${p} ${r}`;console[a](m)}}return{info(s,r=t){e("info",s,r)},warn(s,r=t){e("warn",s,r)},error(s,r=t){e("error",s,r)}}}var ot=/import\.meta\.env\.(.+)/;function V(o){let t=Q("vite:mock-dev-server","warn"),e={},n=process.env.NODE_ENV||o.mode;Object.assign(e,{"process.env.NODE_ENV":JSON.stringify(n),"global.process.env.NODE_ENV":JSON.stringify(n),"globalThis.process.env.NODE_ENV":JSON.stringify(n),__vite_process_env_NODE_ENV:JSON.stringify(n)});let s={},r={},i=[];for(let p in o.define){let m=o.define[p];if(typeof m=="string")try{JSON.parse(m),s[p]=m}catch{i.push(p)}else s[p]=JSON.stringify(m);let k=p.match(ot);k&&s[p]&&(r[k[1]]=`__vite__define__${s[p]}`)}i.length&&t.warn(`The following keys: ${he.yellow(he.underline(i.join(", ")))} declared in 'define' cannot be parsed as regular code snippets.`);let c={},a={};c["import.meta.hot"]="undefined";for(let p in o.env)c[`import.meta.env.${p}`]=JSON.stringify(o.env[p]);return Object.assign(a,{"import.meta.env":JSON.stringify({...o.env,...r}).replace(/"__vite__define__(.+?)"([,}])/g,(p,m,k)=>`${m.replace(/(^\\")|(\\"$)/g,'"')}${k}`)}),{...c,...s,...a,...e}}async function ve(o,t,e){let n=X(e.include),s=X(e.exclude),r=V(t),{httpProxies:i}=z(t.server.proxy||{});i.push(...X(e.prefix));let c=X(e.wsPrefix),a={};try{let u=q(t.root,["package.json"]);u&&(a=JSON.parse(u))}catch{}let p=e.build.dist,m=await mt(process.cwd(),n,s),k=H.join(t.root,`mock-data-${Date.now()}.js`);await K.writeFile(k,m,"utf-8");let{code:w,deps:j}=await G(k,{define:r,alias:t.resolve.alias}),P=at(j);await K.unlink(k);let l=[{filename:H.join(p,"mock-data.js"),source:w},{filename:H.join(p,"index.js"),source:lt(i,c,e.cookiesOptions,e.build.serverPort)},{filename:H.join(p,"package.json"),source:pt(a,P)}];try{if(H.isAbsolute(p)){await K.rm(p,{recursive:!0}),rt.mkdirSync(p,{recursive:!0});for(let{filename:u,source:d}of l)await K.writeFile(u,d,"utf-8")}else for(let{filename:u,source:d}of l)o.emitFile({type:"asset",fileName:u,source:d})}catch{}}function at(o){let t=new Set,e=[me,"connect","cors"];return Object.keys(o).forEach(n=>{o[n].imports.filter(r=>r.external&&!r.path.startsWith("<define:")).map(r=>r.path).forEach(r=>{!e.includes(r)&&!st(r)&&t.add(r)})}),Array.from(t)}function pt(o,t){let{dependencies:e={},devDependencies:n={}}=o,s={...e,...n},r={name:"mock-server",type:"module",scripts:{start:"node index.js"},dependencies:{connect:"^3.7.0","vite-plugin-mock-dev-server":`^${ue}`,cors:"^2.8.5"},pnpm:{peerDependencyRules:{ignoreMissing:["vite"]}}};return t.forEach(i=>{r.dependencies[i]=s[i]||"latest"}),JSON.stringify(r,null,2)}function lt(o,t,e={},n=8080){return`import { createServer } from 'node:http'; | ||
import{toArray as Jt}from"@pengzhanbo/utils";import rt from"node:fs";import K from"node:fs/promises";import H from"node:path";import{toArray as X}from"@pengzhanbo/utils";import nt from"fast-glob";import st from"is-core-module";import{createFilter as it,normalizePath as ct}from"vite";var me="vite-plugin-mock-dev-server",ue="1.3.0";import ge,{promises as se}from"node:fs";import{createRequire as Ae}from"node:module";import ne from"node:path";import{pathToFileURL as ze}from"node:url";import{build as Ge}from"esbuild";import Qe from"json5";import oe from"node:fs";import re from"node:path";import{parse as He}from"node:querystring";import{URL as Fe,fileURLToPath as qe}from"node:url";import Ue from"debug";import{match as Be}from"path-to-regexp";var Je=o=>o!==null&&typeof o=="object"&&typeof o.pipe=="function",de=o=>Je(o)&&o.readable!==!1&&typeof o._read=="function"&&typeof o._readableState=="object";function fe(o){return re.dirname(qe(o))}var A=Ue("vite:mock-dev-server");function q(o,t,e){for(let s of t){let r=re.join(o,s);if(oe.existsSync(r)&&oe.statSync(r).isFile()){let i=e!=null&&e.pathOnly?r:oe.readFileSync(r,"utf-8");if(!(e!=null&&e.predicate)||e.predicate(i))return i}}let n=re.dirname(o);if(n!==o&&(!(e!=null&&e.rootDir)||n.startsWith(e==null?void 0:e.rootDir)))return q(n,t,e)}var z=(o={})=>{let t=[],e=[];return Object.keys(o).forEach(n=>{var r,i;let s=o[n];typeof s=="string"||!s.ws&&!((r=s.target)!=null&&r.toString().startsWith("ws:"))&&!((i=s.target)!=null&&i.toString().startsWith("wss:"))?t.push(n):e.push(n)}),{httpProxies:t,wsProxies:e}};function N(o,t){return o[0]==="^"&&new RegExp(o).test(t)||t.startsWith(o)}function U(o,t){return(Be(o,{decode:decodeURIComponent})(t)||{params:{}}).params||{}}function R(o){let t=new Fe(o,"http://example.com"),e=decodeURIComponent(t.pathname),n=He(t.search.replace(/^\?/,""));return{pathname:e,query:n}}var Ve={name:"externalize-deps",setup(o){o.onResolve({filter:/.*/},({path:t})=>{if(t[0]!=="."&&!ne.isAbsolute(t))return{external:!0}})}},Ke={name:"json5-loader",setup(o){o.onLoad({filter:/\.json5$/},async({path:t})=>{let e=await se.readFile(t,"utf-8");return{contents:`export default ${JSON.stringify(Qe.parse(e))}`,loader:"js"}})}},Xe={name:"json-loader",setup(o){o.onLoad({filter:/\.json$/},async({path:t})=>({contents:`export default ${await se.readFile(t,"utf-8")}`,loader:"js"}))}},Ye=o=>({name:"alias-plugin",setup(t){t.onResolve({filter:/.*/},async({path:e})=>{let n=o.find(({find:c})=>Ze(c,e));if(!n)return null;let{find:s,replacement:r}=n;return{path:(await t.resolve(e.replace(s,r),{kind:"import-statement",resolveDir:r,namespace:"file"})).path,external:!1}})}});function Ze(o,t){return o instanceof RegExp?o.test(t):t.length<o.length?!1:t===o?!0:t.startsWith(`${o}/`)}async function G(o,t){var r;let{isESM:e=!0,define:n,alias:s}=t;try{let i=await Ge({entryPoints:[o],outfile:"out.js",write:!1,target:["node14.18","node16"],platform:"node",bundle:!0,metafile:!0,format:e?"esm":"cjs",define:n,plugins:[Ye(s),Ve,Xe,Ke]});return{code:i.outputFiles[0].text,deps:((r=i.metafile)==null?void 0:r.inputs)||{}}}catch(i){console.error(i)}return{code:"",deps:{}}}var et=fe(import.meta.url),_=Ae(et);async function ke(o,t,e,n){if(e){let s=`${o}.timestamp-${Date.now()}`,r=`${s}.mjs`,i=`${ze(s)}.mjs`;await se.writeFile(r,t,"utf8");try{return await import(i)}finally{try{ge.unlinkSync(r)}catch{}}}else{o=ne.resolve(n,o);let s=ne.extname(o),r=ge.realpathSync(o),i=s in _.extensions?s:".js",c=_.extensions[i];_.extensions[i]=(p,m)=>{m===r?p._compile(t,m):c(p,m)},delete _.cache[_.resolve(o)];let a=_(o);return _.extensions[i]=c,a.__esModule?a:{default:a}}}import he from"picocolors";import{isBoolean as tt}from"@pengzhanbo/utils";import I from"picocolors";var ye={silent:0,error:1,warn:2,info:3};function Q(o,t="info"){o=`[${o}]`;function e(s,r,i){if(i=tt(i)?i?t:"error":i,ye[i]>=ye[s]){let a=s==="info"?"log":s,p=s==="info"?I.cyan(I.bold(o)):s==="warn"?I.yellow(I.bold(o)):I.red(I.bold(o)),m=`${I.dim(new Date().toLocaleTimeString())} ${p} ${r}`;console[a](m)}}return{info(s,r=t){e("info",s,r)},warn(s,r=t){e("warn",s,r)},error(s,r=t){e("error",s,r)}}}var ot=/import\.meta\.env\.(.+)/;function V(o){let t=Q("vite:mock-dev-server","warn"),e={},n=process.env.NODE_ENV||o.mode;Object.assign(e,{"process.env.NODE_ENV":JSON.stringify(n),"global.process.env.NODE_ENV":JSON.stringify(n),"globalThis.process.env.NODE_ENV":JSON.stringify(n),__vite_process_env_NODE_ENV:JSON.stringify(n)});let s={},r={},i=[];for(let p in o.define){let m=o.define[p];if(typeof m=="string")try{JSON.parse(m),s[p]=m}catch{i.push(p)}else s[p]=JSON.stringify(m);let k=p.match(ot);k&&s[p]&&(r[k[1]]=`__vite__define__${s[p]}`)}i.length&&t.warn(`The following keys: ${he.yellow(he.underline(i.join(", ")))} declared in 'define' cannot be parsed as regular code snippets.`);let c={},a={};c["import.meta.hot"]="undefined";for(let p in o.env)c[`import.meta.env.${p}`]=JSON.stringify(o.env[p]);return Object.assign(a,{"import.meta.env":JSON.stringify({...o.env,...r}).replace(/"__vite__define__(.+?)"([,}])/g,(p,m,k)=>`${m.replace(/(^\\")|(\\"$)/g,'"')}${k}`)}),{...c,...s,...a,...e}}async function ve(o,t,e){let n=X(e.include),s=X(e.exclude),r=V(t),{httpProxies:i}=z(t.server.proxy||{});i.push(...X(e.prefix));let c=X(e.wsPrefix),a={};try{let u=q(t.root,["package.json"]);u&&(a=JSON.parse(u))}catch{}let p=e.build.dist,m=await mt(process.cwd(),n,s),k=H.join(t.root,`mock-data-${Date.now()}.js`);await K.writeFile(k,m,"utf-8");let{code:w,deps:j}=await G(k,{define:r,alias:t.resolve.alias}),P=at(j);await K.unlink(k);let l=[{filename:H.join(p,"mock-data.js"),source:w},{filename:H.join(p,"index.js"),source:lt(i,c,e.cookiesOptions,e.build.serverPort)},{filename:H.join(p,"package.json"),source:pt(a,P)}];try{if(H.isAbsolute(p)){await K.rm(p,{recursive:!0}),rt.mkdirSync(p,{recursive:!0});for(let{filename:u,source:d}of l)await K.writeFile(u,d,"utf-8")}else for(let{filename:u,source:d}of l)o.emitFile({type:"asset",fileName:u,source:d})}catch{}}function at(o){let t=new Set,e=[me,"connect","cors"];return Object.keys(o).forEach(n=>{o[n].imports.filter(r=>r.external&&!r.path.startsWith("<define:")).map(r=>r.path).forEach(r=>{!e.includes(r)&&!st(r)&&t.add(r)})}),Array.from(t)}function pt(o,t){let{dependencies:e={},devDependencies:n={}}=o,s={...e,...n},r={name:"mock-server",type:"module",scripts:{start:"node index.js"},dependencies:{connect:"^3.7.0","vite-plugin-mock-dev-server":`^${ue}`,cors:"^2.8.5"},pnpm:{peerDependencyRules:{ignoreMissing:["vite"]}}};return t.forEach(i=>{r.dependencies[i]=s[i]||"latest"}),JSON.stringify(r,null,2)}function lt(o,t,e={},n=8080){return`import { createServer } from 'node:http'; | ||
import connect from 'connect'; | ||
@@ -3,0 +3,0 @@ import corsMiddleware from 'cors'; |
{ | ||
"name": "vite-plugin-mock-dev-server", | ||
"version": "1.3.0-beta.0", | ||
"version": "1.3.0", | ||
"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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
131632