@moneko/core 3.47.4 → 3.47.6
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.d.mts +3 -1
- package/lib/dev.mjs +2 -2
- package/lib/plugin/manifest.d.mts +3 -1
- package/lib/plugin/manifest.mjs +1 -1
- package/package.json +1 -1
package/lib/dev.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { exec, spawn } from 'node:child_process';
|
|
2
2
|
import { watchFile } from 'node:fs';
|
|
3
|
-
import { relative } from 'node:path';
|
|
3
|
+
import { join, relative } from 'node:path';
|
|
4
4
|
import process from 'node:process';
|
|
5
5
|
import { URL } from 'node:url';
|
|
6
6
|
import { ink, print, println, progressBar } from '@moneko/utils';
|
|
@@ -15,6 +15,7 @@ import generateProgressHtml, { type CompliationProcess } from './dev/generate-pr
|
|
|
15
15
|
import server, { type FileSystem, type Server } from './dev/server.mjs';
|
|
16
16
|
import reslove from './options/reslove.mjs';
|
|
17
17
|
import { ESLintPlugin } from './plugin/eslint.mjs';
|
|
18
|
+
import { generateManifest } from './plugin/manifest.mjs';
|
|
18
19
|
import { StylelintPlugin } from './plugin/stylelint.mjs';
|
|
19
20
|
import { empty } from './utils/index.mjs';
|
|
20
21
|
import { commonConfig } from './common.mjs';
|
|
@@ -36,6 +37,7 @@ declare const compiler: Compiler;
|
|
|
36
37
|
declare const watching: Watching;
|
|
37
38
|
declare const hotUrl: string;
|
|
38
39
|
declare const hot: ReturnType<typeof hotMiddleware>;
|
|
40
|
+
declare const manifestUrl: string | false;
|
|
39
41
|
declare const app: Server;
|
|
40
42
|
declare function exit();
|
|
41
43
|
declare const _prev: ConfigType[];
|
package/lib/dev.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{exec as e,spawn as t}from"node:child_process";import{watchFile as o}from"node:fs";import{relative as
|
|
2
|
-
`):(
|
|
1
|
+
import{exec as e,spawn as t}from"node:child_process";import{watchFile as o}from"node:fs";import{join as r,relative as i}from"node:path";import n from"node:process";import{URL as s}from"node:url";import{ink as a,print as m,println as l,progressBar as p}from"@moneko/utils";import c from"webpack";import f from"webpack-hot-middleware";import{merge as h}from"webpack-merge";import{diffObject as u}from"./commom/diff-object.mjs";import d,{config_files as g}from"./commom/paths.mjs";import w from"./commom/sigint-exit.mjs";import{devLog as y,PORT as j}from"./dev/config.mjs";import $ from"./dev/generate-progress-html.mjs";import b from"./dev/server.mjs";import v from"./options/reslove.mjs";import{ESLintPlugin as C}from"./plugin/eslint.mjs";import{generateManifest as x}from"./plugin/manifest.mjs";import{StylelintPlugin as P}from"./plugin/stylelint.mjs";import{empty as _}from"./utils/index.mjs";import{commonConfig as S}from"./common.mjs";import{CONFIG as k,getConfig as H}from"./config.mjs";import{outputFileSystem as O}from"./file-system.mjs";import T from"./module.config.mjs";import{isLibrary as B,isReact as I,refresh as q}from"./process-env.mjs";let G=!1,L="/____progress____",N={percentage:0,info:""},R="/__hmr__",U=new URLSearchParams({name:"client",path:R.substring(1),dynamicPublicPath:!0,timeout:2e3,reload:!q,quiet:!0,noInfo:!0,overlay:!1,autoConnect:!0}).toString(),E=h(S,{watchOptions:{stdin:!0,aggregateTimeout:300,ignored:/node_modules\/(?!(@app)\/)/},entry:{main:[`${v.hotMiddlewareClient}?${U}`]},module:T(!1),plugins:[new c.HotModuleReplacementPlugin,new c.WatchIgnorePlugin({paths:[/node_modules\/(?!(@app)\/)/,/\.d\.ts$/]}),new c.ProgressPlugin({handler(e,t,...o){let r=o.length?`[${t}] ${o.join(" ")}`:" ";G||(N.info=r,N.percentage=e,G=1===e);let i=k.bar;if(i){let t=i.name||"Build";i.quiet?n.stdout.write(`${r}
|
|
2
|
+
`):(p(e||0,1,{msg:r,name:t,barColor:i.barColor,nameColor:i.nameColor,barBgColor:i.barBgColor,msgColor:i.msgColor}),1===e&&n.stdout.write("\r\x1b[2K"))}}})]});if(I){let e=(await import("@pmmmwh/react-refresh-webpack-plugin")).default;E.plugins.push(new e({overlay:!1}))}function F(e){let t=e.join(","),o=[i(d.programPath,`${k.alias["@"]}/**/*.{${t}}`).replace(/\\/g,"/")];return B&&o.push(i(d.programPath,`${k.alias["@pkg"]}/**/*.{${t}}`).replace(/\\/g,"/")),o}k.eslint&&E.plugins.push(new C({fix:!0,cache:!0,cacheLocation:`${d.lintCachePath}/.eslintcache`,cacheStrategy:"metadata",files:F(["js","jsx","ts","tsx","json","html","vue"]),...k.eslint})),k.stylelint&&E.plugins.push(new P({fix:!0,cache:!0,cacheLocation:`${d.lintCachePath}/.stylelintcache`,files:F(["css","scss","sass","less","ts","tsx","js","jsx"]),...k.stylelint}));let J=c(E);J.outputFileSystem=O;let M=J.watch(J.options.watchOptions,y);J.hooks.done.tap("client-log",e=>{y(null,e)});let A=`${k.publicPath}/${R}`.replace(/\/+/g,"/"),K=f(J,{log:!1,path:A,heartbeat:2e3}),W=!!k.manifest&&r("auto"===k.publicPath?"/":k.publicPath,k.manifest.filename).replaceAll(/\\/g,"/"),z=await b({port:j,root_dir:J.options.output.path,fileSystem:J.outputFileSystem,headers:k.devServer.headers,https:k.devServer.https,host:k.devServer.host,open:k.devServer.open,basename:k.basename,onRequest(e,t){let o=new s(`${k.devServer.https?"https":"http"}://${e.headers.host}${e.url}`);if("GET"===e.method){if(W&&o.pathname===W)return t.writeHead(200,{"Content-Type":"application/json; charset=utf-8","Cache-Control":"no-store"}),t.end(JSON.stringify(x({}))),!0;if(o.pathname===L)return t.writeHead(200,{"Content-Type":"application/json; charset=utf-8","Cache-Control":"no-store"}),t.end(JSON.stringify(N)),!0;if(!G)return t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end($(L,N)),!0;if(o.pathname===A&&"text/event-stream"===e.headers.accept)return K(e,t,_),!0}return!1}});function D(){n.exit(0)}z.on("close",()=>{M.close(_),K.close()});let Q=await Promise.all(g.map(H)),V=h(Q[0]||{},Q[1]||{});g.forEach(function(t){o(t,async function(){let[o,r]=await Promise.all(g.map(H)),i=h(o||{},r||{}),s=u(V,i);1===Object.keys(s).length&&"proxy"in s?(m(a(`代理更新中...`,"yellow"),!0),m(a(`代理更新完成...`,"green"),!0),k.proxy=i.proxy,V.proxy=i.proxy,V=i):(V=i,l(a(`检测到工程配置${a(`[${t}]`,"blue")}变更, 程序即将重启...`,"yellow"),!0),e(X?`netstat -ano | findstr :${j}`:`lsof -i :${j} -t`,(e,t)=>{if(e){l(a(`查找端口 ${j} 时发生错误: ${e.message}`,"red")),l(a("请尝试手动重启程序","yellow"));return}let o=t.trim().replace(/\r\n/g,"\n").split("\n").filter(Boolean),r=X?o[0]?.split(/\s+/).pop()?.trim():o[0]?.trim();if(!r){l(a(`未找到占用端口 ${j} 的进程, 请尝试手动重启程序`,"yellow"));return}try{n.kill(Number(r),"SIGHUP")}catch(e){l(a(`终止进程 ${r} 时发生错误: ${e.message}`,"red"))}}))})});let X="win32"===n.platform;n.on("SIGHUP",function(){z.close(_),function(){let e=t(n.argv[0],n.argv.slice(1),{detached:!1,stdio:"inherit"});e.unref(),e.on("close",D)}()}),n.on("exit",function(){z.close(_)}),w(D);
|
|
@@ -33,9 +33,11 @@ export interface ManifestPluginOption {
|
|
|
33
33
|
content_assets?: string[];
|
|
34
34
|
[key: string]: unknown;
|
|
35
35
|
}
|
|
36
|
+
declare const base: ManifestPluginOption;
|
|
37
|
+
export declare function generateManifest(override: Partial<ManifestPluginOption>, hash?: string, content_assets?: string[]);
|
|
36
38
|
export declare class ManifestPlugin {
|
|
37
39
|
private name: string;
|
|
38
40
|
private options: ManifestPluginOption;
|
|
39
|
-
constructor(options?: ManifestPluginOption);
|
|
41
|
+
constructor(options?: Partial<ManifestPluginOption>);
|
|
40
42
|
apply(compiler: Compiler);
|
|
41
43
|
}
|
package/lib/plugin/manifest.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{packageJson as s}from"../process-env.mjs";
|
|
1
|
+
import{packageJson as s}from"../process-env.mjs";let e={filename:"manifest.json",name:s.name,short_name:s.shortName,description:s.description,start_url:s.startUrl??"/?source=pwa",display:s.display??"standalone",background_color:s.backgroundColor??"#fff",theme_color:s.themeColor,icons:[{src:"/favicon.ico",sizes:"48x48",type:"image/x-icon"}]};export function generateManifest(t,o,a){return Object.assign({},e,t,{version:`${s.version}-${o}`,hash:o,content_assets:a})}export class ManifestPlugin{constructor(s){this.name="ManifestPlugin",this.options=Object.assign({},e,s??{})}apply(s){let e=this.name,{filename:t,...o}=this.options;s.hooks.thisCompilation.tap(e,a=>{a.hooks.processAssets.tap({name:e,stage:s.webpack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE},e=>{a.emitAsset(t,new s.webpack.sources.RawSource(JSON.stringify(generateManifest(o,a.fullHash,Object.keys(e)))),{javascriptModule:!1})})})}}
|