@lemon-fe/vite-plugin-micro-frontend 2.0.0 → 2.0.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/README.md +50 -11
- package/dist/index.d.ts +12 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/runtime-federation.d.ts +30 -2
- package/dist/runtime-federation.js +35 -2
- package/dist/runtime-federation.js.map +1 -1
- package/package.json +12 -32
package/README.md
CHANGED
|
@@ -259,18 +259,57 @@ ReactDOM 不提供 Fast Refresh renderer,单独配置 WebSocket 不能让 Reac
|
|
|
259
259
|
处理,不解析 loader 源码、不追加自定义版本 query、不维护更新事件或通过 key 强制重挂载。
|
|
260
260
|
历史 `runtime/react-refresh-init` 副作用入口由构建直接生成空模块,不再维护单独源码或构建任务。
|
|
261
261
|
|
|
262
|
-
###
|
|
262
|
+
### 微应用本地入口加载线上基座
|
|
263
263
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
React development 端点,基座应在执行自身业务模块前按顺序加载这两个脚本,再加载 antd。
|
|
268
|
-
应用地址应统一用于能力文件、整应用和组件 remote,不能只替换其中一类。
|
|
264
|
+
配套基座通过 `./root` 的 `loadBaseRoot` 准备环境并返回 React 根组件和渲染器。
|
|
265
|
+
微应用提供本地 HTML 和启动模块,并用基座提供的渲染器创建唯一 React Root。
|
|
266
|
+
`developmentShell` 仅在 Vite serve 时设置 `base: '/'` 并安装资源代理,生产 remote 构建保持原样。
|
|
269
267
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
268
|
+
```ts
|
|
269
|
+
microFrontendPlugins({
|
|
270
|
+
appName: 'your-app',
|
|
271
|
+
developmentShell: {
|
|
272
|
+
baseOrigin: 'https://your-base.example.com',
|
|
273
|
+
// gatewayOrigin: 'https://your-gateway.example.com',
|
|
274
|
+
},
|
|
275
|
+
federation: {
|
|
276
|
+
debugReactHost: true,
|
|
277
|
+
application: { rootComponent: 'src/app-root.tsx', buildMode: 'remote' },
|
|
278
|
+
shared: {
|
|
279
|
+
react: { singleton: true, import: false },
|
|
280
|
+
'react-dom': { singleton: true, import: false },
|
|
281
|
+
// Router、kits、earth-base-utils 等共享依赖同样消费基座实例。
|
|
282
|
+
},
|
|
283
|
+
},
|
|
284
|
+
});
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
HTML 用 `<script type="module" vite-ignore src="/src/dev.ts"></script>` 引用本地启动模块,
|
|
288
|
+
让基座先于微应用初始化。启动模块不静态导入业务根组件:
|
|
289
|
+
|
|
290
|
+
```ts
|
|
291
|
+
import { loadDevelopmentRoot } from '@lemon-fe/vite-plugin-micro-frontend/runtime/federation';
|
|
292
|
+
|
|
293
|
+
if (import.meta.env.DEV) {
|
|
294
|
+
const container = document.getElementById('root')!;
|
|
295
|
+
const { BaseRoot, props, createRenderer, createElement } = await loadDevelopmentRoot({
|
|
296
|
+
appName: 'your-app',
|
|
297
|
+
});
|
|
298
|
+
createRenderer(container).render(createElement(BaseRoot, props));
|
|
299
|
+
}
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
已有的 `runtime/development` 导入路径也提供 `loadDevelopmentRoot`,两个路径指向同一份运行时产物。
|
|
303
|
+
|
|
304
|
+
开发入口用独立的 MF 实例加载 `base/root`。组件属性中包含本地 `remote.js` 地址
|
|
305
|
+
和 `./app` 模块名。基座需要显示该应用时,用现有加载器提供共享依赖并加载本地组件。
|
|
306
|
+
请先部署提供 `root/loadBaseRoot` 的配套基座。
|
|
307
|
+
|
|
308
|
+
本地页面使用 `/<appName>/...` 业务路由,深层路径刷新由 Vite HTML fallback 处理。
|
|
309
|
+
`/__earth_base__/` 代理基座配置、remote 和 chunks,`/assets/` 代理基座绝对静态资源,
|
|
310
|
+
`/app-*/` 代理其他微应用;本地能力文件只在根路径和本应用的 Vite `base` 下提供。
|
|
311
|
+
浏览器直连基座配置的网关,需要覆盖时填写 `gatewayOrigin`。
|
|
312
|
+
localhost 与线上存储隔离,在本地基座登录;线上调试 URL 开关已不再使用。
|
|
274
313
|
|
|
275
314
|
### 基座启动前加载 React 开发运行时
|
|
276
315
|
|
|
@@ -307,7 +346,7 @@ renderer 前安装官方 Refresh hook,并保存 renderer,供后续 Vite Refr
|
|
|
307
346
|
启用调试后首次完整加载页面,让基座从启动时使用开发版单例。
|
|
308
347
|
后续组件修改由 Fast Refresh 更新,符合刷新边界的函数组件可保留状态。修改 Hook 结构、
|
|
309
348
|
组件导出契约或无法接受 HMR 的依赖时,仍可能按 Vite/React 官方规则重挂载或整页刷新。
|
|
310
|
-
|
|
349
|
+
访问正常线上基座即可使用其原有运行时。不要在页面运行中替换 `window.React`/`window.ReactDOM`。
|
|
311
350
|
|
|
312
351
|
`debugReactHost` 当前面向 React 18 UMD 宿主,不适用于 React 19 或将 React 打包进宿主 JS 的项目;
|
|
313
352
|
这类宿主需要提供自己的开发调试启动入口,确保 Refresh hook、development ReactDOM 和共享依赖
|
package/dist/index.d.ts
CHANGED
|
@@ -42,6 +42,14 @@ type DynamicBaseConfig = {
|
|
|
42
42
|
removeIndexCssPreload?: boolean;
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
+
interface DevelopmentShellConfig {
|
|
46
|
+
/** 已部署支持 base/root 的基座地址。 */
|
|
47
|
+
baseOrigin: string;
|
|
48
|
+
/** 默认使用基座配置;需要覆盖时显式指定浏览器直连的网关。 */
|
|
49
|
+
gatewayOrigin?: string;
|
|
50
|
+
remoteName?: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
45
53
|
/**
|
|
46
54
|
* 远程模块配置
|
|
47
55
|
*/
|
|
@@ -186,6 +194,8 @@ interface MfGeneratorOptions {
|
|
|
186
194
|
interface MicroFrontendPluginOptions {
|
|
187
195
|
/** 应用名称 */
|
|
188
196
|
appName: string;
|
|
197
|
+
/** 本地入口加载已部署基座的根组件,仅 serve 生效。 */
|
|
198
|
+
developmentShell?: DevelopmentShellConfig;
|
|
189
199
|
/** @deprecated 未参与插件行为;开发模式由 Vite command 决定。 */
|
|
190
200
|
useDevMode?: boolean;
|
|
191
201
|
/** 模块联邦配置 */
|
|
@@ -220,6 +230,7 @@ declare function mfGeneratorPlugin(options: MfGeneratorOptions): VitePlugin;
|
|
|
220
230
|
|
|
221
231
|
interface FederationPluginContext {
|
|
222
232
|
appName?: string;
|
|
233
|
+
developmentShell?: boolean;
|
|
223
234
|
}
|
|
224
235
|
/**
|
|
225
236
|
* 模块联邦插件
|
|
@@ -285,4 +296,4 @@ declare const MICRO_FRONTEND_OPTIONS_KEY = "__microFrontendOptions";
|
|
|
285
296
|
declare function microFrontendPlugins(options: MicroFrontendPluginOptions): PluginOption[];
|
|
286
297
|
|
|
287
298
|
export { MICRO_FRONTEND_OPTIONS_KEY, devHmrPlugin, federationPlugin, generateMf, generateRoutesToFile, getDynamicBasePlugins, getRoutes, mfGeneratorPlugin, microFrontendPlugins, pagesRoutesPlugin };
|
|
288
|
-
export type { ComponentMetadata, DynamicBaseConfig, FederationApplicationConfig, FederationConfig, IRoute, MfGeneratorOptions, MicroFrontendPluginOptions, RemoteConfig, RouteConfig, RoutesPluginOptions, RoutesTemplateOptions, VitePlugin };
|
|
299
|
+
export type { ComponentMetadata, DevelopmentShellConfig, DynamicBaseConfig, FederationApplicationConfig, FederationConfig, IRoute, MfGeneratorOptions, MicroFrontendPluginOptions, RemoteConfig, RouteConfig, RoutesPluginOptions, RoutesTemplateOptions, VitePlugin };
|
package/dist/index.js
CHANGED
|
@@ -10,5 +10,5 @@ import*as e from"path";import{resolve as t,relative as n,sep as r,isAbsolute as
|
|
|
10
10
|
|
|
11
11
|
return ${L(i)};
|
|
12
12
|
})(${w(this.node)})
|
|
13
|
-
`;return this.replaceWith(p)[0].get("arguments.0")},to.splitExportDeclaration=function(){if(!this.isExportDeclaration()||this.isExportAllDeclaration())throw new Error("Only default and named export declarations can be split.");if(this.isExportNamedDeclaration()&&this.get("specifiers").length>0)throw new Error("It doesn't make sense to split exported specifiers.");const e=this.get("declaration");if(this.isExportDefaultDeclaration()){const t=e.isFunctionDeclaration()||e.isClassDeclaration(),n=e.isFunctionExpression()||e.isClassExpression(),r=e.isScope()?e.scope.parent:e.scope;let i=e.node.id,s=!1;i?n&&r.hasBinding(i.name)&&(s=!0,i=r.generateUidIdentifier(i.name)):(s=!0,i=r.generateUidIdentifier("default"),(t||n)&&(e.node.id=L(i)));const a=t?e.node:M("var",[F(L(i),e.node)]),o=B(null,[j(L(i),u("default"))]);return this.insertAfter(o),this.replaceWith(a),s&&r.registerDeclaration(this),this}if(this.get("specifiers").length>0)throw new Error("It doesn't make sense to split exported specifiers.");const t=e.getOuterBindingIdentifiers(),n=Object.keys(t).map(e=>j(u(e),u(e))),r=B(null,n);return this.insertAfter(r),this.replaceWith(e.node),this},to.toComputedKey=function(){let e;if(this.isMemberExpression())e=this.node.property;else{if(!this.isProperty()&&!this.isMethod())throw new ReferenceError("todo");e=this.node.key}this.node.computed||d(e)&&(e=v(e.name));return e},to.unwrapFunctionEnvironment=function(){if(!this.isArrowFunctionExpression()&&!this.isFunctionExpression()&&!this.isFunctionDeclaration())throw this.buildCodeFrameError("Can only unwrap the environment of a function.");K(this)};var e=Yr(),t=function(){if(xo)return no;xo=1,Object.defineProperty(no,"__esModule",{value:!0}),no.statements=no.statement=no.smart=no.program=no.expression=no.default=void 0;var e=io(),t=vo();const n=no.smart=(0,t.default)(e.smart),r=no.statement=(0,t.default)(e.statement),i=no.statements=(0,t.default)(e.statements),s=no.expression=(0,t.default)(e.expression),a=no.program=(0,t.default)(e.program);return no.default=Object.assign(n.bind(void 0),{smart:n,statement:r,statements:i,expression:s,program:a,ast:n.ast}),no}(),n=qi(),r=Uo();const{arrowFunctionExpression:i,assignmentExpression:s,binaryExpression:a,blockStatement:o,callExpression:l,conditionalExpression:c,expressionStatement:p,identifier:u,isIdentifier:d,jsxIdentifier:h,logicalExpression:f,LOGICAL_OPERATORS:m,memberExpression:y,metaProperty:T,numericLiteral:g,objectExpression:S,restElement:x,returnStatement:b,sequenceExpression:E,spreadElement:P,stringLiteral:v,super:A,thisExpression:C,toExpression:w,unaryExpression:I,toBindingIdentifierName:N,isFunction:k,isAssignmentPattern:O,isRestElement:_,getFunctionName:D,cloneNode:L,variableDeclaration:M,variableDeclarator:F,exportNamedDeclaration:B,exportSpecifier:j,inherits:R}=e;to.arrowFunctionToShadowed=function(){this.isArrowFunctionExpression()&&this.arrowFunctionToExpression()};const U=(0,n.environmentVisitor)({CallExpression(e,{allSuperCalls:t}){e.get("callee").isSuper()&&t.push(e)}});function K(e,t=!0,n=!0,r=!0){let o,p=e.findParent(e=>e.isArrowFunctionExpression()?(null!=o||(o=e),!1):e.isFunction()||e.isProgram()||e.isClassProperty({static:!1})||e.isClassPrivateProperty({static:!1}));const d=p.isClassMethod({kind:"constructor"});if(p.isClassProperty()||p.isClassPrivateProperty())if(o)p=o;else{if(!n)throw e.buildCodeFrameError("Unable to transform arrow inside class property");e.replaceWith(l(i([],w(e.node)),[])),p=e.get("callee"),e=p.get("body")}const{thisPaths:S,argumentsPaths:b,newTargetPaths:N,superProps:k,superCalls:O}=function(e){const t=[],n=[],r=[],i=[],s=[];return e.traverse(W,{thisPaths:t,argumentsPaths:n,newTargetPaths:r,superProps:i,superCalls:s}),{thisPaths:t,argumentsPaths:n,newTargetPaths:r,superProps:i,superCalls:s}}(e);if(d&&O.length>0){if(!n)throw O[0].buildCodeFrameError("When using '@babel/plugin-transform-arrow-functions', it's not possible to compile `super()` in an arrow function without compiling classes.\nPlease add '@babel/plugin-transform-classes' to your Babel configuration.");if(!r)throw O[0].buildCodeFrameError("When using '@babel/plugin-transform-parameters', it's not possible to compile `super()` in an arrow function with default or rest parameters without compiling classes.\nPlease add '@babel/plugin-transform-classes' to your Babel configuration.");const e=[];p.traverse(U,{allSuperCalls:e});const t=function(e){return q(e,"supercall",()=>{const t=e.scope.generateUidIdentifier("args");return i([x(t)],l(A(),[P(u(t.name))]))})}(p);e.forEach(e=>{const n=u(t);n.loc=e.node.callee.loc,e.get("callee").replaceWith(n)})}if(b.length>0){const e=q(p,"arguments",()=>{const e=()=>u("arguments");return p.scope.path.isProgram()?c(a("===",I("typeof",e()),v("undefined")),p.scope.buildUndefinedNode(),e()):e()});b.forEach(t=>{const n=u(e);n.loc=t.node.loc,t.replaceWith(n)})}if(N.length>0){const e=q(p,"newtarget",()=>T(u("new"),u("target")));N.forEach(t=>{const n=u(e);n.loc=t.node.loc,t.replaceWith(n)})}if(k.length>0){if(!n)throw k[0].buildCodeFrameError("When using '@babel/plugin-transform-arrow-functions', it's not possible to compile `super.prop` in an arrow function without compiling classes.\nPlease add '@babel/plugin-transform-classes' to your Babel configuration.");k.reduce((e,t)=>e.concat(function(e){if(e.parentPath.isAssignmentExpression()&&"="!==e.parentPath.node.operator){const n=e.parentPath,r=n.node.operator.slice(0,-1),i=n.node.right,a=function(e){return m.includes(e)}(r);if(e.node.computed){const o=e.scope.generateDeclaredUidIdentifier("tmp"),{object:l,property:c}=e.node;n.get("left").replaceWith(y(l,s("=",o,c),!0)),n.get("right").replaceWith(t(a?"=":r,y(l,u(o.name),!0),i))}else{const s=e.node.object,o=e.node.property;n.get("left").replaceWith(y(s,o)),n.get("right").replaceWith(t(a?"=":r,y(s,u(o.name)),i))}return a?n.replaceWith(f(r,n.node.left,n.node.right)):n.node.operator="=",[n.get("left"),n.get("right").get("left")]}if(e.parentPath.isUpdateExpression()){const t=e.parentPath,n=e.scope.generateDeclaredUidIdentifier("tmp"),r=e.node.computed?e.scope.generateDeclaredUidIdentifier("prop"):null,i=[s("=",n,y(e.node.object,r?s("=",r,e.node.property):e.node.property,e.node.computed)),s("=",y(e.node.object,r?u(r.name):e.node.property,e.node.computed),a(e.parentPath.node.operator[0],u(n.name),g(1)))];e.parentPath.node.prefix||i.push(u(n.name)),t.replaceWith(E(i));return[t.get("expressions.0.right"),t.get("expressions.1.left")]}return[e];function t(e,t,n){return"="===e?s("=",t,n):a(e,t,n)}}(t)),[]).forEach(e=>{const t=e.node.computed?"":e.get("property").node.name,n=e.parentPath,r=n.isAssignmentExpression({left:e.node}),a=n.isCallExpression({callee:e.node}),o=n.isTaggedTemplateExpression({tag:e.node}),c=function(e,t,n){const r=t?"set":"get";return q(e,`superprop_${r}:${n||""}`,()=>{const r=[];let a;if(n)a=y(A(),u(n));else{const t=e.scope.generateUidIdentifier("prop");r.unshift(t),a=y(A(),u(t.name),!0)}if(t){const t=e.scope.generateUidIdentifier("value");r.push(t),a=s("=",a,u(t.name))}return i(r,a)})}(p,r,t),d=[];if(e.node.computed&&d.push(e.get("property").node),r){const e=n.node.right;d.push(e)}const h=l(u(c),d);a?(n.unshiftContainer("arguments",C()),e.replaceWith(y(h,u("call"))),S.push(n.get("arguments.0"))):r?n.replaceWith(h):o?(e.replaceWith(l(y(h,u("bind"),!1),[C()])),S.push(e.get("arguments.0"))):e.replaceWith(h)})}let _;return(S.length>0||!t)&&(_=function(e,t){return q(e,"this",n=>{if(!t||!V(e))return C();e.traverse($,{supers:new WeakSet,thisBinding:n})})}(p,d),(t||d&&V(p))&&(S.forEach(e=>{const t=e.isJSX()?h(_):u(_);t.loc=e.node.loc,e.replaceWith(t)}),t||(_=null))),{thisBinding:_,fnPath:e}}function V(e){return e.isClassMethod()&&!!e.parentPath.parentPath.node.superClass}const $=(0,n.environmentVisitor)({CallExpression(e,{supers:t,thisBinding:n}){e.get("callee").isSuper()&&(t.has(e.node)||(t.add(e.node),e.replaceWithMultiple([e.node,s("=",u(n),u("this"))])))}});function q(e,t,n){const r="binding:"+t;let i=e.getData(r);if(!i){const s=e.scope.generateUidIdentifier(t);i=s.name,e.setData(r,i),e.scope.push({id:s,init:n(i)})}return i}const W=(0,n.environmentVisitor)({ThisExpression(e,{thisPaths:t}){t.push(e)},JSXIdentifier(e,{thisPaths:t}){"this"===e.node.name&&(e.parentPath.isJSXMemberExpression({object:e.node})||e.parentPath.isJSXOpeningElement({name:e.node}))&&t.push(e)},CallExpression(e,{superCalls:t}){e.get("callee").isSuper()&&t.push(e)},MemberExpression(e,{superProps:t}){e.get("object").isSuper()&&t.push(e)},Identifier(e,{argumentsPaths:t}){if(!e.isReferencedIdentifier({name:"arguments"}))return;let n=e.scope;do{if(n.hasOwnBinding("arguments"))return void n.rename("arguments");if(n.path.isFunction()&&!n.path.isArrowFunctionExpression())break}while(n=n.parent);t.push(e)},MetaProperty(e,{newTargetPaths:t}){e.get("meta").isIdentifier({name:"new"})&&e.get("property").isIdentifier({name:"target"})&&t.push(e)}});const J={"ReferencedIdentifier|BindingIdentifier"(e,t){e.node.name===t.name&&(t.needsRename=!0,e.stop())},Scope(e,t){e.scope.hasOwnBinding(t.name)&&e.skip()}};return to}var Co,wo={};function Io(){return Co||(Co=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e._guessExecutionStatusRelativeTo=function(e){return m(this,e,new Map)},e._resolve=y,e.canHaveVariableDeclarationOrExpression=function(){return("init"===this.key||"left"===this.key)&&this.parentPath.isFor()},e.canSwapBetweenExpressionAndStatement=function(e){if("body"!==this.key||!this.parentPath.isArrowFunctionExpression())return!1;if(this.isExpression())return i(e);if(this.isBlockStatement())return s(e);return!1},e.getSource=function(){const e=this.node;if(e.end){const t=this.hub.getCode();if(t)return t.slice(e.start,e.end)}return""},e.isCompletionRecord=function(e){let t=this,n=!0;do{const{type:r,container:i}=t;if(!n&&(t.isFunction()||"StaticBlock"===r))return!!e;if(n=!1,Array.isArray(i)&&t.key!==i.length-1)return!1}while((t=t.parentPath)&&!t.isProgram()&&!t.isDoExpression());return!0},e.isConstantExpression=function(){if(this.isIdentifier()){const e=this.scope.getBinding(this.node.name);return!!e&&e.constant}if(this.isLiteral())return!this.isRegExpLiteral()&&(!this.isTemplateLiteral()||this.get("expressions").every(e=>e.isConstantExpression()));if(this.isUnaryExpression())return"void"===this.node.operator&&this.get("argument").isConstantExpression();if(this.isBinaryExpression()){const{operator:e}=this.node;return"in"!==e&&"instanceof"!==e&&this.get("left").isConstantExpression()&&this.get("right").isConstantExpression()}if(this.isMemberExpression())return!this.node.computed&&this.get("object").isIdentifier({name:"Symbol"})&&!this.scope.hasBinding("Symbol",{noGlobals:!0});if(this.isCallExpression())return 1===this.node.arguments.length&&this.get("callee").matchesPattern("Symbol.for")&&!this.scope.hasBinding("Symbol",{noGlobals:!0})&&this.get("arguments")[0].isStringLiteral();return!1},e.isInStrictMode=function(){const e=(this.isProgram()?this:this.parentPath).find(e=>{if(e.isProgram({sourceType:"module"}))return!0;if(e.isClass())return!0;if(e.isArrowFunctionExpression()&&!e.get("body").isBlockStatement())return!1;let t;if(e.isFunction())t=e.node.body;else{if(!e.isProgram())return!1;t=e.node}for(const e of t.directives)if("use strict"===e.value.value)return!0;return!1});return!!e},e.isNodeType=function(e){return c(this.type,e)},e.isStatementOrBlock=function(){return!this.parentPath.isLabeledStatement()&&!i(this.container)&&n.includes(this.key)},e.isStatic=function(){return this.scope.isStatic(this.node)},e.matchesPattern=function(e,t){return p(this.node,e,t)},e.referencesImport=function(e,t){if(!this.isReferencedIdentifier()){if(this.isJSXMemberExpression()&&this.node.property.name===t||(this.isMemberExpression()||this.isOptionalMemberExpression())&&(this.node.computed?l(this.node.property,{value:t}):this.node.property.name===t)){const t=this.get("object");return t.isReferencedIdentifier()&&t.referencesImport(e,"*")}return!1}const n=this.scope.getBinding(this.node.name);if(!n||"module"!==n.kind)return!1;const r=n.path,i=r.parentPath;if(!i.isImportDeclaration())return!1;if(i.node.source.value!==e)return!1;if(!t)return!0;if(r.isImportDefaultSpecifier()&&"default"===t)return!0;if(r.isImportNamespaceSpecifier()&&"*"===t)return!0;if(r.isImportSpecifier()&&a(r.node.imported,{name:t}))return!0;return!1},e.resolve=function(e,t){return y.call(this,e,t)||this},e.willIMaybeExecuteBefore=function(e){return"after"!==this._guessExecutionStatusRelativeTo(e)};var t=Yr();const{STATEMENT_OR_BLOCK_KEYS:n,VISITOR_KEYS:r,isBlockStatement:i,isExpression:s,isIdentifier:a,isLiteral:o,isStringLiteral:l,isType:c,matchesPattern:p}=t;function u(e){return e.isProgram()?e:(e.parentPath.scope.getFunctionParent()||e.parentPath.scope.getProgramParent()).path}function d(e,t){switch(e){case"LogicalExpression":case"AssignmentPattern":return"right"===t;case"ConditionalExpression":case"IfStatement":return"consequent"===t||"alternate"===t;case"WhileStatement":case"DoWhileStatement":case"ForInStatement":case"ForOfStatement":return"body"===t;case"ForStatement":return"body"===t||"update"===t;case"SwitchStatement":return"cases"===t;case"TryStatement":return"handler"===t;case"OptionalMemberExpression":return"property"===t;case"OptionalCallExpression":return"arguments"===t;default:return!1}}function h(e,t){for(let n=0;n<t;n++){const t=e[n];if(d(t.parent.type,t.parentKey))return!0}return!1}e.has=function(e){var t;const n=null==(t=this.node)?void 0:t[e];return n&&Array.isArray(n)?!!n.length:!!n},e.is=e.has,e.isnt=function(e){return!this.has(e)},e.equals=function(e,t){return this.node[e]===t};const f=Symbol();function m(e,t,n){const i={this:u(e),target:u(t)};if(i.target.node!==i.this.node)return function(e,t,n){let r,i=n.get(e.node);if(i){if(r=i.get(t.node))return r===f?"unknown":r}else n.set(e.node,i=new Map);i.set(t.node,f);const s=function(e,t,n){if(!t.isFunctionDeclaration())return"before"===m(e,t,n)?"before":"unknown";if(t.parentPath.isExportDeclaration())return"unknown";const r=t.scope.getBinding(t.node.id.name);if(!r.references)return"before";const i=r.referencePaths;let s;for(const r of i){if(!!r.find(e=>e.node===t.node))continue;if("callee"!==r.key||!r.parentPath.isCallExpression())return"unknown";const i=m(e,r,n);if(s&&s!==i)return"unknown";s=i}return s}(e,t,n);return i.set(t.node,s),s}(e,i.target,n);const s={target:t.getAncestry(),this:e.getAncestry()};if(s.target.includes(e))return"after";if(s.this.includes(t))return"before";let a;const o={target:0,this:0};for(;!a&&o.this<s.this.length;){const e=s.this[o.this];o.target=s.target.indexOf(e),o.target>=0?a=e:o.this++}if(!a)throw new Error("Internal Babel error - The two compared nodes don't appear to belong to the same program.");if(h(s.this,o.this-1)||h(s.target,o.target-1))return"unknown";const l={this:s.this[o.this-1],target:s.target[o.target-1]};if(l.target.listKey&&l.this.listKey&&l.target.container===l.this.container)return l.target.key>l.this.key?"before":"after";const c=r[a.type],p=c.indexOf(l.this.parentKey);return c.indexOf(l.target.parentKey)>p?"before":"after"}function y(e,t){var n;if(null==(n=t)||!n.includes(this))if((t=t||[]).push(this),this.isVariableDeclarator()){if(this.get("id").isIdentifier())return this.get("init").resolve(e,t)}else if(this.isReferencedIdentifier()){const n=this.scope.getBinding(this.node.name);if(!n)return;if(!n.constant)return;if("module"===n.kind)return;if(n.path!==this){const r=n.path.resolve(e,t);if(this.find(e=>e.node===r.node))return;return r}}else{if(this.isTypeCastExpression())return this.get("expression").resolve(e,t);if(e&&this.isMemberExpression()){const n=this.toComputedKey();if(!o(n))return;const r=n.value,i=this.get("object").resolve(e,t);if(i.isObjectExpression()){const n=i.get("properties");for(const i of n){if(!i.isProperty())continue;const n=i.get("key");let s=i.isnt("computed")&&n.isIdentifier({name:r});if(s=s||n.isLiteral({value:r}),s)return i.get("value").resolve(e,t)}}else if(i.isArrayExpression()&&!isNaN(+r)){const n=i.get("elements")[r];if(n)return n.resolve(e,t)}}}}}(wo)),wo}var No,ko={};function Oo(){if(No)return ko;No=1,Object.defineProperty(ko,"__esModule",{value:!0}),ko._getKey=f,ko._getPattern=m,ko.get=function(e,t=!0){!0===t&&(t=this.context);const n=e.split(".");return 1===n.length?f.call(this,e,t):m.call(this,n,t)},ko.getAllNextSiblings=function(){let e=this.key,t=this.getSibling(++e);const n=[];for(;t.node;)n.push(t),t=this.getSibling(++e);return n},ko.getAllPrevSiblings=function(){let e=this.key,t=this.getSibling(--e);const n=[];for(;t.node;)n.push(t),t=this.getSibling(--e);return n},ko.getAssignmentIdentifiers=function(){return n(this.node)},ko.getBindingIdentifierPaths=function(e=!1,t=!1){const n=[this],i=Object.create(null);for(;n.length;){const s=n.shift();if(!s)continue;if(!s.node)continue;const a=r.keys[s.node.type];if(s.isIdentifier())if(e){(i[s.node.name]=i[s.node.name]||[]).push(s)}else i[s.node.name]=s;else{if(s.isExportDeclaration()){const e=s.get("declaration");e.isDeclaration()&&n.push(e);continue}if(t){if(s.isFunctionDeclaration()){n.push(s.get("id"));continue}if(s.isFunctionExpression())continue}if(a)for(let e=0;e<a.length;e++){const t=a[e],r=s.get(t);Array.isArray(r)?n.push(...r):r.node&&n.push(r)}}}return i},ko.getBindingIdentifiers=function(e){return r(this.node,e)},ko.getCompletionRecords=function(e=!1){return h(this,{canHaveBreak:!1,shouldPopulateBreak:!1,inCaseClause:!1,shouldPreserveBreak:e}).map(e=>e.path)},ko.getNextSibling=function(){return this.getSibling(this.key+1)},ko.getOpposite=function(){if("left"===this.key)return this.getSibling("right");if("right"===this.key)return this.getSibling("left");return null},ko.getOuterBindingIdentifierPaths=function(e=!1){return this.getBindingIdentifierPaths(e,!0)},ko.getOuterBindingIdentifiers=function(e){return i(this.node,e)},ko.getPrevSibling=function(){return this.getSibling(this.key-1)},ko.getSibling=function(t){return e.default.get({parentPath:this.parentPath,parent:this.parent,container:this.container,listKey:this.listKey,key:t}).setContext(this.context)};var e=jo(),t=Yr();const{getAssignmentIdentifiers:n,getBindingIdentifiers:r,getOuterBindingIdentifiers:i,numericLiteral:s,unaryExpression:a}=t,o=0,l=1;function c(e,t,n){return e&&t.push(...h(e,n)),t}function p(e){e.forEach(e=>{e.type=l})}function u(e,t){e.forEach(e=>{e.path.isBreakStatement({label:null})&&(t?e.path.replaceWith(a("void",s(0))):e.path.remove())})}function d(e,t){const n=[];if(t.canHaveBreak){let r=[];for(let i=0;i<e.length;i++){const s=e[i],a=Object.assign({},t,{inCaseClause:!1});s.isBlockStatement()&&(t.inCaseClause||t.shouldPopulateBreak)?a.shouldPopulateBreak=!0:a.shouldPopulateBreak=!1;const c=h(s,a);if(c.length>0&&c.every(e=>e.type===l)){r.length>0&&c.every(e=>e.path.isBreakStatement({label:null}))?(p(r),n.push(...r),r.some(e=>e.path.isDeclaration())&&(n.push(...c),t.shouldPreserveBreak||u(c,!0)),t.shouldPreserveBreak||u(c,!1)):(n.push(...c),t.shouldPopulateBreak||t.shouldPreserveBreak||u(c,!0));break}if(i===e.length-1)n.push(...c);else{r=[];for(let e=0;e<c.length;e++){const t=c[e];t.type===l&&n.push(t),t.type===o&&r.push(t)}}}}else if(e.length)for(let r=e.length-1;r>=0;r--){const i=h(e[r],t);if(i.length>1||1===i.length&&!i[0].path.isVariableDeclaration()&&!i[0].path.isEmptyStatement()){n.push(...i);break}}return n}function h(e,t){let n=[];if(e.isIfStatement())n=c(e.get("consequent"),n,t),n=c(e.get("alternate"),n,t);else{if(e.isDoExpression()||e.isFor()||e.isWhile()||e.isLabeledStatement())return c(e.get("body"),n,t);if(e.isProgram()||e.isBlockStatement())return d(e.get("body"),t);if(e.isFunction())return h(e.get("body"),t);if(e.isTryStatement())n=c(e.get("block"),n,t),n=c(e.get("handler"),n,t);else{if(e.isCatchClause())return c(e.get("body"),n,t);if(e.isSwitchStatement())return function(e,t,n){let r=[];for(let i=0;i<e.length;i++){const s=h(e[i],n),a=[],c=[];for(const e of s)e.type===o&&a.push(e),e.type===l&&c.push(e);a.length&&(r=a),t.push(...c)}return t.push(...r),t}(e.get("cases"),n,t);if(e.isSwitchCase())return d(e.get("consequent"),{canHaveBreak:!0,shouldPopulateBreak:!1,inCaseClause:!0,shouldPreserveBreak:t.shouldPreserveBreak});e.isBreakStatement()?n.push(function(e){return{type:l,path:e}}(e)):n.push(function(e){return{type:o,path:e}}(e))}}return n}function f(t,n){const r=this.node,i=r[t];return Array.isArray(i)?i.map((s,a)=>e.default.get({listKey:t,parentPath:this,parent:r,container:i,key:a}).setContext(n)):e.default.get({parentPath:this,parent:r,container:r,key:t}).setContext(n)}function m(e,t){let n=this;for(const r of e)n="."===r?n.parentPath:Array.isArray(n)?n[r]:n.get(r,t);return n}return ko}var _o,Do,Lo,Mo,Fo,Bo={};function jo(){if(Do)return Si;Do=1,Object.defineProperty(Si,"__esModule",{value:!0}),Si.default=Si.SHOULD_STOP=Si.SHOULD_SKIP=Si.REMOVED=void 0;var e=bi(),t=Mi(),n=qo(),r=ts(),i=Yr(),s=i,a=Gi(),o=ma(),l=function(){if(ya)return Ta;ya=1,Object.defineProperty(Ta,"__esModule",{value:!0}),Ta.find=function(e){let t=this;do{if(e(t))return t}while(t=t.parentPath);return null},Ta.findParent=function(e){let t=this;for(;t=t.parentPath;)if(e(t))return t;return null},Ta.getAncestry=function(){let e=this;const t=[];do{t.push(e)}while(e=e.parentPath);return t},Ta.getDeepestCommonAncestorFrom=function(e,t){if(!e.length)return this;if(1===e.length)return e[0];let n,r,i=1/0;const s=e.map(e=>{const t=[];do{t.unshift(e)}while((e=e.parentPath)&&e!==this);return t.length<i&&(i=t.length),t}),a=s[0];e:for(let e=0;e<i;e++){const t=a[e];for(const n of s)if(n[e]!==t)break e;n=e,r=t}if(r)return t?t(r,n,s):r;throw new Error("Couldn't find intersection")},Ta.getEarliestCommonAncestorFrom=function(e){return this.getDeepestCommonAncestorFrom(e,function(e,n,r){let i;const s=t[e.type];for(const e of r){const t=e[n+1];i?(t.listKey&&i.listKey===t.listKey&&t.key<i.key||s.indexOf(i.parentKey)>s.indexOf(t.parentKey))&&(i=t):i=t}return i})},Ta.getFunctionParent=function(){return this.findParent(e=>e.isFunction())},Ta.getStatementParent=function(){let e=this;do{if(!e.parentPath||Array.isArray(e.container)&&e.isStatement())break;e=e.parentPath}while(e);if(e&&(e.isProgram()||e.isFile()))throw new Error("File/Program node, we can't possibly find a statement parent to this");return e},Ta.inType=function(...e){let t=this;for(;t;){if(e.includes(t.node.type))return!0;t=t.parentPath}return!1},Ta.isAncestor=function(e){return e.isDescendant(this)},Ta.isDescendant=function(e){return!!this.findParent(t=>t===e)};var e=Yr();const{VISITOR_KEYS:t}=e;return Ta}(),c=function(){if(ba)return Ea;ba=1,Object.defineProperty(Ea,"__esModule",{value:!0}),Ea._getTypeAnnotation=P,Ea.baseTypeStrictlyMatches=function(e){const t=this.getTypeAnnotation(),n=e.getTypeAnnotation();return!(r(t)||!o(t))&&n.type===t.type},Ea.couldBeBaseType=function(e){const t=this.getTypeAnnotation();if(r(t))return!0;if(g(t)){for(const n of t.types)if(r(n)||v(e,n,!0))return!0;return!1}return v(e,t,!0)},Ea.getTypeAnnotation=function(){let e=this.getData("typeAnnotation");return null!=e||(e=P.call(this)||n(),(T(e)||f(e))&&(e=e.typeAnnotation),this.setData("typeAnnotation",e)),e},Ea.isBaseType=function(e,t){return v(e,this.getTypeAnnotation(),t)},Ea.isGenericType=function(e){const t=this.getTypeAnnotation();return!("Array"!==e||!(h(t)||i(t)||y(t)))||(l(t)&&c(t.id,{name:e})||m(t)&&c(t.typeName,{name:e}))};var e=Ia(),t=Yr();const{anyTypeAnnotation:n,isAnyTypeAnnotation:r,isArrayTypeAnnotation:i,isBooleanTypeAnnotation:s,isEmptyTypeAnnotation:a,isFlowBaseAnnotation:o,isGenericTypeAnnotation:l,isIdentifier:c,isMixedTypeAnnotation:p,isNumberTypeAnnotation:u,isStringTypeAnnotation:d,isTSArrayType:h,isTSTypeAnnotation:f,isTSTypeReference:m,isTupleTypeAnnotation:y,isTypeAnnotation:T,isUnionTypeAnnotation:g,isVoidTypeAnnotation:S,stringTypeAnnotation:x,voidTypeAnnotation:b}=t,E=new WeakSet;function P(){const t=this.node;if(t){if(t.typeAnnotation)return t.typeAnnotation;if(!E.has(t)){E.add(t);try{var r;let n=e[t.type];if(n)return n.call(this,t);if(n=e[this.parentPath.type],null!=(r=n)&&r.validParent)return this.parentPath.getTypeAnnotation()}finally{E.delete(t)}}}else if("init"===this.key&&this.parentPath.isVariableDeclarator()){const e=this.parentPath.parentPath,t=e.parentPath;return"left"===e.key&&t.isForInStatement()?x():"left"===e.key&&t.isForOfStatement()?n():b()}}function v(e,t,n){if("string"===e)return d(t);if("number"===e)return u(t);if("boolean"===e)return s(t);if("any"===e)return r(t);if("mixed"===e)return p(t);if("empty"===e)return a(t);if("void"===e)return S(t);if(n)return!1;throw new Error(`Unknown base type ${e}`)}return Ea}(),p=za(),u=Za(),d=Ao(),h=Io(),f=Uo(),m=f,y=qa(),T=Ha(),g=Oo(),S=function(){if(_o)return Bo;_o=1,Object.defineProperty(Bo,"__esModule",{value:!0}),Bo.addComment=function(e,n,r){t(this.node,e,n,r)},Bo.addComments=function(e,t){n(this.node,e,t)},Bo.shareCommentsWithSiblings=function(){if("string"==typeof this.key)return;const e=this.node;if(!e)return;const t=e.trailingComments,n=e.leadingComments;if(!t&&!n)return;const i=this.getSibling(this.key-1),s=this.getSibling(this.key+1),a=Boolean(i.node),o=Boolean(s.node);a&&(n&&i.addComments("trailing",r(n,i.node.trailingComments)),t&&!o&&i.addComments("trailing",t)),o&&(t&&s.addComments("leading",r(t,s.node.leadingComments)),n&&!a&&s.addComments("leading",n))};var e=Yr();const{addComment:t,addComments:n}=e;function r(e,t){if(null==t||!t.length)return e;const n=new Set(t);return e.filter(e=>!n.has(e))}return Bo}(),x=$i();const{validate:b}=i,E=t("babel");Si.REMOVED=1,Si.SHOULD_STOP=2,Si.SHOULD_SKIP=4;const P=Si.default=class e{constructor(e,t){this.contexts=[],this.state=null,this._traverseFlags=0,this.skipKeys=null,this.parentPath=null,this.container=null,this.listKey=null,this.key=null,this.node=null,this.type=null,this._store=null,this.parent=t,this.hub=e,this.data=null,this.context=null,this.scope=null}get removed(){return(1&this._traverseFlags)>0}set removed(e){e?this._traverseFlags|=1:this._traverseFlags&=-2}get shouldStop(){return(2&this._traverseFlags)>0}set shouldStop(e){e?this._traverseFlags|=2:this._traverseFlags&=-3}get shouldSkip(){return(4&this._traverseFlags)>0}set shouldSkip(e){e?this._traverseFlags|=4:this._traverseFlags&=-5}static get({hub:t,parentPath:n,parent:r,container:i,listKey:s,key:o}){if(!t&&n&&(t=n.hub),!r)throw new Error("To get a node path the parent needs to exist");const l=i[o],c=a.getOrCreateCachedPaths(r,n);let p=c.get(l);return p||(p=new e(t,r),l&&c.set(l,p)),f.setup.call(p,n,i,s,o),p}getScope(e){return this.isScope()?new r.default(this):e}setData(e,t){return null==this.data&&(this.data=Object.create(null)),this.data[e]=t}getData(e,t){null==this.data&&(this.data=Object.create(null));let n=this.data[e];return void 0===n&&void 0!==t&&(n=this.data[e]=t),n}hasNode(){return null!=this.node}buildCodeFrameError(e,t=SyntaxError){return this.hub.buildError(this.node,e,t)}traverse(e,t){(0,n.default)(this.node,e,this.scope,t,this)}set(e,t){b(this.node,e,t),this.node[e]=t}getPathLocation(){const e=[];let t=this;do{let n=t.key;t.inList&&(n=`${t.listKey}[${n}]`),e.unshift(n)}while(t=t.parentPath);return e.join(".")}debug(e){E.enabled&&E(`${this.getPathLocation()} ${this.type}: ${e}`)}toString(){return(0,o.default)(this.node).code}get inList(){return!!this.listKey}set inList(e){e||(this.listKey=null)}get parentKey(){return this.listKey||this.key}},v={findParent:l.findParent,find:l.find,getFunctionParent:l.getFunctionParent,getStatementParent:l.getStatementParent,getEarliestCommonAncestorFrom:l.getEarliestCommonAncestorFrom,getDeepestCommonAncestorFrom:l.getDeepestCommonAncestorFrom,getAncestry:l.getAncestry,isAncestor:l.isAncestor,isDescendant:l.isDescendant,inType:l.inType,getTypeAnnotation:c.getTypeAnnotation,isBaseType:c.isBaseType,couldBeBaseType:c.couldBeBaseType,baseTypeStrictlyMatches:c.baseTypeStrictlyMatches,isGenericType:c.isGenericType,replaceWithMultiple:p.replaceWithMultiple,replaceWithSourceString:p.replaceWithSourceString,replaceWith:p.replaceWith,replaceExpressionWithStatements:p.replaceExpressionWithStatements,replaceInline:p.replaceInline,evaluateTruthy:u.evaluateTruthy,evaluate:u.evaluate,toComputedKey:d.toComputedKey,ensureBlock:d.ensureBlock,unwrapFunctionEnvironment:d.unwrapFunctionEnvironment,arrowFunctionToExpression:d.arrowFunctionToExpression,splitExportDeclaration:d.splitExportDeclaration,ensureFunctionName:d.ensureFunctionName,matchesPattern:h.matchesPattern,isStatic:h.isStatic,isNodeType:h.isNodeType,canHaveVariableDeclarationOrExpression:h.canHaveVariableDeclarationOrExpression,canSwapBetweenExpressionAndStatement:h.canSwapBetweenExpressionAndStatement,isCompletionRecord:h.isCompletionRecord,isStatementOrBlock:h.isStatementOrBlock,referencesImport:h.referencesImport,getSource:h.getSource,willIMaybeExecuteBefore:h.willIMaybeExecuteBefore,_guessExecutionStatusRelativeTo:h._guessExecutionStatusRelativeTo,resolve:h.resolve,isConstantExpression:h.isConstantExpression,isInStrictMode:h.isInStrictMode,isDenylisted:m.isDenylisted,visit:m.visit,skip:m.skip,skipKey:m.skipKey,stop:m.stop,setContext:m.setContext,requeue:m.requeue,requeueComputedKeyAndDecorators:m.requeueComputedKeyAndDecorators,remove:y.remove,insertBefore:T.insertBefore,insertAfter:T.insertAfter,unshiftContainer:T.unshiftContainer,pushContainer:T.pushContainer,getOpposite:g.getOpposite,getCompletionRecords:g.getCompletionRecords,getSibling:g.getSibling,getPrevSibling:g.getPrevSibling,getNextSibling:g.getNextSibling,getAllNextSiblings:g.getAllNextSiblings,getAllPrevSiblings:g.getAllPrevSiblings,get:g.get,getAssignmentIdentifiers:g.getAssignmentIdentifiers,getBindingIdentifiers:g.getBindingIdentifiers,getOuterBindingIdentifiers:g.getOuterBindingIdentifiers,getBindingIdentifierPaths:g.getBindingIdentifierPaths,getOuterBindingIdentifierPaths:g.getOuterBindingIdentifierPaths,shareCommentsWithSiblings:S.shareCommentsWithSiblings,addComment:S.addComment,addComments:S.addComments};Object.assign(P.prototype,v),P.prototype.arrowFunctionToShadowed=d[String("arrowFunctionToShadowed")],Object.assign(P.prototype,{has:h[String("has")],is:h[String("is")],isnt:h[String("isnt")],equals:h[String("equals")],hoist:T[String("hoist")],updateSiblingKeys:T.updateSiblingKeys,call:m.call,isBlacklisted:m[String("isBlacklisted")],setScope:m.setScope,resync:m.resync,popContext:m.popContext,pushContext:m.pushContext,setup:m.setup,setKey:m.setKey}),P.prototype._guessExecutionStatusRelativeToDifferentFunctions=h._guessExecutionStatusRelativeTo,P.prototype._guessExecutionStatusRelativeToDifferentFunctions=h._guessExecutionStatusRelativeTo,Object.assign(P.prototype,{_getTypeAnnotation:c._getTypeAnnotation,_replaceWith:p._replaceWith,_resolve:h._resolve,_call:m._call,_resyncParent:m._resyncParent,_resyncKey:m._resyncKey,_resyncList:m._resyncList,_resyncRemoved:m._resyncRemoved,_getQueueContexts:m._getQueueContexts,_removeFromScope:y._removeFromScope,_callRemovalHooks:y._callRemovalHooks,_remove:y._remove,_markRemoved:y._markRemoved,_assertUnremoved:y._assertUnremoved,_containerInsert:T._containerInsert,_containerInsertBefore:T._containerInsertBefore,_containerInsertAfter:T._containerInsertAfter,_verifyNodeList:T._verifyNodeList,_getKey:g._getKey,_getPattern:g._getPattern});for(const e of s.TYPES){const t=`is${e}`,n=s[t];P.prototype[t]=function(e){return n(this.node,e)},P.prototype[`assert${e}`]=function(t){if(!n(this.node,t))throw new TypeError(`Expected node path of type ${e}`)}}Object.assign(P.prototype,x);for(const t of Object.keys(e))"_"!==t[0]&&(s.TYPES.includes(t)||s.TYPES.push(t));return Si}function Ro(){if(Mo)return Ti;Mo=1,Object.defineProperty(Ti,"__esModule",{value:!0}),Ti.traverseNode=function(t,r,i,s,a,o,l){const c=n[t.type];if(!c)return!1;const p=new e.default(i,r,s,a);if(l)return(null==o||!o[a.parentKey])&&p.visitQueue([a]);for(const e of c)if((null==o||!o[e])&&p.visit(t,e))return!0;return!1};var e=function(){if(Lo)return gi;Lo=1,Object.defineProperty(gi,"__esModule",{value:!0}),gi.default=void 0;var e=jo(),t=Yr(),n=Uo();const{VISITOR_KEYS:r}=t;return gi.default=class{constructor(e,t,n,r){this.queue=null,this.priorityQueue=null,this.parentPath=r,this.scope=e,this.state=n,this.opts=t}shouldVisit(e){const t=this.opts;if(t.enter||t.exit)return!0;if(t[e.type])return!0;const n=r[e.type];if(null==n||!n.length)return!1;for(const t of n)if(e[t])return!0;return!1}create(t,n,r,i){return e.default.get({parentPath:this.parentPath,parent:t,container:n,key:r,listKey:i})}maybeQueue(e,t){this.queue&&(t?this.queue.push(e):this.priorityQueue.push(e))}visitMultiple(e,t,n){if(0===e.length)return!1;const r=[];for(let i=0;i<e.length;i++){const s=e[i];s&&this.shouldVisit(s)&&r.push(this.create(t,e,i,n))}return this.visitQueue(r)}visitSingle(e,t){return!!this.shouldVisit(e[t])&&this.visitQueue([this.create(e,e,t)])}visitQueue(e){this.queue=e,this.priorityQueue=[];const t=new WeakSet;let r=!1,i=0;for(;i<e.length;){const s=e[i];if(i++,n.resync.call(s),0!==s.contexts.length&&s.contexts[s.contexts.length-1]===this||n.pushContext.call(s,this),null===s.key)continue;const{node:a}=s;if(!t.has(a)){if(a&&t.add(a),s.visit()){r=!0;break}if(this.priorityQueue.length&&(r=this.visitQueue(this.priorityQueue),this.priorityQueue=[],this.queue=e,r))break}}for(let t=0;t<i;t++)n.popContext.call(e[t]);return this.queue=null,r}visit(e,t){const n=e[t];return!!n&&(Array.isArray(n)?this.visitMultiple(n,e,t):this.visitSingle(e,t))}},gi}();jo();var t=Yr();Uo();const{VISITOR_KEYS:n}=t;return Ti}function Uo(){if(Fo)return yi;Fo=1,Object.defineProperty(yi,"__esModule",{value:!0}),yi._call=s,yi._getQueueContexts=function(){let e=this,t=this.contexts;for(;!t.length&&(e=e.parentPath,e);)t=e.contexts;return t},yi._resyncKey=p,yi._resyncList=u,yi._resyncParent=c,yi._resyncRemoved=function(){null!=this.key&&this.container&&this.container[this.key]===this.node||n._markRemoved.call(this)},yi.call=i,yi.isDenylisted=a,yi.popContext=function(){this.contexts.pop(),this.contexts.length>0?this.setContext(this.contexts[this.contexts.length-1]):this.setContext(void 0)},yi.pushContext=function(e){this.contexts.push(e),this.setContext(e)},yi.requeue=function(e=this){if(e.removed)return;const t=this.contexts;for(const n of t)n.maybeQueue(e)},yi.requeueComputedKeyAndDecorators=function(){const{context:e,node:t}=this;!r.isPrivate(t)&&t.computed&&e.maybeQueue(this.get("key"));if(t.decorators)for(const t of this.get("decorators"))e.maybeQueue(t)},yi.resync=function(){if(this.removed)return;c.call(this),u.call(this),p.call(this)},yi.setContext=function(e){null!=this.skipKeys&&(this.skipKeys={});this._traverseFlags=0,e&&(this.context=e,this.state=e.state,this.opts=e.opts);return l.call(this),this},yi.setKey=d,yi.setScope=l,yi.setup=function(e,t,n,r){this.listKey=n,this.container=t,this.parentPath=e||this.parentPath,d.call(this,r)},yi.skip=function(){this.shouldSkip=!0},yi.skipKey=function(e){null==this.skipKeys&&(this.skipKeys={});this.skipKeys[e]=!0},yi.stop=function(){this._traverseFlags|=t.SHOULD_SKIP|t.SHOULD_STOP},yi.visit=function(){var t,n;if(!this.node)return!1;if(this.isDenylisted())return!1;if(null!=(t=(n=this.opts).shouldSkip)&&t.call(n,this))return!1;const r=this.context;if(this.shouldSkip||i.call(this,"enter"))return this.debug("Skip..."),this.shouldStop;return o(this,r),this.debug("Recursing into..."),this.shouldStop=(0,e.traverseNode)(this.node,this.opts,this.scope,this.state,this,this.skipKeys),o(this,r),i.call(this,"exit"),this.shouldStop};var e=Ro(),t=jo(),n=qa(),r=Yr();function i(e){const t=this.opts;return this.debug(e),!(!this.node||!s.call(this,t[e]))||!!this.node&&s.call(this,null==(n=t[this.node.type])?void 0:n[e]);var n}function s(e){if(!e)return!1;for(const t of e){if(!t)continue;const e=this.node;if(!e)return!0;const n=t.call(this.state,this,this.state);if(n&&"object"==typeof n&&"function"==typeof n.then)throw new Error("You appear to be using a plugin with an async traversal visitor, which your current version of Babel does not support. If you're using a published plugin, you may need to upgrade your @babel/core version.");if(n)throw new Error(`Unexpected return value from visitor method ${t}`);if(this.node!==e)return!0;if(this._traverseFlags>0)return!0}return!1}function a(){var e;const t=null!=(e=this.opts.denylist)?e:this.opts.blacklist;return null==t?void 0:t.includes(this.node.type)}function o(e,t){e.context!==t&&(e.context=t,e.state=t.state,e.opts=t.opts)}function l(){var e,t;if(null!=(e=this.opts)&&e.noScope)return;let n,r=this.parentPath;for((("key"===this.key||"decorators"===this.listKey)&&r.isMethod()||"discriminant"===this.key&&r.isSwitchStatement())&&(r=r.parentPath);r&&!n;){var i;if(null!=(i=r.opts)&&i.noScope)return;n=r.scope,r=r.parentPath}this.scope=this.getScope(n),null==(t=this.scope)||t.init()}function c(){this.parentPath&&(this.parent=this.parentPath.node)}function p(){if(this.container&&this.node!==this.container[this.key]){if(Array.isArray(this.container)){for(let e=0;e<this.container.length;e++)if(this.container[e]===this.node)return void d.call(this,e)}else for(const e of Object.keys(this.container))if(this.container[e]===this.node)return void d.call(this,e);this.key=null}}function u(){if(!this.parent||!this.inList)return;const e=this.parent[this.listKey];this.container!==e&&(this.container=e||null)}function d(e){var t;this.key=e,this.node=this.container[this.key],this.type=null==(t=this.node)?void 0:t.type}return yi.isBlacklisted=a,yi}var Ko,Vo,$o={};function qo(){return Vo||(Vo=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),Object.defineProperty(e,"Hub",{enumerable:!0,get:function(){return o.default}}),Object.defineProperty(e,"NodePath",{enumerable:!0,get:function(){return s.default}}),Object.defineProperty(e,"Scope",{enumerable:!0,get:function(){return a.default}}),e.visitors=e.default=void 0,Uo();var t=qi();e.visitors=t;var n=Yr(),r=Gi(),i=Ro(),s=jo(),a=ts(),o=(Ko||(Ko=1,Object.defineProperty($o,"__esModule",{value:!0}),$o.default=void 0,$o.default=class{getCode(){}getScope(){}addHelper(){throw new Error("Helpers are not supported by the default hub.")}buildError(e,t,n=TypeError){return new n(t)}}),$o);const{VISITOR_KEYS:l,removeProperties:c,traverseFast:p}=n;function u(e,n={},r,s,a,o){if(e){if(!n.noScope&&!r&&"Program"!==e.type&&"File"!==e.type)throw new Error(`You must pass a scope and parentPath unless traversing a Program/File. Instead of that you tried to traverse a ${e.type} node without passing scope and parentPath.`);if(!a&&o)throw new Error("visitSelf can only be used when providing a NodePath.");l[e.type]&&(t.explode(n),(0,i.traverseNode)(e,n,r,s,a,void 0,o))}}e.default=u,u.visitors=t,u.verify=t.verify,u.explode=t.explode,u.cheap=function(e,t){p(e,t)},u.node=function(e,t,n,r,s,a){(0,i.traverseNode)(e,t,n,r,s,a)},u.clearNode=function(e,t){c(e,t)},u.removeProperties=function(e,t){return p(e,u.clearNode,t),e},u.hasType=function(e,t,n){return(null==n||!n.includes(e.type))&&(e.type===t||p(e,function(e){return null!=n&&n.includes(e.type)?p.skip:e.type===t?p.stop:void 0}))},u.cache=r}(mi)),mi}var Wo=q(qo());function Jo(e){const t="string"==typeof e?Zr(e):e;let n=!1;return Wo(t,{noScope:!0,JSXElement(e){n=!0,e.stop()},JSXFragment(e){n=!0,e.stop()}}),n}const Yo=["components","utils","hooks","typings"];function Xo(e){return/^\\\\\?\\/.test(e)?e:e.replace(/\\/g,"/")}const Ho={javascript:[".ts",".tsx",".js",".jsx"],css:[".less",".sass",".scss",".stylus",".css"]};function zo(e){const t=Ho[e.type];for(const n of t){const t=`${e.fileNameWithoutExt}${n}`,r=Xo(s(e.base,t));if(u(r))return{path:r,filename:t}}return null}const Go=/^\[(.+?)\]/;function Qo(e,t,n,r){const{root:i,relDir:o=""}=e,c=r.name,p=s(i,o,c),u=Go.test(c);if(r.isDirectory()){const r=s(o,c),a=zo({base:s(i,r),fileNameWithoutExt:"_layout",type:"javascript"}),l={path:el(r),routes:tl({...e,relDir:s(r)},t),__isDynamic:u,...a?{component:a.path}:{exact:!0,__toMerge:!0}};n.push(Zo(l,e,t))}else{const r=a(c,l(c));n.push(Zo({path:el(s(o,r)),exact:!0,component:p,__isDynamic:u},e,t))}return n}function Zo(e,t,r){let i;return e.component&&(i=r.readComponent(e.component).props,e.component=Xo(n(s(t.root,".."),e.component)),e.component=`${t.componentPrefix||"@/"}${e.component}`),{...e,..."object"==typeof i?i:{}}}function el(e){return"/index/index"===(e=`/${e=Xo(e).split("/").map(e=>((e=e.replace(Go,":$1")).endsWith("$")&&(e=e.slice(0,-1)+"?"),e)).join("/")}`)&&(e="/"),"/"!==(e=e.replace(/\/index$/,"/"))&&"/"===e.slice(-1)&&(e=e.slice(0,-1)),e}function tl(e,t){const{root:n,relDir:r="",config:i}=e,a=function(e,t){return u(e)?f(e,{withFileTypes:!0}).map(t=>{if(!t.isSymbolicLink())return t;const n=d(s(e,t.name));return{name:t.name,isDirectory:()=>n.isDirectory(),isFile:()=>n.isFile()}}).filter(n=>{const r=s(e,n.name);return!!t.acceptsPage(r,n.isDirectory())&&!n.name.startsWith("_")&&(n.isDirectory()||n.isFile()&&t.readComponent(r).isComponent)}):[]}(s(n,r),t),o=function(e){const t=[],n=[],r=[];return e.forEach(e=>{const{__isDynamic:i,exact:s}=e;delete e.__isDynamic,i?t.push(e):s?n.push(e):r.push(e)}),g(t.length<=1,"We should not have multiple dynamic routes under a directory."),[...n,...r,...t].reduce((e,t)=>(t.__toMerge&&t.routes?e=e.concat(t.routes):e.push(t),e),[])}(a.reduce(Qo.bind(null,e,t),[]));if(!r){const r=zo({base:n,fileNameWithoutExt:`../${i.singular?"layout":"layouts"}/index`,type:"javascript"});if(r)return[Zo({path:"/",component:r.path,routes:o},e,t)]}return o}function nl(e){const s={...e,root:t(e.root)},l=new Map,c=function(e,s=Yo,a=[]){const o=new Set(["components","component","utils","util","node_modules",...s]),l=new Set(a.map(e=>t(e)));return(s,a)=>{const c=t(s);if(l.has(c))return!1;const p=n(e,c);if(".."===p||p.startsWith(`..${r}`)||i(p))return!1;if(!p)return a;const u=p.split(r);if((a?u:u.slice(0,-1)).some(e=>o.has(e)||/^[._]/.test(e)))return!1;if(a)return!0;const d=u[u.length-1];return function(e){return/\.(j|t)sx?$/.test(e)&&!/\.(test|spec|e2e)\.(j|t)sx?$/.test(e)&&!/\.d\.ts$/.test(e)}(d)&&(!/^[._]/.test(d)||/^_layout\.(j|t)sx?$/.test(d))}}(s.root,s.ignoreDirs,s.excludedFiles),p=t(s.root,"..",s.config.singular?"layout":"layouts"),u=new Set,f={acceptsPage:c,readComponent(e){const n=t(e),r=l.get(n);if(u.has(n)&&r)return r;u.add(n);const i=d(n),s=`${i.mtimeMs}:${i.ctimeMs}:${i.size}`;if(r?.signature===s)return r;try{const e=Zr(h(n,"utf-8")),t={signature:s,isComponent:Jo(e),props:hi(e)};return l.set(n,t),t}catch(e){const t=e instanceof Error?e.message:String(e);throw new Error(`Parse conventional route component ${n} failed, ${t}`)}}};return{globalLayoutDir:p,getRoutes(){try{const e=tl(s,f);for(const e of l.keys())u.has(e)||l.delete(e);return e}catch(e){throw l.clear(),e}finally{u.clear()}},isRelevant(e,n=!1){const r=t(e);return!s.excludedFiles?.some(e=>t(e)===r)&&(!(!n||r!==p)||(!(n||!/^index\.(j|t)sx?$/.test(a(r))||o(r)!==p)||c(r,n)))},invalidate(e){const n=t(e);for(const e of l.keys())(e===n||e.startsWith(`${n}${r}`))&&l.delete(e)},clear(){l.clear(),u.clear()}}}function rl(e){return nl(e).getRoutes()}function il(e){const t={path:e.path||""};if(void 0!==e.exact&&(t.exact=e.exact),e.component){const n=e.component.replace(/\.(tsx|ts|jsx|js)$/,"");t.component=`dynamic({ loader: () => import(${JSON.stringify(n)}), loading: LoadingComponent})`}return e.title&&"string"==typeof e.title&&(t.title=`$t({ defaultMessage: ${JSON.stringify(e.title)} })`),!0===e.keepAlive&&(t.keepAlive=!0),e.authority&&Array.isArray(e.authority)&&(t.authority=e.authority),e.routes&&e.routes.length>0&&(t.routes=e.routes.map(il)),t}async function sl(e,t,n){function r(e,t=2){const n=" ".repeat(t),i=" ".repeat(t+2);let s=`${n}{\n`;if(s+=`${i}path: ${JSON.stringify(e.path)},\n`,void 0!==e.exact&&null!==e.exact&&(s+=`${i}exact: ${e.exact},\n`),void 0!==e.component&&null!==e.component&&(s+=`${i}component: ${e.component},\n`),void 0!==e.title&&null!==e.title&&(s+=`${i}title: ${e.title},\n`),e.authority&&(s+=`${i}authority: ${JSON.stringify(e.authority)},\n`),e.keepAlive&&(s+=`${i}keepAlive: ${e.keepAlive},\n`),e.routes&&e.routes.length>0){s+=`${i}routes: [\n${e.routes.map(e=>r(e,t+2)).join(",\n")}\n${i}],\n`}return s=s.replace(/,\n$/,"\n"),s+=`${n}}`,s}const i=e.map(e=>r(e)).join(",\n"),s=t.defaultLoadingComponentPath||"@/components/loading",a=t.intlPath||"@/utils/intl",o=`\n/* eslint-disable */\n// @ts-nocheck\n/**\n * 自动根据 pages 目录生成路由配置\n * 新增、删除、修改组件 title、keepAlive、authority 属性时,会自动更新路由配置\n * 路由组件只支持默认导出\n */\nimport { dynamic } from '@lemon-fe/vite-plugin-micro-frontend/runtime/dynamic';\nimport LoadingComponent from ${JSON.stringify(s)};\nimport { $t } from ${JSON.stringify(a)};\n\nexport const routers = [\n${i}\n];\n`,l=await m.resolveConfig(n);return m.format(o,{...l,parser:"typescript"})}function al(t){const n=e.resolve(t.pagesDir||"src/pages"),r=e.resolve(t.outputPath||"src/routes.ts"),i=t.routeTemplate||{},s=nl({root:n,componentPrefix:i.pageAliasPrefix,config:{singular:!1},ignoreDirs:t.ignoreDirs,excludedFiles:[r]});let a,o,l=!1;async function c(){if(!p.existsSync(n)&&void 0===a)return void console.warn("⚠️ pages 目录不存在:",n);const t=s.getRoutes().map(il),o=JSON.stringify(t);if(o===a&&p.existsSync(r))return;const l=await sl(t,i,r);p.existsSync(r)&&p.readFileSync(r,"utf-8")===l||(p.mkdirSync(e.dirname(r),{recursive:!0}),p.writeFileSync(r,l),console.log("✅ 路由已生成:",r)),a=o}return{...s,pagesDir:n,generate:()=>(l=!0,o||(o=Promise.resolve().then(async()=>{try{for(;l;)l=!1,await c()}finally{o=void 0}})),o),async dispose(){try{await o}finally{l=!1,a=void 0,s.clear()}}}}async function ol(e={}){await al(e).generate()}function ll(e={}){const t=al(e);let n,r;const i=()=>{clearTimeout(n),n=void 0,r?.(),r=void 0};return{name:"micro-frontend:routes",enforce:"pre",async configureServer(s){!function(s){if(r||!1===e.watch)return;const a=(e,r)=>{["add","change","unlink","addDir","unlinkDir"].includes(e)&&t.isRelevant(r,"addDir"===e||"unlinkDir"===e)&&(t.invalidate(r),clearTimeout(n),n=setTimeout(()=>{n=void 0,t.generate().catch(e=>{const t=e instanceof Error?e.stack||e.message:String(e);s.config.logger.error(`❌ 路由生成失败:\n${t}`)})},50))};s.watcher.on("all",a),s.watcher.add([t.pagesDir,t.globalLayoutDir]),s.httpServer?.once("close",i),r=()=>{s.watcher.off("all",a),s.httpServer?.off("close",i)}}(s);try{await t.generate()}catch(e){throw i(),await t.dispose(),e}},async buildStart(){await t.generate()},async closeBundle(){i(),await t.dispose()}}}function cl(t){const{outputPath:n}=t,r=n||e.resolve(process.cwd(),"src/utils/mf.tsx"),i=function(e){const t=e.remotes.reduce((e,t)=>(e[t.aliasName||t.remoteName]=t,e),{}),n=JSON.stringify(t,null,2),r=JSON.stringify({hostName:e.hostName,devHost:e.devHost,shareScope:e.shareScope});return"/* eslint-disable */\nimport { lazy, Suspense, type ReactNode, type ComponentType, type ComponentProps } from 'react';\nimport { createRemoteLoader } from '@lemon-fe/vite-plugin-micro-frontend/runtime/federation';\n\n// 配置同时用于类型提示和运行时注册,不依赖 Vite 是否扫描到静态 remote import。\nconst remotes = __REMOTES_JSON__ as const;\nconst loadRemote = createRemoteLoader({ ...__RUNTIME_OPTIONS_JSON__, remotes });\n\ntype RemoteAlias = keyof typeof remotes;\ntype ModuleSpecifier = `${RemoteAlias}/${string}`;\n\nconst entryShared = ((globalThis as any).__entry_shared__ ||= {});\n\n/** 获取多个业务入口共享的懒初始化值。 */\nexport function getEntryShared<T>(key: string, init: () => T): T {\n return (entryShared[key] ??= init()) as T;\n}\n\n/** 使用官方 Module Federation Runtime 加载远程 React 组件。 */\nexport function safeRemoteComponent<T extends ComponentType<any>>(opts: {\n moduleSpecifier: ModuleSpecifier;\n fallbackComponent: T | ComponentType<ComponentProps<T>>;\n loadingElement?: ReactNode;\n}): T {\n const LazyComponent = lazy<T>(async () => {\n try {\n const remoteModule = await loadRemote<Record<string, unknown>>(opts.moduleSpecifier);\n const remoteExport = remoteModule?.default ?? remoteModule;\n\n return {\n default: remoteExport as T,\n };\n } catch (error) {\n console.error(`[MF] Load remote module \"${opts.moduleSpecifier}\" failed:`, error);\n return { default: opts.fallbackComponent as T };\n }\n });\n\n return ((props: any) => (\n <Suspense fallback={opts.loadingElement ?? null}>\n <LazyComponent {...props} />\n </Suspense>\n )) as T;\n}\n".replace("__REMOTES_JSON__",()=>n).replace("__RUNTIME_OPTIONS_JSON__",()=>r)}(t),s=e.dirname(r);if(p.existsSync(s)||p.mkdirSync(s,{recursive:!0}),p.existsSync(r)){if(p.readFileSync(r,"utf-8")===i)return}p.writeFileSync(r,i),console.log("✅ mf.tsx 已生成:",r)}function pl(e){return{name:"micro-frontend:mf-generator",enforce:"pre",configResolved(){cl(e)},buildStart(){cl(e)}}}function ul(e){return{schemaVersion:1,appName:e.appName,loader:"module-federation",remote:{name:e.remoteName,type:"module",entry:`./${e.manifestFileName.replace(/^\/+/,"")}`,module:`${e.remoteName}/app`},application:{contract:"react-component",version:1},...e.buildVersion?{buildVersion:e.buildVersion}:void 0}}function dl(t){let n=`${JSON.stringify(ul(t),null,2)}\n`;function r(r,i){const s=function(e,t){const n=e.split("/").filter(Boolean),r=n[n.length-1],i=t.replace(/_/g,"-");return r===i||r===`app-${i}`?i:t}(i,t.appName),a={...t,appName:t.inferAppNameFromBase?s:t.appName,mountElementId:t.inferMountElementIdFromBase?s:t.mountElementId};if(n=`${JSON.stringify(ul(a),null,2)}\n`,!t.componentEntry)return;const o=e.resolve(r,t.componentEntry),l=e.relative(e.dirname(o),e.resolve(r,t.entry)).replace(/\\/g,"/"),c=l.startsWith(".")?l:`./${l}`,u=c.replace(/([\[\]{}()*?!])/g,"\\$1"),d=['/// <reference types="vite/client" />','import type { ComponentType } from "react";','import { createMicroFrontendApp, type MicroFrontendProps } from "@lemon-fe/vite-plugin-micro-frontend/runtime/app";',`const roots = import.meta.glob<ComponentType<MicroFrontendProps>>(${JSON.stringify(u)}, { eager: true, import: "default" });`,"export default createMicroFrontendApp({",` rootComponent: roots[${JSON.stringify(c)}]!,`,` basename: ${JSON.stringify(`/${a.appName}`)},`,` mountElementId: ${JSON.stringify(a.mountElementId)},`,"});",""].join("\n");p.mkdirSync(e.dirname(o),{recursive:!0}),p.existsSync(o)&&p.readFileSync(o,"utf8")===d||p.writeFileSync(o,d)}return{name:"micro-frontend:federation-application",enforce:"pre",config(e){r(e.root||process.cwd(),e.base||"/"),"remote"===t.buildMode&&(e.build={...e.build,rollupOptions:{...e.build?.rollupOptions,input:{}}})},configResolved(e){r(e.root,e.base)},configureServer(e){e.middlewares.use((e,r,i)=>{!function(e,t){if(!e)return!1;const n=e.split(/[?#]/)[0];return n===`/${t}`||n.endsWith(`/${t}`)}(e.url,t.capabilityFileName)?i():(r.statusCode=200,r.setHeader("Content-Type","application/json; charset=utf-8"),r.setHeader("Cache-Control","no-store"),r.setHeader("Access-Control-Allow-Origin","*"),r.end(n))})},generateBundle(){this.emitFile({type:"asset",fileName:t.capabilityFileName,source:n})}}}const hl="\nconst __remoteUrl = new URL(import.meta.url);\nconst __hostRefreshUrl = globalThis.__MF_REACT_REFRESH_URL__;\nconst __target =\n window.location.origin === __remoteUrl.origin || !__hostRefreshUrl\n ? new URL('./@mf-react-refresh-local', __remoteUrl).href\n : __hostRefreshUrl;\nconst __rt = await import(__target);\n\nexport const injectIntoGlobalHook = __rt.injectIntoGlobalHook;\nexport const register = __rt.register;\nexport const getRefreshReg = __rt.getRefreshReg;\nexport const createSignatureFunctionForTransform = __rt.createSignatureFunctionForTransform;\nexport const registerExportsForReactRefresh = __rt.registerExportsForReactRefresh;\nexport const validateRefreshBoundaryAndEnqueueUpdate = __rt.validateRefreshBoundaryAndEnqueueUpdate;\nexport const __hmr_import = __rt.__hmr_import;\nexport default __rt.default || __rt;\n".trimStart();function fl(){let t;return{name:"micro-frontend:federation-react-refresh-proxy",enforce:"pre",apply:"serve",configureServer(n){n.middlewares.use((r,i,s)=>{const a=r.url?.split(/[?#]/)[0];if("GET"===r.method)return a?.endsWith("/@mf-react-refresh-local")?(t??(t=function(t){try{const n=P(e.join(t,"package.json")).resolve("@vitejs/plugin-react"),r=e.join(e.dirname(n),"refresh-runtime.js");return p.readFileSync(r,"utf8")}catch{return null}}(n.config.root)),t?(i.statusCode=200,i.setHeader("Content-Type","application/javascript; charset=utf-8"),i.setHeader("Cache-Control","no-store"),i.setHeader("Access-Control-Allow-Origin","*"),void i.end(t)):void s()):void(a?.endsWith("/@react-refresh")?(i.statusCode=200,i.setHeader("Content-Type","application/javascript; charset=utf-8"),i.setHeader("Cache-Control","no-store"),i.setHeader("Access-Control-Allow-Origin","*"),i.end(hl)):s());s()})}}}function ml(e,t){if(!e)return e;const n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e,r=e=>Object.prototype.hasOwnProperty.call(n,e);if(!(r("react")||r("react/"))||r("react/jsx-dev-runtime"))return e;const i=n.react??n["react/"],s="object"==typeof i?i.requiredVersion:void 0;return{...n,"react/jsx-dev-runtime":{shareScope:`__micro_frontend_react_dev_${t}`,singleton:!1,...void 0!==s?{requiredVersion:s}:void 0}}}function yl(e){return e.replace(/\\/g,"/")}function Tl(t){const n=function(t){const n={},r=[".tsx",".ts"];if(!p.existsSync(t))return n;const i=p.readdirSync(t,{withFileTypes:!0});for(const s of i)if(s.isDirectory()){const r=e.join(t,s.name),i=["index.tsx","index.ts"];let a=null;for(const t of i){const n=e.join(r,t);if(p.existsSync(n)){a=n;break}}if(a){const t=yl(e.relative(process.cwd(),a));n[`./${s.name}`]=`./${t}`}else console.warn(`⚠️ ${s.name} 目录下没有找到入口文件,已忽略`)}else{const i=e.extname(s.name);if(r.includes(i)){const r=e.join(t,s.name),a=yl(e.relative(process.cwd(),r));n[`./${e.basename(s.name,i)}`]=`./${a}`}}return n}(e.resolve(process.cwd(),t.exposesDir??"src/exposes"));return{...n,...t.exposes||{}}}function gl(t,n={}){const r=t.name||n.appName?.replace(/-/g,"_");if(!r)throw new Error("[micro-frontend] 请配置 appName 或 federation.name。");const i={dts:!0,manifest:!0,publicPath:"auto",shareStrategy:"loaded-first",...t,name:r,shared:ml(t.shared,r),dev:(s=t.dev,!1!==s&&{remoteHmr:!0,disableHotTypesReload:!0,disableDynamicRemoteTypeHints:!0,..."object"==typeof s?s:{}})};var s;const a=[];i.debugReactHost&&a.push({name:"micro-frontend:react-refresh-host",enforce:"pre",apply:"serve",configureServer(e){const t=E(b.join(e.config.root,"package.json")),n=e.config.base.replace(/\/$/,""),r=new Map,i=new Map,s=e=>{const n=b.dirname(t.resolve(`${e}/package.json`)),{version:r}=JSON.parse(x.readFileSync(b.join(n,"package.json"),"utf8"));if(!String(r).startsWith("18."))throw new Error(`debugReactHost 需要 React 18 UMD,当前 ${e} 版本为 ${r}`);return x.readFileSync(b.join(n,"umd",`${e}.development.js`),"utf8")};r.set(`${n}/@micro-frontend/host-react.js`,()=>s("react")),r.set(`${n}/@micro-frontend/host-react-dom.js`,()=>{const e=E(t.resolve("@vitejs/plugin-react")),n=b.dirname(e.resolve("react-refresh/package.json"));return`(() => {\nconst exports = {};\nconst process = { env: { NODE_ENV: 'development' } };\n${x.readFileSync(b.join(n,"cjs/react-refresh-runtime.development.js"),"utf8")}\nexports.injectIntoGlobalHook(window);\n\nconst hook = window.__REACT_DEVTOOLS_GLOBAL_HOOK__;\nif (hook && !hook.__microFrontendTracksRenderers) {\n const inject = hook.inject;\n hook.inject = function(renderer) {\n const id = inject.apply(this, arguments);\n hook.renderers.set(id, renderer);\n return id;\n };\n hook.__microFrontendTracksRenderers = true;\n}\n\n})();\n${s("react-dom")}`}),e.middlewares.use((e,t,n)=>{const s=e.url?.split(/[?#]/)[0]??"",a=r.get(s);if(!a||"GET"!==e.method&&"HEAD"!==e.method)return n();try{i.has(s)||i.set(s,a()),t.setHeader("Content-Type","application/javascript; charset=utf-8"),t.setHeader("Cache-Control","no-store"),t.setHeader("Access-Control-Allow-Origin","*"),t.end("HEAD"===e.method?void 0:i.get(s))}catch(e){n(e)}})}});const o=!1===i.application?void 0:i.application||{};if(o&&!1===i.manifest)throw new Error("[micro-frontend] 完整微应用必须启用 federation.manifest,如只暴露普通联邦组件,请设置 federation.application = false。");if(o?.rootComponent&&o.entry)throw new Error("[micro-frontend] federation.application.rootComponent 与 entry 不能同时配置。");const l="object"==typeof(c=i.manifest)&&c.fileName?c.fileName:"mf-manifest.json";var c;const p=[...!1===i.manifest?[]:[l],...o?[o.capabilityFileName||"micro-frontend.json"]:[]];var u;a.push(fl()),p.length>0&&a.push((u=p,{name:"micro-frontend:federation-dev-preflight",enforce:"pre",apply:"serve",configureServer(e){e.middlewares.use((t,n,r)=>{if("OPTIONS"!==t.method||!1===e.config.server.cors||!function(e,t){if(!e)return!1;const n=e.split(/[?#]/)[0];return t.some(e=>{const t=e.replace(/^\/+/,"");return n===`/${t}`||n.endsWith(`/${t}`)})}(t.url,u)&&"true"!==t.headers["access-control-request-private-network"])return void r();const i=t.headers["access-control-request-headers"];n.statusCode=204,n.setHeader("Access-Control-Allow-Origin","*"),n.setHeader("Access-Control-Allow-Methods","GET, HEAD, PUT, PATCH, POST, DELETE, OPTIONS"),i&&n.setHeader("Access-Control-Allow-Headers",Array.isArray(i)?i.join(", "):i),"true"===t.headers["access-control-request-private-network"]&&n.setHeader("Access-Control-Allow-Private-Network","true"),n.setHeader("Content-Length","0"),n.end()})}}));const d=function(e,t,n){if(!e||0===e.length)return;const r={};for(const i of e){const{aliasName:e,remoteName:s,entry:a,isESModule:o}=i,l=e||s,c=a.startsWith("/")?a:`/${a}`;let p;p=a.startsWith("http")?a:t?new URL(c,`${t.replace(/\/$/,"")}/`).href:c,r[l]={type:o?"module":"var",name:l,entry:p,entryGlobalName:s,shareScope:n||"default"}}return r}(i.remotes,i.devHost,i.shareScope),h=Tl(i);if(o){const e=h["./app"];if(o.rootComponent&&e)throw new Error('[micro-frontend] federation.application.rootComponent 与 exposes["./app"] 不能同时配置。');const t=o.rootComponent||o.entry||("string"==typeof(f=e)?f:f?.import)||"src/main.tsx",s=o.appName||n.appName||i.name,c=o.mountElementId||s,p=o.rootComponent?`src/.external/${encodeURIComponent(r)}/app-component.ts`:void 0;e||(h["./app"]=`./${(p||t).replace(/^\.\//,"")}`),a.push(dl({appName:s,remoteName:i.name,entry:t,componentEntry:p,mountElementId:c,manifestFileName:l,capabilityFileName:o.capabilityFileName||"micro-frontend.json",buildVersion:o.buildVersion,buildMode:o.buildMode,inferAppNameFromBase:!o.appName,inferMountElementIdFromBase:!o.mountElementId}))}var f;const m={...i};return delete m.application,delete m.devHost,delete m.debugReactHost,delete m.exposesDir,delete m.outputPath,delete m.remotes,a.push(S({filename:"remote.js",hostInitInjectLocation:"entry",...m,remotes:d,exposes:h})),a.push({name:"micro-frontend:federation-commonjs",apply:"build",enforce:"pre",transform(e,t){if(!t.includes("__loadShare__")||!e.includes("__mfApplyHostProvidedExports"))return null;const n=e.replace("export const __moduleExports = exportModule;","export { exportModule as __moduleExports };");return n===e?null:{code:n,map:null}},outputOptions:{order:"post",handler(e){const t=e.manualChunks;if("function"==typeof t)return{...e,manualChunks:(e,n)=>"\0commonjsHelpers.js"===e?"commonjs-helpers":t(e,n)}}}}),function(e){return"object"==typeof e&&null!==e&&Boolean(e.remoteHmr)}(i.dev)&&Object.keys(h).length>0&&a.push(K()),a.push(pl({hostName:i.name,devHost:i.devHost,shareScope:i.shareScope,remotes:i.remotes??[],outputPath:i.outputPath?e.resolve(process.cwd(),i.outputPath):"src/utils/mf.tsx"})),a}function Sl(e){return e&&"/"!==e?e.replace(/^\/+|\/+$/g,""):""}function xl(e,t,n){if(!t||!n)return e;const r=function(e){const t=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return new RegExp(`import\\((['"])\\/${t}\\/([^'"]+)\\1\\)`,"g")}(t);return e.replace(r,`import(${n} + '/$2')`)}function bl(e,t){if("boolean"==typeof t&&!t)return"";const n="boolean"==typeof t?{}:t;if(n.publicPath?.trim())return n.publicPath.trim();const r=function(e,t){const n="boolean"==typeof t?{}:t;if(n.appBase?.trim())return n.appBase.trim().replace(/^\/+|\/+$/g,"");const r=Sl(e.base);return r&&"__dynamic_base__"!==r?r:""}(e,t),i=r?`/${r}`:e.base??"/";return`(window.EARTH_BASE_CONFIG && window.EARTH_BASE_CONFIG.EARTH_ALL_SHARE_HOST ? window.EARTH_BASE_CONFIG.EARTH_ALL_SHARE_HOST.replace(/\\/$/, '') : '') + ${JSON.stringify(i)}`}function El(e,t,n){if(e)return"function"==typeof e?e.apply(t,n):e.handler.apply(t,n)}function Pl(e,t){let n;const{transformIndexHtml:r=!0,transformIndexHtmlConfig:i}=e;return{name:"micro-frontend:dynamic-base-deferred",enforce:"post",apply:"build",configResolved:e=>(n=v({publicPath:t(),transformIndexHtml:r,transformIndexHtmlConfig:i}),El(n.configResolved,n,[e])),generateBundle(e,t,r){if(n?.generateBundle)return El(n.generateBundle,n,[e,t,r])}}}function vl(e,t,n){const{transformIndexHtml:r=!0,removeIndexCssPreload:i=!1}=e,s=[];if(r){const e=e=>xl(e,n(),t());s.push({name:"micro-frontend:rewrite-inline-dynamic-base-import",enforce:"post",apply:"build",transformIndexHtml:{order:"post",handler:t=>e(t)},generateBundle(t,n){for(const t of Object.values(n))"asset"===t.type&&t.fileName.endsWith(".html")&&"string"==typeof t.source&&(t.source=e(t.source))}})}return i&&s.push({name:"micro-frontend:remove-index-css-preload",enforce:"post",apply:"build",transformIndexHtml(e){let t=e.replace(/<link[^>]*rel=["']stylesheet["'][^>]*href=["']\/?index-[^"']+\.css["'][^>]*>/gi,"");return t=t.replace(/,\{"parentTagName":"head","tagName":"link","attrs":\{"rel":"stylesheet","crossorigin":"","href":"\/index-[^"]+\.css"\}\}/g,""),t}}),s}function Al(e){const t={publicPath:"",appBasePath:""},n=function(e){return"boolean"==typeof e?{}:e}(e),r=()=>t.publicPath;return[{name:"micro-frontend:dynamic-base-init",enforce:"pre",apply:"build",config(n,r){t.publicPath=bl(n,e),t.appBasePath=Sl(n.base)}},Pl(n,r),...vl(n,r,()=>t.appBasePath)]}const Cl={pagesDir:"src/pages",outputPath:"src/routes.ts",watch:!0,ignoreDirs:["components","utils","hooks","typings"],routeTemplate:{defaultLoadingComponentPath:"@/components/loading",intlPath:"@/utils/intl"}},wl="__microFrontendOptions";function Il(t){const{appName:n,federation:r,routes:i,dynamicBase:s}=t,a=[];a.push({name:"micro-frontend:options",[wl]:t});const o="object"==typeof i?{...Cl,...i}:Cl;return a.push(ll({pagesDir:o.pagesDir?e.resolve(process.cwd(),o.pagesDir):void 0,outputPath:o.outputPath?e.resolve(process.cwd(),o.outputPath):void 0,watch:o.watch,ignoreDirs:o.ignoreDirs,routeTemplate:o.routeTemplate})),r&&a.push(...gl(r,{appName:n})),s&&a.push(...Al(s)),a}export{wl as MICRO_FRONTEND_OPTIONS_KEY,R as cssInjectedByJsPlugin,V as devHmrPlugin,gl as federationPlugin,cl as generateMf,ol as generateRoutesToFile,Al as getDynamicBasePlugins,rl as getRoutes,pl as mfGeneratorPlugin,Il as microFrontendPlugins,ll as pagesRoutesPlugin};
|
|
13
|
+
`;return this.replaceWith(p)[0].get("arguments.0")},to.splitExportDeclaration=function(){if(!this.isExportDeclaration()||this.isExportAllDeclaration())throw new Error("Only default and named export declarations can be split.");if(this.isExportNamedDeclaration()&&this.get("specifiers").length>0)throw new Error("It doesn't make sense to split exported specifiers.");const e=this.get("declaration");if(this.isExportDefaultDeclaration()){const t=e.isFunctionDeclaration()||e.isClassDeclaration(),n=e.isFunctionExpression()||e.isClassExpression(),r=e.isScope()?e.scope.parent:e.scope;let i=e.node.id,s=!1;i?n&&r.hasBinding(i.name)&&(s=!0,i=r.generateUidIdentifier(i.name)):(s=!0,i=r.generateUidIdentifier("default"),(t||n)&&(e.node.id=L(i)));const a=t?e.node:M("var",[F(L(i),e.node)]),o=B(null,[j(L(i),u("default"))]);return this.insertAfter(o),this.replaceWith(a),s&&r.registerDeclaration(this),this}if(this.get("specifiers").length>0)throw new Error("It doesn't make sense to split exported specifiers.");const t=e.getOuterBindingIdentifiers(),n=Object.keys(t).map(e=>j(u(e),u(e))),r=B(null,n);return this.insertAfter(r),this.replaceWith(e.node),this},to.toComputedKey=function(){let e;if(this.isMemberExpression())e=this.node.property;else{if(!this.isProperty()&&!this.isMethod())throw new ReferenceError("todo");e=this.node.key}this.node.computed||d(e)&&(e=v(e.name));return e},to.unwrapFunctionEnvironment=function(){if(!this.isArrowFunctionExpression()&&!this.isFunctionExpression()&&!this.isFunctionDeclaration())throw this.buildCodeFrameError("Can only unwrap the environment of a function.");K(this)};var e=Yr(),t=function(){if(xo)return no;xo=1,Object.defineProperty(no,"__esModule",{value:!0}),no.statements=no.statement=no.smart=no.program=no.expression=no.default=void 0;var e=io(),t=vo();const n=no.smart=(0,t.default)(e.smart),r=no.statement=(0,t.default)(e.statement),i=no.statements=(0,t.default)(e.statements),s=no.expression=(0,t.default)(e.expression),a=no.program=(0,t.default)(e.program);return no.default=Object.assign(n.bind(void 0),{smart:n,statement:r,statements:i,expression:s,program:a,ast:n.ast}),no}(),n=qi(),r=Uo();const{arrowFunctionExpression:i,assignmentExpression:s,binaryExpression:a,blockStatement:o,callExpression:l,conditionalExpression:c,expressionStatement:p,identifier:u,isIdentifier:d,jsxIdentifier:h,logicalExpression:f,LOGICAL_OPERATORS:m,memberExpression:y,metaProperty:T,numericLiteral:g,objectExpression:S,restElement:x,returnStatement:b,sequenceExpression:E,spreadElement:P,stringLiteral:v,super:A,thisExpression:C,toExpression:w,unaryExpression:I,toBindingIdentifierName:N,isFunction:k,isAssignmentPattern:O,isRestElement:_,getFunctionName:D,cloneNode:L,variableDeclaration:M,variableDeclarator:F,exportNamedDeclaration:B,exportSpecifier:j,inherits:R}=e;to.arrowFunctionToShadowed=function(){this.isArrowFunctionExpression()&&this.arrowFunctionToExpression()};const U=(0,n.environmentVisitor)({CallExpression(e,{allSuperCalls:t}){e.get("callee").isSuper()&&t.push(e)}});function K(e,t=!0,n=!0,r=!0){let o,p=e.findParent(e=>e.isArrowFunctionExpression()?(null!=o||(o=e),!1):e.isFunction()||e.isProgram()||e.isClassProperty({static:!1})||e.isClassPrivateProperty({static:!1}));const d=p.isClassMethod({kind:"constructor"});if(p.isClassProperty()||p.isClassPrivateProperty())if(o)p=o;else{if(!n)throw e.buildCodeFrameError("Unable to transform arrow inside class property");e.replaceWith(l(i([],w(e.node)),[])),p=e.get("callee"),e=p.get("body")}const{thisPaths:S,argumentsPaths:b,newTargetPaths:N,superProps:k,superCalls:O}=function(e){const t=[],n=[],r=[],i=[],s=[];return e.traverse(W,{thisPaths:t,argumentsPaths:n,newTargetPaths:r,superProps:i,superCalls:s}),{thisPaths:t,argumentsPaths:n,newTargetPaths:r,superProps:i,superCalls:s}}(e);if(d&&O.length>0){if(!n)throw O[0].buildCodeFrameError("When using '@babel/plugin-transform-arrow-functions', it's not possible to compile `super()` in an arrow function without compiling classes.\nPlease add '@babel/plugin-transform-classes' to your Babel configuration.");if(!r)throw O[0].buildCodeFrameError("When using '@babel/plugin-transform-parameters', it's not possible to compile `super()` in an arrow function with default or rest parameters without compiling classes.\nPlease add '@babel/plugin-transform-classes' to your Babel configuration.");const e=[];p.traverse(U,{allSuperCalls:e});const t=function(e){return q(e,"supercall",()=>{const t=e.scope.generateUidIdentifier("args");return i([x(t)],l(A(),[P(u(t.name))]))})}(p);e.forEach(e=>{const n=u(t);n.loc=e.node.callee.loc,e.get("callee").replaceWith(n)})}if(b.length>0){const e=q(p,"arguments",()=>{const e=()=>u("arguments");return p.scope.path.isProgram()?c(a("===",I("typeof",e()),v("undefined")),p.scope.buildUndefinedNode(),e()):e()});b.forEach(t=>{const n=u(e);n.loc=t.node.loc,t.replaceWith(n)})}if(N.length>0){const e=q(p,"newtarget",()=>T(u("new"),u("target")));N.forEach(t=>{const n=u(e);n.loc=t.node.loc,t.replaceWith(n)})}if(k.length>0){if(!n)throw k[0].buildCodeFrameError("When using '@babel/plugin-transform-arrow-functions', it's not possible to compile `super.prop` in an arrow function without compiling classes.\nPlease add '@babel/plugin-transform-classes' to your Babel configuration.");k.reduce((e,t)=>e.concat(function(e){if(e.parentPath.isAssignmentExpression()&&"="!==e.parentPath.node.operator){const n=e.parentPath,r=n.node.operator.slice(0,-1),i=n.node.right,a=function(e){return m.includes(e)}(r);if(e.node.computed){const o=e.scope.generateDeclaredUidIdentifier("tmp"),{object:l,property:c}=e.node;n.get("left").replaceWith(y(l,s("=",o,c),!0)),n.get("right").replaceWith(t(a?"=":r,y(l,u(o.name),!0),i))}else{const s=e.node.object,o=e.node.property;n.get("left").replaceWith(y(s,o)),n.get("right").replaceWith(t(a?"=":r,y(s,u(o.name)),i))}return a?n.replaceWith(f(r,n.node.left,n.node.right)):n.node.operator="=",[n.get("left"),n.get("right").get("left")]}if(e.parentPath.isUpdateExpression()){const t=e.parentPath,n=e.scope.generateDeclaredUidIdentifier("tmp"),r=e.node.computed?e.scope.generateDeclaredUidIdentifier("prop"):null,i=[s("=",n,y(e.node.object,r?s("=",r,e.node.property):e.node.property,e.node.computed)),s("=",y(e.node.object,r?u(r.name):e.node.property,e.node.computed),a(e.parentPath.node.operator[0],u(n.name),g(1)))];e.parentPath.node.prefix||i.push(u(n.name)),t.replaceWith(E(i));return[t.get("expressions.0.right"),t.get("expressions.1.left")]}return[e];function t(e,t,n){return"="===e?s("=",t,n):a(e,t,n)}}(t)),[]).forEach(e=>{const t=e.node.computed?"":e.get("property").node.name,n=e.parentPath,r=n.isAssignmentExpression({left:e.node}),a=n.isCallExpression({callee:e.node}),o=n.isTaggedTemplateExpression({tag:e.node}),c=function(e,t,n){const r=t?"set":"get";return q(e,`superprop_${r}:${n||""}`,()=>{const r=[];let a;if(n)a=y(A(),u(n));else{const t=e.scope.generateUidIdentifier("prop");r.unshift(t),a=y(A(),u(t.name),!0)}if(t){const t=e.scope.generateUidIdentifier("value");r.push(t),a=s("=",a,u(t.name))}return i(r,a)})}(p,r,t),d=[];if(e.node.computed&&d.push(e.get("property").node),r){const e=n.node.right;d.push(e)}const h=l(u(c),d);a?(n.unshiftContainer("arguments",C()),e.replaceWith(y(h,u("call"))),S.push(n.get("arguments.0"))):r?n.replaceWith(h):o?(e.replaceWith(l(y(h,u("bind"),!1),[C()])),S.push(e.get("arguments.0"))):e.replaceWith(h)})}let _;return(S.length>0||!t)&&(_=function(e,t){return q(e,"this",n=>{if(!t||!V(e))return C();e.traverse($,{supers:new WeakSet,thisBinding:n})})}(p,d),(t||d&&V(p))&&(S.forEach(e=>{const t=e.isJSX()?h(_):u(_);t.loc=e.node.loc,e.replaceWith(t)}),t||(_=null))),{thisBinding:_,fnPath:e}}function V(e){return e.isClassMethod()&&!!e.parentPath.parentPath.node.superClass}const $=(0,n.environmentVisitor)({CallExpression(e,{supers:t,thisBinding:n}){e.get("callee").isSuper()&&(t.has(e.node)||(t.add(e.node),e.replaceWithMultiple([e.node,s("=",u(n),u("this"))])))}});function q(e,t,n){const r="binding:"+t;let i=e.getData(r);if(!i){const s=e.scope.generateUidIdentifier(t);i=s.name,e.setData(r,i),e.scope.push({id:s,init:n(i)})}return i}const W=(0,n.environmentVisitor)({ThisExpression(e,{thisPaths:t}){t.push(e)},JSXIdentifier(e,{thisPaths:t}){"this"===e.node.name&&(e.parentPath.isJSXMemberExpression({object:e.node})||e.parentPath.isJSXOpeningElement({name:e.node}))&&t.push(e)},CallExpression(e,{superCalls:t}){e.get("callee").isSuper()&&t.push(e)},MemberExpression(e,{superProps:t}){e.get("object").isSuper()&&t.push(e)},Identifier(e,{argumentsPaths:t}){if(!e.isReferencedIdentifier({name:"arguments"}))return;let n=e.scope;do{if(n.hasOwnBinding("arguments"))return void n.rename("arguments");if(n.path.isFunction()&&!n.path.isArrowFunctionExpression())break}while(n=n.parent);t.push(e)},MetaProperty(e,{newTargetPaths:t}){e.get("meta").isIdentifier({name:"new"})&&e.get("property").isIdentifier({name:"target"})&&t.push(e)}});const J={"ReferencedIdentifier|BindingIdentifier"(e,t){e.node.name===t.name&&(t.needsRename=!0,e.stop())},Scope(e,t){e.scope.hasOwnBinding(t.name)&&e.skip()}};return to}var Co,wo={};function Io(){return Co||(Co=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e._guessExecutionStatusRelativeTo=function(e){return m(this,e,new Map)},e._resolve=y,e.canHaveVariableDeclarationOrExpression=function(){return("init"===this.key||"left"===this.key)&&this.parentPath.isFor()},e.canSwapBetweenExpressionAndStatement=function(e){if("body"!==this.key||!this.parentPath.isArrowFunctionExpression())return!1;if(this.isExpression())return i(e);if(this.isBlockStatement())return s(e);return!1},e.getSource=function(){const e=this.node;if(e.end){const t=this.hub.getCode();if(t)return t.slice(e.start,e.end)}return""},e.isCompletionRecord=function(e){let t=this,n=!0;do{const{type:r,container:i}=t;if(!n&&(t.isFunction()||"StaticBlock"===r))return!!e;if(n=!1,Array.isArray(i)&&t.key!==i.length-1)return!1}while((t=t.parentPath)&&!t.isProgram()&&!t.isDoExpression());return!0},e.isConstantExpression=function(){if(this.isIdentifier()){const e=this.scope.getBinding(this.node.name);return!!e&&e.constant}if(this.isLiteral())return!this.isRegExpLiteral()&&(!this.isTemplateLiteral()||this.get("expressions").every(e=>e.isConstantExpression()));if(this.isUnaryExpression())return"void"===this.node.operator&&this.get("argument").isConstantExpression();if(this.isBinaryExpression()){const{operator:e}=this.node;return"in"!==e&&"instanceof"!==e&&this.get("left").isConstantExpression()&&this.get("right").isConstantExpression()}if(this.isMemberExpression())return!this.node.computed&&this.get("object").isIdentifier({name:"Symbol"})&&!this.scope.hasBinding("Symbol",{noGlobals:!0});if(this.isCallExpression())return 1===this.node.arguments.length&&this.get("callee").matchesPattern("Symbol.for")&&!this.scope.hasBinding("Symbol",{noGlobals:!0})&&this.get("arguments")[0].isStringLiteral();return!1},e.isInStrictMode=function(){const e=(this.isProgram()?this:this.parentPath).find(e=>{if(e.isProgram({sourceType:"module"}))return!0;if(e.isClass())return!0;if(e.isArrowFunctionExpression()&&!e.get("body").isBlockStatement())return!1;let t;if(e.isFunction())t=e.node.body;else{if(!e.isProgram())return!1;t=e.node}for(const e of t.directives)if("use strict"===e.value.value)return!0;return!1});return!!e},e.isNodeType=function(e){return c(this.type,e)},e.isStatementOrBlock=function(){return!this.parentPath.isLabeledStatement()&&!i(this.container)&&n.includes(this.key)},e.isStatic=function(){return this.scope.isStatic(this.node)},e.matchesPattern=function(e,t){return p(this.node,e,t)},e.referencesImport=function(e,t){if(!this.isReferencedIdentifier()){if(this.isJSXMemberExpression()&&this.node.property.name===t||(this.isMemberExpression()||this.isOptionalMemberExpression())&&(this.node.computed?l(this.node.property,{value:t}):this.node.property.name===t)){const t=this.get("object");return t.isReferencedIdentifier()&&t.referencesImport(e,"*")}return!1}const n=this.scope.getBinding(this.node.name);if(!n||"module"!==n.kind)return!1;const r=n.path,i=r.parentPath;if(!i.isImportDeclaration())return!1;if(i.node.source.value!==e)return!1;if(!t)return!0;if(r.isImportDefaultSpecifier()&&"default"===t)return!0;if(r.isImportNamespaceSpecifier()&&"*"===t)return!0;if(r.isImportSpecifier()&&a(r.node.imported,{name:t}))return!0;return!1},e.resolve=function(e,t){return y.call(this,e,t)||this},e.willIMaybeExecuteBefore=function(e){return"after"!==this._guessExecutionStatusRelativeTo(e)};var t=Yr();const{STATEMENT_OR_BLOCK_KEYS:n,VISITOR_KEYS:r,isBlockStatement:i,isExpression:s,isIdentifier:a,isLiteral:o,isStringLiteral:l,isType:c,matchesPattern:p}=t;function u(e){return e.isProgram()?e:(e.parentPath.scope.getFunctionParent()||e.parentPath.scope.getProgramParent()).path}function d(e,t){switch(e){case"LogicalExpression":case"AssignmentPattern":return"right"===t;case"ConditionalExpression":case"IfStatement":return"consequent"===t||"alternate"===t;case"WhileStatement":case"DoWhileStatement":case"ForInStatement":case"ForOfStatement":return"body"===t;case"ForStatement":return"body"===t||"update"===t;case"SwitchStatement":return"cases"===t;case"TryStatement":return"handler"===t;case"OptionalMemberExpression":return"property"===t;case"OptionalCallExpression":return"arguments"===t;default:return!1}}function h(e,t){for(let n=0;n<t;n++){const t=e[n];if(d(t.parent.type,t.parentKey))return!0}return!1}e.has=function(e){var t;const n=null==(t=this.node)?void 0:t[e];return n&&Array.isArray(n)?!!n.length:!!n},e.is=e.has,e.isnt=function(e){return!this.has(e)},e.equals=function(e,t){return this.node[e]===t};const f=Symbol();function m(e,t,n){const i={this:u(e),target:u(t)};if(i.target.node!==i.this.node)return function(e,t,n){let r,i=n.get(e.node);if(i){if(r=i.get(t.node))return r===f?"unknown":r}else n.set(e.node,i=new Map);i.set(t.node,f);const s=function(e,t,n){if(!t.isFunctionDeclaration())return"before"===m(e,t,n)?"before":"unknown";if(t.parentPath.isExportDeclaration())return"unknown";const r=t.scope.getBinding(t.node.id.name);if(!r.references)return"before";const i=r.referencePaths;let s;for(const r of i){if(!!r.find(e=>e.node===t.node))continue;if("callee"!==r.key||!r.parentPath.isCallExpression())return"unknown";const i=m(e,r,n);if(s&&s!==i)return"unknown";s=i}return s}(e,t,n);return i.set(t.node,s),s}(e,i.target,n);const s={target:t.getAncestry(),this:e.getAncestry()};if(s.target.includes(e))return"after";if(s.this.includes(t))return"before";let a;const o={target:0,this:0};for(;!a&&o.this<s.this.length;){const e=s.this[o.this];o.target=s.target.indexOf(e),o.target>=0?a=e:o.this++}if(!a)throw new Error("Internal Babel error - The two compared nodes don't appear to belong to the same program.");if(h(s.this,o.this-1)||h(s.target,o.target-1))return"unknown";const l={this:s.this[o.this-1],target:s.target[o.target-1]};if(l.target.listKey&&l.this.listKey&&l.target.container===l.this.container)return l.target.key>l.this.key?"before":"after";const c=r[a.type],p=c.indexOf(l.this.parentKey);return c.indexOf(l.target.parentKey)>p?"before":"after"}function y(e,t){var n;if(null==(n=t)||!n.includes(this))if((t=t||[]).push(this),this.isVariableDeclarator()){if(this.get("id").isIdentifier())return this.get("init").resolve(e,t)}else if(this.isReferencedIdentifier()){const n=this.scope.getBinding(this.node.name);if(!n)return;if(!n.constant)return;if("module"===n.kind)return;if(n.path!==this){const r=n.path.resolve(e,t);if(this.find(e=>e.node===r.node))return;return r}}else{if(this.isTypeCastExpression())return this.get("expression").resolve(e,t);if(e&&this.isMemberExpression()){const n=this.toComputedKey();if(!o(n))return;const r=n.value,i=this.get("object").resolve(e,t);if(i.isObjectExpression()){const n=i.get("properties");for(const i of n){if(!i.isProperty())continue;const n=i.get("key");let s=i.isnt("computed")&&n.isIdentifier({name:r});if(s=s||n.isLiteral({value:r}),s)return i.get("value").resolve(e,t)}}else if(i.isArrayExpression()&&!isNaN(+r)){const n=i.get("elements")[r];if(n)return n.resolve(e,t)}}}}}(wo)),wo}var No,ko={};function Oo(){if(No)return ko;No=1,Object.defineProperty(ko,"__esModule",{value:!0}),ko._getKey=f,ko._getPattern=m,ko.get=function(e,t=!0){!0===t&&(t=this.context);const n=e.split(".");return 1===n.length?f.call(this,e,t):m.call(this,n,t)},ko.getAllNextSiblings=function(){let e=this.key,t=this.getSibling(++e);const n=[];for(;t.node;)n.push(t),t=this.getSibling(++e);return n},ko.getAllPrevSiblings=function(){let e=this.key,t=this.getSibling(--e);const n=[];for(;t.node;)n.push(t),t=this.getSibling(--e);return n},ko.getAssignmentIdentifiers=function(){return n(this.node)},ko.getBindingIdentifierPaths=function(e=!1,t=!1){const n=[this],i=Object.create(null);for(;n.length;){const s=n.shift();if(!s)continue;if(!s.node)continue;const a=r.keys[s.node.type];if(s.isIdentifier())if(e){(i[s.node.name]=i[s.node.name]||[]).push(s)}else i[s.node.name]=s;else{if(s.isExportDeclaration()){const e=s.get("declaration");e.isDeclaration()&&n.push(e);continue}if(t){if(s.isFunctionDeclaration()){n.push(s.get("id"));continue}if(s.isFunctionExpression())continue}if(a)for(let e=0;e<a.length;e++){const t=a[e],r=s.get(t);Array.isArray(r)?n.push(...r):r.node&&n.push(r)}}}return i},ko.getBindingIdentifiers=function(e){return r(this.node,e)},ko.getCompletionRecords=function(e=!1){return h(this,{canHaveBreak:!1,shouldPopulateBreak:!1,inCaseClause:!1,shouldPreserveBreak:e}).map(e=>e.path)},ko.getNextSibling=function(){return this.getSibling(this.key+1)},ko.getOpposite=function(){if("left"===this.key)return this.getSibling("right");if("right"===this.key)return this.getSibling("left");return null},ko.getOuterBindingIdentifierPaths=function(e=!1){return this.getBindingIdentifierPaths(e,!0)},ko.getOuterBindingIdentifiers=function(e){return i(this.node,e)},ko.getPrevSibling=function(){return this.getSibling(this.key-1)},ko.getSibling=function(t){return e.default.get({parentPath:this.parentPath,parent:this.parent,container:this.container,listKey:this.listKey,key:t}).setContext(this.context)};var e=jo(),t=Yr();const{getAssignmentIdentifiers:n,getBindingIdentifiers:r,getOuterBindingIdentifiers:i,numericLiteral:s,unaryExpression:a}=t,o=0,l=1;function c(e,t,n){return e&&t.push(...h(e,n)),t}function p(e){e.forEach(e=>{e.type=l})}function u(e,t){e.forEach(e=>{e.path.isBreakStatement({label:null})&&(t?e.path.replaceWith(a("void",s(0))):e.path.remove())})}function d(e,t){const n=[];if(t.canHaveBreak){let r=[];for(let i=0;i<e.length;i++){const s=e[i],a=Object.assign({},t,{inCaseClause:!1});s.isBlockStatement()&&(t.inCaseClause||t.shouldPopulateBreak)?a.shouldPopulateBreak=!0:a.shouldPopulateBreak=!1;const c=h(s,a);if(c.length>0&&c.every(e=>e.type===l)){r.length>0&&c.every(e=>e.path.isBreakStatement({label:null}))?(p(r),n.push(...r),r.some(e=>e.path.isDeclaration())&&(n.push(...c),t.shouldPreserveBreak||u(c,!0)),t.shouldPreserveBreak||u(c,!1)):(n.push(...c),t.shouldPopulateBreak||t.shouldPreserveBreak||u(c,!0));break}if(i===e.length-1)n.push(...c);else{r=[];for(let e=0;e<c.length;e++){const t=c[e];t.type===l&&n.push(t),t.type===o&&r.push(t)}}}}else if(e.length)for(let r=e.length-1;r>=0;r--){const i=h(e[r],t);if(i.length>1||1===i.length&&!i[0].path.isVariableDeclaration()&&!i[0].path.isEmptyStatement()){n.push(...i);break}}return n}function h(e,t){let n=[];if(e.isIfStatement())n=c(e.get("consequent"),n,t),n=c(e.get("alternate"),n,t);else{if(e.isDoExpression()||e.isFor()||e.isWhile()||e.isLabeledStatement())return c(e.get("body"),n,t);if(e.isProgram()||e.isBlockStatement())return d(e.get("body"),t);if(e.isFunction())return h(e.get("body"),t);if(e.isTryStatement())n=c(e.get("block"),n,t),n=c(e.get("handler"),n,t);else{if(e.isCatchClause())return c(e.get("body"),n,t);if(e.isSwitchStatement())return function(e,t,n){let r=[];for(let i=0;i<e.length;i++){const s=h(e[i],n),a=[],c=[];for(const e of s)e.type===o&&a.push(e),e.type===l&&c.push(e);a.length&&(r=a),t.push(...c)}return t.push(...r),t}(e.get("cases"),n,t);if(e.isSwitchCase())return d(e.get("consequent"),{canHaveBreak:!0,shouldPopulateBreak:!1,inCaseClause:!0,shouldPreserveBreak:t.shouldPreserveBreak});e.isBreakStatement()?n.push(function(e){return{type:l,path:e}}(e)):n.push(function(e){return{type:o,path:e}}(e))}}return n}function f(t,n){const r=this.node,i=r[t];return Array.isArray(i)?i.map((s,a)=>e.default.get({listKey:t,parentPath:this,parent:r,container:i,key:a}).setContext(n)):e.default.get({parentPath:this,parent:r,container:r,key:t}).setContext(n)}function m(e,t){let n=this;for(const r of e)n="."===r?n.parentPath:Array.isArray(n)?n[r]:n.get(r,t);return n}return ko}var _o,Do,Lo,Mo,Fo,Bo={};function jo(){if(Do)return Si;Do=1,Object.defineProperty(Si,"__esModule",{value:!0}),Si.default=Si.SHOULD_STOP=Si.SHOULD_SKIP=Si.REMOVED=void 0;var e=bi(),t=Mi(),n=qo(),r=ts(),i=Yr(),s=i,a=Gi(),o=ma(),l=function(){if(ya)return Ta;ya=1,Object.defineProperty(Ta,"__esModule",{value:!0}),Ta.find=function(e){let t=this;do{if(e(t))return t}while(t=t.parentPath);return null},Ta.findParent=function(e){let t=this;for(;t=t.parentPath;)if(e(t))return t;return null},Ta.getAncestry=function(){let e=this;const t=[];do{t.push(e)}while(e=e.parentPath);return t},Ta.getDeepestCommonAncestorFrom=function(e,t){if(!e.length)return this;if(1===e.length)return e[0];let n,r,i=1/0;const s=e.map(e=>{const t=[];do{t.unshift(e)}while((e=e.parentPath)&&e!==this);return t.length<i&&(i=t.length),t}),a=s[0];e:for(let e=0;e<i;e++){const t=a[e];for(const n of s)if(n[e]!==t)break e;n=e,r=t}if(r)return t?t(r,n,s):r;throw new Error("Couldn't find intersection")},Ta.getEarliestCommonAncestorFrom=function(e){return this.getDeepestCommonAncestorFrom(e,function(e,n,r){let i;const s=t[e.type];for(const e of r){const t=e[n+1];i?(t.listKey&&i.listKey===t.listKey&&t.key<i.key||s.indexOf(i.parentKey)>s.indexOf(t.parentKey))&&(i=t):i=t}return i})},Ta.getFunctionParent=function(){return this.findParent(e=>e.isFunction())},Ta.getStatementParent=function(){let e=this;do{if(!e.parentPath||Array.isArray(e.container)&&e.isStatement())break;e=e.parentPath}while(e);if(e&&(e.isProgram()||e.isFile()))throw new Error("File/Program node, we can't possibly find a statement parent to this");return e},Ta.inType=function(...e){let t=this;for(;t;){if(e.includes(t.node.type))return!0;t=t.parentPath}return!1},Ta.isAncestor=function(e){return e.isDescendant(this)},Ta.isDescendant=function(e){return!!this.findParent(t=>t===e)};var e=Yr();const{VISITOR_KEYS:t}=e;return Ta}(),c=function(){if(ba)return Ea;ba=1,Object.defineProperty(Ea,"__esModule",{value:!0}),Ea._getTypeAnnotation=P,Ea.baseTypeStrictlyMatches=function(e){const t=this.getTypeAnnotation(),n=e.getTypeAnnotation();return!(r(t)||!o(t))&&n.type===t.type},Ea.couldBeBaseType=function(e){const t=this.getTypeAnnotation();if(r(t))return!0;if(g(t)){for(const n of t.types)if(r(n)||v(e,n,!0))return!0;return!1}return v(e,t,!0)},Ea.getTypeAnnotation=function(){let e=this.getData("typeAnnotation");return null!=e||(e=P.call(this)||n(),(T(e)||f(e))&&(e=e.typeAnnotation),this.setData("typeAnnotation",e)),e},Ea.isBaseType=function(e,t){return v(e,this.getTypeAnnotation(),t)},Ea.isGenericType=function(e){const t=this.getTypeAnnotation();return!("Array"!==e||!(h(t)||i(t)||y(t)))||(l(t)&&c(t.id,{name:e})||m(t)&&c(t.typeName,{name:e}))};var e=Ia(),t=Yr();const{anyTypeAnnotation:n,isAnyTypeAnnotation:r,isArrayTypeAnnotation:i,isBooleanTypeAnnotation:s,isEmptyTypeAnnotation:a,isFlowBaseAnnotation:o,isGenericTypeAnnotation:l,isIdentifier:c,isMixedTypeAnnotation:p,isNumberTypeAnnotation:u,isStringTypeAnnotation:d,isTSArrayType:h,isTSTypeAnnotation:f,isTSTypeReference:m,isTupleTypeAnnotation:y,isTypeAnnotation:T,isUnionTypeAnnotation:g,isVoidTypeAnnotation:S,stringTypeAnnotation:x,voidTypeAnnotation:b}=t,E=new WeakSet;function P(){const t=this.node;if(t){if(t.typeAnnotation)return t.typeAnnotation;if(!E.has(t)){E.add(t);try{var r;let n=e[t.type];if(n)return n.call(this,t);if(n=e[this.parentPath.type],null!=(r=n)&&r.validParent)return this.parentPath.getTypeAnnotation()}finally{E.delete(t)}}}else if("init"===this.key&&this.parentPath.isVariableDeclarator()){const e=this.parentPath.parentPath,t=e.parentPath;return"left"===e.key&&t.isForInStatement()?x():"left"===e.key&&t.isForOfStatement()?n():b()}}function v(e,t,n){if("string"===e)return d(t);if("number"===e)return u(t);if("boolean"===e)return s(t);if("any"===e)return r(t);if("mixed"===e)return p(t);if("empty"===e)return a(t);if("void"===e)return S(t);if(n)return!1;throw new Error(`Unknown base type ${e}`)}return Ea}(),p=za(),u=Za(),d=Ao(),h=Io(),f=Uo(),m=f,y=qa(),T=Ha(),g=Oo(),S=function(){if(_o)return Bo;_o=1,Object.defineProperty(Bo,"__esModule",{value:!0}),Bo.addComment=function(e,n,r){t(this.node,e,n,r)},Bo.addComments=function(e,t){n(this.node,e,t)},Bo.shareCommentsWithSiblings=function(){if("string"==typeof this.key)return;const e=this.node;if(!e)return;const t=e.trailingComments,n=e.leadingComments;if(!t&&!n)return;const i=this.getSibling(this.key-1),s=this.getSibling(this.key+1),a=Boolean(i.node),o=Boolean(s.node);a&&(n&&i.addComments("trailing",r(n,i.node.trailingComments)),t&&!o&&i.addComments("trailing",t)),o&&(t&&s.addComments("leading",r(t,s.node.leadingComments)),n&&!a&&s.addComments("leading",n))};var e=Yr();const{addComment:t,addComments:n}=e;function r(e,t){if(null==t||!t.length)return e;const n=new Set(t);return e.filter(e=>!n.has(e))}return Bo}(),x=$i();const{validate:b}=i,E=t("babel");Si.REMOVED=1,Si.SHOULD_STOP=2,Si.SHOULD_SKIP=4;const P=Si.default=class e{constructor(e,t){this.contexts=[],this.state=null,this._traverseFlags=0,this.skipKeys=null,this.parentPath=null,this.container=null,this.listKey=null,this.key=null,this.node=null,this.type=null,this._store=null,this.parent=t,this.hub=e,this.data=null,this.context=null,this.scope=null}get removed(){return(1&this._traverseFlags)>0}set removed(e){e?this._traverseFlags|=1:this._traverseFlags&=-2}get shouldStop(){return(2&this._traverseFlags)>0}set shouldStop(e){e?this._traverseFlags|=2:this._traverseFlags&=-3}get shouldSkip(){return(4&this._traverseFlags)>0}set shouldSkip(e){e?this._traverseFlags|=4:this._traverseFlags&=-5}static get({hub:t,parentPath:n,parent:r,container:i,listKey:s,key:o}){if(!t&&n&&(t=n.hub),!r)throw new Error("To get a node path the parent needs to exist");const l=i[o],c=a.getOrCreateCachedPaths(r,n);let p=c.get(l);return p||(p=new e(t,r),l&&c.set(l,p)),f.setup.call(p,n,i,s,o),p}getScope(e){return this.isScope()?new r.default(this):e}setData(e,t){return null==this.data&&(this.data=Object.create(null)),this.data[e]=t}getData(e,t){null==this.data&&(this.data=Object.create(null));let n=this.data[e];return void 0===n&&void 0!==t&&(n=this.data[e]=t),n}hasNode(){return null!=this.node}buildCodeFrameError(e,t=SyntaxError){return this.hub.buildError(this.node,e,t)}traverse(e,t){(0,n.default)(this.node,e,this.scope,t,this)}set(e,t){b(this.node,e,t),this.node[e]=t}getPathLocation(){const e=[];let t=this;do{let n=t.key;t.inList&&(n=`${t.listKey}[${n}]`),e.unshift(n)}while(t=t.parentPath);return e.join(".")}debug(e){E.enabled&&E(`${this.getPathLocation()} ${this.type}: ${e}`)}toString(){return(0,o.default)(this.node).code}get inList(){return!!this.listKey}set inList(e){e||(this.listKey=null)}get parentKey(){return this.listKey||this.key}},v={findParent:l.findParent,find:l.find,getFunctionParent:l.getFunctionParent,getStatementParent:l.getStatementParent,getEarliestCommonAncestorFrom:l.getEarliestCommonAncestorFrom,getDeepestCommonAncestorFrom:l.getDeepestCommonAncestorFrom,getAncestry:l.getAncestry,isAncestor:l.isAncestor,isDescendant:l.isDescendant,inType:l.inType,getTypeAnnotation:c.getTypeAnnotation,isBaseType:c.isBaseType,couldBeBaseType:c.couldBeBaseType,baseTypeStrictlyMatches:c.baseTypeStrictlyMatches,isGenericType:c.isGenericType,replaceWithMultiple:p.replaceWithMultiple,replaceWithSourceString:p.replaceWithSourceString,replaceWith:p.replaceWith,replaceExpressionWithStatements:p.replaceExpressionWithStatements,replaceInline:p.replaceInline,evaluateTruthy:u.evaluateTruthy,evaluate:u.evaluate,toComputedKey:d.toComputedKey,ensureBlock:d.ensureBlock,unwrapFunctionEnvironment:d.unwrapFunctionEnvironment,arrowFunctionToExpression:d.arrowFunctionToExpression,splitExportDeclaration:d.splitExportDeclaration,ensureFunctionName:d.ensureFunctionName,matchesPattern:h.matchesPattern,isStatic:h.isStatic,isNodeType:h.isNodeType,canHaveVariableDeclarationOrExpression:h.canHaveVariableDeclarationOrExpression,canSwapBetweenExpressionAndStatement:h.canSwapBetweenExpressionAndStatement,isCompletionRecord:h.isCompletionRecord,isStatementOrBlock:h.isStatementOrBlock,referencesImport:h.referencesImport,getSource:h.getSource,willIMaybeExecuteBefore:h.willIMaybeExecuteBefore,_guessExecutionStatusRelativeTo:h._guessExecutionStatusRelativeTo,resolve:h.resolve,isConstantExpression:h.isConstantExpression,isInStrictMode:h.isInStrictMode,isDenylisted:m.isDenylisted,visit:m.visit,skip:m.skip,skipKey:m.skipKey,stop:m.stop,setContext:m.setContext,requeue:m.requeue,requeueComputedKeyAndDecorators:m.requeueComputedKeyAndDecorators,remove:y.remove,insertBefore:T.insertBefore,insertAfter:T.insertAfter,unshiftContainer:T.unshiftContainer,pushContainer:T.pushContainer,getOpposite:g.getOpposite,getCompletionRecords:g.getCompletionRecords,getSibling:g.getSibling,getPrevSibling:g.getPrevSibling,getNextSibling:g.getNextSibling,getAllNextSiblings:g.getAllNextSiblings,getAllPrevSiblings:g.getAllPrevSiblings,get:g.get,getAssignmentIdentifiers:g.getAssignmentIdentifiers,getBindingIdentifiers:g.getBindingIdentifiers,getOuterBindingIdentifiers:g.getOuterBindingIdentifiers,getBindingIdentifierPaths:g.getBindingIdentifierPaths,getOuterBindingIdentifierPaths:g.getOuterBindingIdentifierPaths,shareCommentsWithSiblings:S.shareCommentsWithSiblings,addComment:S.addComment,addComments:S.addComments};Object.assign(P.prototype,v),P.prototype.arrowFunctionToShadowed=d[String("arrowFunctionToShadowed")],Object.assign(P.prototype,{has:h[String("has")],is:h[String("is")],isnt:h[String("isnt")],equals:h[String("equals")],hoist:T[String("hoist")],updateSiblingKeys:T.updateSiblingKeys,call:m.call,isBlacklisted:m[String("isBlacklisted")],setScope:m.setScope,resync:m.resync,popContext:m.popContext,pushContext:m.pushContext,setup:m.setup,setKey:m.setKey}),P.prototype._guessExecutionStatusRelativeToDifferentFunctions=h._guessExecutionStatusRelativeTo,P.prototype._guessExecutionStatusRelativeToDifferentFunctions=h._guessExecutionStatusRelativeTo,Object.assign(P.prototype,{_getTypeAnnotation:c._getTypeAnnotation,_replaceWith:p._replaceWith,_resolve:h._resolve,_call:m._call,_resyncParent:m._resyncParent,_resyncKey:m._resyncKey,_resyncList:m._resyncList,_resyncRemoved:m._resyncRemoved,_getQueueContexts:m._getQueueContexts,_removeFromScope:y._removeFromScope,_callRemovalHooks:y._callRemovalHooks,_remove:y._remove,_markRemoved:y._markRemoved,_assertUnremoved:y._assertUnremoved,_containerInsert:T._containerInsert,_containerInsertBefore:T._containerInsertBefore,_containerInsertAfter:T._containerInsertAfter,_verifyNodeList:T._verifyNodeList,_getKey:g._getKey,_getPattern:g._getPattern});for(const e of s.TYPES){const t=`is${e}`,n=s[t];P.prototype[t]=function(e){return n(this.node,e)},P.prototype[`assert${e}`]=function(t){if(!n(this.node,t))throw new TypeError(`Expected node path of type ${e}`)}}Object.assign(P.prototype,x);for(const t of Object.keys(e))"_"!==t[0]&&(s.TYPES.includes(t)||s.TYPES.push(t));return Si}function Ro(){if(Mo)return Ti;Mo=1,Object.defineProperty(Ti,"__esModule",{value:!0}),Ti.traverseNode=function(t,r,i,s,a,o,l){const c=n[t.type];if(!c)return!1;const p=new e.default(i,r,s,a);if(l)return(null==o||!o[a.parentKey])&&p.visitQueue([a]);for(const e of c)if((null==o||!o[e])&&p.visit(t,e))return!0;return!1};var e=function(){if(Lo)return gi;Lo=1,Object.defineProperty(gi,"__esModule",{value:!0}),gi.default=void 0;var e=jo(),t=Yr(),n=Uo();const{VISITOR_KEYS:r}=t;return gi.default=class{constructor(e,t,n,r){this.queue=null,this.priorityQueue=null,this.parentPath=r,this.scope=e,this.state=n,this.opts=t}shouldVisit(e){const t=this.opts;if(t.enter||t.exit)return!0;if(t[e.type])return!0;const n=r[e.type];if(null==n||!n.length)return!1;for(const t of n)if(e[t])return!0;return!1}create(t,n,r,i){return e.default.get({parentPath:this.parentPath,parent:t,container:n,key:r,listKey:i})}maybeQueue(e,t){this.queue&&(t?this.queue.push(e):this.priorityQueue.push(e))}visitMultiple(e,t,n){if(0===e.length)return!1;const r=[];for(let i=0;i<e.length;i++){const s=e[i];s&&this.shouldVisit(s)&&r.push(this.create(t,e,i,n))}return this.visitQueue(r)}visitSingle(e,t){return!!this.shouldVisit(e[t])&&this.visitQueue([this.create(e,e,t)])}visitQueue(e){this.queue=e,this.priorityQueue=[];const t=new WeakSet;let r=!1,i=0;for(;i<e.length;){const s=e[i];if(i++,n.resync.call(s),0!==s.contexts.length&&s.contexts[s.contexts.length-1]===this||n.pushContext.call(s,this),null===s.key)continue;const{node:a}=s;if(!t.has(a)){if(a&&t.add(a),s.visit()){r=!0;break}if(this.priorityQueue.length&&(r=this.visitQueue(this.priorityQueue),this.priorityQueue=[],this.queue=e,r))break}}for(let t=0;t<i;t++)n.popContext.call(e[t]);return this.queue=null,r}visit(e,t){const n=e[t];return!!n&&(Array.isArray(n)?this.visitMultiple(n,e,t):this.visitSingle(e,t))}},gi}();jo();var t=Yr();Uo();const{VISITOR_KEYS:n}=t;return Ti}function Uo(){if(Fo)return yi;Fo=1,Object.defineProperty(yi,"__esModule",{value:!0}),yi._call=s,yi._getQueueContexts=function(){let e=this,t=this.contexts;for(;!t.length&&(e=e.parentPath,e);)t=e.contexts;return t},yi._resyncKey=p,yi._resyncList=u,yi._resyncParent=c,yi._resyncRemoved=function(){null!=this.key&&this.container&&this.container[this.key]===this.node||n._markRemoved.call(this)},yi.call=i,yi.isDenylisted=a,yi.popContext=function(){this.contexts.pop(),this.contexts.length>0?this.setContext(this.contexts[this.contexts.length-1]):this.setContext(void 0)},yi.pushContext=function(e){this.contexts.push(e),this.setContext(e)},yi.requeue=function(e=this){if(e.removed)return;const t=this.contexts;for(const n of t)n.maybeQueue(e)},yi.requeueComputedKeyAndDecorators=function(){const{context:e,node:t}=this;!r.isPrivate(t)&&t.computed&&e.maybeQueue(this.get("key"));if(t.decorators)for(const t of this.get("decorators"))e.maybeQueue(t)},yi.resync=function(){if(this.removed)return;c.call(this),u.call(this),p.call(this)},yi.setContext=function(e){null!=this.skipKeys&&(this.skipKeys={});this._traverseFlags=0,e&&(this.context=e,this.state=e.state,this.opts=e.opts);return l.call(this),this},yi.setKey=d,yi.setScope=l,yi.setup=function(e,t,n,r){this.listKey=n,this.container=t,this.parentPath=e||this.parentPath,d.call(this,r)},yi.skip=function(){this.shouldSkip=!0},yi.skipKey=function(e){null==this.skipKeys&&(this.skipKeys={});this.skipKeys[e]=!0},yi.stop=function(){this._traverseFlags|=t.SHOULD_SKIP|t.SHOULD_STOP},yi.visit=function(){var t,n;if(!this.node)return!1;if(this.isDenylisted())return!1;if(null!=(t=(n=this.opts).shouldSkip)&&t.call(n,this))return!1;const r=this.context;if(this.shouldSkip||i.call(this,"enter"))return this.debug("Skip..."),this.shouldStop;return o(this,r),this.debug("Recursing into..."),this.shouldStop=(0,e.traverseNode)(this.node,this.opts,this.scope,this.state,this,this.skipKeys),o(this,r),i.call(this,"exit"),this.shouldStop};var e=Ro(),t=jo(),n=qa(),r=Yr();function i(e){const t=this.opts;return this.debug(e),!(!this.node||!s.call(this,t[e]))||!!this.node&&s.call(this,null==(n=t[this.node.type])?void 0:n[e]);var n}function s(e){if(!e)return!1;for(const t of e){if(!t)continue;const e=this.node;if(!e)return!0;const n=t.call(this.state,this,this.state);if(n&&"object"==typeof n&&"function"==typeof n.then)throw new Error("You appear to be using a plugin with an async traversal visitor, which your current version of Babel does not support. If you're using a published plugin, you may need to upgrade your @babel/core version.");if(n)throw new Error(`Unexpected return value from visitor method ${t}`);if(this.node!==e)return!0;if(this._traverseFlags>0)return!0}return!1}function a(){var e;const t=null!=(e=this.opts.denylist)?e:this.opts.blacklist;return null==t?void 0:t.includes(this.node.type)}function o(e,t){e.context!==t&&(e.context=t,e.state=t.state,e.opts=t.opts)}function l(){var e,t;if(null!=(e=this.opts)&&e.noScope)return;let n,r=this.parentPath;for((("key"===this.key||"decorators"===this.listKey)&&r.isMethod()||"discriminant"===this.key&&r.isSwitchStatement())&&(r=r.parentPath);r&&!n;){var i;if(null!=(i=r.opts)&&i.noScope)return;n=r.scope,r=r.parentPath}this.scope=this.getScope(n),null==(t=this.scope)||t.init()}function c(){this.parentPath&&(this.parent=this.parentPath.node)}function p(){if(this.container&&this.node!==this.container[this.key]){if(Array.isArray(this.container)){for(let e=0;e<this.container.length;e++)if(this.container[e]===this.node)return void d.call(this,e)}else for(const e of Object.keys(this.container))if(this.container[e]===this.node)return void d.call(this,e);this.key=null}}function u(){if(!this.parent||!this.inList)return;const e=this.parent[this.listKey];this.container!==e&&(this.container=e||null)}function d(e){var t;this.key=e,this.node=this.container[this.key],this.type=null==(t=this.node)?void 0:t.type}return yi.isBlacklisted=a,yi}var Ko,Vo,$o={};function qo(){return Vo||(Vo=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),Object.defineProperty(e,"Hub",{enumerable:!0,get:function(){return o.default}}),Object.defineProperty(e,"NodePath",{enumerable:!0,get:function(){return s.default}}),Object.defineProperty(e,"Scope",{enumerable:!0,get:function(){return a.default}}),e.visitors=e.default=void 0,Uo();var t=qi();e.visitors=t;var n=Yr(),r=Gi(),i=Ro(),s=jo(),a=ts(),o=(Ko||(Ko=1,Object.defineProperty($o,"__esModule",{value:!0}),$o.default=void 0,$o.default=class{getCode(){}getScope(){}addHelper(){throw new Error("Helpers are not supported by the default hub.")}buildError(e,t,n=TypeError){return new n(t)}}),$o);const{VISITOR_KEYS:l,removeProperties:c,traverseFast:p}=n;function u(e,n={},r,s,a,o){if(e){if(!n.noScope&&!r&&"Program"!==e.type&&"File"!==e.type)throw new Error(`You must pass a scope and parentPath unless traversing a Program/File. Instead of that you tried to traverse a ${e.type} node without passing scope and parentPath.`);if(!a&&o)throw new Error("visitSelf can only be used when providing a NodePath.");l[e.type]&&(t.explode(n),(0,i.traverseNode)(e,n,r,s,a,void 0,o))}}e.default=u,u.visitors=t,u.verify=t.verify,u.explode=t.explode,u.cheap=function(e,t){p(e,t)},u.node=function(e,t,n,r,s,a){(0,i.traverseNode)(e,t,n,r,s,a)},u.clearNode=function(e,t){c(e,t)},u.removeProperties=function(e,t){return p(e,u.clearNode,t),e},u.hasType=function(e,t,n){return(null==n||!n.includes(e.type))&&(e.type===t||p(e,function(e){return null!=n&&n.includes(e.type)?p.skip:e.type===t?p.stop:void 0}))},u.cache=r}(mi)),mi}var Wo=q(qo());function Jo(e){const t="string"==typeof e?Zr(e):e;let n=!1;return Wo(t,{noScope:!0,JSXElement(e){n=!0,e.stop()},JSXFragment(e){n=!0,e.stop()}}),n}const Yo=["components","utils","hooks","typings"];function Xo(e){return/^\\\\\?\\/.test(e)?e:e.replace(/\\/g,"/")}const Ho={javascript:[".ts",".tsx",".js",".jsx"],css:[".less",".sass",".scss",".stylus",".css"]};function zo(e){const t=Ho[e.type];for(const n of t){const t=`${e.fileNameWithoutExt}${n}`,r=Xo(s(e.base,t));if(u(r))return{path:r,filename:t}}return null}const Go=/^\[(.+?)\]/;function Qo(e,t,n,r){const{root:i,relDir:o=""}=e,c=r.name,p=s(i,o,c),u=Go.test(c);if(r.isDirectory()){const r=s(o,c),a=zo({base:s(i,r),fileNameWithoutExt:"_layout",type:"javascript"}),l={path:el(r),routes:tl({...e,relDir:s(r)},t),__isDynamic:u,...a?{component:a.path}:{exact:!0,__toMerge:!0}};n.push(Zo(l,e,t))}else{const r=a(c,l(c));n.push(Zo({path:el(s(o,r)),exact:!0,component:p,__isDynamic:u},e,t))}return n}function Zo(e,t,r){let i;return e.component&&(i=r.readComponent(e.component).props,e.component=Xo(n(s(t.root,".."),e.component)),e.component=`${t.componentPrefix||"@/"}${e.component}`),{...e,..."object"==typeof i?i:{}}}function el(e){return"/index/index"===(e=`/${e=Xo(e).split("/").map(e=>((e=e.replace(Go,":$1")).endsWith("$")&&(e=e.slice(0,-1)+"?"),e)).join("/")}`)&&(e="/"),"/"!==(e=e.replace(/\/index$/,"/"))&&"/"===e.slice(-1)&&(e=e.slice(0,-1)),e}function tl(e,t){const{root:n,relDir:r="",config:i}=e,a=function(e,t){return u(e)?f(e,{withFileTypes:!0}).map(t=>{if(!t.isSymbolicLink())return t;const n=d(s(e,t.name));return{name:t.name,isDirectory:()=>n.isDirectory(),isFile:()=>n.isFile()}}).filter(n=>{const r=s(e,n.name);return!!t.acceptsPage(r,n.isDirectory())&&!n.name.startsWith("_")&&(n.isDirectory()||n.isFile()&&t.readComponent(r).isComponent)}):[]}(s(n,r),t),o=function(e){const t=[],n=[],r=[];return e.forEach(e=>{const{__isDynamic:i,exact:s}=e;delete e.__isDynamic,i?t.push(e):s?n.push(e):r.push(e)}),g(t.length<=1,"We should not have multiple dynamic routes under a directory."),[...n,...r,...t].reduce((e,t)=>(t.__toMerge&&t.routes?e=e.concat(t.routes):e.push(t),e),[])}(a.reduce(Qo.bind(null,e,t),[]));if(!r){const r=zo({base:n,fileNameWithoutExt:`../${i.singular?"layout":"layouts"}/index`,type:"javascript"});if(r)return[Zo({path:"/",component:r.path,routes:o},e,t)]}return o}function nl(e){const s={...e,root:t(e.root)},l=new Map,c=function(e,s=Yo,a=[]){const o=new Set(["components","component","utils","util","node_modules",...s]),l=new Set(a.map(e=>t(e)));return(s,a)=>{const c=t(s);if(l.has(c))return!1;const p=n(e,c);if(".."===p||p.startsWith(`..${r}`)||i(p))return!1;if(!p)return a;const u=p.split(r);if((a?u:u.slice(0,-1)).some(e=>o.has(e)||/^[._]/.test(e)))return!1;if(a)return!0;const d=u[u.length-1];return function(e){return/\.(j|t)sx?$/.test(e)&&!/\.(test|spec|e2e)\.(j|t)sx?$/.test(e)&&!/\.d\.ts$/.test(e)}(d)&&(!/^[._]/.test(d)||/^_layout\.(j|t)sx?$/.test(d))}}(s.root,s.ignoreDirs,s.excludedFiles),p=t(s.root,"..",s.config.singular?"layout":"layouts"),u=new Set,f={acceptsPage:c,readComponent(e){const n=t(e),r=l.get(n);if(u.has(n)&&r)return r;u.add(n);const i=d(n),s=`${i.mtimeMs}:${i.ctimeMs}:${i.size}`;if(r?.signature===s)return r;try{const e=Zr(h(n,"utf-8")),t={signature:s,isComponent:Jo(e),props:hi(e)};return l.set(n,t),t}catch(e){const t=e instanceof Error?e.message:String(e);throw new Error(`Parse conventional route component ${n} failed, ${t}`)}}};return{globalLayoutDir:p,getRoutes(){try{const e=tl(s,f);for(const e of l.keys())u.has(e)||l.delete(e);return e}catch(e){throw l.clear(),e}finally{u.clear()}},isRelevant(e,n=!1){const r=t(e);return!s.excludedFiles?.some(e=>t(e)===r)&&(!(!n||r!==p)||(!(n||!/^index\.(j|t)sx?$/.test(a(r))||o(r)!==p)||c(r,n)))},invalidate(e){const n=t(e);for(const e of l.keys())(e===n||e.startsWith(`${n}${r}`))&&l.delete(e)},clear(){l.clear(),u.clear()}}}function rl(e){return nl(e).getRoutes()}function il(e){const t={path:e.path||""};if(void 0!==e.exact&&(t.exact=e.exact),e.component){const n=e.component.replace(/\.(tsx|ts|jsx|js)$/,"");t.component=`dynamic({ loader: () => import(${JSON.stringify(n)}), loading: LoadingComponent})`}return e.title&&"string"==typeof e.title&&(t.title=`$t({ defaultMessage: ${JSON.stringify(e.title)} })`),!0===e.keepAlive&&(t.keepAlive=!0),e.authority&&Array.isArray(e.authority)&&(t.authority=e.authority),e.routes&&e.routes.length>0&&(t.routes=e.routes.map(il)),t}async function sl(e,t,n){function r(e,t=2){const n=" ".repeat(t),i=" ".repeat(t+2);let s=`${n}{\n`;if(s+=`${i}path: ${JSON.stringify(e.path)},\n`,void 0!==e.exact&&null!==e.exact&&(s+=`${i}exact: ${e.exact},\n`),void 0!==e.component&&null!==e.component&&(s+=`${i}component: ${e.component},\n`),void 0!==e.title&&null!==e.title&&(s+=`${i}title: ${e.title},\n`),e.authority&&(s+=`${i}authority: ${JSON.stringify(e.authority)},\n`),e.keepAlive&&(s+=`${i}keepAlive: ${e.keepAlive},\n`),e.routes&&e.routes.length>0){s+=`${i}routes: [\n${e.routes.map(e=>r(e,t+2)).join(",\n")}\n${i}],\n`}return s=s.replace(/,\n$/,"\n"),s+=`${n}}`,s}const i=e.map(e=>r(e)).join(",\n"),s=t.defaultLoadingComponentPath||"@/components/loading",a=t.intlPath||"@/utils/intl",o=`\n/* eslint-disable */\n// @ts-nocheck\n/**\n * 自动根据 pages 目录生成路由配置\n * 新增、删除、修改组件 title、keepAlive、authority 属性时,会自动更新路由配置\n * 路由组件只支持默认导出\n */\nimport { dynamic } from '@lemon-fe/vite-plugin-micro-frontend/runtime/dynamic';\nimport LoadingComponent from ${JSON.stringify(s)};\nimport { $t } from ${JSON.stringify(a)};\n\nexport const routers = [\n${i}\n];\n`,l=await m.resolveConfig(n);return m.format(o,{...l,parser:"typescript"})}function al(t){const n=e.resolve(t.pagesDir||"src/pages"),r=e.resolve(t.outputPath||"src/routes.ts"),i=t.routeTemplate||{},s=nl({root:n,componentPrefix:i.pageAliasPrefix,config:{singular:!1},ignoreDirs:t.ignoreDirs,excludedFiles:[r]});let a,o,l=!1;async function c(){if(!p.existsSync(n)&&void 0===a)return void console.warn("⚠️ pages 目录不存在:",n);const t=s.getRoutes().map(il),o=JSON.stringify(t);if(o===a&&p.existsSync(r))return;const l=await sl(t,i,r);p.existsSync(r)&&p.readFileSync(r,"utf-8")===l||(p.mkdirSync(e.dirname(r),{recursive:!0}),p.writeFileSync(r,l),console.log("✅ 路由已生成:",r)),a=o}return{...s,pagesDir:n,generate:()=>(l=!0,o||(o=Promise.resolve().then(async()=>{try{for(;l;)l=!1,await c()}finally{o=void 0}})),o),async dispose(){try{await o}finally{l=!1,a=void 0,s.clear()}}}}async function ol(e={}){await al(e).generate()}function ll(e={}){const t=al(e);let n,r;const i=()=>{clearTimeout(n),n=void 0,r?.(),r=void 0};return{name:"micro-frontend:routes",enforce:"pre",async configureServer(s){!function(s){if(r||!1===e.watch)return;const a=(e,r)=>{["add","change","unlink","addDir","unlinkDir"].includes(e)&&t.isRelevant(r,"addDir"===e||"unlinkDir"===e)&&(t.invalidate(r),clearTimeout(n),n=setTimeout(()=>{n=void 0,t.generate().catch(e=>{const t=e instanceof Error?e.stack||e.message:String(e);s.config.logger.error(`❌ 路由生成失败:\n${t}`)})},50))};s.watcher.on("all",a),s.watcher.add([t.pagesDir,t.globalLayoutDir]),s.httpServer?.once("close",i),r=()=>{s.watcher.off("all",a),s.httpServer?.off("close",i)}}(s);try{await t.generate()}catch(e){throw i(),await t.dispose(),e}},async buildStart(){await t.generate()},async closeBundle(){i(),await t.dispose()}}}function cl(t){const{outputPath:n}=t,r=n||e.resolve(process.cwd(),"src/utils/mf.tsx"),i=function(e){const t=e.remotes.reduce((e,t)=>(e[t.aliasName||t.remoteName]=t,e),{}),n=JSON.stringify(t,null,2),r=JSON.stringify({hostName:e.hostName,devHost:e.devHost,shareScope:e.shareScope});return"/* eslint-disable */\nimport { lazy, Suspense, type ReactNode, type ComponentType, type ComponentProps } from 'react';\nimport { createRemoteLoader } from '@lemon-fe/vite-plugin-micro-frontend/runtime/federation';\n\n// 配置同时用于类型提示和运行时注册,不依赖 Vite 是否扫描到静态 remote import。\nconst remotes = __REMOTES_JSON__ as const;\nconst loadRemote = createRemoteLoader({ ...__RUNTIME_OPTIONS_JSON__, remotes });\n\ntype RemoteAlias = keyof typeof remotes;\ntype ModuleSpecifier = `${RemoteAlias}/${string}`;\n\nconst entryShared = ((globalThis as any).__entry_shared__ ||= {});\n\n/** 获取多个业务入口共享的懒初始化值。 */\nexport function getEntryShared<T>(key: string, init: () => T): T {\n return (entryShared[key] ??= init()) as T;\n}\n\n/** 使用官方 Module Federation Runtime 加载远程 React 组件。 */\nexport function safeRemoteComponent<T extends ComponentType<any>>(opts: {\n moduleSpecifier: ModuleSpecifier;\n fallbackComponent: T | ComponentType<ComponentProps<T>>;\n loadingElement?: ReactNode;\n}): T {\n const LazyComponent = lazy<T>(async () => {\n try {\n const remoteModule = await loadRemote<Record<string, unknown>>(opts.moduleSpecifier);\n const remoteExport = remoteModule?.default ?? remoteModule;\n\n return {\n default: remoteExport as T,\n };\n } catch (error) {\n console.error(`[MF] Load remote module \"${opts.moduleSpecifier}\" failed:`, error);\n return { default: opts.fallbackComponent as T };\n }\n });\n\n return ((props: any) => (\n <Suspense fallback={opts.loadingElement ?? null}>\n <LazyComponent {...props} />\n </Suspense>\n )) as T;\n}\n".replace("__REMOTES_JSON__",()=>n).replace("__RUNTIME_OPTIONS_JSON__",()=>r)}(t),s=e.dirname(r);if(p.existsSync(s)||p.mkdirSync(s,{recursive:!0}),p.existsSync(r)){if(p.readFileSync(r,"utf-8")===i)return}p.writeFileSync(r,i),console.log("✅ mf.tsx 已生成:",r)}function pl(e){return{name:"micro-frontend:mf-generator",enforce:"pre",configResolved(){cl(e)},buildStart(){cl(e)}}}function ul(e){return{schemaVersion:1,appName:e.appName,loader:"module-federation",remote:{name:e.remoteName,type:"module",entry:`./${e.manifestFileName.replace(/^\/+/,"")}`,module:`${e.remoteName}/app`},application:{contract:"react-component",version:1},...e.buildVersion?{buildVersion:e.buildVersion}:void 0}}function dl(t){let n=`${JSON.stringify(ul(t),null,2)}\n`;function r(r,i){const s=function(e,t){const n=e.split("/").filter(Boolean),r=n[n.length-1],i=t.replace(/_/g,"-");return r===i||r===`app-${i}`?i:t}(i,t.appName),a={...t,appName:t.inferAppNameFromBase?s:t.appName,mountElementId:t.inferMountElementIdFromBase?s:t.mountElementId};if(n=`${JSON.stringify(ul(a),null,2)}\n`,!t.componentEntry)return;const o=e.resolve(r,t.componentEntry),l=e.relative(e.dirname(o),e.resolve(r,t.entry)).replace(/\\/g,"/"),c=l.startsWith(".")?l:`./${l}`,u=c.replace(/([\[\]{}()*?!])/g,"\\$1"),d=['/// <reference types="vite/client" />','import type { ComponentType } from "react";','import { createMicroFrontendApp, type MicroFrontendProps } from "@lemon-fe/vite-plugin-micro-frontend/runtime/app";',`const roots = import.meta.glob<ComponentType<MicroFrontendProps>>(${JSON.stringify(u)}, { eager: true, import: "default" });`,"export default createMicroFrontendApp({",` rootComponent: roots[${JSON.stringify(c)}]!,`,` basename: ${JSON.stringify(`/${a.appName}`)},`,` mountElementId: ${JSON.stringify(a.mountElementId)},`,"});",""].join("\n");p.mkdirSync(e.dirname(o),{recursive:!0}),p.existsSync(o)&&p.readFileSync(o,"utf8")===d||p.writeFileSync(o,d)}return{name:"micro-frontend:federation-application",enforce:"pre",config(e){r(e.root||process.cwd(),e.base||"/"),"remote"===t.buildMode&&(e.build={...e.build,rollupOptions:{...e.build?.rollupOptions,input:{}}})},configResolved(e){r(e.root,e.base)},configureServer(e){const r=t.capabilityFileName.replace(/^\/+/,""),i=`/${r}`,s=`${e.config.base}${r}`;e.middlewares.use((e,t,r)=>{const a=e.url?.split(/[?#]/,1)[0];a===i||a===s?(t.statusCode=200,t.setHeader("Content-Type","application/json; charset=utf-8"),t.setHeader("Cache-Control","no-store"),t.setHeader("Access-Control-Allow-Origin","*"),t.end(n)):r()})},generateBundle(){this.emitFile({type:"asset",fileName:t.capabilityFileName,source:n})}}}const hl="\nconst __remoteUrl = new URL(import.meta.url);\nconst __hostRefreshUrl = globalThis.__MF_REACT_REFRESH_URL__;\nconst __target =\n window.location.origin === __remoteUrl.origin || !__hostRefreshUrl\n ? new URL('./@mf-react-refresh-local', __remoteUrl).href\n : __hostRefreshUrl;\nconst __rt = await import(__target);\n\nexport const injectIntoGlobalHook = __rt.injectIntoGlobalHook;\nexport const register = __rt.register;\nexport const getRefreshReg = __rt.getRefreshReg;\nexport const createSignatureFunctionForTransform = __rt.createSignatureFunctionForTransform;\nexport const registerExportsForReactRefresh = __rt.registerExportsForReactRefresh;\nexport const validateRefreshBoundaryAndEnqueueUpdate = __rt.validateRefreshBoundaryAndEnqueueUpdate;\nexport const __hmr_import = __rt.__hmr_import;\nexport default __rt.default || __rt;\n".trimStart();function fl(){let t;return{name:"micro-frontend:federation-react-refresh-proxy",enforce:"pre",apply:"serve",configureServer(n){n.middlewares.use((r,i,s)=>{const a=r.url?.split(/[?#]/)[0];if("GET"===r.method)return a?.endsWith("/@mf-react-refresh-local")?(t??(t=function(t){try{const n=P(e.join(t,"package.json")).resolve("@vitejs/plugin-react"),r=e.join(e.dirname(n),"refresh-runtime.js");return p.readFileSync(r,"utf8")}catch{return null}}(n.config.root)),t?(i.statusCode=200,i.setHeader("Content-Type","application/javascript; charset=utf-8"),i.setHeader("Cache-Control","no-store"),i.setHeader("Access-Control-Allow-Origin","*"),void i.end(t)):void s()):void(a?.endsWith("/@react-refresh")?(i.statusCode=200,i.setHeader("Content-Type","application/javascript; charset=utf-8"),i.setHeader("Cache-Control","no-store"),i.setHeader("Access-Control-Allow-Origin","*"),i.end(hl)):s());s()})}}}function ml(e,t){if(!e)return e;const n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e,r=e=>Object.prototype.hasOwnProperty.call(n,e);if(!(r("react")||r("react/"))||r("react/jsx-dev-runtime"))return e;const i=n.react??n["react/"],s="object"==typeof i?i.requiredVersion:void 0;return{...n,"react/jsx-dev-runtime":{shareScope:`__micro_frontend_react_dev_${t}`,singleton:!1,...void 0!==s?{requiredVersion:s}:void 0}}}function yl(e){return e.replace(/\\/g,"/")}function Tl(t){const n=function(t){const n={},r=[".tsx",".ts"];if(!p.existsSync(t))return n;const i=p.readdirSync(t,{withFileTypes:!0});for(const s of i)if(s.isDirectory()){const r=e.join(t,s.name),i=["index.tsx","index.ts"];let a=null;for(const t of i){const n=e.join(r,t);if(p.existsSync(n)){a=n;break}}if(a){const t=yl(e.relative(process.cwd(),a));n[`./${s.name}`]=`./${t}`}else console.warn(`⚠️ ${s.name} 目录下没有找到入口文件,已忽略`)}else{const i=e.extname(s.name);if(r.includes(i)){const r=e.join(t,s.name),a=yl(e.relative(process.cwd(),r));n[`./${e.basename(s.name,i)}`]=`./${a}`}}return n}(e.resolve(process.cwd(),t.exposesDir??"src/exposes"));return{...n,...t.exposes||{}}}function gl(t,n={}){const r=t.name||n.appName?.replace(/-/g,"_");if(!r)throw new Error("[micro-frontend] 请配置 appName 或 federation.name。");const i={dts:!0,manifest:!0,publicPath:"auto",shareStrategy:"loaded-first",...t,name:r,shared:ml(t.shared,r),dev:(s=t.dev,!1!==s&&{remoteHmr:!0,disableHotTypesReload:!0,disableDynamicRemoteTypeHints:!0,..."object"==typeof s?s:{}})};var s;const a=[];i.debugReactHost&&a.push({name:"micro-frontend:react-refresh-host",enforce:"pre",apply:"serve",configureServer(e){const t=E(b.join(e.config.root,"package.json")),n=e.config.base.replace(/\/$/,""),r=new Map,i=new Map,s=e=>{const n=b.dirname(t.resolve(`${e}/package.json`)),{version:r}=JSON.parse(x.readFileSync(b.join(n,"package.json"),"utf8"));if(!String(r).startsWith("18."))throw new Error(`debugReactHost 需要 React 18 UMD,当前 ${e} 版本为 ${r}`);return x.readFileSync(b.join(n,"umd",`${e}.development.js`),"utf8")};r.set(`${n}/@micro-frontend/host-react.js`,()=>s("react")),r.set(`${n}/@micro-frontend/host-react-dom.js`,()=>{const e=E(t.resolve("@vitejs/plugin-react")),n=b.dirname(e.resolve("react-refresh/package.json"));return`(() => {\nconst exports = {};\nconst process = { env: { NODE_ENV: 'development' } };\n${x.readFileSync(b.join(n,"cjs/react-refresh-runtime.development.js"),"utf8")}\nexports.injectIntoGlobalHook(window);\n\nconst hook = window.__REACT_DEVTOOLS_GLOBAL_HOOK__;\nif (hook && !hook.__microFrontendTracksRenderers) {\n const inject = hook.inject;\n hook.inject = function(renderer) {\n const id = inject.apply(this, arguments);\n hook.renderers.set(id, renderer);\n return id;\n };\n hook.__microFrontendTracksRenderers = true;\n}\n\n})();\n${s("react-dom")}`}),e.middlewares.use((e,t,n)=>{const s=e.url?.split(/[?#]/)[0]??"",a=r.get(s);if(!a||"GET"!==e.method&&"HEAD"!==e.method)return n();try{i.has(s)||i.set(s,a()),t.setHeader("Content-Type","application/javascript; charset=utf-8"),t.setHeader("Cache-Control","no-store"),t.setHeader("Access-Control-Allow-Origin","*"),t.end("HEAD"===e.method?void 0:i.get(s))}catch(e){n(e)}})}});const o=!1===i.application?void 0:i.application||{};if(o&&!1===i.manifest)throw new Error("[micro-frontend] 完整微应用必须启用 federation.manifest,如只暴露普通联邦组件,请设置 federation.application = false。");if(o?.rootComponent&&o.entry)throw new Error("[micro-frontend] federation.application.rootComponent 与 entry 不能同时配置。");const l="object"==typeof(c=i.manifest)&&c.fileName?c.fileName:"mf-manifest.json";var c;const p=[...!1===i.manifest?[]:[l],...o?[o.capabilityFileName||"micro-frontend.json"]:[]];var u;a.push(fl()),p.length>0&&a.push((u=p,{name:"micro-frontend:federation-dev-preflight",enforce:"pre",apply:"serve",configureServer(e){e.middlewares.use((t,n,r)=>{if("OPTIONS"!==t.method||!1===e.config.server.cors||!function(e,t){if(!e)return!1;const n=e.split(/[?#]/)[0];return t.some(e=>{const t=e.replace(/^\/+/,"");return n===`/${t}`||n.endsWith(`/${t}`)})}(t.url,u)&&"true"!==t.headers["access-control-request-private-network"])return void r();const i=t.headers["access-control-request-headers"];n.statusCode=204,n.setHeader("Access-Control-Allow-Origin","*"),n.setHeader("Access-Control-Allow-Methods","GET, HEAD, PUT, PATCH, POST, DELETE, OPTIONS"),i&&n.setHeader("Access-Control-Allow-Headers",Array.isArray(i)?i.join(", "):i),"true"===t.headers["access-control-request-private-network"]&&n.setHeader("Access-Control-Allow-Private-Network","true"),n.setHeader("Content-Length","0"),n.end()})}}));const d=function(e,t,n){if(!e||0===e.length)return;const r={};for(const i of e){const{aliasName:e,remoteName:s,entry:a,isESModule:o}=i,l=e||s,c=a.startsWith("/")?a:`/${a}`;let p;p=a.startsWith("http")?a:t?new URL(c,`${t.replace(/\/$/,"")}/`).href:c,r[l]={type:o?"module":"var",name:l,entry:p,entryGlobalName:s,shareScope:n||"default"}}return r}(i.remotes,i.devHost,i.shareScope),h=Tl(i);if(o){const e=h["./app"];if(o.rootComponent&&e)throw new Error('[micro-frontend] federation.application.rootComponent 与 exposes["./app"] 不能同时配置。');const t=o.rootComponent||o.entry||("string"==typeof(f=e)?f:f?.import)||"src/main.tsx",s=o.appName||n.appName||i.name,c=o.mountElementId||s,p=o.rootComponent?`src/.external/${encodeURIComponent(r)}/app-component.ts`:void 0;e||(h["./app"]=`./${(p||t).replace(/^\.\//,"")}`),a.push(dl({appName:s,remoteName:i.name,entry:t,componentEntry:p,mountElementId:c,manifestFileName:l,capabilityFileName:o.capabilityFileName||"micro-frontend.json",buildVersion:o.buildVersion,buildMode:o.buildMode,inferAppNameFromBase:!o.appName,inferMountElementIdFromBase:!o.mountElementId}))}var f;const m={...i};delete m.application,delete m.devHost,delete m.debugReactHost,delete m.exposesDir,delete m.outputPath,delete m.remotes;const y=S({filename:"remote.js",hostInitInjectLocation:"entry",...m,remotes:d,exposes:h});if(n.developmentShell)for(const e of y)"add-entry"===e.name&&"serve"===e.apply&&delete e.transformIndexHtml;return a.push(y),a.push({name:"micro-frontend:federation-commonjs",apply:"build",enforce:"pre",transform(e,t){if(!t.includes("__loadShare__")||!e.includes("__mfApplyHostProvidedExports"))return null;const n=e.replace("export const __moduleExports = exportModule;","export { exportModule as __moduleExports };");return n===e?null:{code:n,map:null}},outputOptions:{order:"post",handler(e){const t=e.manualChunks;if("function"==typeof t)return{...e,manualChunks:(e,n)=>"\0commonjsHelpers.js"===e?"commonjs-helpers":t(e,n)}}}}),function(e){return"object"==typeof e&&null!==e&&Boolean(e.remoteHmr)}(i.dev)&&Object.keys(h).length>0&&a.push(K()),a.push(pl({hostName:i.name,devHost:i.devHost,shareScope:i.shareScope,remotes:i.remotes??[],outputPath:i.outputPath?e.resolve(process.cwd(),i.outputPath):"src/utils/mf.tsx"})),a}function Sl(e){return e&&"/"!==e?e.replace(/^\/+|\/+$/g,""):""}function xl(e,t,n){if(!t||!n)return e;const r=function(e){const t=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return new RegExp(`import\\((['"])\\/${t}\\/([^'"]+)\\1\\)`,"g")}(t);return e.replace(r,`import(${n} + '/$2')`)}function bl(e,t){if("boolean"==typeof t&&!t)return"";const n="boolean"==typeof t?{}:t;if(n.publicPath?.trim())return n.publicPath.trim();const r=function(e,t){const n="boolean"==typeof t?{}:t;if(n.appBase?.trim())return n.appBase.trim().replace(/^\/+|\/+$/g,"");const r=Sl(e.base);return r&&"__dynamic_base__"!==r?r:""}(e,t),i=r?`/${r}`:e.base??"/";return`(window.EARTH_BASE_CONFIG && window.EARTH_BASE_CONFIG.EARTH_ALL_SHARE_HOST ? window.EARTH_BASE_CONFIG.EARTH_ALL_SHARE_HOST.replace(/\\/$/, '') : '') + ${JSON.stringify(i)}`}function El(e,t,n){if(e)return"function"==typeof e?e.apply(t,n):e.handler.apply(t,n)}function Pl(e,t){let n;const{transformIndexHtml:r=!0,transformIndexHtmlConfig:i}=e;return{name:"micro-frontend:dynamic-base-deferred",enforce:"post",apply:"build",configResolved:e=>(n=v({publicPath:t(),transformIndexHtml:r,transformIndexHtmlConfig:i}),El(n.configResolved,n,[e])),generateBundle(e,t,r){if(n?.generateBundle)return El(n.generateBundle,n,[e,t,r])}}}function vl(e,t,n){const{transformIndexHtml:r=!0,removeIndexCssPreload:i=!1}=e,s=[];if(r){const e=e=>xl(e,n(),t());s.push({name:"micro-frontend:rewrite-inline-dynamic-base-import",enforce:"post",apply:"build",transformIndexHtml:{order:"post",handler:t=>e(t)},generateBundle(t,n){for(const t of Object.values(n))"asset"===t.type&&t.fileName.endsWith(".html")&&"string"==typeof t.source&&(t.source=e(t.source))}})}return i&&s.push({name:"micro-frontend:remove-index-css-preload",enforce:"post",apply:"build",transformIndexHtml(e){let t=e.replace(/<link[^>]*rel=["']stylesheet["'][^>]*href=["']\/?index-[^"']+\.css["'][^>]*>/gi,"");return t=t.replace(/,\{"parentTagName":"head","tagName":"link","attrs":\{"rel":"stylesheet","crossorigin":"","href":"\/index-[^"]+\.css"\}\}/g,""),t}}),s}function Al(e){const t={publicPath:"",appBasePath:""},n=function(e){return"boolean"==typeof e?{}:e}(e),r=()=>t.publicPath;return[{name:"micro-frontend:dynamic-base-init",enforce:"pre",apply:"build",config(n,r){t.publicPath=bl(n,e),t.appBasePath=Sl(n.base)}},Pl(n,r),...vl(n,r,()=>t.appBasePath)]}const Cl="/__earth_base__";function wl(e,t){const n=new URL(e);if(!["http:","https:"].includes(n.protocol)||"/"!==n.pathname||n.search||n.hash||n.username||n.password)throw new Error(`developmentShell.${t} 必须是 HTTP(S) origin`);return n.origin}const Il={pagesDir:"src/pages",outputPath:"src/routes.ts",watch:!0,ignoreDirs:["components","utils","hooks","typings"],routeTemplate:{defaultLoadingComponentPath:"@/components/loading",intlPath:"@/utils/intl"}},Nl="__microFrontendOptions";function kl(t){const{appName:n,federation:r,routes:i,dynamicBase:s}=t,a=[];a.push({name:"micro-frontend:options",[Nl]:t});const o="object"==typeof i?{...Il,...i}:Il;return a.push(ll({pagesDir:o.pagesDir?e.resolve(process.cwd(),o.pagesDir):void 0,outputPath:o.outputPath?e.resolve(process.cwd(),o.outputPath):void 0,watch:o.watch,ignoreDirs:o.ignoreDirs,routeTemplate:o.routeTemplate})),r&&(t.developmentShell&&a.push(function(e){const t=wl(e.baseOrigin,"baseOrigin"),n=e.gatewayOrigin?wl(e.gatewayOrigin,"gatewayOrigin"):void 0;return{name:"micro-frontend:development-shell",apply:"serve",config(){const r={[Cl]:{target:t,changeOrigin:!0,rewrite:e=>e.slice(15)||"/",configure(e){e.on("proxyRes",(e,t)=>{"/remote.js"===t.url?.split("?")[0]&&(e.headers["cache-control"]="no-store")})}},"/assets/":{target:t,changeOrigin:!0},"^/app-.+":{target:t,changeOrigin:!0}};return{base:"/",define:{__MICRO_FRONTEND_DEVELOPMENT_SHELL__:JSON.stringify({basePath:Cl,remoteName:e.remoteName||"base",gatewayOrigin:n})},server:{proxy:r}}}}}(t.developmentShell)),a.push(...gl(r,{appName:n,developmentShell:Boolean(t.developmentShell)}))),s&&a.push(...Al(s)),a}export{Nl as MICRO_FRONTEND_OPTIONS_KEY,R as cssInjectedByJsPlugin,V as devHmrPlugin,gl as federationPlugin,cl as generateMf,ol as generateRoutesToFile,Al as getDynamicBasePlugins,rl as getRoutes,pl as mfGeneratorPlugin,kl as microFrontendPlugins,ll as pagesRoutesPlugin};
|
|
14
14
|
//# sourceMappingURL=index.js.map
|