@moneko/core 3.19.2 → 3.19.3-beta.1
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/plugin/copy.d.mts +5 -3
- package/lib/plugin/copy.mjs +1 -1
- package/lib/plugin/exposes-declararion.d.mts +12 -0
- package/lib/plugin/exposes-declararion.mjs +1 -0
- package/lib/plugin/module-federation.mjs +1 -1
- package/lib/plugin/virtual-module.d.mts +1 -0
- package/lib/plugin/virtual-module.mjs +1 -1
- package/lib/utils/dts.mjs +1 -1
- package/lib/utils/fetch-module-federation-dts.d.mts +2 -0
- package/lib/utils/fetch-module-federation-dts.mjs +1 -0
- package/package.json +4 -3
- package/typings/global.d.ts +15 -1
package/lib/plugin/copy.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Compiler } from 'webpack';
|
|
1
|
+
import { type Compiler } from 'webpack';
|
|
2
2
|
/** 需要拷贝的文件列表
|
|
3
3
|
* @example
|
|
4
4
|
* ```ts
|
|
@@ -19,8 +19,10 @@ export interface CopyPluginOption {
|
|
|
19
19
|
dirs?: string[];
|
|
20
20
|
}
|
|
21
21
|
export declare class CopyPlugin {
|
|
22
|
-
private
|
|
22
|
+
private readonly baseFiles;
|
|
23
|
+
private readonly dirs;
|
|
24
|
+
private cacheFiles;
|
|
23
25
|
constructor(option: CopyPluginOption);
|
|
24
|
-
private
|
|
26
|
+
private getFiles;
|
|
25
27
|
apply(compiler: Compiler): void;
|
|
26
28
|
}
|
package/lib/plugin/copy.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{resolve as e}from"path";import s from"webpack";import{loadFile as t,scanFolderSync as i}from"@moneko/utils";let l="CopyPlugin",{sources:{RawSource:o}}=s;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)i(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:l,stage:e.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS},e=>{e.hooks.processAssets.tapPromise(l,async()=>{let s=this.getFiles(),i=s.files.map(e=>t(e));(await Promise.all(i)).forEach((t,i)=>{null!==t&&e.emitAsset(s.files[i],new o(t))}),s.deleted.forEach(s=>{e.deleteAsset(s)})})})}}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Compiler } from 'webpack';
|
|
2
|
+
interface ModuleFederationExposesDeclarationPluginOptions {
|
|
3
|
+
name: string;
|
|
4
|
+
exposes: Record<string, string>;
|
|
5
|
+
}
|
|
6
|
+
export declare class ModuleFederationExposesDeclarationPlugin {
|
|
7
|
+
private option;
|
|
8
|
+
private project;
|
|
9
|
+
constructor(option: ModuleFederationExposesDeclarationPluginOptions);
|
|
10
|
+
apply(compiler: Compiler): void;
|
|
11
|
+
}
|
|
12
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"webpack";import{ModuleDeclarationKind as t,Project as o}from"ts-morph";import{resolve as s,join as a}from"path";import{generateDeclaration as i}from"../utils/dts.mjs";import{loadFile as r}from"@moneko/utils";let n="ModuleFederationExposesDeclarationPlugin";export class ModuleFederationExposesDeclarationPlugin{constructor(e){this.project=new o({useInMemoryFileSystem:!0}),this.option=e}apply(o){let{exposes:p}=this.option,l=Object.keys(p).map(e=>{let t=e.replace(/\.tsx?$/i,"");return{key:e,name:t,path:s(`types/${this.option.name}/${t}.d.ts`),originPath:p[e]}});o.hooks.thisCompilation.tap({name:n,stage:o.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS},o=>{o.hooks.processAssets.tapPromise(n,async()=>{let s=l.map(async e=>{let o=[],s=await r(e.originPath);if(null!==s){let r=i(s,`${e.name}.ts`),n=this.project.getSourceFile(e.path)||this.project.createSourceFile(e.path);n.removeText();let p=a(this.option.name,e.name);n.addModule({name:`'${p}'`,declarationKind:t.Module,hasDeclareKeyword:!0,statements:r}),o.push(`// remote module: ${p}`),o.push(n.getText(!0))}return o.join("\n")}),n=await Promise.all(s);o.emitAsset("module-federation.d.ts",new e.sources.RawSource(n.join("\n")),{javascriptModule:!1})})})}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"webpack";import r from"./external-remotes.mjs";import{CONFIG as t}from"../config.mjs";import s from"../utils/require.mjs";import{resolveProgram as o}from"../utils/index.mjs";let{NormalModuleReplacementPlugin:i,container:{ModuleFederationPlugin:
|
|
1
|
+
import e from"webpack";import r from"./external-remotes.mjs";import{CONFIG as t}from"../config.mjs";import s from"../utils/require.mjs";import{resolveProgram as o}from"../utils/index.mjs";import{ModuleFederationExposesDeclarationPlugin as m}from"./exposes-declararion.mjs";import a from"../utils/fetch-module-federation-dts.mjs";let{NormalModuleReplacementPlugin:i,container:{ModuleFederationPlugin:l}}=e,n={},p=[],f=t.moduleFederation?.map(e=>{let r={},t={},i={};if(Array.isArray(e.remotes))for(let r=0,s=e.remotes.length;r<s;r++){let s=e.remotes[r],o=s.alias||s.name,m=s.filename||"remote_entry.js";if(t[o]=`${s.name}@${s.host}/${m}`,Array.isArray(s.library))for(let e=0,r=s.library.length;e<r;e++)n[s.library[e]]=`${o}/${s.library[e]}`;a(s.host,s.name)}if(Array.isArray(e.exposes)){for(let t=0,m=e.exposes.length;t<m;t++){let m=e.exposes[t];if("string"==typeof m){let e=m.startsWith(".");r[`./${m}`]=s.resolve(e?o(m):m),e&&(i[m]=r[`./${m}`])}else if("[object Object]"===Object.prototype.toString.call(m)){let e=m.path.startsWith(".");r[`./${m.name}`]=s.resolve(e?o(m.path):m.path),e&&(i[`./${m.name}`]=r[`./${m.name}`])}}e.exposes?.length&&p.push(new m({exposes:i,name:e.name}))}return new l({filename:"remote_entry.js",...e,remotes:t,exposes:r})});f.length>0&&(f.push(new r),f.push(new i(/(.*)/,e=>{n[e.request]&&(e.request=n[e.request])})),p.forEach(e=>f.push(e))),t.env.injectRemoteReactRefresh=Object.keys(n).includes("react-dom");export default f;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import t from"webpack-virtual-modules";import{isLibrary as o}from"../process-env.mjs";import{node_modules as i}from"../utils/index.mjs";import{comment as e,docs as s}from"../vm/docs.mjs";import{examples as r}from"../vm/example.mjs";import{locales as l}from"../vm/locales.mjs";import m from"../vm/modules.mjs";import{route as p}from"../vm/routes.mjs";import n from"../paths.mjs";export class VirtualModuleWebpackPlugin{constructor(o={}){this.virtualModules=new t(m),this.options={},this.init=!1;let i={};for(let t in o)if(Object.prototype.hasOwnProperty.call(o,t)){let e=o[t];Object.assign(i,{[t]:"string"==typeof e?e:`export default ${JSON.stringify(e)}`})}this.options=i}modify(t,o,e){let s=e||"",r=o.startsWith(n.nodeModules)?o:i(o),l=t;for(;l&&l._inputFileSystem;)l=l._inputFileSystem;let m=l?._virtualFiles?.[r];m&&m.contents===s||this.virtualModules.writeModule(r,s)}apply(t){this.virtualModules.apply(t);let i=(o,i)=>{this.modify(t.inputFileSystem,o,i)};p.on("change",i),l.on("change",i),o&&(r.on("change",i),s.on("change",i),e.on("change",i)),t.hooks.beforeCompile.tap("VirtualModuleWebpackPlugin",()=>{if(!this.init){for(let t in this.init=!0,this.options)Object.prototype.hasOwnProperty.call(this.options,t)&&i(t,this.options[t]);for(let t of r)i(t[0],t[1]);for(let t of s)i(t[0],t[1]);for(let t of e)i(t[0],t[1])}})}}
|
package/lib/utils/dts.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"typescript";import{createSystem as t,createDefaultMapFromNodeModules as r,createVirtualTypeScriptEnvironment as i}from"@typescript/vfs";let o={declaration:!0,emitDeclarationOnly:!0,target:e.ScriptTarget.ESNext,skipLibCheck:!0},a=r(o),c=i(t(a),[],e,o);export function generateDeclaration(e,t){return a.set(t,e),c.createFile(t,e),c.languageService.getEmitOutput(t).outputFiles.reduce((e,t)=>e+=t.text,"")}export function getExportKeys(e,t){a.set(t,e),c.createFile(t,e);let r=c.getSourceFile(t)?.symbol;return Array.from(r?.exports?.keys()||[])}
|
|
1
|
+
import e from"typescript";import{createSystem as t,createDefaultMapFromNodeModules as r,createVirtualTypeScriptEnvironment as i}from"@typescript/vfs";let o={declaration:!0,emitDeclarationOnly:!0,target:e.ScriptTarget.ESNext,skipLibCheck:!0},a=r(o),c=i(t(a),[],e,o);export function generateDeclaration(e,t){return a.set(t,e),c.createFile(t,e),c.languageService.getEmitOutput(t,!0).outputFiles.reduce((e,t)=>e+=t.text,"")}export function getExportKeys(e,t){a.set(t,e),c.createFile(t,e);let r=c.getSourceFile(t)?.symbol;return Array.from(r?.exports?.keys()||[])}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{updateFile as t}from"@moneko/utils";import{node_modules as e}from"./index.mjs";async function o(o,i){try{let n=`${o.startsWith("//")?`http:${o}`:o}/module-federation.d.ts`,r=await fetch(n).then(t=>t.text());t(e(`@types/${i}/index.d.ts`),r)}catch(t){}}export default o;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moneko/core",
|
|
3
|
-
"version": "3.19.
|
|
3
|
+
"version": "3.19.3-beta.1",
|
|
4
4
|
"description": "core",
|
|
5
5
|
"main": "lib/index.mjs",
|
|
6
6
|
"type": "module",
|
|
@@ -38,12 +38,13 @@
|
|
|
38
38
|
"style-loader": "4.0.0",
|
|
39
39
|
"swc-loader": "0.2.6",
|
|
40
40
|
"terser-webpack-plugin": "5.3.10",
|
|
41
|
-
"
|
|
41
|
+
"ts-morph": "23.0.0",
|
|
42
|
+
"typescript": "5.5.3",
|
|
42
43
|
"webpack": "5.92.1",
|
|
43
44
|
"webpack-bundle-analyzer": "4.10.2",
|
|
44
45
|
"webpack-dev-middleware": "7.2.1",
|
|
45
46
|
"webpack-hot-middleware": "2.26.1",
|
|
46
|
-
"webpack-merge": "
|
|
47
|
+
"webpack-merge": "6.0.1",
|
|
47
48
|
"webpack-virtual-modules": "0.6.2",
|
|
48
49
|
"xml2js": "0.6.2"
|
|
49
50
|
},
|
package/typings/global.d.ts
CHANGED
|
@@ -249,7 +249,21 @@ export declare type ConfigType = {
|
|
|
249
249
|
};
|
|
250
250
|
/** HtmlWebpackPlugin Option */
|
|
251
251
|
htmlPluginOption: HtmlWebpackOption | false;
|
|
252
|
-
|
|
252
|
+
/** 需要拷贝的文件列表
|
|
253
|
+
* @example
|
|
254
|
+
* ```ts
|
|
255
|
+
* const conf = {
|
|
256
|
+
* copy: {
|
|
257
|
+
* // 将 public 下的 a.json 和 s.txt 添加到资源
|
|
258
|
+
* files: ['public/a.json', 'public/s.txt'],
|
|
259
|
+
* // 将 static 文件夹添加到资源
|
|
260
|
+
* dirs: ['static']
|
|
261
|
+
* }
|
|
262
|
+
* };
|
|
263
|
+
*
|
|
264
|
+
* export default conf;
|
|
265
|
+
* ```
|
|
266
|
+
*/
|
|
253
267
|
copy: CopyPluginOption;
|
|
254
268
|
/** 路由模式
|
|
255
269
|
* @description
|