@module-federation/utilities 0.0.0-perf-devtools-20260107043700 → 0.0.0-perf-website-code-usage-20260914033703

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 (51) hide show
  1. package/README.md +10 -8
  2. package/dist/cjs/Logger.js +63 -0
  3. package/dist/cjs/components/ErrorBoundary.js +98 -0
  4. package/dist/cjs/components/FederationBoundary.js +103 -0
  5. package/dist/cjs/index.js +172 -0
  6. package/dist/cjs/plugins/DelegateModulesPlugin.js +134 -0
  7. package/dist/cjs/plugins/DelegateModulesPlugin.test.js +87 -0
  8. package/dist/cjs/types/index.js +31 -0
  9. package/dist/cjs/utils/common.js +175 -0
  10. package/dist/cjs/utils/getRuntimeRemotes.js +104 -0
  11. package/dist/cjs/utils/getRuntimeRemotes.test.js +98 -0
  12. package/dist/cjs/utils/importDelegateModule.test.js +99 -0
  13. package/dist/cjs/utils/importDelegatedModule.js +126 -0
  14. package/dist/cjs/utils/importRemote.js +176 -0
  15. package/dist/cjs/utils/isEmpty.js +60 -0
  16. package/dist/cjs/utils/pure.js +215 -0
  17. package/dist/cjs/utils/react.js +73 -0
  18. package/dist/esm/Logger.mjs +12 -0
  19. package/dist/esm/components/ErrorBoundary.mjs +31 -0
  20. package/dist/esm/components/FederationBoundary.mjs +35 -0
  21. package/dist/esm/index.mjs +24 -0
  22. package/dist/esm/plugins/DelegateModulesPlugin.mjs +82 -0
  23. package/dist/esm/plugins/DelegateModulesPlugin.test.mjs +39 -0
  24. package/dist/esm/rslib-runtime.mjs +37 -0
  25. package/dist/esm/types/index.mjs +4 -0
  26. package/dist/esm/utils/common.mjs +116 -0
  27. package/dist/esm/utils/getRuntimeRemotes.mjs +50 -0
  28. package/dist/esm/utils/getRuntimeRemotes.test.mjs +84 -0
  29. package/dist/esm/utils/importDelegateModule.test.mjs +72 -0
  30. package/dist/esm/utils/importDelegatedModule.mjs +72 -0
  31. package/dist/esm/utils/importRemote.mjs +105 -0
  32. package/dist/esm/utils/isEmpty.mjs +8 -0
  33. package/dist/esm/utils/pure.mjs +138 -0
  34. package/dist/esm/utils/react.mjs +4 -0
  35. package/package.json +17 -10
  36. package/dist/index.cjs.js +0 -555
  37. package/dist/index.d.ts +0 -1
  38. package/dist/index.esm.js +0 -543
  39. /package/dist/{src → types}/Logger.d.ts +0 -0
  40. /package/dist/{src → types}/components/ErrorBoundary.d.ts +0 -0
  41. /package/dist/{src → types}/components/FederationBoundary.d.ts +0 -0
  42. /package/dist/{src → types}/index.d.ts +0 -0
  43. /package/dist/{src → types}/plugins/DelegateModulesPlugin.d.ts +0 -0
  44. /package/dist/{src → types}/types/index.d.ts +0 -0
  45. /package/dist/{src → types}/utils/common.d.ts +0 -0
  46. /package/dist/{src → types}/utils/getRuntimeRemotes.d.ts +0 -0
  47. /package/dist/{src → types}/utils/importDelegatedModule.d.ts +0 -0
  48. /package/dist/{src → types}/utils/importRemote.d.ts +0 -0
  49. /package/dist/{src → types}/utils/isEmpty.d.ts +0 -0
  50. /package/dist/{src → types}/utils/pure.d.ts +0 -0
  51. /package/dist/{src → types}/utils/react.d.ts +0 -0
@@ -0,0 +1,105 @@
1
+ import { __webpack_require__ } from "../rslib-runtime.mjs";
2
+
3
+ /**
4
+ * Constant for remote entry file
5
+ * @constant {string}
6
+ */ const REMOTE_ENTRY_FILE = 'remoteEntry.js';
7
+ /**
8
+ * Function to load remote
9
+ * @function
10
+ * @param {ImportRemoteOptions['url']} url - The url of the remote module
11
+ * @param {ImportRemoteOptions['scope']} scope - The scope of the remote module
12
+ * @param {ImportRemoteOptions['bustRemoteEntryCache']} bustRemoteEntryCache - Flag to bust the remote entry cache
13
+ * @returns {Promise<void>} A promise that resolves when the remote is loaded
14
+ */ const loadRemote = (url, scope, bustRemoteEntryCache)=>new Promise((resolve, reject)=>{
15
+ const timestamp = bustRemoteEntryCache ? `?t=${new Date().getTime()}` : '';
16
+ const webpackRequire = __webpack_require__;
17
+ webpackRequire.l(`${url}${timestamp}`, (event)=>{
18
+ if (event?.type === 'load') {
19
+ // Script loaded successfully:
20
+ return resolve();
21
+ }
22
+ const realSrc = event?.target?.src;
23
+ const error = new Error();
24
+ error.message = 'Loading script failed.\n(missing: ' + realSrc + ')';
25
+ error.name = 'ScriptExternalLoadError';
26
+ reject(error);
27
+ }, scope);
28
+ });
29
+ const loadEsmRemote = async (url, scope)=>{
30
+ const module = await import(/* webpackIgnore: true */ url);
31
+ if (!module) {
32
+ throw new Error(`Unable to load requested remote from ${url} with scope ${scope}`);
33
+ }
34
+ window[scope] = {
35
+ ...module,
36
+ __initializing: false,
37
+ __initialized: false
38
+ };
39
+ };
40
+ /**
41
+ * Function to initialize sharing
42
+ * @async
43
+ * @function
44
+ */ const initSharing = async ()=>{
45
+ const webpackShareScopes = __webpack_require__.S;
46
+ if (!webpackShareScopes?.default) {
47
+ await __webpack_require__.I('default');
48
+ }
49
+ };
50
+ /**
51
+ * Function to initialize container
52
+ * @async
53
+ * @function
54
+ * @param {WebpackRemoteContainer} containerScope - The container scope
55
+ */ const initContainer = async (containerScope)=>{
56
+ try {
57
+ const webpackShareScopes = __webpack_require__.S;
58
+ if (!containerScope.__initialized && !containerScope.__initializing) {
59
+ containerScope.__initializing = true;
60
+ await containerScope.init(webpackShareScopes.default);
61
+ containerScope.__initialized = true;
62
+ delete containerScope.__initializing;
63
+ }
64
+ } catch (error) {
65
+ console.error(error);
66
+ }
67
+ };
68
+ /**
69
+ * Function to import remote
70
+ * @async
71
+ * @function
72
+ * @param {ImportRemoteOptions} options - The options for importing the remote
73
+ * @returns {Promise<T>} A promise that resolves with the imported module
74
+ */ const importRemote = async ({ url, scope, module, remoteEntryFileName = REMOTE_ENTRY_FILE, bustRemoteEntryCache = true, esm = false })=>{
75
+ const remoteScope = scope;
76
+ if (!window[remoteScope]) {
77
+ let remoteUrl = '';
78
+ if (typeof url === 'string') {
79
+ remoteUrl = url;
80
+ } else {
81
+ remoteUrl = await url();
82
+ }
83
+ const remoteUrlWithEntryFile = `${remoteUrl}/${remoteEntryFileName}`;
84
+ const asyncContainer = !esm ? loadRemote(remoteUrlWithEntryFile, scope, bustRemoteEntryCache) : loadEsmRemote(remoteUrlWithEntryFile, scope);
85
+ // Load the remote and initialize the share scope if it's empty
86
+ await Promise.all([
87
+ asyncContainer,
88
+ initSharing()
89
+ ]);
90
+ if (!window[remoteScope]) {
91
+ throw new Error(`Remote loaded successfully but ${scope} could not be found! Verify that the name is correct in the Webpack configuration!`);
92
+ }
93
+ // Initialize the container to get shared modules and get the module factory:
94
+ const [, moduleFactory] = await Promise.all([
95
+ initContainer(window[remoteScope]),
96
+ window[remoteScope].get(module === '.' || module.startsWith('./') ? module : `./${module}`)
97
+ ]);
98
+ return moduleFactory();
99
+ } else {
100
+ const moduleFactory = await window[remoteScope].get(module === '.' || module.startsWith('./') ? module : `./${module}`);
101
+ return moduleFactory();
102
+ }
103
+ };
104
+
105
+ export { importRemote };
@@ -0,0 +1,8 @@
1
+ const isObjectEmpty = (obj)=>{
2
+ for(const x in obj){
3
+ return false;
4
+ }
5
+ return true;
6
+ };
7
+
8
+ export { isObjectEmpty };
@@ -0,0 +1,138 @@
1
+ import { __webpack_require__ } from "../rslib-runtime.mjs";
2
+
3
+ const pure = typeof process !== 'undefined' ? process.env['REMOTES'] || {} : {};
4
+ const remoteVars = pure;
5
+ const extractUrlAndGlobal = (urlAndGlobal)=>{
6
+ const index = urlAndGlobal.indexOf('@');
7
+ if (index <= 0 || index === urlAndGlobal.length - 1) {
8
+ throw new Error(`Invalid request "${urlAndGlobal}"`);
9
+ }
10
+ return [
11
+ urlAndGlobal.substring(index + 1),
12
+ urlAndGlobal.substring(0, index)
13
+ ];
14
+ };
15
+ const loadScript = (keyOrRuntimeRemoteItem)=>{
16
+ const runtimeRemotes = getRuntimeRemotes();
17
+ // 1) Load remote container if needed
18
+ let asyncContainer;
19
+ const reference = typeof keyOrRuntimeRemoteItem === 'string' ? runtimeRemotes[keyOrRuntimeRemoteItem] : keyOrRuntimeRemoteItem;
20
+ if (reference.asyncContainer) {
21
+ asyncContainer = typeof reference.asyncContainer.then === 'function' ? reference.asyncContainer : reference.asyncContainer();
22
+ } else {
23
+ // This casting is just to satisfy typescript,
24
+ // In reality remoteGlobal will always be a string;
25
+ const remoteGlobal = reference.global;
26
+ // Check if theres an override for container key if not use remote global
27
+ const containerKey = reference.uniqueKey ? reference.uniqueKey : remoteGlobal;
28
+ const __webpack_error__ = new Error();
29
+ // @ts-ignore
30
+ const globalScope = // @ts-ignore
31
+ typeof window !== 'undefined' ? window : globalThis.__remote_scope__;
32
+ if (typeof window === 'undefined') {
33
+ //@ts-ignore
34
+ globalScope['_config'][containerKey] = reference.url;
35
+ } else {
36
+ // to match promise template system, can be removed once promise template is gone
37
+ //@ts-ignore
38
+ if (!globalScope['remoteLoading']) {
39
+ //@ts-ignore
40
+ globalScope['remoteLoading'] = {};
41
+ }
42
+ //@ts-ignore
43
+ if (globalScope['remoteLoading'][containerKey]) {
44
+ //@ts-ignore
45
+ return globalScope['remoteLoading'][containerKey];
46
+ }
47
+ }
48
+ // @ts-ignore
49
+ asyncContainer = new Promise(function(resolve, reject) {
50
+ function resolveRemoteGlobal() {
51
+ //@ts-ignore
52
+ const asyncContainer = globalScope[remoteGlobal];
53
+ return resolve(asyncContainer);
54
+ }
55
+ //@ts-ignore
56
+ if (typeof globalScope[remoteGlobal] !== 'undefined') {
57
+ return resolveRemoteGlobal();
58
+ }
59
+ __webpack_require__.l(reference.url, function(event) {
60
+ //@ts-ignore
61
+ if (typeof globalScope[remoteGlobal] !== 'undefined') {
62
+ return resolveRemoteGlobal();
63
+ }
64
+ const errorType = event && (event.type === 'load' ? 'missing' : event.type);
65
+ const realSrc = event && event.target && event.target.src;
66
+ __webpack_error__.message = 'Loading script failed.\n(' + errorType + ': ' + realSrc + ' or global var ' + remoteGlobal + ')';
67
+ __webpack_error__.name = 'ScriptExternalLoadError';
68
+ __webpack_error__.type = errorType;
69
+ __webpack_error__.request = realSrc;
70
+ reject(__webpack_error__);
71
+ }, containerKey);
72
+ }).catch(function(err) {
73
+ console.error('container is offline, returning fake remote');
74
+ console.error(err);
75
+ return {
76
+ fake: true,
77
+ // @ts-ignore
78
+ get: (arg)=>{
79
+ console.warn('faking', arg, 'module on, its offline');
80
+ return Promise.resolve(()=>{
81
+ return {
82
+ __esModule: true,
83
+ default: ()=>{
84
+ return null;
85
+ }
86
+ };
87
+ });
88
+ },
89
+ //eslint-disable-next-line
90
+ init: ()=>{}
91
+ };
92
+ });
93
+ if (typeof window !== 'undefined') {
94
+ //@ts-ignore
95
+ globalScope['remoteLoading'][containerKey] = asyncContainer;
96
+ }
97
+ }
98
+ return asyncContainer;
99
+ };
100
+ const getRuntimeRemotes = ()=>{
101
+ return Object.entries(remoteVars).reduce((acc, [key, value])=>{
102
+ if (typeof value === 'object' && typeof value.then === 'function') {
103
+ acc[key] = {
104
+ asyncContainer: value
105
+ };
106
+ } else if (typeof value === 'function') {
107
+ acc[key] = {
108
+ asyncContainer: Promise.resolve(value())
109
+ };
110
+ } else if (typeof value === 'string') {
111
+ if (value.startsWith('internal ')) {
112
+ const [request, query] = value.replace('internal ', '').split('?');
113
+ if (query) {
114
+ const remoteSyntax = new URLSearchParams(query).get('remote');
115
+ if (remoteSyntax) {
116
+ const [url, global] = extractUrlAndGlobal(remoteSyntax);
117
+ acc[key] = {
118
+ global,
119
+ url
120
+ };
121
+ }
122
+ }
123
+ } else {
124
+ const [url, global] = extractUrlAndGlobal(value);
125
+ acc[key] = {
126
+ global,
127
+ url
128
+ };
129
+ }
130
+ } else {
131
+ console.warn('remotes process', process.env['REMOTES']);
132
+ throw new Error(`[mf] Invalid value received for runtime_remote "${key}"`);
133
+ }
134
+ return acc;
135
+ }, {});
136
+ };
137
+
138
+ export { extractUrlAndGlobal, getRuntimeRemotes, loadScript, remoteVars };
@@ -0,0 +1,4 @@
1
+
2
+
3
+
4
+ export { default as FederationBoundary } from "../components/FederationBoundary.mjs";
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@module-federation/utilities",
3
- "version": "0.0.0-perf-devtools-20260107043700",
4
- "main": "./dist/index.cjs.js",
5
- "module": "./dist/index.esm.js",
6
- "types": "./dist/index.d.ts",
3
+ "version": "0.0.0-perf-website-code-usage-20260914033703",
4
+ "main": "./dist/cjs/index.js",
5
+ "module": "./dist/esm/index.mjs",
6
+ "types": "./dist/types/index.d.ts",
7
7
  "license": "MIT",
8
8
  "publishConfig": {
9
9
  "access": "public"
@@ -18,11 +18,12 @@
18
18
  "directory": "packages/utilities"
19
19
  },
20
20
  "devDependencies": {
21
+ "@types/react": "^18.3.11",
21
22
  "react": "18.3.1",
22
- "@types/react": "^18.3.11"
23
+ "rsbuild-plugin-publint": "^0.2.1"
23
24
  },
24
25
  "dependencies": {
25
- "@module-federation/sdk": "0.0.0-perf-devtools-20260107043700"
26
+ "@module-federation/sdk": "0.0.0-perf-website-code-usage-20260914033703"
26
27
  },
27
28
  "peerDependencies": {
28
29
  "react": "^16 || ^17 || ^18",
@@ -42,20 +43,26 @@
42
43
  },
43
44
  "exports": {
44
45
  ".": {
45
- "types": "./dist/index.d.ts",
46
- "import": "./dist/index.esm.js",
47
- "require": "./dist/index.cjs.js"
46
+ "types": "./dist/types/index.d.ts",
47
+ "import": "./dist/esm/index.mjs",
48
+ "require": "./dist/cjs/index.js"
48
49
  },
49
50
  "./package.json": "./package.json"
50
51
  },
51
52
  "typesVersions": {
52
53
  "*": {
53
54
  ".": [
54
- "./dist/index.d.ts"
55
+ "./dist/types/index.d.ts"
55
56
  ],
56
57
  "type": [
57
58
  "./dist/type.d.ts"
58
59
  ]
59
60
  }
61
+ },
62
+ "scripts": {
63
+ "build": "rslib build",
64
+ "lint": "ESLINT_USE_FLAT_CONFIG=false pnpm exec eslint --ignore-pattern node_modules \"**/*.ts\"",
65
+ "test": "pnpm exec jest --config jest.config.ts --passWithNoTests",
66
+ "pre-release": "pnpm run test && pnpm run build"
60
67
  }
61
68
  }