@module-federation/sdk 0.0.0-canary-1702522677984 → 0.0.0-codex-node24-dev-node20-compat-ci-20260713063237

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.
Files changed (117) hide show
  1. package/README.md +105 -0
  2. package/dist/LICENSE +21 -0
  3. package/dist/_virtual/_rolldown/runtime.cjs +19 -0
  4. package/dist/_virtual/_rolldown/runtime.js +18 -0
  5. package/dist/constant.cjs +62 -0
  6. package/dist/constant.cjs.map +1 -0
  7. package/dist/constant.d.ts +46 -0
  8. package/dist/constant.js +48 -0
  9. package/dist/constant.js.map +1 -0
  10. package/dist/createModuleFederationConfig.cjs +9 -0
  11. package/dist/createModuleFederationConfig.cjs.map +1 -0
  12. package/dist/createModuleFederationConfig.d.ts +6 -0
  13. package/dist/createModuleFederationConfig.js +8 -0
  14. package/dist/createModuleFederationConfig.js.map +1 -0
  15. package/dist/dom.cjs +214 -0
  16. package/dist/dom.cjs.map +1 -0
  17. package/dist/dom.d.ts +33 -0
  18. package/dist/dom.js +210 -0
  19. package/dist/dom.js.map +1 -0
  20. package/dist/env.cjs +34 -0
  21. package/dist/env.cjs.map +1 -0
  22. package/dist/env.d.ts +12 -0
  23. package/dist/env.js +30 -0
  24. package/dist/env.js.map +1 -0
  25. package/dist/generateSnapshotFromManifest.cjs +123 -0
  26. package/dist/generateSnapshotFromManifest.cjs.map +1 -0
  27. package/dist/generateSnapshotFromManifest.d.ts +20 -0
  28. package/dist/generateSnapshotFromManifest.js +119 -0
  29. package/dist/generateSnapshotFromManifest.js.map +1 -0
  30. package/dist/index.cjs +103 -0
  31. package/dist/index.d.ts +21 -0
  32. package/dist/index.js +17 -0
  33. package/dist/logger.cjs +129 -0
  34. package/dist/logger.cjs.map +1 -0
  35. package/dist/logger.d.ts +34 -0
  36. package/dist/logger.js +125 -0
  37. package/dist/logger.js.map +1 -0
  38. package/dist/node.cjs +180 -0
  39. package/dist/node.cjs.map +1 -0
  40. package/dist/node.d.ts +15 -0
  41. package/dist/node.js +178 -0
  42. package/dist/node.js.map +1 -0
  43. package/dist/normalize-webpack-path.cjs +28 -0
  44. package/dist/normalize-webpack-path.cjs.map +1 -0
  45. package/dist/normalize-webpack-path.d.ts +10 -0
  46. package/dist/normalize-webpack-path.js +26 -0
  47. package/dist/normalize-webpack-path.js.map +1 -0
  48. package/dist/normalizeOptions.cjs +19 -0
  49. package/dist/normalizeOptions.cjs.map +1 -0
  50. package/dist/normalizeOptions.d.ts +5 -0
  51. package/dist/normalizeOptions.js +18 -0
  52. package/dist/normalizeOptions.js.map +1 -0
  53. package/dist/types/common.d.ts +14 -0
  54. package/dist/types/hooks.d.ts +21 -0
  55. package/dist/types/index.d.ts +11 -0
  56. package/dist/types/manifest.d.ts +34 -0
  57. package/dist/types/plugins/ConsumeSharedPlugin.cjs +13 -0
  58. package/dist/types/plugins/ConsumeSharedPlugin.cjs.map +1 -0
  59. package/dist/types/plugins/ConsumeSharedPlugin.d.ts +109 -0
  60. package/dist/types/plugins/ConsumeSharedPlugin.js +8 -0
  61. package/dist/types/plugins/ConsumeSharedPlugin.js.map +1 -0
  62. package/dist/types/plugins/ContainerPlugin.cjs +13 -0
  63. package/dist/types/plugins/ContainerPlugin.cjs.map +1 -0
  64. package/dist/types/plugins/ContainerPlugin.d.ts +38 -0
  65. package/dist/types/plugins/ContainerPlugin.js +8 -0
  66. package/dist/types/plugins/ContainerPlugin.js.map +1 -0
  67. package/dist/types/plugins/ContainerReferencePlugin.cjs +13 -0
  68. package/dist/types/plugins/ContainerReferencePlugin.cjs.map +1 -0
  69. package/dist/types/plugins/ContainerReferencePlugin.d.ts +24 -0
  70. package/dist/types/plugins/ContainerReferencePlugin.js +8 -0
  71. package/dist/types/plugins/ContainerReferencePlugin.js.map +1 -0
  72. package/dist/types/plugins/ModuleFederationPlugin.cjs +13 -0
  73. package/dist/types/plugins/ModuleFederationPlugin.cjs.map +1 -0
  74. package/dist/types/plugins/ModuleFederationPlugin.d.ts +462 -0
  75. package/dist/types/plugins/ModuleFederationPlugin.js +8 -0
  76. package/dist/types/plugins/ModuleFederationPlugin.js.map +1 -0
  77. package/dist/types/plugins/ProvideSharedPlugin.cjs +13 -0
  78. package/dist/types/plugins/ProvideSharedPlugin.cjs.map +1 -0
  79. package/dist/types/plugins/ProvideSharedPlugin.d.ts +97 -0
  80. package/dist/types/plugins/ProvideSharedPlugin.js +8 -0
  81. package/dist/types/plugins/ProvideSharedPlugin.js.map +1 -0
  82. package/dist/types/plugins/SharePlugin.cjs +13 -0
  83. package/dist/types/plugins/SharePlugin.cjs.map +1 -0
  84. package/dist/types/plugins/SharePlugin.d.ts +26 -0
  85. package/dist/types/plugins/SharePlugin.js +8 -0
  86. package/dist/types/plugins/SharePlugin.js.map +1 -0
  87. package/dist/types/plugins/index.d.ts +6 -0
  88. package/dist/types/snapshot.d.ts +78 -0
  89. package/dist/types/stats.d.ts +101 -0
  90. package/dist/utils.cjs +127 -0
  91. package/dist/utils.cjs.map +1 -0
  92. package/{src → dist}/utils.d.ts +10 -6
  93. package/dist/utils.js +116 -0
  94. package/dist/utils.js.map +1 -0
  95. package/package.json +56 -12
  96. package/index.cjs.d.ts +0 -1
  97. package/index.cjs.default.js +0 -1
  98. package/index.cjs.js +0 -793
  99. package/index.cjs.mjs +0 -2
  100. package/index.esm.js +0 -761
  101. package/normalize-webpack-path.cjs.d.ts +0 -1
  102. package/normalize-webpack-path.cjs.default.js +0 -1
  103. package/normalize-webpack-path.cjs.js +0 -42
  104. package/normalize-webpack-path.cjs.mjs +0 -2
  105. package/normalize-webpack-path.esm.js +0 -33
  106. package/src/constant.d.ts +0 -16
  107. package/src/dom.d.ts +0 -10
  108. package/src/env.d.ts +0 -7
  109. package/src/generateSnapshotFromManifest.d.ts +0 -10
  110. package/src/index.d.ts +0 -7
  111. package/src/logger.d.ts +0 -8
  112. package/src/normalize-webpack-path.d.ts +0 -3
  113. package/src/types/common.d.ts +0 -10
  114. package/src/types/index.d.ts +0 -4
  115. package/src/types/manifest.d.ts +0 -26
  116. package/src/types/snapshot.d.ts +0 -62
  117. package/src/types/stats.d.ts +0 -79
package/README.md ADDED
@@ -0,0 +1,105 @@
1
+ # `@module-federation/sdk` Documentation
2
+
3
+ - This SDK provides utilities and tools to support the implementation of Module Federation in your projects.
4
+ - It contains utility functions for parsing, encoding, and decoding module names, as well as generating filenames for exposed modules and shared packages.
5
+ - It also includes a logger for debugging and environment detection utilities.
6
+ - Additionally, it provides a function to generate a snapshot from a manifest and environment detection utilities.
7
+
8
+ ## Usage
9
+
10
+ ```javascript
11
+ // The SDK can be used to parse entry strings, encode and decode module names, and generate filenames for exposed modules and shared packages.
12
+ // It also includes a logger for debugging and environment detection utilities.
13
+ // Additionally, it provides a function to generate a snapshot from a manifest and environment detection utilities.
14
+ import { parseEntry, encodeName, decodeName, generateExposeFilename, generateShareFilename, createLogger, isBrowserEnv, isBrowserEnvValue, isDebugMode, getProcessEnv, generateSnapshotFromManifest } from '@module-federation/sdk';
15
+
16
+ // Parse an entry string into a RemoteEntryInfo object
17
+ parseEntry('entryString');
18
+
19
+ // Encode a module name with a prefix and optional extension
20
+ encodeName('moduleName', 'prefix');
21
+
22
+ // Decode a module name with a prefix and optional extension
23
+ decodeName('encodedModuleName', 'prefix');
24
+
25
+ // Generate a filename for an exposed module
26
+ generateExposeFilename('exposeName', true);
27
+
28
+ // Generate a filename for a shared package
29
+ generateShareFilename('packageName', true);
30
+
31
+ // Create a logger
32
+ const logger = createLogger('identifier');
33
+
34
+ // Check if the current environment is a browser
35
+ const inBrowser = isBrowserEnv();
36
+ const inBrowserStatic = isBrowserEnvValue;
37
+
38
+ // Check if the current environment is in debug mode
39
+ isDebugMode();
40
+
41
+ // Get the process environment
42
+ getProcessEnv();
43
+
44
+ // Generate a snapshot from a manifest
45
+ generateSnapshotFromManifest(manifest, options);
46
+ ```
47
+
48
+ ### parseEntry
49
+
50
+ - Type: `parseEntry(str: string, devVerOrUrl?: string, separator?: string) `
51
+ - Parses a string into a RemoteEntryInfo object.
52
+
53
+ ### encodeName
54
+
55
+ - Type: `encodeName(name: string, prefix?: string, withExt?: boolean)`
56
+ - Encodes a name with a prefix and optional extension.
57
+
58
+ ### decodeName
59
+
60
+ - Type: `decodeName(name: string, prefix?: string, withExt?: boolean)`
61
+ - Decodes a name with a prefix and optional extension.
62
+
63
+ ### generateExposeFilename
64
+
65
+ - Type: `generateExposeFilename(exposeName: string, withExt: boolean)`
66
+ - Generates a filename for an expose.
67
+
68
+ ### generateShareFilename
69
+
70
+ - Type: `generateShareFilename(pkgName: string, withExt: boolean)`
71
+ - Generates a filename for a shared package.
72
+
73
+ ### createLogger
74
+
75
+ - Type: `createLogger(prefix: string)`
76
+ - Creates a logger for debugging.
77
+
78
+ ### isBrowserEnv
79
+
80
+ - Type: `isBrowserEnv(): boolean`
81
+ - Checks if the current environment is a browser.
82
+
83
+ ### isBrowserEnvValue
84
+
85
+ - Type: `isBrowserEnvValue: boolean`
86
+ - Static browser environment flag (tree-shakable when ENV_TARGET is defined).
87
+
88
+ ### isDebugMode
89
+
90
+ - Type: `isDebugMode()`
91
+ - Checks if the current environment is in debug mode.
92
+
93
+ ### getProcessEnv
94
+
95
+ - Type: `getProcessEnv()`
96
+ - Gets the process environment.
97
+
98
+ ### generateSnapshotFromManifest
99
+
100
+ - Type: `generateSnapshotFromManifest(manifest: Manifest, options?: IOptions)`
101
+ - Generates a snapshot from a manifest.
102
+
103
+ ## Testing
104
+
105
+ The SDK uses Jest for testing. The configuration can be found in `jest.config.js`. The tests are located in the **tests** directory.
package/dist/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-present zhanghang(2heal1)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,19 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __defProp = Object.defineProperty;
3
+ var __exportAll = (all, no_symbols) => {
4
+ let target = {};
5
+ for (var name in all) {
6
+ __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ }
11
+ if (!no_symbols) {
12
+ __defProp(target, Symbol.toStringTag, { value: "Module" });
13
+ }
14
+ return target;
15
+ };
16
+
17
+ //#endregion
18
+
19
+ exports.__exportAll = __exportAll;
@@ -0,0 +1,18 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __defProp = Object.defineProperty;
3
+ var __exportAll = (all, no_symbols) => {
4
+ let target = {};
5
+ for (var name in all) {
6
+ __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ }
11
+ if (!no_symbols) {
12
+ __defProp(target, Symbol.toStringTag, { value: "Module" });
13
+ }
14
+ return target;
15
+ };
16
+
17
+ //#endregion
18
+ export { __exportAll };
@@ -0,0 +1,62 @@
1
+
2
+ //#region src/constant.ts
3
+ const FederationModuleManifest = "federation-manifest.json";
4
+ const MANIFEST_EXT = ".json";
5
+ const BROWSER_LOG_KEY = "FEDERATION_DEBUG";
6
+ const NameTransformSymbol = {
7
+ AT: "@",
8
+ HYPHEN: "-",
9
+ SLASH: "/"
10
+ };
11
+ const NameTransformMap = {
12
+ [NameTransformSymbol.AT]: "scope_",
13
+ [NameTransformSymbol.HYPHEN]: "_",
14
+ [NameTransformSymbol.SLASH]: "__"
15
+ };
16
+ const EncodedNameTransformMap = {
17
+ [NameTransformMap[NameTransformSymbol.AT]]: NameTransformSymbol.AT,
18
+ [NameTransformMap[NameTransformSymbol.HYPHEN]]: NameTransformSymbol.HYPHEN,
19
+ [NameTransformMap[NameTransformSymbol.SLASH]]: NameTransformSymbol.SLASH
20
+ };
21
+ const SEPARATOR = ":";
22
+ const ManifestFileName = "mf-manifest.json";
23
+ const StatsFileName = "mf-stats.json";
24
+ const MFModuleType = {
25
+ NPM: "npm",
26
+ APP: "app"
27
+ };
28
+ const MODULE_DEVTOOL_IDENTIFIER = "__MF_DEVTOOLS_MODULE_INFO__";
29
+ const ENCODE_NAME_PREFIX = "ENCODE_NAME_PREFIX";
30
+ const TEMP_DIR = ".federation";
31
+ let TreeShakingStatus = /* @__PURE__ */ function(TreeShakingStatus) {
32
+ /**
33
+ * Not handled by deploy server, needs to infer by the real runtime period.
34
+ */
35
+ TreeShakingStatus[TreeShakingStatus["UNKNOWN"] = 1] = "UNKNOWN";
36
+ /**
37
+ * It means the shared has been calculated , runtime should take this shared as first choice.
38
+ */
39
+ TreeShakingStatus[TreeShakingStatus["CALCULATED"] = 2] = "CALCULATED";
40
+ /**
41
+ * It means the shared has been calculated, and marked as no used
42
+ */
43
+ TreeShakingStatus[TreeShakingStatus["NO_USE"] = 0] = "NO_USE";
44
+ return TreeShakingStatus;
45
+ }({});
46
+
47
+ //#endregion
48
+ exports.BROWSER_LOG_KEY = BROWSER_LOG_KEY;
49
+ exports.ENCODE_NAME_PREFIX = ENCODE_NAME_PREFIX;
50
+ exports.EncodedNameTransformMap = EncodedNameTransformMap;
51
+ exports.FederationModuleManifest = FederationModuleManifest;
52
+ exports.MANIFEST_EXT = MANIFEST_EXT;
53
+ exports.MFModuleType = MFModuleType;
54
+ exports.MODULE_DEVTOOL_IDENTIFIER = MODULE_DEVTOOL_IDENTIFIER;
55
+ exports.ManifestFileName = ManifestFileName;
56
+ exports.NameTransformMap = NameTransformMap;
57
+ exports.NameTransformSymbol = NameTransformSymbol;
58
+ exports.SEPARATOR = SEPARATOR;
59
+ exports.StatsFileName = StatsFileName;
60
+ exports.TEMP_DIR = TEMP_DIR;
61
+ exports.TreeShakingStatus = TreeShakingStatus;
62
+ //# sourceMappingURL=constant.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constant.cjs","names":[],"sources":["../src/constant.ts"],"sourcesContent":["export const FederationModuleManifest = 'federation-manifest.json';\nexport const MANIFEST_EXT = '.json';\n\nexport const BROWSER_LOG_KEY = 'FEDERATION_DEBUG';\n\nexport const NameTransformSymbol = {\n AT: '@',\n HYPHEN: '-',\n SLASH: '/',\n} as const;\nexport const NameTransformMap = {\n [NameTransformSymbol.AT]: 'scope_',\n [NameTransformSymbol.HYPHEN]: '_',\n [NameTransformSymbol.SLASH]: '__',\n} as const;\n\nexport const EncodedNameTransformMap = {\n [NameTransformMap[NameTransformSymbol.AT]]: NameTransformSymbol.AT,\n [NameTransformMap[NameTransformSymbol.HYPHEN]]: NameTransformSymbol.HYPHEN,\n [NameTransformMap[NameTransformSymbol.SLASH]]: NameTransformSymbol.SLASH,\n};\n\nexport const SEPARATOR = ':';\n\nexport const ManifestFileName = 'mf-manifest.json';\nexport const StatsFileName = 'mf-stats.json';\n\nexport const MFModuleType = {\n NPM: 'npm',\n APP: 'app',\n};\n\nexport const MODULE_DEVTOOL_IDENTIFIER = '__MF_DEVTOOLS_MODULE_INFO__';\nexport const ENCODE_NAME_PREFIX = 'ENCODE_NAME_PREFIX';\nexport const TEMP_DIR = '.federation';\n\nexport const enum TreeShakingStatus {\n /**\n * Not handled by deploy server, needs to infer by the real runtime period.\n */\n UNKNOWN = 1,\n /**\n * It means the shared has been calculated , runtime should take this shared as first choice.\n */\n CALCULATED = 2,\n /**\n * It means the shared has been calculated, and marked as no used\n */\n NO_USE = 0,\n}\n"],"mappings":";;AAAA,MAAa,2BAA2B;AACxC,MAAa,eAAe;AAE5B,MAAa,kBAAkB;AAE/B,MAAa,sBAAsB;CACjC,IAAI;CACJ,QAAQ;CACR,OAAO;CACR;AACD,MAAa,mBAAmB;EAC7B,oBAAoB,KAAK;EACzB,oBAAoB,SAAS;EAC7B,oBAAoB,QAAQ;CAC9B;AAED,MAAa,0BAA0B;EACpC,iBAAiB,oBAAoB,MAAM,oBAAoB;EAC/D,iBAAiB,oBAAoB,UAAU,oBAAoB;EACnE,iBAAiB,oBAAoB,SAAS,oBAAoB;CACpE;AAED,MAAa,YAAY;AAEzB,MAAa,mBAAmB;AAChC,MAAa,gBAAgB;AAE7B,MAAa,eAAe;CAC1B,KAAK;CACL,KAAK;CACN;AAED,MAAa,4BAA4B;AACzC,MAAa,qBAAqB;AAClC,MAAa,WAAW;AAExB,IAAkB,gEAAX;;;;AAIL;;;;AAIA;;;;AAIA"}
@@ -0,0 +1,46 @@
1
+ //#region src/constant.d.ts
2
+ declare const FederationModuleManifest = "federation-manifest.json";
3
+ declare const MANIFEST_EXT = ".json";
4
+ declare const BROWSER_LOG_KEY = "FEDERATION_DEBUG";
5
+ declare const NameTransformSymbol: {
6
+ readonly AT: "@";
7
+ readonly HYPHEN: "-";
8
+ readonly SLASH: "/";
9
+ };
10
+ declare const NameTransformMap: {
11
+ readonly "@": "scope_";
12
+ readonly "-": "_";
13
+ readonly "/": "__";
14
+ };
15
+ declare const EncodedNameTransformMap: {
16
+ scope_: "@";
17
+ _: "-";
18
+ __: "/";
19
+ };
20
+ declare const SEPARATOR = ":";
21
+ declare const ManifestFileName = "mf-manifest.json";
22
+ declare const StatsFileName = "mf-stats.json";
23
+ declare const MFModuleType: {
24
+ NPM: string;
25
+ APP: string;
26
+ };
27
+ declare const MODULE_DEVTOOL_IDENTIFIER = "__MF_DEVTOOLS_MODULE_INFO__";
28
+ declare const ENCODE_NAME_PREFIX = "ENCODE_NAME_PREFIX";
29
+ declare const TEMP_DIR = ".federation";
30
+ declare const enum TreeShakingStatus {
31
+ /**
32
+ * Not handled by deploy server, needs to infer by the real runtime period.
33
+ */
34
+ UNKNOWN = 1,
35
+ /**
36
+ * It means the shared has been calculated , runtime should take this shared as first choice.
37
+ */
38
+ CALCULATED = 2,
39
+ /**
40
+ * It means the shared has been calculated, and marked as no used
41
+ */
42
+ NO_USE = 0
43
+ }
44
+ //#endregion
45
+ export { BROWSER_LOG_KEY, ENCODE_NAME_PREFIX, EncodedNameTransformMap, FederationModuleManifest, MANIFEST_EXT, MFModuleType, MODULE_DEVTOOL_IDENTIFIER, ManifestFileName, NameTransformMap, NameTransformSymbol, SEPARATOR, StatsFileName, TEMP_DIR, TreeShakingStatus };
46
+ //# sourceMappingURL=constant.d.ts.map
@@ -0,0 +1,48 @@
1
+ //#region src/constant.ts
2
+ const FederationModuleManifest = "federation-manifest.json";
3
+ const MANIFEST_EXT = ".json";
4
+ const BROWSER_LOG_KEY = "FEDERATION_DEBUG";
5
+ const NameTransformSymbol = {
6
+ AT: "@",
7
+ HYPHEN: "-",
8
+ SLASH: "/"
9
+ };
10
+ const NameTransformMap = {
11
+ [NameTransformSymbol.AT]: "scope_",
12
+ [NameTransformSymbol.HYPHEN]: "_",
13
+ [NameTransformSymbol.SLASH]: "__"
14
+ };
15
+ const EncodedNameTransformMap = {
16
+ [NameTransformMap[NameTransformSymbol.AT]]: NameTransformSymbol.AT,
17
+ [NameTransformMap[NameTransformSymbol.HYPHEN]]: NameTransformSymbol.HYPHEN,
18
+ [NameTransformMap[NameTransformSymbol.SLASH]]: NameTransformSymbol.SLASH
19
+ };
20
+ const SEPARATOR = ":";
21
+ const ManifestFileName = "mf-manifest.json";
22
+ const StatsFileName = "mf-stats.json";
23
+ const MFModuleType = {
24
+ NPM: "npm",
25
+ APP: "app"
26
+ };
27
+ const MODULE_DEVTOOL_IDENTIFIER = "__MF_DEVTOOLS_MODULE_INFO__";
28
+ const ENCODE_NAME_PREFIX = "ENCODE_NAME_PREFIX";
29
+ const TEMP_DIR = ".federation";
30
+ let TreeShakingStatus = /* @__PURE__ */ function(TreeShakingStatus) {
31
+ /**
32
+ * Not handled by deploy server, needs to infer by the real runtime period.
33
+ */
34
+ TreeShakingStatus[TreeShakingStatus["UNKNOWN"] = 1] = "UNKNOWN";
35
+ /**
36
+ * It means the shared has been calculated , runtime should take this shared as first choice.
37
+ */
38
+ TreeShakingStatus[TreeShakingStatus["CALCULATED"] = 2] = "CALCULATED";
39
+ /**
40
+ * It means the shared has been calculated, and marked as no used
41
+ */
42
+ TreeShakingStatus[TreeShakingStatus["NO_USE"] = 0] = "NO_USE";
43
+ return TreeShakingStatus;
44
+ }({});
45
+
46
+ //#endregion
47
+ export { BROWSER_LOG_KEY, ENCODE_NAME_PREFIX, EncodedNameTransformMap, FederationModuleManifest, MANIFEST_EXT, MFModuleType, MODULE_DEVTOOL_IDENTIFIER, ManifestFileName, NameTransformMap, NameTransformSymbol, SEPARATOR, StatsFileName, TEMP_DIR, TreeShakingStatus };
48
+ //# sourceMappingURL=constant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constant.js","names":[],"sources":["../src/constant.ts"],"sourcesContent":["export const FederationModuleManifest = 'federation-manifest.json';\nexport const MANIFEST_EXT = '.json';\n\nexport const BROWSER_LOG_KEY = 'FEDERATION_DEBUG';\n\nexport const NameTransformSymbol = {\n AT: '@',\n HYPHEN: '-',\n SLASH: '/',\n} as const;\nexport const NameTransformMap = {\n [NameTransformSymbol.AT]: 'scope_',\n [NameTransformSymbol.HYPHEN]: '_',\n [NameTransformSymbol.SLASH]: '__',\n} as const;\n\nexport const EncodedNameTransformMap = {\n [NameTransformMap[NameTransformSymbol.AT]]: NameTransformSymbol.AT,\n [NameTransformMap[NameTransformSymbol.HYPHEN]]: NameTransformSymbol.HYPHEN,\n [NameTransformMap[NameTransformSymbol.SLASH]]: NameTransformSymbol.SLASH,\n};\n\nexport const SEPARATOR = ':';\n\nexport const ManifestFileName = 'mf-manifest.json';\nexport const StatsFileName = 'mf-stats.json';\n\nexport const MFModuleType = {\n NPM: 'npm',\n APP: 'app',\n};\n\nexport const MODULE_DEVTOOL_IDENTIFIER = '__MF_DEVTOOLS_MODULE_INFO__';\nexport const ENCODE_NAME_PREFIX = 'ENCODE_NAME_PREFIX';\nexport const TEMP_DIR = '.federation';\n\nexport const enum TreeShakingStatus {\n /**\n * Not handled by deploy server, needs to infer by the real runtime period.\n */\n UNKNOWN = 1,\n /**\n * It means the shared has been calculated , runtime should take this shared as first choice.\n */\n CALCULATED = 2,\n /**\n * It means the shared has been calculated, and marked as no used\n */\n NO_USE = 0,\n}\n"],"mappings":";AAAA,MAAa,2BAA2B;AACxC,MAAa,eAAe;AAE5B,MAAa,kBAAkB;AAE/B,MAAa,sBAAsB;CACjC,IAAI;CACJ,QAAQ;CACR,OAAO;CACR;AACD,MAAa,mBAAmB;EAC7B,oBAAoB,KAAK;EACzB,oBAAoB,SAAS;EAC7B,oBAAoB,QAAQ;CAC9B;AAED,MAAa,0BAA0B;EACpC,iBAAiB,oBAAoB,MAAM,oBAAoB;EAC/D,iBAAiB,oBAAoB,UAAU,oBAAoB;EACnE,iBAAiB,oBAAoB,SAAS,oBAAoB;CACpE;AAED,MAAa,YAAY;AAEzB,MAAa,mBAAmB;AAChC,MAAa,gBAAgB;AAE7B,MAAa,eAAe;CAC1B,KAAK;CACL,KAAK;CACN;AAED,MAAa,4BAA4B;AACzC,MAAa,qBAAqB;AAClC,MAAa,WAAW;AAExB,IAAkB,gEAAX;;;;AAIL;;;;AAIA;;;;AAIA"}
@@ -0,0 +1,9 @@
1
+
2
+ //#region src/createModuleFederationConfig.ts
3
+ const createModuleFederationConfig = (options) => {
4
+ return options;
5
+ };
6
+
7
+ //#endregion
8
+ exports.createModuleFederationConfig = createModuleFederationConfig;
9
+ //# sourceMappingURL=createModuleFederationConfig.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createModuleFederationConfig.cjs","names":[],"sources":["../src/createModuleFederationConfig.ts"],"sourcesContent":["import type { moduleFederationPlugin } from './types/plugins';\n\nexport const createModuleFederationConfig = (\n options: moduleFederationPlugin.ModuleFederationPluginOptions,\n): moduleFederationPlugin.ModuleFederationPluginOptions => {\n return options;\n};\n"],"mappings":";;AAEA,MAAa,gCACX,YACyD;AACzD,QAAO"}
@@ -0,0 +1,6 @@
1
+ import { ModuleFederationPluginOptions } from "./types/plugins/ModuleFederationPlugin.js";
2
+ //#region src/createModuleFederationConfig.d.ts
3
+ declare const createModuleFederationConfig: (options: ModuleFederationPluginOptions) => ModuleFederationPluginOptions;
4
+ //#endregion
5
+ export { createModuleFederationConfig };
6
+ //# sourceMappingURL=createModuleFederationConfig.d.ts.map
@@ -0,0 +1,8 @@
1
+ //#region src/createModuleFederationConfig.ts
2
+ const createModuleFederationConfig = (options) => {
3
+ return options;
4
+ };
5
+
6
+ //#endregion
7
+ export { createModuleFederationConfig };
8
+ //# sourceMappingURL=createModuleFederationConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createModuleFederationConfig.js","names":[],"sources":["../src/createModuleFederationConfig.ts"],"sourcesContent":["import type { moduleFederationPlugin } from './types/plugins';\n\nexport const createModuleFederationConfig = (\n options: moduleFederationPlugin.ModuleFederationPluginOptions,\n): moduleFederationPlugin.ModuleFederationPluginOptions => {\n return options;\n};\n"],"mappings":";AAEA,MAAa,gCACX,YACyD;AACzD,QAAO"}
package/dist/dom.cjs ADDED
@@ -0,0 +1,214 @@
1
+ const require_utils = require('./utils.cjs');
2
+
3
+ //#region src/dom.ts
4
+ async function safeWrapper(callback, disableWarn) {
5
+ try {
6
+ return await callback();
7
+ } catch (e) {
8
+ !disableWarn && require_utils.warn(e);
9
+ return;
10
+ }
11
+ }
12
+ function isStaticResourcesEqual(url1, url2) {
13
+ const REG_EXP = /^(https?:)?\/\//i;
14
+ return url1.replace(REG_EXP, "").replace(/\/$/, "") === url2.replace(REG_EXP, "").replace(/\/$/, "");
15
+ }
16
+ function createScript(info) {
17
+ let script = null;
18
+ let needAttach = true;
19
+ let timeout = 2e4;
20
+ let timeoutId;
21
+ const scripts = document.getElementsByTagName("script");
22
+ for (let i = 0; i < scripts.length; i++) {
23
+ const s = scripts[i];
24
+ const scriptSrc = s.getAttribute("src");
25
+ if (scriptSrc && isStaticResourcesEqual(scriptSrc, info.url)) {
26
+ script = s;
27
+ needAttach = false;
28
+ break;
29
+ }
30
+ }
31
+ if (!script) {
32
+ const attrs = info.attrs;
33
+ script = document.createElement("script");
34
+ script.type = attrs?.["type"] === "module" ? "module" : "text/javascript";
35
+ let createScriptRes = void 0;
36
+ if (info.createScriptHook) {
37
+ createScriptRes = info.createScriptHook(info.url, info.attrs);
38
+ if (createScriptRes instanceof HTMLScriptElement) script = createScriptRes;
39
+ else if (typeof createScriptRes === "object") {
40
+ if ("script" in createScriptRes && createScriptRes.script) script = createScriptRes.script;
41
+ if ("timeout" in createScriptRes && createScriptRes.timeout) timeout = createScriptRes.timeout;
42
+ }
43
+ }
44
+ if (!script.src) script.src = info.url;
45
+ if (attrs && !createScriptRes) Object.keys(attrs).forEach((name) => {
46
+ if (script) {
47
+ if (name === "async" || name === "defer") script[name] = attrs[name];
48
+ else if (!script.getAttribute(name)) script.setAttribute(name, attrs[name]);
49
+ }
50
+ });
51
+ }
52
+ let executionError = null;
53
+ const executionErrorHandler = typeof window !== "undefined" ? (evt) => {
54
+ if (evt.filename && isStaticResourcesEqual(evt.filename, info.url)) {
55
+ const err = /* @__PURE__ */ new Error(`ScriptExecutionError: Script "${info.url}" loaded but threw a runtime error during execution: ${evt.message} (${evt.filename}:${evt.lineno}:${evt.colno})`);
56
+ err.name = "ScriptExecutionError";
57
+ executionError = err;
58
+ }
59
+ } : null;
60
+ if (executionErrorHandler) window.addEventListener("error", executionErrorHandler);
61
+ const onScriptComplete = async (prev, event) => {
62
+ clearTimeout(timeoutId);
63
+ if (executionErrorHandler) window.removeEventListener("error", executionErrorHandler);
64
+ const onScriptCompleteCallback = () => {
65
+ if (event?.type === "error") {
66
+ const networkError = /* @__PURE__ */ new Error(event?.isTimeout ? `ScriptNetworkError: Script "${info.url}" timed out.` : `ScriptNetworkError: Failed to load script "${info.url}" - the script URL is unreachable or the server returned an error (network failure, 404, CORS, etc.)`);
67
+ networkError.name = "ScriptNetworkError";
68
+ info?.onErrorCallback && info?.onErrorCallback(networkError);
69
+ } else if (executionError) info?.onErrorCallback && info?.onErrorCallback(executionError);
70
+ else info?.cb && info?.cb();
71
+ };
72
+ if (script) {
73
+ script.onerror = null;
74
+ script.onload = null;
75
+ safeWrapper(() => {
76
+ const { needDeleteScript = true } = info;
77
+ if (needDeleteScript) script?.parentNode && script.parentNode.removeChild(script);
78
+ });
79
+ if (prev && typeof prev === "function") {
80
+ const result = prev(event);
81
+ if (result instanceof Promise) {
82
+ const res = await result;
83
+ onScriptCompleteCallback();
84
+ return res;
85
+ }
86
+ onScriptCompleteCallback();
87
+ return result;
88
+ }
89
+ }
90
+ onScriptCompleteCallback();
91
+ };
92
+ script.onerror = onScriptComplete.bind(null, script.onerror);
93
+ script.onload = onScriptComplete.bind(null, script.onload);
94
+ timeoutId = setTimeout(() => {
95
+ onScriptComplete(null, {
96
+ type: "error",
97
+ isTimeout: true
98
+ });
99
+ }, timeout);
100
+ return {
101
+ script,
102
+ needAttach
103
+ };
104
+ }
105
+ function createLink(info) {
106
+ let link = null;
107
+ let needAttach = true;
108
+ let timeout = 2e4;
109
+ let timeoutId;
110
+ const links = document.getElementsByTagName("link");
111
+ for (let i = 0; i < links.length; i++) {
112
+ const l = links[i];
113
+ const linkHref = l.getAttribute("href");
114
+ const linkRel = l.getAttribute("rel");
115
+ if (linkHref && isStaticResourcesEqual(linkHref, info.url) && linkRel === info.attrs["rel"]) {
116
+ link = l;
117
+ needAttach = false;
118
+ break;
119
+ }
120
+ }
121
+ if (!link) {
122
+ link = document.createElement("link");
123
+ link.setAttribute("href", info.url);
124
+ let createLinkRes = void 0;
125
+ let shouldApplyAttrs = true;
126
+ const attrs = info.attrs;
127
+ if (info.createLinkHook) {
128
+ createLinkRes = info.createLinkHook(info.url, attrs);
129
+ if (createLinkRes instanceof HTMLLinkElement) {
130
+ link = createLinkRes;
131
+ shouldApplyAttrs = false;
132
+ } else if (typeof createLinkRes === "object") {
133
+ if ("link" in createLinkRes && createLinkRes.link) {
134
+ link = createLinkRes.link;
135
+ shouldApplyAttrs = false;
136
+ }
137
+ if ("timeout" in createLinkRes && createLinkRes.timeout) timeout = createLinkRes.timeout;
138
+ }
139
+ }
140
+ if (attrs && shouldApplyAttrs) Object.keys(attrs).forEach((name) => {
141
+ if (link && !link.getAttribute(name)) link.setAttribute(name, attrs[name]);
142
+ });
143
+ }
144
+ if (!needAttach) {
145
+ Promise.resolve().then(() => {
146
+ info?.cb && info?.cb();
147
+ });
148
+ return {
149
+ link,
150
+ needAttach
151
+ };
152
+ }
153
+ const onLinkComplete = (prev, event) => {
154
+ if (timeoutId) clearTimeout(timeoutId);
155
+ const onLinkCompleteCallback = () => {
156
+ if (event?.type === "error") {
157
+ const linkError = /* @__PURE__ */ new Error(event?.isTimeout ? `LinkNetworkError: Link "${info.url}" timed out.` : `LinkNetworkError: Failed to load link "${info.url}" - the URL is unreachable or the server returned an error.`);
158
+ linkError.name = "LinkNetworkError";
159
+ info?.onErrorCallback && info?.onErrorCallback(linkError);
160
+ } else info?.cb && info?.cb();
161
+ };
162
+ if (link) {
163
+ link.onerror = null;
164
+ link.onload = null;
165
+ safeWrapper(() => {
166
+ const { needDeleteLink = true } = info;
167
+ if (needDeleteLink) link?.parentNode && link.parentNode.removeChild(link);
168
+ });
169
+ if (prev) {
170
+ const res = prev(event);
171
+ onLinkCompleteCallback();
172
+ return res;
173
+ }
174
+ }
175
+ onLinkCompleteCallback();
176
+ };
177
+ link.onerror = onLinkComplete.bind(null, link.onerror);
178
+ link.onload = onLinkComplete.bind(null, link.onload);
179
+ timeoutId = setTimeout(() => {
180
+ onLinkComplete(null, {
181
+ type: "error",
182
+ isTimeout: true
183
+ });
184
+ }, timeout);
185
+ return {
186
+ link,
187
+ needAttach
188
+ };
189
+ }
190
+ function loadScript(url, info) {
191
+ const { attrs = {}, createScriptHook } = info;
192
+ return new Promise((resolve, reject) => {
193
+ const { script, needAttach } = createScript({
194
+ url,
195
+ cb: resolve,
196
+ onErrorCallback: reject,
197
+ attrs: {
198
+ fetchpriority: "high",
199
+ ...attrs
200
+ },
201
+ createScriptHook,
202
+ needDeleteScript: true
203
+ });
204
+ needAttach && document.head.appendChild(script);
205
+ });
206
+ }
207
+
208
+ //#endregion
209
+ exports.createLink = createLink;
210
+ exports.createScript = createScript;
211
+ exports.isStaticResourcesEqual = isStaticResourcesEqual;
212
+ exports.loadScript = loadScript;
213
+ exports.safeWrapper = safeWrapper;
214
+ //# sourceMappingURL=dom.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dom.cjs","names":["warn"],"sources":["../src/dom.ts"],"sourcesContent":["import type {\n CreateLinkHookDom,\n CreateLinkHookReturnDom,\n CreateScriptHookDom,\n CreateScriptHookReturnDom,\n} from './types';\nimport { warn } from './utils';\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport async function safeWrapper<T extends (...args: Array<any>) => any>(\n callback: T,\n disableWarn?: boolean,\n): Promise<ReturnType<T> | undefined> {\n try {\n const res = await callback();\n return res;\n } catch (e) {\n !disableWarn && warn(e);\n return;\n }\n}\n\nexport function isStaticResourcesEqual(url1: string, url2: string): boolean {\n const REG_EXP = /^(https?:)?\\/\\//i;\n // Transform url1 and url2 into relative paths\n const relativeUrl1 = url1.replace(REG_EXP, '').replace(/\\/$/, '');\n const relativeUrl2 = url2.replace(REG_EXP, '').replace(/\\/$/, '');\n // Check if the relative paths are identical\n return relativeUrl1 === relativeUrl2;\n}\n\nexport function createScript(info: {\n url: string;\n cb?: (value: void | PromiseLike<void>) => void;\n onErrorCallback?: (error: Error) => void;\n attrs?: Record<string, any>;\n needDeleteScript?: boolean;\n createScriptHook?: CreateScriptHookDom;\n}): { script: HTMLScriptElement; needAttach: boolean } {\n // Retrieve the existing script element by its src attribute\n let script: HTMLScriptElement | null = null;\n let needAttach = true;\n let timeout = 20000;\n let timeoutId: NodeJS.Timeout;\n const scripts = document.getElementsByTagName('script');\n\n for (let i = 0; i < scripts.length; i++) {\n const s = scripts[i];\n const scriptSrc = s.getAttribute('src');\n if (scriptSrc && isStaticResourcesEqual(scriptSrc, info.url)) {\n script = s;\n needAttach = false;\n break;\n }\n }\n\n if (!script) {\n const attrs = info.attrs;\n script = document.createElement('script');\n script.type = attrs?.['type'] === 'module' ? 'module' : 'text/javascript';\n let createScriptRes: CreateScriptHookReturnDom = undefined;\n if (info.createScriptHook) {\n createScriptRes = info.createScriptHook(info.url, info.attrs);\n\n if (createScriptRes instanceof HTMLScriptElement) {\n script = createScriptRes;\n } else if (typeof createScriptRes === 'object') {\n if ('script' in createScriptRes && createScriptRes.script) {\n script = createScriptRes.script;\n }\n if ('timeout' in createScriptRes && createScriptRes.timeout) {\n timeout = createScriptRes.timeout;\n }\n }\n }\n if (!script.src) {\n script.src = info.url;\n }\n if (attrs && !createScriptRes) {\n Object.keys(attrs).forEach((name) => {\n if (script) {\n if (name === 'async' || name === 'defer') {\n script[name] = attrs[name];\n // Attributes that do not exist are considered overridden\n } else if (!script.getAttribute(name)) {\n script.setAttribute(name, attrs[name]);\n }\n }\n });\n }\n }\n\n // Capture JS runtime errors thrown by this script's IIFE during execution.\n // The browser still fires onload even when the script throws, so without this\n // listener the execution error would silently become an uncaught global exception.\n let executionError: Error | null = null;\n const executionErrorHandler =\n typeof window !== 'undefined'\n ? (evt: ErrorEvent) => {\n if (evt.filename && isStaticResourcesEqual(evt.filename, info.url)) {\n const err = new Error(\n `ScriptExecutionError: Script \"${info.url}\" loaded but threw a runtime error during execution: ${evt.message} (${evt.filename}:${evt.lineno}:${evt.colno})`,\n );\n err.name = 'ScriptExecutionError';\n executionError = err;\n }\n }\n : null;\n if (executionErrorHandler) {\n window.addEventListener('error', executionErrorHandler);\n }\n\n const onScriptComplete = async (\n prev: OnErrorEventHandler | GlobalEventHandlers['onload'] | null,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n event: any,\n ): Promise<void> => {\n clearTimeout(timeoutId);\n if (executionErrorHandler) {\n window.removeEventListener('error', executionErrorHandler);\n }\n const onScriptCompleteCallback = () => {\n if (event?.type === 'error') {\n const networkError = new Error(\n event?.isTimeout\n ? `ScriptNetworkError: Script \"${info.url}\" timed out.`\n : `ScriptNetworkError: Failed to load script \"${info.url}\" - the script URL is unreachable or the server returned an error (network failure, 404, CORS, etc.)`,\n );\n networkError.name = 'ScriptNetworkError';\n info?.onErrorCallback && info?.onErrorCallback(networkError);\n } else if (executionError) {\n // Script fetched OK (onload fired) but IIFE threw during execution.\n info?.onErrorCallback && info?.onErrorCallback(executionError);\n } else {\n info?.cb && info?.cb();\n }\n };\n\n // Prevent memory leaks in IE.\n if (script) {\n script.onerror = null;\n script.onload = null;\n safeWrapper(() => {\n const { needDeleteScript = true } = info;\n if (needDeleteScript) {\n script?.parentNode && script.parentNode.removeChild(script);\n }\n });\n if (prev && typeof prev === 'function') {\n const result = (prev as any)(event);\n if (result instanceof Promise) {\n const res = await result;\n onScriptCompleteCallback();\n return res;\n }\n onScriptCompleteCallback();\n return result;\n }\n }\n onScriptCompleteCallback();\n };\n\n script.onerror = onScriptComplete.bind(null, script.onerror);\n script.onload = onScriptComplete.bind(null, script.onload);\n\n timeoutId = setTimeout(() => {\n onScriptComplete(null, { type: 'error', isTimeout: true });\n }, timeout);\n\n return { script, needAttach };\n}\n\nexport function createLink(info: {\n url: string;\n cb?: (value: void | PromiseLike<void>) => void;\n onErrorCallback?: (error: Error) => void;\n attrs: Record<string, string>;\n needDeleteLink?: boolean;\n createLinkHook?: CreateLinkHookDom;\n}) {\n // <link rel=\"preload\" href=\"script.js\" as=\"script\">\n\n // Retrieve the existing script element by its src attribute\n let link: HTMLLinkElement | null = null;\n let needAttach = true;\n let timeout = 20000;\n let timeoutId: NodeJS.Timeout | undefined;\n const links = document.getElementsByTagName('link');\n for (let i = 0; i < links.length; i++) {\n const l = links[i];\n const linkHref = l.getAttribute('href');\n const linkRel = l.getAttribute('rel');\n if (\n linkHref &&\n isStaticResourcesEqual(linkHref, info.url) &&\n linkRel === info.attrs['rel']\n ) {\n link = l;\n needAttach = false;\n break;\n }\n }\n\n if (!link) {\n link = document.createElement('link');\n link.setAttribute('href', info.url);\n\n let createLinkRes: CreateLinkHookReturnDom = undefined;\n let shouldApplyAttrs = true;\n const attrs = info.attrs;\n\n if (info.createLinkHook) {\n createLinkRes = info.createLinkHook(info.url, attrs);\n if (createLinkRes instanceof HTMLLinkElement) {\n link = createLinkRes;\n shouldApplyAttrs = false;\n } else if (typeof createLinkRes === 'object') {\n if ('link' in createLinkRes && createLinkRes.link) {\n link = createLinkRes.link;\n shouldApplyAttrs = false;\n }\n if ('timeout' in createLinkRes && createLinkRes.timeout) {\n timeout = createLinkRes.timeout;\n }\n }\n }\n\n if (attrs && shouldApplyAttrs) {\n Object.keys(attrs).forEach((name) => {\n if (link && !link.getAttribute(name)) {\n link.setAttribute(name, attrs[name]);\n }\n });\n }\n }\n\n if (!needAttach) {\n Promise.resolve().then(() => {\n info?.cb && info?.cb();\n });\n return { link, needAttach };\n }\n\n const onLinkComplete = (\n prev: OnErrorEventHandler | GlobalEventHandlers['onload'] | null,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n event: any,\n ): void => {\n if (timeoutId) {\n clearTimeout(timeoutId);\n }\n const onLinkCompleteCallback = () => {\n if (event?.type === 'error') {\n const linkError = new Error(\n event?.isTimeout\n ? `LinkNetworkError: Link \"${info.url}\" timed out.`\n : `LinkNetworkError: Failed to load link \"${info.url}\" - the URL is unreachable or the server returned an error.`,\n );\n linkError.name = 'LinkNetworkError';\n info?.onErrorCallback && info?.onErrorCallback(linkError);\n } else {\n info?.cb && info?.cb();\n }\n };\n // Prevent memory leaks in IE.\n if (link) {\n link.onerror = null;\n link.onload = null;\n safeWrapper(() => {\n const { needDeleteLink = true } = info;\n if (needDeleteLink) {\n link?.parentNode && link.parentNode.removeChild(link);\n }\n });\n if (prev) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const res = (prev as any)(event);\n onLinkCompleteCallback();\n return res;\n }\n }\n onLinkCompleteCallback();\n };\n\n link.onerror = onLinkComplete.bind(null, link.onerror);\n link.onload = onLinkComplete.bind(null, link.onload);\n timeoutId = setTimeout(() => {\n onLinkComplete(null, { type: 'error', isTimeout: true });\n }, timeout);\n\n return { link, needAttach };\n}\n\nexport function loadScript(\n url: string,\n info: {\n attrs?: Record<string, any>;\n createScriptHook?: CreateScriptHookDom;\n },\n) {\n const { attrs = {}, createScriptHook } = info;\n return new Promise<void>((resolve, reject) => {\n const { script, needAttach } = createScript({\n url,\n cb: resolve,\n onErrorCallback: reject,\n attrs: {\n fetchpriority: 'high',\n ...attrs,\n },\n createScriptHook,\n needDeleteScript: true,\n });\n needAttach && document.head.appendChild(script);\n });\n}\n"],"mappings":";;;AAQA,eAAsB,YACpB,UACA,aACoC;AACpC,KAAI;AAEF,SADY,MAAM,UAAU;UAErB,GAAG;AACV,GAAC,eAAeA,mBAAK,EAAE;AACvB;;;AAIJ,SAAgB,uBAAuB,MAAc,MAAuB;CAC1E,MAAM,UAAU;AAKhB,QAHqB,KAAK,QAAQ,SAAS,GAAG,CAAC,QAAQ,OAAO,GAAG,KAC5C,KAAK,QAAQ,SAAS,GAAG,CAAC,QAAQ,OAAO,GAAG;;AAKnE,SAAgB,aAAa,MAO0B;CAErD,IAAI,SAAmC;CACvC,IAAI,aAAa;CACjB,IAAI,UAAU;CACd,IAAI;CACJ,MAAM,UAAU,SAAS,qBAAqB,SAAS;AAEvD,MAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;EACvC,MAAM,IAAI,QAAQ;EAClB,MAAM,YAAY,EAAE,aAAa,MAAM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;;;AAGX,0BAAwB;;AAG1B,MAAK,UAAU,eAAe,KAAK,MAAM,KAAK,QAAQ;AACtD,MAAK,SAAS,eAAe,KAAK,MAAM,KAAK,OAAO;AACpD,aAAY,iBAAiB;AAC3B,iBAAe,MAAM;GAAE,MAAM;GAAS,WAAW;GAAM,CAAC;IACvD,QAAQ;AAEX,QAAO;EAAE;EAAM;EAAY;;AAG7B,SAAgB,WACd,KACA,MAIA;CACA,MAAM,EAAE,QAAQ,EAAE,EAAE,qBAAqB;AACzC,QAAO,IAAI,SAAe,SAAS,WAAW;EAC5C,MAAM,EAAE,QAAQ,eAAe,aAAa;GAC1C;GACA,IAAI;GACJ,iBAAiB;GACjB,OAAO;IACL,eAAe;IACf,GAAG;IACJ;GACD;GACA,kBAAkB;GACnB,CAAC;AACF,gBAAc,SAAS,KAAK,YAAY,OAAO;GAC/C"}
package/dist/dom.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ import { CreateLinkHookDom, CreateScriptHookDom } from "./types/hooks.js";
2
+ //#region src/dom.d.ts
3
+ declare function safeWrapper<T extends (...args: Array<any>) => any>(callback: T, disableWarn?: boolean): Promise<ReturnType<T> | undefined>;
4
+ declare function isStaticResourcesEqual(url1: string, url2: string): boolean;
5
+ declare function createScript(info: {
6
+ url: string;
7
+ cb?: (value: void | PromiseLike<void>) => void;
8
+ onErrorCallback?: (error: Error) => void;
9
+ attrs?: Record<string, any>;
10
+ needDeleteScript?: boolean;
11
+ createScriptHook?: CreateScriptHookDom;
12
+ }): {
13
+ script: HTMLScriptElement;
14
+ needAttach: boolean;
15
+ };
16
+ declare function createLink(info: {
17
+ url: string;
18
+ cb?: (value: void | PromiseLike<void>) => void;
19
+ onErrorCallback?: (error: Error) => void;
20
+ attrs: Record<string, string>;
21
+ needDeleteLink?: boolean;
22
+ createLinkHook?: CreateLinkHookDom;
23
+ }): {
24
+ link: HTMLLinkElement;
25
+ needAttach: boolean;
26
+ };
27
+ declare function loadScript(url: string, info: {
28
+ attrs?: Record<string, any>;
29
+ createScriptHook?: CreateScriptHookDom;
30
+ }): Promise<void>;
31
+ //#endregion
32
+ export { createLink, createScript, isStaticResourcesEqual, loadScript, safeWrapper };
33
+ //# sourceMappingURL=dom.d.ts.map