@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
- * 多包时共享 processedPkgs,全局去重,避免 declare module 重复声明。
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 t,statSync as e}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 d,sep as c}from"node:path";import u from"node:process";import a from"typescript";let p=new Map;function m(t){if(p.has(t))return p.get(t);try{let r=e(t).isFile();return p.set(t,r),r}catch{return p.set(t,!1),!1}}let y=new Map;function g(t){return y.has(t)||y.set(t,r(s(t,"__x__.js"))),y.get(t)}let h=r(import.meta.url),x=null;function $(){if(x)return x;let t=u.cwd(),e=a.findConfigFile(t,a.sys.fileExists,"tsconfig.json");if(e){let{config:t,error:r}=a.readConfigFile(e,a.sys.readFile);if(!r){let{options:r}=a.parseJsonConfigFileContent(t,a.sys,n(e));return x={...r,declaration:!0,emitDeclarationOnly:!0,noEmit:!1,skipLibCheck:!0,noEmitOnError:!1,declarationMap:!1}}}return x={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=null,k=null,j=new Map,O=/^(?:import|export)\s[\s\S]*?\bfrom\s+['"]([^'"]+)['"]\s*;?/gm,S=/\bimport\(\s*['"]([^'"]+)['"]\s*\)/g,w=/^\/\/\/\s*<reference\s+types="([^"]+)"\s*\/>/gm,D=/^\/\/\/\s*<reference\s+path="([^"]+)"\s*\/>/gm;function v(t){if(t){if("string"==typeof t)return t;for(let e of["import","require","default","node","browser"]){let r=t[e];if("string"==typeof r)return r;if(r&&"object"==typeof r){let t=v(r);if(t)return t}}}}function E(t,e=!1){if(t){if("string"==typeof t)return e?t:void 0;for(let e of Object.keys(t).filter(t=>"types"===t||t.startsWith("types@")).sort((t,e)=>"types"===t?-1:+("types"===e))){let r=E(t[e],!0);if(r)return r}for(let r of["import","require","default","node"]){let i=t[r];if("string"==typeof i){if(e)return i;continue}if(i&&"object"==typeof i){let t=E(i,e);if(t)return t}}}}function W(t){return t.startsWith("@types/")?t:t.startsWith("@")?`@types/${t.slice(1).replace("/","__")}`:`@types/${t}`}function b(e,r){try{let i=e.resolve(`${r}/package.json`),l=JSON.parse(t(i,"utf-8"));return{pkgDir:n(i),pkgJson:l}}catch{try{let i=n(e.resolve(r));for(;i!==n(i);){let e=s(i,"package.json");if(m(e)){let n=JSON.parse(t(e,"utf-8")),l=n.name;if(!l||l===r)return{pkgDir:i,pkgJson:n}}i=n(i)}}catch{}return null}}function J(e,r){let i,l,o=r?g(r):h,f=b(o,e)??(r?b(h,e):null);if(f&&(i=f.pkgDir,l=f.pkgJson),i&&l){let t=l.types??l.typings;if(t){let e=s(i,t);if(m(e))return{entryFile:e,pkgDir:i}}let e=s(i,"index.d.ts");if(m(e))return{entryFile:e,pkgDir:i};if(l.exports)for(let t of[".","./index"]){let e=l.exports[t];if(!e)continue;let r="string"==typeof e?void 0:E(e);if(r){let t=s(i,r);if(m(t))return{entryFile:t,pkgDir:i}}let n="string"==typeof e?e:v(e);if(n){let t=s(i,n).replace(/\.([cm]?)js$/,".d.$1ts");if(m(t))return{entryFile:t,pkgDir:i}}}if(l.typesVersions){let t=l.typesVersions["*"];if(t){let e=t["*"]??t.index;if(Array.isArray(e)&&e.length>0){let t=s(i,e[0].replace("*","index"));if(m(t))return{entryFile:t,pkgDir:i}}}}}let d=W(e);for(let e of r?[o,h]:[h])try{let r=e.resolve(`${d}/package.json`),i=JSON.parse(t(r,"utf-8")),l=n(r),o=i.types??i.typings??"index.d.ts",f=s(l,o);if(m(f))return{entryFile:f,pkgDir:l}}catch{}throw Error(`Cannot find types for "${e}"`)}function C(t,e){return f(e,t).split(c).join(o.sep).replace(/\.d\.[cm]?ts$/,"").replace(/\.[cm]?tsx?$/,"")}function M(e,r,o,f){let c=new Set,u=[],p=new Set,y=new Set;return!function o(g){let h,x=d(g);if(c.has(x))return;c.add(x);let v=/\.[cm]?tsx?$/.test(x)&&!/\.d\.[cm]?ts$/.test(x);try{if(v){if(!(h=function(t){let e=d(t);if(j.has(e))return j.get(e);let r=function(t){let e=d(t);if(k?.getSourceFile(e))return k;let r=$(),i=k?[...k.getRootFileNames(),e]:[e];return k=a.createProgram(i,r,F||(F=a.createCompilerHost($())),k??void 0)}(e),i=r.getSourceFile(e);if(!i)return j.set(e,""),"";let n="";r.emit(i,(t,e)=>{/\.d\.[cm]?ts$/.test(t)&&(n=e)},void 0,!0);let l=n.replace(/^export\s*\{\s*\};\s*$/gm,"").replace(/^#![^\n]*\n?/,"").trim();return j.set(e,l),l}(x)))return void c.delete(x)}else h=t(g,"utf-8").replace(/^#![^\n]*\n?/,"")}catch{c.delete(x);return}let E=new Map,W=t=>(E.has(t)||E.set(t,function(t,e){let r=s(n(e),t);if(m(r))return r;let i=r.lastIndexOf(".");if(i>Math.max(r.lastIndexOf("/"),r.lastIndexOf("\\"))){let t=r.slice(0,i);for(let e of[".d.ts",".d.mts",".d.cts"]){let r=t+e;if(m(r))return r}}for(let t of[".d.ts",".d.mts",".d.cts"])if(m(r+t))return r+t;for(let t of["index.d.ts","index.d.mts","index.d.cts"]){let e=s(r,t);if(m(e))return e}for(let t of[".ts",".tsx",".mts",".cts"])if(m(r+t))return r+t;for(let t of["index.ts","index.tsx","index.mts","index.cts"]){let e=s(r,t);if(m(e))return e}return null}(t,g)),E.get(t));for(let[,t]of h.matchAll(O))if(t.startsWith(".")){let e=W(t);e&&o(e)}else if(!l(t)&&!i(t)){let e=t.startsWith("@")?t.split("/").slice(0,2).join("/"):t.split("/")[0];p.add(e),t!==e&&y.add(t)}for(let[,t]of h.matchAll(w))i(t)||p.add(t);for(let[,t]of h.matchAll(D)){let e=W(t);e&&o(e)}for(let[,t]of h.matchAll(S))if(!t.startsWith(".")&&!l(t)&&!i(t)){let e=t.startsWith("@")?t.split("/").slice(0,2).join("/"):t.split("/")[0];p.add(e),t!==e&&y.add(t)}let b=t=>{let i=C(t,r);return e?`${e}/${i}`:f?`${f}:${i}`:i},J=h.replace(O,(t,e)=>{if(!e.startsWith("."))return t;let r=W(e);if(!r)return t;let i=b(r),n=`'${e}'`,l=`"${e}"`,s=t.lastIndexOf(n),o=t.lastIndexOf(l);return s>o?`${t.slice(0,s)}'${i}'${t.slice(s+n.length)}`:o>=0?`${t.slice(0,o)}"${i}"${t.slice(o+l.length)}`:t}).replace(D,(t,e)=>{let r=W(e);return r?`/// <reference types="${b(r)}" />`:""}).replace(/\n{3,}/g,"\n\n").trim();if(!J)return;let M=b(x),A=J.replace(/^(?=.)/gm," ");u.push({id:M,content:`declare module "${M}" {
2
- ${A}
3
- }`})}(o),{blocks:u,externalDeps:p,externalSubpaths:y}}function A(e,r,i,l,o,f){let c,{blocks:u,externalDeps:a,externalSubpaths:p}=M(e,i,r,f);for(let t of(e&&(c=`${e}/${C(d(r),i)}`,u.push({id:e,content:`declare module "${e}" {
4
- export * from "${c}";
5
- }`})),a))if(!l.has(t))try{let{entryFile:e,pkgDir:r}=J(t,i);l.add(t),A(t,e,r,l,o)}catch{}for(let e of p)if(!l.has(e))try{let r=function(e,r){let i,l,o=e.startsWith("@")?e.indexOf("/",e.indexOf("/")+1):e.indexOf("/");if(-1===o)return null;let f=e.slice(0,o),d=`./${e.slice(o+1)}`,c=r?g(r):h,u=b(c,f)??(r?b(h,f):null);if(u&&(i=u.pkgDir,l=u.pkgJson),!i||!l)return null;if(l.exports){let t=l.exports[d];if(t){let e="string"==typeof t?void 0:E(t);if(e){let t=s(i,e);if(m(t))return{entryFile:t,pkgDir:i}}let r="string"==typeof t?t:v(t);if(r){let t=s(i,r).replace(/\.([cm]?)js$/,".d.$1ts");if(m(t))return{entryFile:t,pkgDir:i}}}}let a=d.slice(2),p=s(i,a);if(m(p))return{entryFile:p,pkgDir:i};for(let t of[".d.ts",".d.mts",".d.cts"]){let e=p+t;if(m(e))return{entryFile:e,pkgDir:i}}for(let t of["index.d.ts","index.d.mts","index.d.cts"]){let e=s(p,t);if(m(e))return{entryFile:e,pkgDir:i}}let y=W(f);for(let e of r?[c,h]:[h])try{let r=e.resolve(`${y}/package.json`),i=JSON.parse(t(r,"utf-8")),l=n(r);if(i.exports){let t=i.exports[d];if(t){let e="string"==typeof t?void 0:E(t);if(e){let t=s(l,e);if(m(t))return{entryFile:t,pkgDir:l}}}}let o=s(l,a);if(m(o))return{entryFile:o,pkgDir:l};for(let t of[".d.ts",".d.mts",".d.cts"]){let e=o+t;if(m(e))return{entryFile:e,pkgDir:l}}}catch{}return null}(e,i);if(!r)continue;l.add(e);let f=e.startsWith("@")?e.split("/").slice(0,2).join("/"):e.split("/")[0],{blocks:d}=M(f,r.pkgDir,r.entryFile);for(let t of d)o.push(t)}catch{}for(let t of u)o.push(t)}function N(t){let e=d(t),r=u.cwd();if(/\.d\.[cm]?ts$/.test(e)&&m(e))return{entryFile:e,pkgDir:r};let i=e.match(/^(.*)\.[cm]?[tj]sx?$/);if(i){let t=i[1];for(let e of[".d.ts",".d.mts",".d.cts"]){let i=t+e;if(m(i))return{entryFile:i,pkgDir:r}}return/\.[cm]?tsx?$/.test(e)&&m(e)?{entryFile:e,pkgDir:r}:null}for(let t of[".d.ts",".d.mts",".d.cts"])if(m(e+t))return{entryFile:e+t,pkgDir:r};for(let t of["index.d.ts","index.d.mts","index.d.cts"]){let i=s(e,t);if(m(i))return{entryFile:i,pkgDir:r}}throw Error(`Cannot find local file: "${t}"`)}export async function bundleDts(t,e){let r=Array.isArray(t)?t:[t],i=new Set,n=[],s=[];for(let t of r)if("string"==typeof t)if(l(t)||t.startsWith("./")||t.startsWith("../")){let r=d(t);if(i.has(r))continue;i.add(r);let l=N(t);if(!l)continue;let{entryFile:s,pkgDir:o}=l;A("",s,o,i,n,e)}else{if(i.has(t))continue;i.add(t);let{entryFile:e,pkgDir:r}=J(t);A(t,e,r,i,n)}else for(let[r,l]of Object.entries(t)){let t=d(l);if(i.has(t))continue;i.add(t);let o=N(l);if(!o)continue;let{entryFile:f,pkgDir:c}=o,u=C(d(f),c),a=e?`${e}:${u}`:u;s.push({name:r,moduleId:a}),A("",f,c,i,n,e)}for(let{name:t,moduleId:e}of s)n.push({id:t,content:`declare module "${t}" {
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: Record<string, string>;
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 n from"../utils/fetch-module-federation-dts.mjs";import{resolveProgram as i}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 u}from"./exposes-declararion.mjs";import{ExternalRemotesPlugin as c}from"./external-remotes.mjs";let d=s.NormalModuleReplacementPlugin,$=s.container.ModuleFederationPlugin,x={},j=[];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 g=l.moduleFederation?.map(t=>{let o={},s={},l={};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++)x[r.library[e]]=`${o}/${r.library[e]}`;n(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?i(e):e),s&&(l[r]=o[`./${r}`],y(`${t.name}/${r}`,l[r]))}else if("[object Object]"===Object.prototype.toString.call(r)){let e=r.path.startsWith(".");o[`./${r.name}`]=m(e?i(r.path):r.path),e&&(l[`./${r.name}`]=o[`./${r.name}`],y(`${t.name}/${r.name}`,l[`./${r.name}`]))}}t.exposes?.length&&j.push(new u({exposes:l,name:t.name}))}return new $({filename:"remote_entry.js",...t,remotes:s,exposes:o})});g.length>0&&(g.push(new c),g.push(new d(/(.*)/,e=>{x[e.request]&&(e.request=x[e.request])})),j.forEach(e=>g.push(e))),l.env.injectRemoteReactRefresh=Object.keys(x).includes("react-dom");export default g;
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;
@@ -1 +1 @@
1
- import{join as e,sep as r}from"node:path";import{parentPort as o}from"node:worker_threads";import{bundleDts as t}from"../commom/bundle-dts.mjs";import{module_federation_schema as s}from"../process-env.mjs";if(!o)throw Error("This file must be run as a worker");o?.setMaxListeners(0),o.on("message",async({options:a})=>{try{let{name:m,exposes:l}=a,p={},i=[];for(let o in l)if(Object.prototype.hasOwnProperty.call(l,o)){let t=o.replace(/\.tsx?$/i,""),a=e(m,t).replaceAll(r,"/");p[a]=l[o],i.push(`declare module "${s}:${a}" { export * from "${a}"; }`)}let n=await t(p,m);i.unshift(n);let c=i.join("\n\n");o.postMessage(c)}catch{o.postMessage("")}});
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("")}});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moneko/core",
3
- "version": "4.8.6-beta.0",
3
+ "version": "4.8.6-beta.2",
4
4
  "description": "@moneko/core",
5
5
  "main": "lib/index.mjs",
6
6
  "type": "module",