@nx/angular
Version:
1 lines • 11 kB
Source Map (JSON)
{"version":3,"file":"nx-angular-mf.mjs","sources":["../../../../packages/angular/mf/url-helpers.ts","../../../../packages/angular/mf/mf.ts","../../../../packages/angular/mf/nx-angular-mf.ts"],"sourcesContent":["// Helper function to extract file extension from a path\nfunction extname(path: string): string {\n const lastDot = path.lastIndexOf('.');\n const lastSlash = Math.max(path.lastIndexOf('/'), path.lastIndexOf('\\\\'));\n if (lastDot === -1 || lastDot < lastSlash) {\n return '';\n }\n return path.slice(lastDot);\n}\n\n/**\n * Checks if a URL string is absolute (has protocol)\n */\nexport function isAbsoluteUrl(url: string): boolean {\n try {\n new URL(url);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Safely processes remote locations, handling both relative and absolute URLs\n * while preserving query parameters and hash fragments for absolute URLs\n */\nexport function processRemoteLocation(\n remoteLocation: string,\n remoteEntryExt: 'js' | 'mjs'\n): string {\n // Handle promise-based remotes as-is\n if (remoteLocation.startsWith('promise new Promise')) {\n return remoteLocation;\n }\n\n if (isAbsoluteUrl(remoteLocation)) {\n // Use new URL parsing for absolute URLs (supports query params/hash)\n const url = new URL(remoteLocation);\n const ext = extname(url.pathname);\n const needsRemoteEntry = !['.js', '.mjs', '.json'].includes(ext);\n\n if (needsRemoteEntry) {\n url.pathname = url.pathname.endsWith('/')\n ? `${url.pathname}remoteEntry.${remoteEntryExt}`\n : `${url.pathname}/remoteEntry.${remoteEntryExt}`;\n }\n\n return url.href;\n } else {\n // Use string manipulation for relative URLs (backward compatibility)\n const ext = extname(remoteLocation);\n const needsRemoteEntry = !['.js', '.mjs', '.json'].includes(ext);\n\n if (needsRemoteEntry) {\n const baseRemote = remoteLocation.endsWith('/')\n ? remoteLocation.slice(0, -1)\n : remoteLocation;\n return `${baseRemote}/remoteEntry.${remoteEntryExt}`;\n }\n\n return remoteLocation;\n }\n}\n\n/**\n * Processes remote URLs for runtime environments, resolving relative URLs against window.location.origin\n */\nexport function processRuntimeRemoteUrl(\n remoteUrl: string,\n remoteEntryExt: 'js' | 'mjs'\n): string {\n if (isAbsoluteUrl(remoteUrl)) {\n return processRemoteLocation(remoteUrl, remoteEntryExt);\n } else {\n // For runtime relative URLs, resolve against current origin\n const baseUrl =\n typeof globalThis !== 'undefined' &&\n typeof (globalThis as any).window !== 'undefined' &&\n (globalThis as any).window.location\n ? (globalThis as any).window.location.origin\n : 'http://localhost';\n const absoluteUrl = new URL(remoteUrl, baseUrl).href;\n return processRemoteLocation(absoluteUrl, remoteEntryExt);\n }\n}\n","import { processRuntimeRemoteUrl } from './url-helpers';\n\nexport type ResolveRemoteUrlFunction = (\n remoteName: string\n) => string | Promise<string>;\n\ndeclare const __webpack_init_sharing__: (scope: 'default') => Promise<void>;\ndeclare const __webpack_share_scopes__: { default: unknown };\n\nlet resolveRemoteUrl: ResolveRemoteUrlFunction;\n\n/**\n * @deprecated Use Runtime Helpers from '@module-federation/enhanced/runtime' instead. This will be removed in Nx 22.\n */\nexport function setRemoteUrlResolver(\n _resolveRemoteUrl: ResolveRemoteUrlFunction\n) {\n resolveRemoteUrl = _resolveRemoteUrl;\n}\n\nlet remoteUrlDefinitions: Record<string, string>;\n\n/**\n * @deprecated Use init() from '@module-federation/enhanced/runtime' instead. This will be removed in Nx 22.\n * If you have a remote app called `my-remote-app` and you want to use the `http://localhost:4201/mf-manifest.json` as the remote url, you should change it from:\n * ```ts\n * import { setRemoteDefinitions } from '@nx/angular/mf';\n *\n * setRemoteDefinitions({\n * 'my-remote-app': 'http://localhost:4201/mf-manifest.json'\n * });\n * ```\n * to use init():\n * ```ts\n * import { init } from '@module-federation/enhanced/runtime';\n *\n * init({\n * name: 'host',\n * remotes: [{\n * name: 'my-remote-app',\n * entry: 'http://localhost:4201/mf-manifest.json'\n * }]\n * });\n * ```\n */\nexport function setRemoteDefinitions(definitions: Record<string, string>) {\n remoteUrlDefinitions = definitions;\n}\n\n/**\n * @deprecated Use registerRemotes() from '@module-federation/enhanced/runtime' instead. This will be removed in Nx 22.\n * If you set a remote app with `setRemoteDefinition` such as:\n * ```ts\n * import { setRemoteDefinition } from '@nx/angular/mf';\n *\n * setRemoteDefinition(\n * 'my-remote-app',\n * 'http://localhost:4201/mf-manifest.json'\n * );\n * ```\n * change it to use registerRemotes():\n * ```ts\n * import { registerRemotes } from '@module-federation/enhanced/runtime';\n *\n * registerRemotes([\n * {\n * name: 'my-remote-app',\n * entry: 'http://localhost:4201/mf-manifest.json'\n * }\n * ]);\n * ```\n */\nexport function setRemoteDefinition(remoteName: string, remoteUrl: string) {\n remoteUrlDefinitions ??= {};\n remoteUrlDefinitions[remoteName] = remoteUrl;\n}\n\nlet remoteModuleMap = new Map<string, unknown>();\nlet remoteContainerMap = new Map<string, unknown>();\n\n/**\n * @deprecated Use loadRemote() from '@module-federation/enhanced/runtime' instead. This will be removed in Nx 22.\n * If you set a load a remote with `loadRemoteModule` such as:\n * ```ts\n * import { loadRemoteModule } from '@nx/angular/mf';\n *\n * loadRemoteModule('my-remote-app', './Module').then(m => m.RemoteEntryModule);\n * ```\n * change it to use loadRemote():\n * ```ts\n * import { loadRemote } from '@module-federation/enhanced/runtime';\n *\n * loadRemote<typeof import('my-remote-app/Module')>('my-remote-app/Module').then(m => m.RemoteEntryModule);\n * ```\n */\nexport async function loadRemoteModule(remoteName: string, moduleName: string) {\n const remoteModuleKey = `${remoteName}:${moduleName}`;\n if (remoteModuleMap.has(remoteModuleKey)) {\n return remoteModuleMap.get(remoteModuleKey);\n }\n\n const container = remoteContainerMap.has(remoteName)\n ? remoteContainerMap.get(remoteName)\n : await loadRemoteContainer(remoteName);\n\n const factory = await container.get(moduleName);\n const Module = factory();\n\n remoteModuleMap.set(remoteModuleKey, Module);\n\n return Module;\n}\n\nfunction loadModule(url: string) {\n return import(/* webpackIgnore:true */ url);\n}\n\nlet initialSharingScopeCreated = false;\n\nasync function loadRemoteContainer(remoteName: string) {\n if (!resolveRemoteUrl && !remoteUrlDefinitions) {\n throw new Error(\n 'Call setRemoteDefinitions or setRemoteUrlResolver to allow Dynamic Federation to find the remote apps correctly.'\n );\n }\n\n if (!initialSharingScopeCreated) {\n initialSharingScopeCreated = true;\n await __webpack_init_sharing__('default');\n }\n\n const remoteUrl = remoteUrlDefinitions\n ? remoteUrlDefinitions[remoteName]\n : await resolveRemoteUrl(remoteName);\n\n const containerUrl = processRuntimeRemoteUrl(remoteUrl, 'mjs');\n\n const container = await loadModule(containerUrl);\n await container.init(__webpack_share_scopes__.default);\n\n remoteContainerMap.set(remoteName, container);\n return container;\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":"AAAA;AACA,SAAS,OAAO,CAAC,IAAY,EAAA;IAC3B,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC;IACrC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IACzE,IAAI,OAAO,KAAK,CAAC,CAAC,IAAI,OAAO,GAAG,SAAS,EAAE;AACzC,QAAA,OAAO,EAAE;IACX;AACA,IAAA,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;AAC5B;AAEA;;AAEG;AACG,SAAU,aAAa,CAAC,GAAW,EAAA;AACvC,IAAA,IAAI;AACF,QAAA,IAAI,GAAG,CAAC,GAAG,CAAC;AACZ,QAAA,OAAO,IAAI;IACb;AAAE,IAAA,MAAM;AACN,QAAA,OAAO,KAAK;IACd;AACF;AAEA;;;AAGG;AACG,SAAU,qBAAqB,CACnC,cAAsB,EACtB,cAA4B,EAAA;;AAG5B,IAAA,IAAI,cAAc,CAAC,UAAU,CAAC,qBAAqB,CAAC,EAAE;AACpD,QAAA,OAAO,cAAc;IACvB;AAEA,IAAA,IAAI,aAAa,CAAC,cAAc,CAAC,EAAE;;AAEjC,QAAA,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,cAAc,CAAC;QACnC,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