@moneko/core 3.33.1 → 3.33.3-beta.0

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.
@@ -1,6 +1,6 @@
1
1
  import { createRequire } from 'node:module';
2
2
  import { type Options, transformFileSync } from '@swc/core';
3
- declare const require: NodeRequire;
3
+ declare const require: NodeJS.Require;
4
4
  declare const transformOptions: Options;
5
5
  declare function requireEsm(module: NodeJS.Module & {
6
6
  _compile?: (code: string, filename: string) => void;
@@ -1,4 +1,5 @@
1
1
  import marked from 'marked-completed';
2
- declare const renderer: marked.Renderer;
2
+ declare function setup();
3
+ declare let initial: boolean;
3
4
  declare function mdToHtml(text: string);
4
5
  export default mdToHtml;
@@ -1 +1 @@
1
- import e from"marked-completed";let r=new e.Renderer;r.code=(e,r)=>"treeview"===r?`<n-tree data="${e}" />`:`<n-code class="n-code" toolbar="${JSON.stringify(["copy"])}" language="${r}" line-number="true">${encodeURIComponent(e)}</n-code>`,r.image=(e,r,t)=>`<n-img lazy="true" role="img" src="${e}" alt="${t}" ${r?`title="${r}"`:""}></n-img>`,e.use({langToolbar:["copy"],headerPrefix:"# ",breaks:!0,pedantic:!1,smartLists:!0,smartypants:!0,xhtml:!0,renderer:r});export default function(r){return e.parse(r)}
1
+ import e from"marked-completed";let r=!0;export default function(t){return r&&(r=!1,function(){let r=new e.Renderer;r.code=(e,r)=>"treeview"===r?`<n-tree data="${e}" />`:`<n-code class="n-code" toolbar="${JSON.stringify(["copy"])}" language="${r}" line-number="true">${encodeURIComponent(e)}</n-code>`,r.image=(e,r,t)=>`<n-img lazy="true" role="img" src="${e}" alt="${t}" ${r?`title="${r}"`:""}></n-img>`,e.use({langToolbar:["copy"],headerPrefix:"# ",breaks:!0,pedantic:!1,smartLists:!0,smartypants:!0,xhtml:!0,renderer:r})}()),e.parse(t)}
@@ -1,5 +1,5 @@
1
1
  import { resolve } from 'node:path';
2
- import { loadFile, scanFolderSync } from '@moneko/utils';
2
+ import { loadFileRaw, scanFolderSync } from '@moneko/utils';
3
3
  import webpack, { type Compiler } from 'webpack';
4
4
  export interface CopyPluginOption {
5
5
  files?: string[];
@@ -1 +1 @@
1
- import{resolve as e}from"node:path";import{loadFile as s,scanFolderSync as t}from"@moneko/utils";import i from"webpack";let o="CopyPlugin",l=i.sources.RawSource;export class CopyPlugin{constructor(s){this.cacheFiles=[],this.baseFiles=new Set(s.files?.map(s=>e(s))||[]),this.dirs=new Set(s.dirs||[])}getFiles(){let e=new Set(this.baseFiles);for(let s of this.dirs)t(s).forEach(s=>e.add(s));let s={deleted:[],files:[...e]};for(let t of new Set(this.cacheFiles))e.has(t)||s.deleted.push(t);return this.cacheFiles=s.files,s}apply(e){e.hooks.thisCompilation.tap({name:o,stage:e.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS},e=>{e.hooks.processAssets.tapPromise(o,async()=>{let t=this.getFiles(),i=t.files.map(e=>s(e));(await Promise.all(i)).forEach((s,i)=>{null!==s&&e.emitAsset(t.files[i],new l(s))}),t.deleted.forEach(s=>{e.deleteAsset(s)})})})}}
1
+ import{resolve as e}from"node:path";import{loadFileRaw as s,scanFolderSync as t}from"@moneko/utils";import i from"webpack";let o="CopyPlugin",l=i.sources.RawSource;export class CopyPlugin{constructor(s){this.cacheFiles=[],this.baseFiles=new Set(s.files?.map(s=>e(s))||[]),this.dirs=new Set(s.dirs||[])}getFiles(){let e=new Set(this.baseFiles);for(let s of this.dirs)t(s,["\\.*"]).forEach(s=>e.add(s));let s={deleted:[],files:[...e]};for(let t of new Set(this.cacheFiles))e.has(t)||s.deleted.push(t);return this.cacheFiles=s.files,s}apply(e){e.hooks.thisCompilation.tap({name:o,stage:e.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS},e=>{e.hooks.processAssets.tapPromise(o,async()=>{let t=this.getFiles();(await Promise.all(t.files.map(e=>s(e)))).forEach((s,i)=>{null!==s&&e.emitAsset(t.files[i],new l(Buffer.from(s)))}),t.deleted.forEach(s=>{e.deleteAsset(s)})})})}}
@@ -2,7 +2,7 @@ import { fileURLToPath } from 'node:url';
2
2
  import { ESLint } from '@moneko/eslint';
3
3
  import webpack, { type Compilation, type Compiler } from 'webpack';
4
4
  import { Worker } from 'worker_threads';
5
- import type { ESLintWorkerMessage } from './worker/eslint.mjs';
5
+ import type { ESLintWorkerMessage } from '../worker/eslint.mjs';
6
6
  declare class ESLintError extends webpack.WebpackError {
7
7
  constructor(message: string);
8
8
  }
@@ -1 +1 @@
1
- import{fileURLToPath as t}from"node:url";import r from"webpack";import{Worker as s}from"worker_threads";class e extends r.WebpackError{constructor(t){super(`[ESLint] ${t}`),this.name="ESLintError",this.stack=""}}export default class{constructor(r={files:[]}){this.name="ESLintPlugin",this.options=r,this.worker=new s(t(new URL("./worker/eslint.mjs",import.meta.url)))}apply(t){t.hooks.thisCompilation.tap(this.name,t=>{this.worker.postMessage({options:this.options}),this.worker.once("message",r=>{this.report(t,r)})}),t.hooks.shutdown.tap(this.name,()=>{this.worker.terminate()})}report(t,r){r?.length&&t&&(r[0]?.length&&t.warnings.push(new e(r[0])),r[1]?.length&&t.errors.push(new e(r[1])))}}
1
+ import{fileURLToPath as t}from"node:url";import r from"webpack";import{Worker as s}from"worker_threads";class e extends r.WebpackError{constructor(t){super(`[ESLint] ${t}`),this.name="ESLintError",this.stack=""}}export default class{constructor(r={files:[]}){this.name="ESLintPlugin",this.options=r,this.worker=new s(t(new URL("../worker/eslint.mjs",import.meta.url)))}apply(t){t.hooks.thisCompilation.tap(this.name,t=>{this.worker.postMessage({options:this.options}),this.worker.once("message",r=>{this.report(t,r)})}),t.hooks.shutdown.tap(this.name,()=>{this.worker.terminate()})}report(t,r){r?.length&&t&&(r[0]?.length&&t.warnings.push(new e(r[0])),r[1]?.length&&t.errors.push(new e(r[1])))}}
@@ -2,7 +2,7 @@ import { fileURLToPath } from 'node:url';
2
2
  import type { LinterOptions } from '@moneko/stylelint';
3
3
  import webpack, { type Compilation, type Compiler } from 'webpack';
4
4
  import { Worker } from 'worker_threads';
5
- import type { StylelintWorkerMessage } from './worker/stylelint.mjs';
5
+ import type { StylelintWorkerMessage } from '../worker/stylelint.mjs';
6
6
  declare class StylelintError extends webpack.WebpackError {
7
7
  constructor(message: string);
8
8
  }
@@ -1 +1 @@
1
- import{fileURLToPath as t}from"node:url";import r from"webpack";import{Worker as e}from"worker_threads";class s extends r.WebpackError{constructor(t){super(`[Stylelint] ${t}`),this.name="StylelintError",this.stack=""}}export default class{constructor(r={files:[]}){this.name="StylelintPlugin",this.options=r,this.worker=new e(t(new URL("./worker/stylelint.mjs",import.meta.url)))}apply(t){t.hooks.thisCompilation.tap(this.name,t=>{this.worker.postMessage({options:this.options}),this.worker.once("message",r=>{this.report(r,t)})}),t.hooks.shutdown.tap(this.name,()=>{this.worker.terminate()})}report(t,r){t?.length&&r&&(t[0]?.length&&r.warnings.push(new s(t[0])),t[1]?.length&&r.errors.push(new s(t[1])))}}
1
+ import{fileURLToPath as t}from"node:url";import r from"webpack";import{Worker as e}from"worker_threads";class s extends r.WebpackError{constructor(t){super(`[Stylelint] ${t}`),this.name="StylelintError",this.stack=""}}export default class{constructor(r={files:[]}){this.name="StylelintPlugin",this.options=r,this.worker=new e(t(new URL("../worker/stylelint.mjs",import.meta.url)))}apply(t){t.hooks.thisCompilation.tap(this.name,t=>{this.worker.postMessage({options:this.options}),this.worker.once("message",r=>{this.report(r,t)})}),t.hooks.shutdown.tap(this.name,()=>{this.worker.terminate()})}report(t,r){t?.length&&r&&(t[0]?.length&&r.warnings.push(new s(t[0])),t[1]?.length&&r.errors.push(new s(t[1])))}}
@@ -1 +1 @@
1
- import e from"compression-webpack-plugin";import t from"webpack";import{CopyPlugin as i}from"./plugin/copy.mjs";import{HtmlPlugin as o}from"./plugin/html-plugin.mjs";import r from"./plugin/module-federation.mjs";import{VirtualModuleWebpackPlugin as l}from"./plugin/virtual-module.mjs";import{CONFIG as n}from"./config.mjs";import{packageJson as p}from"./process-env.mjs";let a=[...r,new l(n.virtualModule),new i(n.copy),new t.DefinePlugin({"process.env":JSON.stringify(n.env)}),new t.IgnorePlugin({resourceRegExp:/\/(__(tests|mocks)__|test|spec|e2e)\//}),...n.plugins,new e({filename:"[path][base].gz",algorithm:"gzip",test:/./,threshold:0,minRatio:.8})].filter(Boolean);if(n.htmlPluginOption){let e={charset:"UTF-8","X-UA-Compatible":{"http-equiv":"X-UA-Compatible",content:"IE=edge,Chrome=1"},HandheldFriendly:"true",MobileOptimized:"320","screen-orientation":"portrait","x5-orientation":"portrait",browsermode:"application","x5-page-mode":"app","msapplication-tap-highlight":"no","mobile-web-app-capable":"yes",renderer:"webkit",description:p.description,keywords:Array.isArray(p.keywords)?p.keywords.toString():"","http-equiv":"refresh",viewport:"width=device-width, initial-scale=1"};n.seo&&(e.relCanonical={rel:"canonical",href:`https://${n.seo.domain}${n.basename}`}),n.htmlPluginOption.meta&&Object.assign(e,n.htmlPluginOption.meta),a.push(new o({...n.htmlPluginOption,meta:e}))}if(n.fixBrowserRouter){let e=n.basename.split("/").filter(Boolean).length,t=`${Array(e).fill("..").join("/")+(e?"/":"")}404.html`,i=n.fixBrowserRouter.pathSegmentsToKeep??e;a.push(new o({filename:n.fixBrowserRouter.path??t,inject:!1,templateContent:()=>`<html lang="en"><head><title>Redirect</title><script>const pathKeep = ${i};const l = window.location;l.replace(l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') + l.pathname.split('/').slice(0, 1 + pathKeep).join('/') + '/?/' + l.pathname.slice(1).split('/').slice(pathKeep).join('/').replace(/&/g, '~and~') + (l.search ? '&' + l.search.slice(1).replace(/&/g, '~and~') : '') + l.hash);</script></head><body></body></html>`}))}n.sourceMap&&a.push(new t.SourceMapDevToolPlugin(n.sourceMap));export default a;
1
+ import e from"compression-webpack-plugin";import t from"webpack";import{CopyPlugin as i}from"./plugin/copy.mjs";import{HtmlPlugin as o}from"./plugin/html-plugin.mjs";import r from"./plugin/module-federation.mjs";import{VirtualModuleWebpackPlugin as l}from"./plugin/virtual-module.mjs";import{CONFIG as n}from"./config.mjs";import{packageJson as p}from"./process-env.mjs";let a=[...r,new l(n.virtualModule),new i(n.copy),new t.DefinePlugin({"process.env":JSON.stringify(n.env)}),new t.IgnorePlugin({resourceRegExp:/\/(__(tests|mocks)__|test|spec|e2e)\//}),...n.plugins,new e({filename:"[path][base].gz",algorithm:"gzip",test:/\.(js|css|html|svg)$/})].filter(Boolean);if(n.htmlPluginOption){let e={charset:"UTF-8","X-UA-Compatible":{"http-equiv":"X-UA-Compatible",content:"IE=edge,Chrome=1"},HandheldFriendly:"true",MobileOptimized:"320","screen-orientation":"portrait","x5-orientation":"portrait",browsermode:"application","x5-page-mode":"app","msapplication-tap-highlight":"no","mobile-web-app-capable":"yes",renderer:"webkit",description:p.description,keywords:Array.isArray(p.keywords)?p.keywords.toString():"","http-equiv":"refresh",viewport:"width=device-width, initial-scale=1"};n.seo&&(e.relCanonical={rel:"canonical",href:`https://${n.seo.domain}${n.basename}`}),n.htmlPluginOption.meta&&Object.assign(e,n.htmlPluginOption.meta),a.push(new o({...n.htmlPluginOption,meta:e}))}if(n.fixBrowserRouter){let e=n.basename.split("/").filter(Boolean).length,t=`${Array(e).fill("..").join("/")+(e?"/":"")}404.html`,i=n.fixBrowserRouter.pathSegmentsToKeep??e;a.push(new o({filename:n.fixBrowserRouter.path??t,inject:!1,templateContent:()=>`<html lang="en"><head><title>Redirect</title><script>const pathKeep = ${i};const l = window.location;l.replace(l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') + l.pathname.split('/').slice(0, 1 + pathKeep).join('/') + '/?/' + l.pathname.slice(1).split('/').slice(pathKeep).join('/').replace(/&/g, '~and~') + (l.search ? '&' + l.search.slice(1).replace(/&/g, '~and~') : '') + l.hash);</script></head><body></body></html>`}))}n.sourceMap&&a.push(new t.SourceMapDevToolPlugin(n.sourceMap));export default a;
package/lib/vm/docs.mjs CHANGED
@@ -1 +1 @@
1
- import{relative as e,sep as t}from"node:path";import{loadFile as o,scanFolderSync as m}from"@moneko/utils";import a from"../commom/parse-module-meta.mjs";import n from"../commom/paths.mjs";import r from"../commom/reactive-object.mjs";import s from"../commom/rule.mjs";import{CONFIG as l}from"../config.mjs";import{FRAMEWORK as c,framework as p,isLibrary as i,isReact as d,isSolid as f}from"../process-env.mjs";import u from"./generate-doc.mjs";let g={react:"createElement",solid:"createComponent"}[c],h=a("@app/docs");export const docsModuleName=h.file;export const docsModulePkgJson=h.pkg;export const docsModuleMeta=h.meta;export const docs=new r({[docsModuleName]:"export default {}",[docsModulePkgJson]:docsModuleMeta});export const comment=new r({});export const getCommentPath=function(){let e=/\/(.+?)\.tsx?$/,t=l.alias["@pkg"]?.length;return o=>o.substring(t).replace(/\\/g,"/").replace(e,"@app/comment/$1.md")}();if(i&&!1!==l.htmlPluginOption){let r={},c=`import { ${g}${f?",Dynamic":""} } from "${p}${f?"/web":""}";import SuspenseComp from "@app/suspense";function call_then(res) {return {default: ${d?"() =>":""}${g}(${f?"Dynamic":"'div'"}, {${f?"innerHTML: res.default, component: 'div', class: 'n-md-box' ":"dangerouslySetInnerHTML: {__html:res.default}, className: 'n-md-box'"} })};}`,i=(e,o)=>{if(!e.endsWith("package.json")){let m=e.replace(/@app[/\\]comment[/\\]/,"").split(t),a=m.pop(),n=m.join("/");r[n]||(r[n]={}),o?r[n][a]&&delete r[n][a]:r[n][a]=`rr(() => ${g}(SuspenseComp, { comp: () => import(/* webpackChunkName: '${e}' */ '${e}?raw').then(call_then)}))rr`;let l={};for(let e in r)Object.prototype.hasOwnProperty.call(r,e)&&(l[e]=Object.values(r[e]));docs.setData(docsModuleName,`${c}export default ${JSON.stringify(l).replace(s.extract_func,"$1")}`)}};comment.on("change",(t,o)=>{i(e(n.nodeModules,t),o?.length<0)});let h=m(l.alias["@pkg"],["\\.tsx?$"]).filter(e=>!/(^|\/)\.[^\\/\\.]|\.test\./i.test(e));await Promise.all(h.map(async e=>({data:await o(e),file:e}))).then(e=>{for(let t=0;t<e.length;t++){let o=e[t];if(o.data){let{file:e,pkg:t,meta:m}=a(getCommentPath(o.file));comment.setData(e,u(o.data,o.file)),comment.setData(t,m)}}})}
1
+ import{relative as e,sep as t}from"node:path";import{loadFile as o,scanFolderSync as m}from"@moneko/utils";import a from"../commom/parse-module-meta.mjs";import r from"../commom/paths.mjs";import n from"../commom/reactive-object.mjs";import s from"../commom/rule.mjs";import{CONFIG as l}from"../config.mjs";import{FRAMEWORK as c,framework as p,isLibrary as i,isReact as d,isSolid as f}from"../process-env.mjs";import u from"./generate-doc.mjs";let g={react:"createElement",solid:"createComponent"}[c],$=a("@app/docs");export const docsModuleName=$.file;export const docsModulePkgJson=$.pkg;export const docsModuleMeta=$.meta;export const docs=new n({[docsModuleName]:"export default {}",[docsModulePkgJson]:docsModuleMeta});export const comment=new n({});export const getCommentPath=function(){let e=/\/(.+?)\.tsx?$/,t=l.alias["@pkg"]?.length;return o=>o.substring(t).replace(/\\/g,"/").replace(e,"@app/comment/$1.md")}();if(i&&!1!==l.htmlPluginOption){let n={},c=`import { ${g}${f?",Dynamic":""} } from "${p}${f?"/web":""}";import SuspenseComp from "@app/suspense";function call_then(res) {return {default: ${d?"() =>":""}${g}(${f?"Dynamic":"'div'"}, {${f?"innerHTML: res.default, component: 'div', class: 'n-md-box' ":"dangerouslySetInnerHTML: {__html:res.default}, className: 'n-md-box'"} })};}`,i=(e,o)=>{if(!e.endsWith("package.json")){let m=e.replace(/@app[/\\]comment[/\\]/,"").split(t),a=m.pop(),r=m.join("/");n[r]||(n[r]={}),o?n[r][a]&&delete n[r][a]:n[r][a]=`rr(() => ${g}(SuspenseComp, { comp: () => import(/* webpackChunkName: '${e}' */ '${e}?raw').then(call_then)}))rr`;let l={};for(let e in n)Object.prototype.hasOwnProperty.call(n,e)&&(l[e]=Object.values(n[e]));docs.setData(docsModuleName,`${c}export default ${JSON.stringify(l).replace(s.extract_func,"$1")}`)}};comment.on("change",(t,o)=>{i(e(r.nodeModules,t),o?.length<0)});let $=m(l.alias["@pkg"],["\\.tsx?$"]).filter(e=>!/(^|\/)\.[^\\/\\.]|\.test\./i.test(e)),h=await Promise.all($.map(async e=>({data:await o(e),file:e})));for(let e=0;e<h.length;e++){let t=h[e];if(t.data){let{file:e,pkg:o,meta:m}=a(getCommentPath(t.file));comment.setData(e,u(t.data,t.file)),comment.setData(o,m)}}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moneko/core",
3
- "version": "3.33.1",
3
+ "version": "3.33.3-beta.0",
4
4
  "description": "core",
5
5
  "main": "lib/index.mjs",
6
6
  "type": "module",
@@ -34,6 +34,8 @@
34
34
  "less-loader": "12.2.0",
35
35
  "lightningcss": "1.29.3",
36
36
  "marked-completed": "1.2.14",
37
+ "memfs": "4.17.0",
38
+ "unionfs": "4.5.4",
37
39
  "mini-css-extract-plugin": "2.9.2",
38
40
  "style-loader": "4.0.0",
39
41
  "swc-loader": "0.2.6",
package/lib/dev.d.mts DELETED
@@ -1,56 +0,0 @@
1
- import { exec, spawn } from 'node:child_process';
2
- import { type createReadStream, type existsSync, watchFile } from 'node:fs';
3
- import { extname, relative, sep } from 'node:path';
4
- import { ink, loadFile, print, println, progressBar } from '@moneko/utils';
5
- import fastify, { type FastifyInstance, type FastifyReply, type FastifyRequest } from 'fastify';
6
- import webpack, { type Compiler, type OutputFileSystem, type Watching, type WebpackPluginInstance } from 'webpack';
7
- import webpackHotMiddleware, { type ClientOptions } from 'webpack-hot-middleware';
8
- import { merge } from 'webpack-merge';
9
- import { diffObject } from './commom/diff-object.mjs';
10
- import mime from './commom/mime.mjs';
11
- import paths, { config_files } from './commom/paths.mjs';
12
- import sigintExit from './commom/sigint-exit.mjs';
13
- import { devLog, PORT } from './dev/config.mjs';
14
- import setupMock from './dev/mock.mjs';
15
- import { type ProxyConfig, setupProxy } from './dev/proxy.mjs';
16
- import reslove from './options/reslove.mjs';
17
- import ESLintPlugin from './plugin/eslint.mjs';
18
- import StylelintPlugin from './plugin/stylelint.mjs';
19
- import { empty } from './utils/index.mjs';
20
- import { commonConfig } from './common.mjs';
21
- import { CONFIG, getConfig, PUBLICPATH } from './config.mjs';
22
- import type { ConfigType } from './index.mjs';
23
- import moduleConfig from './module.config.mjs';
24
- import { isLibrary, isReact, refresh } from './process-env.mjs';
25
- type WebpackPlugin = new(opt?: object) => WebpackPluginInstance;
26
- declare const hmrPath: string;
27
- declare const clientParams: ClientOptions;
28
- declare const hotParams: string;
29
- declare const path: string | undefined;
30
- declare const clientOption: webpack.Configuration;
31
- declare function getLintFiles(exts: string[]);
32
- declare const compilers: Compiler;
33
- declare const watching: Watching;
34
- interface FastifyOptions {
35
- http2?: boolean;
36
- https?: {
37
- key: string;
38
- cert: string;
39
- };
40
- }
41
- declare const fastifyOptions: FastifyOptions;
42
- declare const hotMiddleware: ReturnType<typeof webpackHotMiddleware>;
43
- declare const app: FastifyInstance;
44
- declare const normalHeaders: Record<string, string>;
45
- type FileSystem = OutputFileSystem & {
46
- existsSync: typeof existsSync;
47
- createReadStream: typeof createReadStream;
48
- };
49
- declare function replyStream(req: FastifyRequest, reply: FastifyReply, filePath: string);
50
- declare function exit();
51
- declare const _prev: ConfigType[];
52
- declare let prev: ConfigType;
53
- declare function watchConfig(filepath: string);
54
- declare function restart();
55
- declare const isWindow: boolean;
56
- declare function killPort(port: number);
package/lib/dev.mjs DELETED
@@ -1 +0,0 @@
1
- import{exec as e,spawn as t}from"node:child_process";import{watchFile as o}from"node:fs";import{extname as r,relative as s,sep as n}from"node:path";import{ink as i,loadFile as l,print as a,println as m,progressBar as p}from"@moneko/utils";import c from"fastify";import d from"webpack";import u from"webpack-hot-middleware";import{merge as h}from"webpack-merge";import{diffObject as f}from"./commom/diff-object.mjs";import g from"./commom/mime.mjs";import y,{config_files as w}from"./commom/paths.mjs";import $ from"./commom/sigint-exit.mjs";import{devLog as x,PORT as v}from"./dev/config.mjs";import C from"./dev/mock.mjs";import{setupProxy as j}from"./dev/proxy.mjs";import P from"./options/reslove.mjs";import k from"./plugin/eslint.mjs";import S from"./plugin/stylelint.mjs";import{empty as b}from"./utils/index.mjs";import{commonConfig as A}from"./common.mjs";import{CONFIG as O,getConfig as T,PUBLICPATH as H}from"./config.mjs";import E from"./module.config.mjs";import{isLibrary as _,isReact as I,refresh as M}from"./process-env.mjs";let R=`${H.endsWith("/")?"":"/"}__hmr__`,z=new URLSearchParams({name:"client",path:R,dynamicPublicPath:!0,timeout:2e3,reload:!M,quiet:!0,noInfo:!0,overlay:!1,autoConnect:!0}).toString(),U=A.output.path,q=h(A,{watchOptions:{ignored:/node_modules\/(?!(@app|@moneko)).+/},entry:{main:[`${P.hotMiddlewareClient}?${z}`]},output:{path:U},module:E(!1),plugins:[new d.HotModuleReplacementPlugin,new d.WatchIgnorePlugin({paths:[/node_modules\/(?!(@app|@moneko)).+/,/\.d\.ts$/]})]});if(q.plugins||(q.plugins=[]),I){let e=(await import("@pmmmwh/react-refresh-webpack-plugin")).default;q.plugins.push(new e({overlay:!1}))}function B(e){let t=e.join(","),o=[s(y.programPath,`${O.alias["@"]}/**/*.{${t}}`).replace(/\\/g,"/")];return _&&o.push(s(y.programPath,`${O.alias["@pkg"]}/**/*.{${t}}`).replace(/\\/g,"/")),o}if(O.eslint&&q.plugins.push(new k({fix:!0,cache:!0,cacheLocation:`${y.lintCachePath}/.eslintcache`,cacheStrategy:"metadata",lintDirtyModulesOnly:!0,...O.eslint,files:B(["js","jsx","ts","tsx","json","html","vue"])})),O.stylelint&&q.plugins.push(new S({fix:!0,cache:!0,cacheLocation:`${y.lintCachePath}/.stylelintcache`,...O.stylelint,files:B(["css","scss","sass","less","ts","tsx","js","jsx"])})),O.bar){let e=O.bar,t=e.name||"Build";q.plugins.push(new d.ProgressPlugin({handler(o,r,...s){p(o||0,1,{msg:s.length?`[${r}] ${s.join(" ")}`:"",name:t,barColor:e.barColor,nameColor:e.nameColor,barBgColor:e.barBgColor,msgColor:e.msgColor}),1===o&&process.stdout.write("\r\x1b[2K")}}))}let F=d(q),L=F.watch(F.options.watchOptions,x);F.hooks.done.tap("client-log",e=>{x(null,e)});let N={};if(O.devServer.https){let[e,t]=await Promise.all([l(O.devServer.https.key),l(O.devServer.https.cert)]);e||(m(i(`法加载私钥。请检查路径和文件是否存在,并确保路径正确:${O.devServer.https.key}`,"red")),process.exit(1)),t||(m(i(`无法加载证书。请检查路径和文件是否存在,并确保路径正确:${O.devServer.https.cert}`,"red")),process.exit(1)),N.http2=!0,N.https={key:e,cert:t}}let D=u(F,{log:!1,path:R,heartbeat:2e3}),G=c({logger:!1,...N});C(G,{directory:y.mockPath}),j(G,O.proxy);let W={"Access-Control-Allow-Credentials":"true","Access-Control-Allow-Headers":"DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization","Access-Control-Allow-Methods":"GET, POST, OPTIONS, DELETE, PATCH, PUT","Access-Control-Allow-Origin":"*","Cache-Control":"no-store, no-cache, must-revalidate, proxy-revalidate",Pragma:"no-cache",Expires:"0",...O.devServer.headers||{}};function K(e,t,o){t.headers(W),e.headers.origin&&t.header("Access-Control-Allow-Origin",e.headers.origin);let s=F.outputFileSystem,n=e.headers["accept-encoding"],i=n?.includes("gzip"),l=s.existsSync?.(`${o}.gz`);i&&l&&t.header("content-encoding","gzip");let a=s.createReadStream?.(i&&l?`${o}.gz`:o,{autoClose:!0});a?.on("error",e=>{if(a.destroy(),!t.sent)return t.code(404).type("text/html").send(`File not found: ${e.message}`)});let m=g[r(o)];return m&&t.header("content-type",m),t.send(a)}function X(){process.exit(0)}G.get(`/${R}`.replace("//","/"),async(e,t)=>{if("text/event-stream"===e.headers.accept){e.raw.url=R,D(e.raw,t.raw,()=>{t.raw.writableEnded&&(t.sent=!0)});return}}),G.addHook("onRequest",(e,t,o)=>{let r=`${q.output.path}${n}${"/"===e.url?"index.html":e.url}`;return F.outputFileSystem?.existsSync?.(r)?K(e,t,r):o()}),G.setNotFoundHandler((e,t)=>K(e,t,`${q.output.path}${n}index.html`)),G.addHook("onClose",()=>{L.close(b),G.server.close(b)}),G.listen({port:v});let J=await Promise.all(w.map(T)),Q=h(J[0]||{},J[1]||{});w.forEach(function(t){o(t,async function(){let[o,r]=await Promise.all(w.map(T)),s=h(o||{},r||{}),n=f(Q,s);1===Object.keys(n).length&&"proxy"in n?(a(i(`代理更新中...`,"yellow"),!0),await j(G,s.proxy),a(i(`代理更新完成...`,"green"),!0),O.proxy=s.proxy,Q.proxy=s.proxy,Q=s):(Q=s,m(i(`检测到工程配置${i(`[${t}]`,"blue")}变更, 程序即将重启...`,"yellow"),!0),e(V?`netstat -ano | findstr :${v}`:`lsof -i :${v} -t`,(e,t)=>{if(e){m(i(`查找端口 ${v} 时发生错误: ${e.message}`,"red")),m(i("请尝试手动重启程序","yellow"));return}let o=t.trim().replace(/\r\n/g,"\n").split("\n").filter(Boolean),r=V?o[0]?.split(/\s+/).pop()?.trim():o[0]?.trim();if(!r){m(i(`未找到占用端口 ${v} 的进程, 请尝试手动重启程序`,"yellow"));return}try{process.kill(Number(r),"SIGHUP")}catch(e){m(i(`终止进程 ${r} 时发生错误: ${e.message}`,"red"))}}))})});let V="win32"===process.platform;process.on("SIGHUP",function(){G.close(b),function(){let e=t(process.argv[0],process.argv.slice(1),{detached:!1,stdio:"inherit"});e.unref(),e.on("close",X)}()}),process.on("exit",function(){G.close(b)}),$(X);
File without changes
File without changes
File without changes
File without changes