@moneko/core 3.43.0 → 3.43.2
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.
- package/lib/dev/mock.d.mts +4 -4
- package/lib/plugin/html-plugin.mjs +1 -1
- package/package.json +1 -1
package/lib/dev/mock.d.mts
CHANGED
|
@@ -23,11 +23,11 @@ export interface RequestFormData extends IncomingMessage {
|
|
|
23
23
|
query?: Record<string, string>;
|
|
24
24
|
body?: Promise<BodyInit | null>;
|
|
25
25
|
}
|
|
26
|
-
export
|
|
26
|
+
export interface MockServerResponse extends ServerResponse<IncomingMessage> {
|
|
27
27
|
req: IncomingMessage;
|
|
28
|
-
send(chunk:
|
|
29
|
-
}
|
|
30
|
-
export type ProxyFuncType = (req:
|
|
28
|
+
send<T>(chunk: T): ReturnType<ServerResponse<IncomingMessage>['end']>;
|
|
29
|
+
}
|
|
30
|
+
export type ProxyFuncType = (req: RequestFormData, res: MockServerResponse) => void | Promise<void>;
|
|
31
31
|
export type MockConfiguration = Record<string, ProxyFuncType | Record<string, any> | null>;
|
|
32
32
|
declare function clearProxy(iproxy: MockConfiguration, path: string, old: MockConfiguration);
|
|
33
33
|
export type YApiOptionBySchema = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as t,readFileSync as e}from"node:fs";import{basename as s,resolve as i}from"node:path";import o from"webpack";export class HtmlPlugin{constructor(t={}){this.AddEntry=/(?:.*\/)?main\.[a-zA-Z0-9]+\.bundle\.js$/,this.faviconPath="",this.name="HtmlPlugin",this.cachedMetaTags=null,this.cachedCustomTags=null,this.options={title:"WebApp",filename:"index.html",inject:"head",...t}}apply(n){n.hooks.compilation.tap(this.name,a=>{a.hooks.processAssets.tap({name:this.name,stage:o.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL},()=>{let h;if(this.options.favicon){let h=i(n.context,this.options.favicon);if(t(h)){let t=s(this.options.favicon),i=e(h);a.emitAsset(t,new o.sources.RawSource(i),{javascriptModule:!1}),this.faviconPath=(a.outputOptions.publicPath||"")+t}else a.warnings.push(new o.WebpackError(`Favicon file ${h} does not exist`))}if(h=this.options.templateContent?this.options.templateContent(this.options):this.options.template?e(i(n.context,this.options.template),{encoding:"utf-8"}):this.generateDefaultTemplate(),this.options.inject){let t=this.getAssets(a);h=this.injectAssets(h,t,this.options.inject)}let r="function"==typeof this.options.filename?this.options.filename("index"):this.options.filename||"index.html";a.emitAsset(r,new o.sources.RawSource(h),{javascriptModule:!1})})})}generateDefaultTemplate(){let t=this.generateMetaTags()
|
|
1
|
+
import{existsSync as t,readFileSync as e}from"node:fs";import{basename as s,resolve as i}from"node:path";import o from"webpack";export class HtmlPlugin{constructor(t={}){this.AddEntry=/(?:.*\/)?main\.[a-zA-Z0-9]+\.bundle\.js$/,this.faviconPath="",this.name="HtmlPlugin",this.cachedMetaTags=null,this.cachedCustomTags=null,this.options={title:"WebApp",filename:"index.html",inject:"head",...t}}apply(n){n.hooks.compilation.tap(this.name,a=>{a.hooks.processAssets.tap({name:this.name,stage:o.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL},()=>{let h;if(this.options.favicon){let h=i(n.context,this.options.favicon);if(t(h)){let t=s(this.options.favicon),i=e(h);a.emitAsset(t,new o.sources.RawSource(i),{javascriptModule:!1}),this.faviconPath=(a.outputOptions.publicPath||"")+t}else a.warnings.push(new o.WebpackError(`Favicon file ${h} does not exist`))}if(h=this.options.templateContent?this.options.templateContent(this.options):this.options.template?e(i(n.context,this.options.template),{encoding:"utf-8"}):this.generateDefaultTemplate(),this.options.inject){let t=this.getAssets(a);h=this.injectAssets(h,t,this.options.inject)}let r="function"==typeof this.options.filename?this.options.filename("index"):this.options.filename||"index.html";a.emitAsset(r,new o.sources.RawSource(h),{javascriptModule:!1})})})}generateDefaultTemplate(){let t=this.generateMetaTags();return`<!DOCTYPE html><html><head><meta charset="utf-8">${t}<title>${this.options.title}</title><link rel="icon" type="image/x-icon" href="${this.faviconPath}"></head><body><div id="root"></div></body></html>`}generateMetaTags(){if(null!==this.cachedMetaTags)return this.cachedMetaTags;if(!this.options.meta)return this.cachedMetaTags="","";let t=Object.entries(this.options.meta).map(([t,e])=>{if("string"==typeof e)return`<meta name="${t}" content="${e}">`;if(void 0===e)return"";let s=Object.entries(e).map(([t,e])=>`${t}="${e}"`).join(" ");return`<meta ${s}>`}).join("");return this.cachedMetaTags=t,t}generateCustomTags(){if(null!==this.cachedCustomTags)return this.cachedCustomTags;let t={head:"",body:""};if(!this.options.tags)return this.cachedCustomTags=t,t;let e=[],s=[];return this.options.tags.forEach(t=>{let{tag:i="script",textContent:o="",inject:n=this.options.inject,...a}=t,h=Object.entries(a).filter(([,t])=>null!=t).map(([t,e])=>!0===e?t:`${t}="${e}"`).join(" "),r=`<${i} ${h}>${o}</${i}>`;"head"===n?e.push(r):s.push(r)}),t.head=e.join(""),t.body=s.join(""),this.cachedCustomTags=t,t}getAssets(t){let e={js:[],css:[]},s=t.outputOptions.publicPath||"";for(let i of t.entrypoints.values())for(let t of i.chunks)for(let i of t.files)i.endsWith(".js")?e.js.push(s+i):i.endsWith(".css")&&e.css.push(s+i);return e}injectAssets(t,e,s){let i=e.css.length?e.css.map(t=>`<link href="${t}" rel="stylesheet" />`).join(""):"",o=e.js.length?e.js.map(t=>`<script defer ${this.AddEntry.test(t)?'entry="true" ':""}src="${t}"></script>`).join(""):"",n=this.generateCustomTags(),a=t.split("</head>");if(2===a.length){let[t,e]=a,h=e.split("</body>");return"head"===s?`${t}${i}${o}${n.head}</head>${h[0]}${n.body}</body>${h[1]||""}`:`${t}${n.head}</head>${h[0]}${i}${o}${n.body}</body>${h[1]||""}`}return t}}
|