@moneko/core 4.8.6-beta.0 → 4.8.6-beta.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.
|
@@ -3,8 +3,12 @@
|
|
|
3
3
|
}
|
|
4
4
|
/**
|
|
5
5
|
* 将一个或多个 npm 包或本地文件的类型声明打包成单一的 .d.ts 字符串。
|
|
6
|
-
* 每个文件对应一个 declare module "..." { ... }
|
|
7
|
-
*
|
|
6
|
+
* 每个文件对应一个 declare module "..." { ... } 块。
|
|
7
|
+
* 外部依赖用 TypeScript 的 `resolveModuleName`(与入口文件同一 tsconfig)按**完整模块说明符**解析到唯一磁盘入口,再沿相对路径展开;
|
|
8
|
+
* 不会把 `pkg/sub` 折叠成包根后再 `resolveTypesEntry(包名)`,从而避免打入未在依赖链中出现的子图。
|
|
9
|
+
* **仅当依赖边起点不在 `node_modules` 内**(即业务源码或已内联包内的相对路径仍照常展开)时,才继续内联该边上的裸模块;
|
|
10
|
+
* 第三方 `.d.ts` 里对 `csstype`、样式库等的传递引用保留为外部说明符,避免几十万行类型重复打进单文件。
|
|
11
|
+
* 混合输入时先处理本地路径与 BundleEntry,再处理裸 npm 包名;多入口共享同一 `completed` 集合,避免重复声明。
|
|
8
12
|
*
|
|
9
13
|
* @param pkgOrPkgs - 包名、路径或带别名条目(支持混合数组),例如:
|
|
10
14
|
* - `'react'` — npm 包名
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import{readFileSync as
|
|
2
|
-
${
|
|
3
|
-
}`})}(
|
|
4
|
-
export * from "${
|
|
5
|
-
}`})
|
|
6
|
-
export * from "${e}";
|
|
7
|
-
}`});let o=new Set,f=[];for(let t of n)o.has(t.id)||(o.add(t.id),f.push(t.content));return f.join("\n\n")}
|
|
1
|
+
import{readFileSync as e,statSync as t}from"node:fs";import{createRequire as r,isBuiltin as i}from"node:module";import{dirname as n,isAbsolute as l,join as s,posix as o,relative as f,resolve as u,sep as c}from"node:path";import a from"typescript";function p(e){if(!e)return!1;if(i(e))return!0;if(e.startsWith("node:")){let t=e.slice(5);return t.length>0&&i(t)}return!1}function d(e){return"node"===e||"@types/node"===e||e.startsWith("@types/node/")}function m(e){if(!e.startsWith("@types/"))return e;let t=e.slice(7),r=/^([^_]+)__(.+)$/.exec(t);return r?`@${r[1]}/${r[2]}`:t}function g(e){if(!e.startsWith("@types/"))return e;let t=e.slice(7),r=t.indexOf("/");if(-1===r)return m(e);let i=t.slice(0,r),n=t.slice(r);return m(`@types/${i}`)+n}function y(t){let r=n(u(t));for(let t=0;t<200&&r!==n(r);t++){let t=s(r,"package.json");if(h(t))try{let i=JSON.parse(e(t,"utf-8"));if(i.name&&"string"==typeof i.name)return{pkgDir:r,pkgName:i.name}}catch{}r=n(r)}return null}let x=new Map;function h(e){if(x.has(e))return x.get(e);try{let r=t(e).isFile();return x.set(e,r),r}catch{return x.set(e,!1),!1}}let $=new Map,k=r(import.meta.url);function j(){return{allowJs:!0,declaration:!0,emitDeclarationOnly:!0,noEmit:!1,skipLibCheck:!0,noEmitOnError:!1,declarationMap:!1,target:a.ScriptTarget.ESNext,module:a.ModuleKind.ESNext,moduleResolution:a.ModuleResolutionKind.Bundler,jsx:a.JsxEmit.ReactJSX}}let F=new Map;function S(e){let t=u(e),r=a.findConfigFile(n(t),a.sys.fileExists,"tsconfig.json");if(!r)return{options:j(),key:"__no_tsconfig__"};let i=u(r),l=F.get(i);if(l)return{options:l,key:i};let{config:s,error:o}=a.readConfigFile(r,a.sys.readFile);if(o)return{options:j(),key:"__no_tsconfig__"};let f={...a.parseJsonConfigFileContent(s,a.sys,n(r),void 0,r).options,allowJs:!0,declaration:!0,emitDeclarationOnly:!0,noEmit:!1,skipLibCheck:!0,noEmitOnError:!1,declarationMap:!1};return F.set(i,f),{options:f,key:i}}let v=new Map,D=new Map;function N(e,t){let r=D.get(e);if(!r){let i=a.sys.useCaseSensitiveFileNames?e=>e:e=>e.toLowerCase();r=a.createModuleResolutionCache(t,i),D.set(e,r)}return r}function w(e,t,r){if(!e||e.startsWith(".")||l(e)||p(e))return null;let i=u(r),{options:n,key:s}=S(t),o=N(s,i),c=a.createCompilerHost(n),d=a.resolveModuleName(e,t,n,c,o).resolvedModule;if(!d?.resolvedFileName||d.isExternalLibraryImport)return null;let m=u(d.resolvedFileName),g=f(i,m);return!g||g.startsWith("..")||"node_modules"===g.split(/[/\\]/)[0]?null:m}function O(e,t,r){let i=`'${t}'`,n=`"${t}"`,l=e.lastIndexOf(i),s=e.lastIndexOf(n);return l>s?`${e.slice(0,l)}'${r}'${e.slice(l+i.length)}`:s>=0?`${e.slice(0,s)}"${r}"${e.slice(s+n.length)}`:e}let W=new Map;function _(e){return e.replace(/\/\/[#@][ \t]*sourceMappingURL=[^\r\n]*/g,"").replace(/\/\*[#@][ \t]*sourceMappingURL=[^*]*\*\//g,"")}let b=/^(?:import|export)\s[\s\S]*?\bfrom\s+['"]([^'"]+)['"]\s*;?/gm,M=/\bimport\(\s*['"]([^'"]+)['"]\s*\)/g,E=/^\/\/\/\s*<reference\s+path="([^"]+)"\s*\/>/gm;function L(e){if(e){if("string"==typeof e)return e;for(let t of["import","require","default","node","browser"]){let r=e[t];if("string"==typeof r)return r;if(r&&"object"==typeof r){let e=L(r);if(e)return e}}}}function C(e,t=!1){if(e){if("string"==typeof e)return t?e:void 0;for(let t of Object.keys(e).filter(e=>"types"===e||e.startsWith("types@")).sort((e,t)=>"types"===e?-1:+("types"===t))){let r=C(e[t],!0);if(r)return r}for(let r of["import","require","default","node"]){let i=e[r];if("string"==typeof i){if(t)return i;continue}if(i&&"object"==typeof i){let e=C(i,t);if(e)return e}}}}function J(e){return e.startsWith("@types/")?e:e.startsWith("@")?`@types/${e.slice(1).replace("/","__")}`:`@types/${e}`}function R(t,r){try{let i=t.resolve(`${r}/package.json`),l=JSON.parse(e(i,"utf-8"));return{pkgDir:n(i),pkgJson:l}}catch{try{let i=n(t.resolve(r));for(;i!==n(i);){let t=s(i,"package.json");if(h(t)){let n=JSON.parse(e(t,"utf-8")),l=n.name;if(!l||l===r)return{pkgDir:i,pkgJson:n}}i=n(i)}}catch{}return null}}function I(e){if(!/\.([cm]?jsx?|[cm]js)$/i.test(e))return e;let t=e.replace(/\.([cm]?jsx?|[cm]js)$/i,"");for(let e of[".d.ts",".d.mts",".d.cts"]){let r=t+e;if(h(r))return r}return e}function K(e,t){return f(t,e).split(c).join(o.sep).replace(/\.d\.[cm]?ts$/,"").replace(/\.[cm]?tsx?$/,"").replace(/\.[cm]?jsx?$|\.[cm]js$/,"")}function T(t,i,x,j,F,D,q,H){let X=u(i);if(!F.has(X)&&!j.has(X)){j.add(X);try{var P,U;let V=t?m(t):"",{blocks:B,externalEdges:z}=function(t,r,i,y,x){var $;let k=t?m(t):"",j=($=u(i),!!k&&(void 0!==x?(x.startsWith("@types/")?m(x):x)===k:function(t,r){let i,n=u(r);try{i=JSON.parse(e(s(t,"package.json"),"utf-8"))}catch{return!1}let l=[];if(i.types&&l.push(i.types.replace(/^\.\//,"")),i.typings&&l.push(i.typings.replace(/^\.\//,"")),i.exports&&"object"==typeof i.exports&&i.exports["."]){let e=i.exports["."];if(e&&"object"==typeof e){let t=C(e);t&&l.push(t.replace(/^\.\//,""))}}let a=e=>{if(!e)return;let r=s(t,e.replace(/^\.\//,""));if(!h(r))return;let i=r.replace(/\.(mjs|cjs|js)$/i,"");for(let e of[".d.ts",".d.mts",".d.cts"])if(h(i+e))return void l.push(f(t,i+e).split(c).join(o.sep))};for(let e of(a(i.module),a(i.main),l))if(u(s(t,e))===n)return!0;return u(s(t,"index.d.ts"))===n}(r,$))),F=new Set,D=[],N=new Set,L=[],J=u(i);function R(e,t){let r=`${e}\0${t}`;N.has(r)||(N.add(r),L.push({specifier:e,fromFile:t}))}return!function t(i){let o,f=u(i);if(F.has(f))return;F.add(f);let c=!/\.d\.[cm]?ts$/i.test(f)&&/\.(ts|tsx|mts|cts|js|jsx|mjs|cjs|mjsx|cjsx)$/i.test(f);try{if(c){if(!(o=function(e){let t=u(e);if(W.has(t))return W.get(t);let r=function(e){let t=u(e),{options:r,key:i}=S(t),n=v.get(i);if(!n){let e=a.createCompilerHost(r),l=a.createProgram([t],r,e);return n={program:l,host:e,options:r},v.set(i,n),l}if(n.program.getSourceFile(t))return n.program;let l=[...n.program.getRootFileNames(),t];return n.program=a.createProgram(l,r,n.host,n.program),n.program}(t),i=r.getSourceFile(t);if(!i)return W.set(t,""),"";let n="";r.emit(i,(e,t)=>{/\.d\.[cm]?ts$/.test(e)&&(n=t)},void 0,!0);let l=_(n.replace(/^export\s*\{\s*\};\s*$/gm,"").replace(/^import\s+['"][^'"]+['"]\s*;?\s*$/gm,"").replace(/^#![^\n]*\n?/,"").replace(/\n{3,}/g,"\n\n").trim());return W.set(t,l),l}(f)))return void F.delete(f)}else o=_(e(i,"utf-8").replace(/^#![^\n]*\n?/,""))}catch{F.delete(f);return}let m=new Map,x=e=>(m.has(e)||m.set(e,function(e,t){let r=s(n(t),e);if(h(r))return I(r);let i=r.lastIndexOf(".");if(i>Math.max(r.lastIndexOf("/"),r.lastIndexOf("\\"))){let e=r.slice(0,i);for(let t of[".d.ts",".d.mts",".d.cts"]){let r=e+t;if(h(r))return r}}for(let e of[".d.ts",".d.mts",".d.cts"])if(h(r+e))return r+e;for(let e of["index.d.ts","index.d.mts","index.d.cts"]){let t=s(r,e);if(h(t))return t}for(let e of[".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs"])if(h(r+e))return I(r+e);for(let e of["index.ts","index.tsx","index.mts","index.cts","index.js","index.jsx"]){let t=s(r,e);if(h(t))return I(t)}return null}(e,i)),m.get(e)),{relSpecs:$,bareSpecs:N,refTypes:L}=function(e,t){let r,i=a.createSourceFile(e,t,a.ScriptTarget.Latest,!0,(r=e.toLowerCase()).endsWith(".tsx")?a.ScriptKind.TSX:r.endsWith(".jsx")?a.ScriptKind.JSX:a.ScriptKind.TS),n=[],l=[];function s(e){e&&(e.startsWith(".")||e.startsWith("/")?n.push(e):l.push(e))}!function e(t){if(a.isImportDeclaration(t)&&t.moduleSpecifier&&a.isStringLiteralLike(t.moduleSpecifier)&&s(t.moduleSpecifier.text),a.isExportDeclaration(t)&&t.moduleSpecifier&&a.isStringLiteralLike(t.moduleSpecifier)&&s(t.moduleSpecifier.text),a.isImportEqualsDeclaration(t)&&t.moduleReference&&a.isExternalModuleReference(t.moduleReference)){let e=t.moduleReference.expression;a.isStringLiteralLike(e)&&s(e.text)}if(a.isImportTypeNode(t)){let e=t.argument;a.isLiteralTypeNode(e)&&a.isStringLiteralLike(e.literal)&&s(e.literal.text)}if(a.isCallExpression(t)&&t.expression.kind===a.SyntaxKind.ImportKeyword&&t.arguments.length>0){let e=t.arguments[0];a.isStringLiteralLike(e)&&s(e.text)}a.forEachChild(t,e)}(i);let o=[];for(let e of i.typeReferenceDirectives)o.push(e.fileName);for(let e of i.referencedFiles??[])n.push(e.fileName);return{relSpecs:n,bareSpecs:l,refTypes:o}}(f,o);for(let e of $){if(l(e))continue;let r=x(e);r&&t(r)}for(let e of N){if(p(e))continue;let i=w(e,f,r);if(i){t(i);continue}d(e)||R(e,f)}for(let e of L)p(e)||d(e)||R(e,f);let C=e=>{let t=u(e);if(k&&j&&t===J)return k;let i=K(t,r);return k?`${k}/${i}`:y?`${y}:${i}`:i},T=o.replace(b,(e,t)=>{if(t.startsWith(".")){let r=x(t);return r?O(e,t,C(r)):e}let i=w(t,f,r);return i?O(e,t,C(i)):e}).replace(M,(e,t)=>{if(t.startsWith(".")){let r=x(t);return r?O(e,t,C(r)):e}let i=w(t,f,r);return i?O(e,t,C(i)):e}).replace(E,(e,t)=>{let r=x(t);return r?`/// <reference types="${C(r)}" />`:""}).replace(/\n{3,}/g,"\n\n").trim();if(!T)return;let A=C(f),q=function(e,t){let r=e,i=0;for(;i++<16;){let e=function(e,t){let r=e.trim(),i=r.match(RegExp(`^declare\\s+module\\s+["']${t.replace(/[\\^$.*+?()[\]{}|]/g,"\\$&")}["']\\s*\\{`,"m"));if(!i||0!==i.index)return e;let n=r.indexOf("{",i.index);if(-1===n)return e;let l=function(e,t){if("{"!==e[t])return null;let r=1,i=t+1,n=e.length;for(;i<n&&r>0;){let t=e[i];if('"'===t||"'"===t||"`"===t){for(i++;i<n;){if("\\"===e[i]){i+=2;continue}if(e[i]===t){i++;break}i++}continue}if("/"===t&&"/"===e[i+1]){for(i+=2;i<n&&"\n"!==e[i];)i++;continue}if("/"===t&&"*"===e[i+1]){for(i+=2;i<n-1&&("*"!==e[i]||"/"!==e[i+1]);)i++;i+=2;continue}"{"===t?r++:"}"===t&&r--,i++}return 0!==r?null:e.slice(t+1,i-1)}(r,n);if(null===l)return e;let s=n+1+l.length+1;return""!==r.slice(s).trim()?e:l}(r,t);if(e===r)break;r=e}return r}(T,A);if(!(q=(q=q.replace(/^(\s*)(export\s+)?declare\s+(?!module\b)(?!global\b)/gm,"$1$2").trim()).replace(/(\bfrom\s+)(['"])(@types\/[^'"]+)\2/g,(e,t,r,i)=>`${t}${r}${g(i)}${r}`).replace(/\b(import\s*\(\s*)(['"])(@types\/[^'"]+)\2(\s*\))/g,(e,t,r,i,n)=>`${t}${r}${g(i)}${r}${n}`).replace(/^(\/\/\/\s*<reference\s+types=["'])(@types\/[^'"]+)(["']\s*\/>)/gm,(e,t,r,i)=>`${t}${g(r)}${i}`)))return;let H=q.replace(/^(?=.)/gm," ");D.push({id:A,content:`declare module "${A}" {
|
|
2
|
+
${H}
|
|
3
|
+
}`})}(i),{blocks:D,externalEdges:L}}(V,x,i,q,H);for(let t of z){if(p(t.specifier)||d(t.specifier)||(P=t.fromFile,u(P).split(c).includes("node_modules")&&"csstype"!==t.specifier))continue;let i=function(t,i){if(!t||t.startsWith(".")||l(t)||p(t))return null;let o=u(i),f=A(o),{options:c,key:d}=S(o),m=N(d,f),g=a.createCompilerHost(c),x=a.resolveModuleName(t,o,c,g,m).resolvedModule;if(x?.resolvedFileName){let e=I(u(x.resolvedFileName)),t=y(e);if(t)return{entryFile:e,pkgDir:t.pkgDir,pkgName:t.pkgName}}if(t.includes("/")){let i=function(t,i){var l;let o,f,u=t.startsWith("@")?t.indexOf("/",t.indexOf("/")+1):t.indexOf("/");if(-1===u)return null;let c=t.slice(0,u),a=`./${t.slice(u+1)}`,p=i?(l=i,$.has(l)||$.set(l,r(s(l,"__x__.js"))),$.get(l)):k,d=R(p,c)??(i?R(k,c):null);if(d&&(o=d.pkgDir,f=d.pkgJson),!o||!f)return null;if(f.exports){let e=f.exports[a];if(e){let t="string"==typeof e?void 0:C(e);if(t){let e=s(o,t);if(h(e))return{entryFile:e,pkgDir:o}}let r="string"==typeof e?e:L(e);if(r){let e=s(o,r).replace(/\.([cm]?)js$/,".d.$1ts");if(h(e))return{entryFile:e,pkgDir:o}}}}let m=a.slice(2),g=s(o,m);if(h(g))return{entryFile:g,pkgDir:o};for(let e of[".d.ts",".d.mts",".d.cts"]){let t=g+e;if(h(t))return{entryFile:t,pkgDir:o}}for(let e of["index.d.ts","index.d.mts","index.d.cts"]){let t=s(g,e);if(h(t))return{entryFile:t,pkgDir:o}}let y=J(c);for(let t of i?[p,k]:[k])try{let r=t.resolve(`${y}/package.json`),i=JSON.parse(e(r,"utf-8")),l=n(r);if(i.exports){let e=i.exports[a];if(e){let t="string"==typeof e?void 0:C(e);if(t){let e=s(l,t);if(h(e))return{entryFile:e,pkgDir:l}}}}let o=s(l,m);if(h(o))return{entryFile:o,pkgDir:l};for(let e of[".d.ts",".d.mts",".d.cts"]){let t=o+e;if(h(t))return{entryFile:t,pkgDir:l}}}catch{}return null}(t,n(o));if(i){let e=I(u(i.entryFile)),r=y(e);return{entryFile:e,pkgDir:i.pkgDir,pkgName:r?.pkgName??(t.startsWith("@")?t.split("/").slice(0,2).join("/"):t.split("/")[0])}}}return null}(t.specifier,t.fromFile);if(!i)continue;let o=u(i.entryFile);F.has(o)||T((U=i.pkgName,m(U)),i.entryFile,i.pkgDir,j,F,D,q,t.specifier)}for(let e of B)D.push(e);F.add(X)}finally{j.delete(X)}}}function A(e){let t=n(u(e));for(let e=0;e<200&&t!==n(t);e++){if(h(s(t,"package.json")))return t;t=n(t)}t=n(u(e));for(let e=0;e<200&&t!==n(t);e++){if(h(s(t,"tsconfig.json")))return t;t=n(t)}return n(u(e))}function q(e){let t=u(e),r=A(t);if(/\.d\.[cm]?ts$/.test(t)&&h(t))return{entryFile:t,pkgDir:r};let i=t.match(/^(.*)\.[cm]?[tj]sx?$/);if(i){let e=i[1];for(let t of[".d.ts",".d.mts",".d.cts"]){let i=e+t;if(h(i))return{entryFile:i,pkgDir:r}}return/\.[cm]?tsx?$/.test(t)&&h(t)?{entryFile:t,pkgDir:r}:null}for(let e of[".d.ts",".d.mts",".d.cts"])if(h(t+e))return{entryFile:t+e,pkgDir:r};for(let e of["index.d.ts","index.d.mts","index.d.cts"]){let i=s(t,e);if(h(i))return{entryFile:i,pkgDir:r}}throw Error(`Cannot find local file: "${e}"`)}export async function bundleDts(t,r){let i=Array.isArray(t)?t:[t],o=new Set,f=new Set,c=new Set,a=[],p=[],m=[],g=[],y=new Set;for(let e of i)if("string"==typeof e)if(l(e)||e.startsWith("./")||e.startsWith("../")){let t=u(e);if(o.has(t))continue;let r=q(e);if(!r)continue;o.add(t),m.push({entryFile:r.entryFile,pkgDir:r.pkgDir})}else y.has(e)||(y.add(e),g.push(e));else for(let[t,i]of Object.entries(e)){let e=u(i);if(o.has(e))continue;let n=q(i);if(!n)continue;o.add(e);let l=K(u(n.entryFile),n.pkgDir),s=r?`${r}:${l}`:l;p.push({name:t,moduleId:s}),m.push({entryFile:n.entryFile,pkgDir:n.pkgDir})}for(let e of m)T("",e.entryFile,e.pkgDir,f,c,a,r);for(let t of g){if(d(t))continue;let{entryFile:i,pkgDir:l}=function(t){let r,i,l=R(k,t)??null;if(l&&(r=l.pkgDir,i=l.pkgJson),r&&i){let e=i.types??i.typings;if(e){let t=s(r,e);if(h(t))return{entryFile:t,pkgDir:r}}let t=s(r,"index.d.ts");if(h(t))return{entryFile:t,pkgDir:r};if(i.exports)for(let e of[".","./index"]){let t=i.exports[e];if(!t)continue;let n="string"==typeof t?void 0:C(t);if(n){let e=s(r,n);if(h(e))return{entryFile:e,pkgDir:r}}let l="string"==typeof t?t:L(t);if(l){let e=s(r,l).replace(/\.([cm]?)js$/,".d.$1ts");if(h(e))return{entryFile:e,pkgDir:r}}}if(i.typesVersions){let e=i.typesVersions["*"];if(e){let t=e["*"]??e.index;if(Array.isArray(t)&&t.length>0){let e=s(r,t[0].replace("*","index"));if(h(e))return{entryFile:e,pkgDir:r}}}}}let o=J(t);for(let t of[k])try{let r=t.resolve(`${o}/package.json`),i=JSON.parse(e(r,"utf-8")),l=n(r),f=i.types??i.typings??"index.d.ts",u=s(l,f);if(h(u))return{entryFile:u,pkgDir:l}}catch{}throw Error(`Cannot find types for "${t}"`)}(t),o=u(i);c.has(o)||T(t,i,l,f,c,a,r,t)}for(let{name:e,moduleId:t}of p)a.push({id:e,content:`declare module "${e}" {
|
|
4
|
+
export * from "${t}";
|
|
5
|
+
}`});let x=new Set,$=[];for(let e of a)x.has(e.id)||(x.add(e.id),$.push(e.content));return $.join("\n\n")}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Compiler } from 'webpack';
|
|
2
2
|
interface ModuleFederationExposesDeclarationPluginOptions {
|
|
3
3
|
name: string;
|
|
4
|
-
exposes
|
|
4
|
+
exposes?: Record<string, string>;
|
|
5
5
|
}
|
|
6
6
|
export declare class ModuleFederationExposesDeclarationPlugin {
|
|
7
7
|
private name;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{join as e,parse as t,relative as r,sep as o}from"node:path";import s from"webpack";import m from"../commom/module-resolve.mjs";import a from"../commom/paths.mjs";import{CONFIG as l}from"../config.mjs";import{re_export_schema as p}from"../process-env.mjs";import
|
|
1
|
+
import{join as e,parse as t,relative as r,sep as o}from"node:path";import s from"webpack";import m from"../commom/module-resolve.mjs";import a from"../commom/paths.mjs";import{CONFIG as l}from"../config.mjs";import{re_export_schema as p}from"../process-env.mjs";import i from"../utils/fetch-module-federation-dts.mjs";import{resolveProgram as n}from"../utils/index.mjs";import{mf_vm as f}from"../vm/mf.mjs";import{re_export_vm as h}from"../vm/re-export.mjs";import{ModuleFederationExposesDeclarationPlugin as c}from"./exposes-declararion.mjs";import{ExternalRemotesPlugin as u}from"./external-remotes.mjs";let d=s.NormalModuleReplacementPlugin,j=s.container.ModuleFederationPlugin,$={},x=[];function y(e,r){let s=e.replaceAll(o,"/").replace(/\.tsx?$/i,""),m=t(r);f.setData(s,{type:".tsx",source:()=>{if(r.startsWith(a.nodeModules)){let e=r.substring(a.nodeModules.length).split("node_modules").pop()?.replaceAll(o,"/").replace(/^\//,"");return`export * from '${e}';`}return r.startsWith(l.alias["@"])?`export * from '@/${t(m.dir).name}/${m.name}'`:"export {};"}})}let b=l.moduleFederation?.map(t=>{let o={},s={};if(Array.isArray(t.remotes))for(let e=0,r=t.remotes.length;e<r;e++){let r=t.remotes[e],o=r.alias||r.name,m=r.filename||"remote_entry.js";if(s[o]=`${r.name}@${r.host}/${m}`,Array.isArray(r.library))for(let e=0,t=r.library.length;e<t;e++)$[r.library[e]]=`${o}/${r.library[e]}`;i(r.host,r.name)}if(Array.isArray(t.exposes)){t.exposes.length>0&&!t.exposes.find(e=>"public-path"===e)&&t.exposes.push({name:"public-path",path:`./${r(a.programPath,e(a.corePath,"./polyfills/public-path.mjs"))}`});for(let e=0,r=t.exposes.length;e<r;e++){let r=t.exposes[e];if("string"==typeof r){let e=r,s=r.startsWith(".");!s&&h.has(r)&&(e=`${p}:${r}`),o[`./${r}`]=m(s?n(e):e),s&&y(`${t.name}/${r}`,o[`./${r}`])}else if("[object Object]"===Object.prototype.toString.call(r)){let e=r.path.startsWith(".");o[`./${r.name}`]=m(e?n(r.path):r.path),e&&y(`${t.name}/${r.name}`,o[`./${r.name}`])}}t.exposes?.length&&x.push(new c({exposes:Object.fromEntries(Object.entries(o).map(([e,t])=>[e.replace("./",""),t])),name:t.name}))}return new j({filename:"remote_entry.js",...t,remotes:s,exposes:o})});b.length>0&&(b.push(new u),b.push(new d(/(.*)/,e=>{$[e.request]&&(e.request=$[e.request])})),x.forEach(e=>b.push(e))),l.env.injectRemoteReactRefresh=Object.keys($).includes("react-dom");export default b;
|
package/lib/worker/dts.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{parentPort as e}from"node:worker_threads";import{bundleDts as s}from"../commom/bundle-dts.mjs";import{module_federation_schema as t}from"../process-env.mjs";if(!e)throw Error("This file must be run as a worker");e?.setMaxListeners(0),e.on("message",async({options:o})=>{try{let{name:r,exposes:m={}}=o,a=[];if(Object.keys(m).length){Object.keys(m).forEach(e=>{let s=`${r}/${e}`;a.push(`declare module "${t}:${s}" { export * from "${s}"; }`)});let o=await s(m,`_${r}_`);a.unshift(o);let n=a.join("\n\n");e.postMessage(n)}else e.postMessage("")}catch{e.postMessage("")}});
|