@module-federation/nextjs-mf 0.0.0-feat-node-support-1702694175665

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 (91) hide show
  1. package/client/UrlNode.d.ts +17 -0
  2. package/client/UrlNode.js +150 -0
  3. package/client/UrlNode.js.map +1 -0
  4. package/node.d.ts +1 -0
  5. package/node.js +18 -0
  6. package/node.js.map +1 -0
  7. package/package.json +44 -0
  8. package/src/default-delegate.cjs +308 -0
  9. package/src/default-delegate.d.ts +1 -0
  10. package/src/default-delegate.js.map +1 -0
  11. package/src/federation-noop.cjs +15 -0
  12. package/src/federation-noop.d.ts +0 -0
  13. package/src/federation-noop.js.map +1 -0
  14. package/src/index.d.ts +3 -0
  15. package/src/index.js +12 -0
  16. package/src/index.js.map +1 -0
  17. package/src/internal.d.ts +48 -0
  18. package/src/internal.js +256 -0
  19. package/src/internal.js.map +1 -0
  20. package/src/loaders/delegateLoader.d.ts +10 -0
  21. package/src/loaders/delegateLoader.js +46 -0
  22. package/src/loaders/delegateLoader.js.map +1 -0
  23. package/src/loaders/fixImageLoader.d.ts +22 -0
  24. package/src/loaders/fixImageLoader.js +118 -0
  25. package/src/loaders/fixImageLoader.js.map +1 -0
  26. package/src/loaders/fixUrlLoader.d.ts +13 -0
  27. package/src/loaders/fixUrlLoader.js +25 -0
  28. package/src/loaders/fixUrlLoader.js.map +1 -0
  29. package/src/loaders/helpers.d.ts +17 -0
  30. package/src/loaders/helpers.js +60 -0
  31. package/src/loaders/helpers.js.map +1 -0
  32. package/src/loaders/nextPageMapLoader.d.ts +24 -0
  33. package/src/loaders/nextPageMapLoader.js +167 -0
  34. package/src/loaders/nextPageMapLoader.js.map +1 -0
  35. package/src/plugins/AddRuntimeRequirementToPromiseExternalPlugin.d.ts +5 -0
  36. package/src/plugins/AddRuntimeRequirementToPromiseExternalPlugin.js +19 -0
  37. package/src/plugins/AddRuntimeRequirementToPromiseExternalPlugin.js.map +1 -0
  38. package/src/plugins/CopyFederationPlugin.d.ts +20 -0
  39. package/src/plugins/CopyFederationPlugin.js +71 -0
  40. package/src/plugins/CopyFederationPlugin.js.map +1 -0
  41. package/src/plugins/NextFederationPlugin/apply-client-plugins.d.ts +23 -0
  42. package/src/plugins/NextFederationPlugin/apply-client-plugins.js +72 -0
  43. package/src/plugins/NextFederationPlugin/apply-client-plugins.js.map +1 -0
  44. package/src/plugins/NextFederationPlugin/apply-server-plugins.d.ts +60 -0
  45. package/src/plugins/NextFederationPlugin/apply-server-plugins.js +173 -0
  46. package/src/plugins/NextFederationPlugin/apply-server-plugins.js.map +1 -0
  47. package/src/plugins/NextFederationPlugin/index.d.ts +30 -0
  48. package/src/plugins/NextFederationPlugin/index.js +148 -0
  49. package/src/plugins/NextFederationPlugin/index.js.map +1 -0
  50. package/src/plugins/NextFederationPlugin/next-fragments.d.ts +18 -0
  51. package/src/plugins/NextFederationPlugin/next-fragments.js +65 -0
  52. package/src/plugins/NextFederationPlugin/next-fragments.js.map +1 -0
  53. package/src/plugins/NextFederationPlugin/regex-equal.d.ts +14 -0
  54. package/src/plugins/NextFederationPlugin/regex-equal.js +25 -0
  55. package/src/plugins/NextFederationPlugin/regex-equal.js.map +1 -0
  56. package/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.d.ts +8 -0
  57. package/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.js +31 -0
  58. package/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.js.map +1 -0
  59. package/src/plugins/NextFederationPlugin/set-options.d.ts +20 -0
  60. package/src/plugins/NextFederationPlugin/set-options.js +38 -0
  61. package/src/plugins/NextFederationPlugin/set-options.js.map +1 -0
  62. package/src/plugins/NextFederationPlugin/validate-options.d.ts +25 -0
  63. package/src/plugins/NextFederationPlugin/validate-options.js +46 -0
  64. package/src/plugins/NextFederationPlugin/validate-options.js.map +1 -0
  65. package/src/plugins/container/EmbeddedContainerPlugin.d.ts +40 -0
  66. package/src/plugins/container/EmbeddedContainerPlugin.js +73 -0
  67. package/src/plugins/container/EmbeddedContainerPlugin.js.map +1 -0
  68. package/src/plugins/container/HoistPseudoEagerModules.d.ts +19 -0
  69. package/src/plugins/container/HoistPseudoEagerModules.js +79 -0
  70. package/src/plugins/container/HoistPseudoEagerModules.js.map +1 -0
  71. package/src/plugins/container/InvertedContainerPlugin.d.ts +15 -0
  72. package/src/plugins/container/InvertedContainerPlugin.js +25 -0
  73. package/src/plugins/container/InvertedContainerPlugin.js.map +1 -0
  74. package/src/plugins/container/InvertedContainerRuntimeModule.d.ts +15 -0
  75. package/src/plugins/container/InvertedContainerRuntimeModule.js +65 -0
  76. package/src/plugins/container/InvertedContainerRuntimeModule.js.map +1 -0
  77. package/src/plugins/container/RemoveEagerModulesFromRuntimePlugin.d.ts +39 -0
  78. package/src/plugins/container/RemoveEagerModulesFromRuntimePlugin.js +72 -0
  79. package/src/plugins/container/RemoveEagerModulesFromRuntimePlugin.js.map +1 -0
  80. package/src/plugins/container/runtimePlugin.d.ts +2 -0
  81. package/src/plugins/container/runtimePlugin.js +64 -0
  82. package/src/plugins/container/runtimePlugin.js.map +1 -0
  83. package/src/plugins/container/types.d.ts +2 -0
  84. package/src/plugins/container/types.js +3 -0
  85. package/src/plugins/container/types.js.map +1 -0
  86. package/src/types.d.ts +28 -0
  87. package/src/types.js +3 -0
  88. package/src/types.js.map +1 -0
  89. package/utilities.d.ts +1 -0
  90. package/utilities.js +18 -0
  91. package/utilities.js.map +1 -0
@@ -0,0 +1,48 @@
1
+ import type { SharedObject } from '@module-federation/utilities';
2
+ /**
3
+ * @typedef SharedObject
4
+ * @type {object}
5
+ * @property {object} [key] - The key representing the shared object's package name.
6
+ * @property {boolean} key.singleton - Whether the shared object should be a singleton.
7
+ * @property {boolean} key.requiredVersion - Whether a specific version of the shared object is required.
8
+ * @property {boolean} key.eager - Whether the shared object should be eagerly loaded.
9
+ * @property {boolean} key.import - Whether the shared object should be imported or not.
10
+ */
11
+ export declare const DEFAULT_SHARE_SCOPE: SharedObject;
12
+ /**
13
+ * Defines a default share scope for the browser environment.
14
+ * This function takes the DEFAULT_SHARE_SCOPE and sets eager to undefined and import to undefined for all entries.
15
+ * For 'react', 'react-dom', 'next/router', and 'next/link', it sets eager to true.
16
+ * The module hoisting system relocates these modules into the right runtime and out of the remote.
17
+ *
18
+ * @type {SharedObject}
19
+ * @returns {SharedObject} - The modified share scope for the browser environment.
20
+ */
21
+ export declare const DEFAULT_SHARE_SCOPE_BROWSER: SharedObject;
22
+ /**
23
+ * Parses the remotes object and checks if they are using a custom promise template or not.
24
+ * If it's a custom promise template, the remote syntax is parsed to get the module name and version number.
25
+ * If the remote value is using the standard remote syntax, a delegated module is created.
26
+ *
27
+ * @param {Record<string, any>} remotes - The remotes object to be parsed.
28
+ * @returns {Record<string, string>} - The parsed remotes object with either the original value,
29
+ * the value for internal or promise delegate module reference, or the created delegated module.
30
+ */
31
+ export declare const parseRemotes: (remotes: Record<string, any>) => Record<string, string>;
32
+ /**
33
+ * Extracts the delegate modules from the provided remotes object.
34
+ * This function iterates over the remotes object and checks if each remote value is an internal delegate module reference.
35
+ * If it is, the function adds it to the returned object.
36
+ *
37
+ * @param {Record<string, any>} remotes - The remotes object containing delegate module references.
38
+ * @returns {Record<string, string>} - An object containing only the delegate modules from the remotes object.
39
+ */
40
+ export declare const getDelegates: (remotes: Record<string, any>) => Record<string, string>;
41
+ /**
42
+ * Transforms an array of Error objects into a single string. Each error message is formatted using the 'formatError' function.
43
+ * The resulting error messages are then joined together, separated by newline characters.
44
+ *
45
+ * @param {Error[]} err - An array of Error objects that need to be formatted and combined.
46
+ * @returns {string} - A single string containing all the formatted error messages, separated by newline characters.
47
+ */
48
+ export declare const toDisplayErrors: (err: Error[]) => string;
@@ -0,0 +1,256 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toDisplayErrors = exports.getDelegates = exports.parseRemotes = exports.DEFAULT_SHARE_SCOPE_BROWSER = exports.DEFAULT_SHARE_SCOPE = void 0;
4
+ const utils_1 = require("@module-federation/enhanced/src/lib/sharing/utils");
5
+ const options_1 = require("@module-federation/enhanced/src/lib/container/options");
6
+ /**
7
+ * @typedef SharedObject
8
+ * @type {object}
9
+ * @property {object} [key] - The key representing the shared object's package name.
10
+ * @property {boolean} key.singleton - Whether the shared object should be a singleton.
11
+ * @property {boolean} key.requiredVersion - Whether a specific version of the shared object is required.
12
+ * @property {boolean} key.eager - Whether the shared object should be eagerly loaded.
13
+ * @property {boolean} key.import - Whether the shared object should be imported or not.
14
+ */
15
+ exports.DEFAULT_SHARE_SCOPE = {
16
+ 'next/dynamic': {
17
+ requiredVersion: undefined,
18
+ singleton: true,
19
+ import: undefined,
20
+ },
21
+ 'next/head': {
22
+ requiredVersion: undefined,
23
+ singleton: true,
24
+ import: undefined,
25
+ },
26
+ 'next/link': {
27
+ requiredVersion: undefined,
28
+ singleton: true,
29
+ import: undefined,
30
+ },
31
+ 'next/router': {
32
+ requiredVersion: false,
33
+ singleton: true,
34
+ import: undefined,
35
+ },
36
+ '@module-federation/utilities': {
37
+ eager: true,
38
+ version: require('@module-federation/utilities/package.json').version,
39
+ requiredVersion: require('@module-federation/utilities/package.json')
40
+ .version,
41
+ },
42
+ 'next/image': {
43
+ requiredVersion: undefined,
44
+ singleton: true,
45
+ import: undefined,
46
+ },
47
+ 'next/script': {
48
+ requiredVersion: undefined,
49
+ singleton: true,
50
+ import: undefined,
51
+ },
52
+ react: {
53
+ singleton: true,
54
+ requiredVersion: false,
55
+ import: false,
56
+ },
57
+ 'react/': {
58
+ singleton: true,
59
+ requiredVersion: false,
60
+ import: false,
61
+ },
62
+ 'react-dom/': {
63
+ singleton: true,
64
+ requiredVersion: false,
65
+ import: false,
66
+ },
67
+ 'react-dom': {
68
+ singleton: true,
69
+ requiredVersion: false,
70
+ import: false,
71
+ },
72
+ 'react/jsx-dev-runtime': {
73
+ singleton: true,
74
+ requiredVersion: undefined,
75
+ import: undefined,
76
+ },
77
+ 'react/jsx-runtime': {
78
+ singleton: true,
79
+ requiredVersion: undefined,
80
+ // import: false,
81
+ },
82
+ 'styled-jsx': {
83
+ singleton: true,
84
+ import: undefined,
85
+ version: require('styled-jsx/package.json').version,
86
+ requiredVersion: '^' + require('styled-jsx/package.json').version,
87
+ },
88
+ 'styled-jsx/style': {
89
+ singleton: true,
90
+ import: false,
91
+ version: require('styled-jsx/package.json').version,
92
+ requiredVersion: '^' + require('styled-jsx/package.json').version,
93
+ },
94
+ 'styled-jsx/css': {
95
+ singleton: true,
96
+ import: undefined,
97
+ version: require('styled-jsx/package.json').version,
98
+ requiredVersion: '^' + require('styled-jsx/package.json').version,
99
+ },
100
+ };
101
+ /**
102
+ * Defines a default share scope for the browser environment.
103
+ * This function takes the DEFAULT_SHARE_SCOPE and sets eager to undefined and import to undefined for all entries.
104
+ * For 'react', 'react-dom', 'next/router', and 'next/link', it sets eager to true.
105
+ * The module hoisting system relocates these modules into the right runtime and out of the remote.
106
+ *
107
+ * @type {SharedObject}
108
+ * @returns {SharedObject} - The modified share scope for the browser environment.
109
+ */
110
+ exports.DEFAULT_SHARE_SCOPE_BROWSER = Object.entries(exports.DEFAULT_SHARE_SCOPE).reduce((acc, item) => {
111
+ const [key, value] = item;
112
+ // Set eager and import to undefined for all entries, except for the ones specified above
113
+ acc[key] = { ...value, import: undefined };
114
+ return acc;
115
+ }, {});
116
+ /**
117
+ * Checks if the remote value is an internal or promise delegate module reference.
118
+ *
119
+ * @param {string} value - The remote value to check.
120
+ * @returns {boolean} - True if the value is an internal or promise delegate module reference, false otherwise.
121
+ */
122
+ const isInternalOrPromise = (value) => ['internal ', 'promise '].some((prefix) => value.startsWith(prefix));
123
+ /**
124
+ * Checks if the remote value is using the standard remote syntax.
125
+ *
126
+ * @param {string} value - The remote value to check.
127
+ * @returns {boolean} - True if the value is using the standard remote syntax, false otherwise.
128
+ */
129
+ const isStandardRemoteSyntax = (value) => {
130
+ return value.includes('@');
131
+ };
132
+ /**
133
+ * Parses the remotes object and checks if they are using a custom promise template or not.
134
+ * If it's a custom promise template, the remote syntax is parsed to get the module name and version number.
135
+ * If the remote value is using the standard remote syntax, a delegated module is created.
136
+ *
137
+ * @param {Record<string, any>} remotes - The remotes object to be parsed.
138
+ * @returns {Record<string, string>} - The parsed remotes object with either the original value,
139
+ * the value for internal or promise delegate module reference, or the created delegated module.
140
+ */
141
+ const parseRemotes = (remotes) => {
142
+ return Object.entries(remotes).reduce((acc, [key, value]) => {
143
+ if (isInternalOrPromise(value)) {
144
+ // If the value is an internal or promise delegate module reference, keep the original value
145
+ return { ...acc, [key]: value };
146
+ }
147
+ return { ...acc, [key]: value };
148
+ }, {});
149
+ };
150
+ exports.parseRemotes = parseRemotes;
151
+ /**
152
+ * Checks if the remote value is an internal delegate module reference.
153
+ * An internal delegate module reference starts with the string 'internal '.
154
+ *
155
+ * @param {string} value - The remote value to check.
156
+ * @returns {boolean} - Returns true if the value is an internal delegate module reference, otherwise returns false.
157
+ */
158
+ const isInternalDelegate = (value) => {
159
+ return value.startsWith('internal ');
160
+ };
161
+ /**
162
+ * Extracts the delegate modules from the provided remotes object.
163
+ * This function iterates over the remotes object and checks if each remote value is an internal delegate module reference.
164
+ * If it is, the function adds it to the returned object.
165
+ *
166
+ * @param {Record<string, any>} remotes - The remotes object containing delegate module references.
167
+ * @returns {Record<string, string>} - An object containing only the delegate modules from the remotes object.
168
+ */
169
+ const getDelegates = (remotes) => Object.entries(remotes).reduce((acc, [key, value]) => isInternalDelegate(value) ? { ...acc, [key]: value } : acc, {});
170
+ exports.getDelegates = getDelegates;
171
+ /**
172
+ * This function validates the type of the shared item and constructs a shared configuration object based on the item and key.
173
+ * If the item is identical to the key or if the item does not necessitate a specific version,
174
+ * the function returns an object with the import property set to the item.
175
+ * Otherwise, it returns an object with the import property set to the key and the requiredVersion property set to the item.
176
+ *
177
+ * @param {string | string[]} item - The shared item to be validated and used to construct the shared configuration object. It can be a string or an array of strings.
178
+ * @param {string} key - The key associated with the shared item.
179
+ * @returns {object} - The constructed shared configuration object.
180
+ * @throws {Error} - An error is thrown if the item type is not a string or an array of strings.
181
+ */
182
+ const getSharedConfig = (item, key) => {
183
+ if (Array.isArray(item)) {
184
+ // This handles the case where item is an array
185
+ // Replace the following line with your actual logic
186
+ return item.map((i) => ({
187
+ import: i === key || !(0, utils_1.isRequiredVersion)(i) ? i : key,
188
+ requiredVersion: i === key || !(0, utils_1.isRequiredVersion)(i) ? undefined : i,
189
+ }));
190
+ }
191
+ else if (typeof item === 'string') {
192
+ // Handle the case where item is a string
193
+ return {
194
+ import: item === key || !(0, utils_1.isRequiredVersion)(item) ? item : key,
195
+ requiredVersion: item === key || !(0, utils_1.isRequiredVersion)(item) ? undefined : item,
196
+ };
197
+ }
198
+ else {
199
+ throw new Error('Unexpected type in shared');
200
+ }
201
+ };
202
+ /**
203
+ * Parses the share options from the provided ModuleFederationPluginOptions object and constructs a new object containing all shared configurations.
204
+ * This newly constructed object is then used as the value for the 'shared' property of the Module Federation Plugin Options.
205
+ * The function uses the 'parseOptions' utility function from webpack to parse the 'shared' property of the provided options object.
206
+ * The 'getSharedConfig' function is used as the 'config' argument for 'parseOptions' to construct the shared configuration object for each shared item.
207
+ * The 'item' argument for 'parseOptions' is a function that simply returns the item as it is.
208
+ * The function then reduces the parsed shared options into a new object with the shared configuration for each shared item.
209
+ *
210
+ * @param {ModuleFederationPluginOptions} options - The ModuleFederationPluginOptions object to parse the share options from.
211
+ * @returns {Record<string, SharedConfig>} - An object containing the shared configuration for each shared item.
212
+ */
213
+ const parseShareOptions = (options) => {
214
+ if (!options.shared)
215
+ return options;
216
+ const sharedOptions = (0, options_1.parseOptions)(options.shared, getSharedConfig, (item) => item);
217
+ return sharedOptions.reduce((acc, [key, options]) => {
218
+ acc[key] = {
219
+ import: options.import,
220
+ shareKey: options.shareKey || key,
221
+ shareScope: options.shareScope,
222
+ requiredVersion: options.requiredVersion,
223
+ strictVersion: options.strictVersion,
224
+ singleton: options.singleton,
225
+ packageName: options.packageName,
226
+ eager: options.eager,
227
+ };
228
+ return acc;
229
+ }, {});
230
+ };
231
+ /**
232
+ * Takes an error object and formats it into a displayable string.
233
+ * If the error object contains a stack trace, it is appended to the error message.
234
+ *
235
+ * @param {Error} error - The error object to be formatted.
236
+ * @returns {string} - The formatted error message string. If a stack trace is present in the error object, it is appended to the error message.
237
+ */
238
+ const formatError = (error) => {
239
+ let { message } = error;
240
+ if (error.stack) {
241
+ message += `\n${error.stack}`;
242
+ }
243
+ return message;
244
+ };
245
+ /**
246
+ * Transforms an array of Error objects into a single string. Each error message is formatted using the 'formatError' function.
247
+ * The resulting error messages are then joined together, separated by newline characters.
248
+ *
249
+ * @param {Error[]} err - An array of Error objects that need to be formatted and combined.
250
+ * @returns {string} - A single string containing all the formatted error messages, separated by newline characters.
251
+ */
252
+ const toDisplayErrors = (err) => {
253
+ return err.map(formatError).join('\n');
254
+ };
255
+ exports.toDisplayErrors = toDisplayErrors;
256
+ //# sourceMappingURL=internal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../../packages/nextjs-mf/src/internal.ts"],"names":[],"mappings":";;;AAMA,6EAAsF;AACtF,mFAAqF;AAErF;;;;;;;;GAQG;AACU,QAAA,mBAAmB,GAAiB;IAC/C,cAAc,EAAE;QACd,eAAe,EAAE,SAAS;QAC1B,SAAS,EAAE,IAAI;QACf,MAAM,EAAE,SAAS;KAClB;IACD,WAAW,EAAE;QACX,eAAe,EAAE,SAAS;QAC1B,SAAS,EAAE,IAAI;QACf,MAAM,EAAE,SAAS;KAClB;IACD,WAAW,EAAE;QACX,eAAe,EAAE,SAAS;QAC1B,SAAS,EAAE,IAAI;QACf,MAAM,EAAE,SAAS;KAClB;IACD,aAAa,EAAE;QACb,eAAe,EAAE,KAAK;QACtB,SAAS,EAAE,IAAI;QACf,MAAM,EAAE,SAAS;KAClB;IACD,8BAA8B,EAAE;QAC9B,KAAK,EAAE,IAAI;QACX,OAAO,EAAE,OAAO,CAAC,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AAG,CAAC,KAAY,EAAU,EAAE;IAC3C,IAAI,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;IACxB,IAAI,KAAK,CAAC,KAAK,EAAE;QACf,OAAO,IAAI,KAAK,KAAK,CAAC,KAAK,EAAE,CAAC;KAC/B;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF;;;;;;GAMG;AACI,MAAM,eAAe,GAAG,CAAC,GAAY,EAAU,EAAE;IACtD,OAAO,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACzC,CAAC,CAAC;AAFW,QAAA,eAAe,mBAE1B"}
@@ -0,0 +1,10 @@
1
+ import type { LoaderContext } from 'webpack';
2
+ /**
3
+ * This function patches the default shared loader.
4
+ * It requires either the default delegate module or a custom one.
5
+ *
6
+ * @param {LoaderContext<Record<string, unknown>>} this - The loader context.
7
+ * @param {string} content - The content to be processed.
8
+ * @returns {string} The processed content with required delegates.
9
+ */
10
+ export default function patchDefaultSharedLoader(this: LoaderContext<Record<string, unknown>>, content: string): string;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * This function patches the default shared loader.
5
+ * It requires either the default delegate module or a custom one.
6
+ *
7
+ * @param {LoaderContext<Record<string, unknown>>} this - The loader context.
8
+ * @param {string} content - The content to be processed.
9
+ * @returns {string} The processed content with required delegates.
10
+ */
11
+ function patchDefaultSharedLoader(content) {
12
+ const { delegates } = this.getOptions();
13
+ /**
14
+ * Resolves delegates by splitting the delegate into request and query.
15
+ * If a query is present, it is parsed and appended to the request.
16
+ * The request is then contextified and absolutified.
17
+ */
18
+ const resolvedDelegates = Object.values(delegates).map((delegate) => {
19
+ const [request, query] = delegate.replace('internal ', '').split('?');
20
+ if (query) {
21
+ const queries = [];
22
+ for (const [key, value] of new URLSearchParams(query).entries()) {
23
+ queries.push(`${key}=${encodeURIComponent(value)}`);
24
+ }
25
+ return this.utils.contextify(this.context, this.utils.absolutify(this._compiler?.context || '', request) +
26
+ '?' +
27
+ queries.join('&'));
28
+ }
29
+ return request;
30
+ });
31
+ /**
32
+ * If the content includes 'hasDelegateMarkers', return the content as is.
33
+ */
34
+ if (content.includes('hasDelegateMarkers')) {
35
+ return content;
36
+ }
37
+ /**
38
+ * Requires each resolved delegate and appends it to the content.
39
+ */
40
+ const requiredDelegates = resolvedDelegates.map((delegate) => {
41
+ return `require('${delegate}')`;
42
+ });
43
+ return ['', ...requiredDelegates, '//hasDelegateMarkers', content].join('\n');
44
+ }
45
+ exports.default = patchDefaultSharedLoader;
46
+ //# sourceMappingURL=delegateLoader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delegateLoader.js","sourceRoot":"","sources":["../../../../../packages/nextjs-mf/src/loaders/delegateLoader.ts"],"names":[],"mappings":";;AAEA;;;;;;;GAOG;AACH,SAAwB,wBAAwB,CAE9C,OAAe;IAEf,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,UAAU,EAA4B,CAAC;IAElE;;;;OAIG;IACH,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE;QAClE,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACtE,IAAI,KAAK,EAAE;YACT,MAAM,OAAO,GAAG,EAAE,CAAC;YACnB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,IAAI,eAAe,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,EAAE;gBAC/D,OAAO,CAAC,IAAI,CAAC,GAAG,GAAG,IAAI,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;aACrD;YACD,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAC1B,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,IAAI,EAAE,EAAE,OAAO,CAAC;gBAC3D,GAAG;gBACH,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CACpB,CAAC;SACH;QACD,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC,CAAC;IAEH;;OAEG;IACH,IAAI,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAC,EAAE;QAC1C,OAAO,OAAO,CAAC;KAChB;IAED;;OAEG;IACH,MAAM,iBAAiB,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE;QAC3D,OAAO,YAAY,QAAQ,IAAI,CAAC;IAClC,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,EAAE,EAAE,GAAG,iBAAiB,EAAE,sBAAsB,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAChF,CAAC;AA3CD,2CA2CC"}
@@ -0,0 +1,22 @@
1
+ import type { LoaderContext } from 'webpack';
2
+ /**
3
+ * This loader is specifically created for tuning the next-image-loader result.
4
+ * It modifies the regular string output of the next-image-loader.
5
+ * For server-side rendering (SSR), it injects the remote scope of a specific remote URL.
6
+ * For client-side rendering (CSR), it injects the document.currentScript.src.
7
+ * After these injections, it selects the full URI before _next.
8
+ *
9
+ * @example
10
+ * http://localhost:1234/test/test2/_next/static/media/ssl.e3019f0e.svg
11
+ * will become
12
+ * http://localhost:1234/test/test2
13
+ *
14
+ * @param {LoaderContext<Record<string, unknown>>} this - The loader context.
15
+ * @param {string} remaining - The remaining part of the resource path.
16
+ * @returns {string} The modified source code with the injected code.
17
+ */
18
+ export declare function fixImageLoader(this: LoaderContext<Record<string, unknown>>, remaining: string): Promise<string>;
19
+ /**
20
+ * The pitch function of the loader, which is the same as the fixImageLoader function.
21
+ */
22
+ export declare const pitch: typeof fixImageLoader;
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.pitch = exports.fixImageLoader = void 0;
7
+ const normalize_webpack_path_1 = require("@module-federation/sdk/normalize-webpack-path");
8
+ const { Template } = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack'));
9
+ const path_1 = __importDefault(require("path"));
10
+ /**
11
+ * This loader is specifically created for tuning the next-image-loader result.
12
+ * It modifies the regular string output of the next-image-loader.
13
+ * For server-side rendering (SSR), it injects the remote scope of a specific remote URL.
14
+ * For client-side rendering (CSR), it injects the document.currentScript.src.
15
+ * After these injections, it selects the full URI before _next.
16
+ *
17
+ * @example
18
+ * http://localhost:1234/test/test2/_next/static/media/ssl.e3019f0e.svg
19
+ * will become
20
+ * http://localhost:1234/test/test2
21
+ *
22
+ * @param {LoaderContext<Record<string, unknown>>} this - The loader context.
23
+ * @param {string} remaining - The remaining part of the resource path.
24
+ * @returns {string} The modified source code with the injected code.
25
+ */
26
+ async function fixImageLoader(remaining) {
27
+ this.cacheable(true);
28
+ const isServer = this._compiler?.options.name !== 'client';
29
+ //@ts-ignore
30
+ const { publicPath } = this._compiler.webpack.RuntimeGlobals;
31
+ const result = await this.importModule(`${this.resourcePath}.webpack[javascript/auto]!=!${remaining}`);
32
+ const content = (result.default || result);
33
+ const computedAssetPrefix = isServer
34
+ ? `${Template.asString([
35
+ 'function getSSRImagePath(){',
36
+ //TODO: use auto public path plugin instead
37
+ `const pubpath = ${publicPath};`,
38
+ Template.asString([
39
+ 'try {',
40
+ Template.indent([
41
+ "const globalThisVal = new Function('return globalThis')();",
42
+ 'const name = __webpack_require__.federation.instance.name',
43
+ `const container = globalThisVal['__FEDERATION__']['__INSTANCES__'].find(
44
+ (instance) => {
45
+ if (!instance.moduleCache.has(name)) return;
46
+ const container = instance.moduleCache.get(name);
47
+ if (!container.remoteInfo) return;
48
+ return container.remoteInfo.entry;
49
+ },
50
+ );`,
51
+ 'const cache = container.moduleCache',
52
+ 'const remote = cache.get(name).remoteInfo',
53
+ `const remoteEntry = remote.entry;`,
54
+ `if (remoteEntry) {`,
55
+ Template.indent([
56
+ `const splitted = remoteEntry.split('/_next')`,
57
+ `return splitted.length === 2 ? splitted[0] : '';`,
58
+ ]),
59
+ `}`,
60
+ `return '';`,
61
+ ]),
62
+ '} catch (e) {',
63
+ Template.indent([
64
+ `console.error('failed generating SSR image path', e);`,
65
+ 'return "";',
66
+ ]),
67
+ '}',
68
+ ]),
69
+ '}()',
70
+ ])}`
71
+ : `${Template.asString([
72
+ 'function getCSRImagePath(){',
73
+ Template.indent([
74
+ 'try {',
75
+ Template.indent([
76
+ `if(typeof document === 'undefined')`,
77
+ Template.indent(`return ${publicPath} && ${publicPath}.indexOf('://') > 0 ? new URL(${publicPath}).origin : ''`),
78
+ `const path = (document.currentScript && document.currentScript.src) || new URL(${publicPath}).origin;`,
79
+ `const splitted = path.split('/_next')`,
80
+ `return splitted.length === 2 ? splitted[0] : '';`,
81
+ ]),
82
+ '} catch (e) {',
83
+ Template.indent([
84
+ `const path = document.currentScript && document.currentScript.src;`,
85
+ `console.error('failed generating CSR image path', e, path);`,
86
+ 'return "";',
87
+ ]),
88
+ '}',
89
+ ]),
90
+ '}()',
91
+ ])}`;
92
+ const constructedObject = Object.entries(content).reduce((acc, [key, value]) => {
93
+ if (key === 'src') {
94
+ if (value && !value.includes('://')) {
95
+ value = path_1.default.join(value);
96
+ }
97
+ acc.push(`${key}: computedAssetsPrefixReference + ${JSON.stringify(value)}`);
98
+ return acc;
99
+ }
100
+ acc.push(`${key}: ${JSON.stringify(value)}`);
101
+ return acc;
102
+ }, []);
103
+ return Template.asString([
104
+ "let computedAssetsPrefixReference = '';",
105
+ 'try {',
106
+ Template.indent(`computedAssetsPrefixReference = ${computedAssetPrefix};`),
107
+ '} catch (e) {}',
108
+ 'export default {',
109
+ Template.indent(constructedObject.join(',\n')),
110
+ '}',
111
+ ]);
112
+ }
113
+ exports.fixImageLoader = fixImageLoader;
114
+ /**
115
+ * The pitch function of the loader, which is the same as the fixImageLoader function.
116
+ */
117
+ exports.pitch = fixImageLoader;
118
+ //# sourceMappingURL=fixImageLoader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fixImageLoader.js","sourceRoot":"","sources":["../../../../../packages/nextjs-mf/src/loaders/fixImageLoader.ts"],"names":[],"mappings":";;;;;;AACA,0FAAqF;AACrF,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAC1B,IAAA,6CAAoB,EAAC,SAAS,CAAC,CACJ,CAAC;AAC9B,gDAAwB;AAExB;;;;;;;;;;;;;;;GAeG;AACI,KAAK,UAAU,cAAc,CAElC,SAAiB;IAEjB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAErB,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,IAAI,KAAK,QAAQ,CAAC;IAC3D,YAAY;IACZ,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,cAAc,CAAC;IAE7D,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,YAAY,CACpC,GAAG,IAAI,CAAC,YAAY,+BAA+B,SAAS,EAAE,CAC/D,CAAC;IAEF,MAAM,OAAO,GAAG,CAAC,MAAM,CAAC,OAAO,IAAI,MAAM,CAA2B,CAAC;IAErE,MAAM,mBAAmB,GAAG,QAAQ;QAClC,CAAC,CAAC,GAAG,QAAQ,CAAC,QAAQ,CAAC;YACnB,6BAA6B;YAC7B,2CAA2C;YAC3C,mBAAmB,UAAU,GAAG;YAChC,QAAQ,CAAC,QAAQ,CAAC;gBAChB,OAAO;gBACP,QAAQ,CAAC,MAAM,CAAC;oBACd,4DAA4D;oBAC5D,2DAA2D;oBAC3D;;;;;;;eAOG;oBACH,qCAAqC;oBACrC,2CAA2C;oBAC3C,mCAAmC;oBACnC,oBAAoB;oBACpB,QAA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,EAAE,CAAC,CAAC;QAC7C,OAAO,GAAG,CAAC;IACb,CAAC,EACD,EAAc,CACf,CAAC;IAEF,OAAO,QAAQ,CAAC,QAAQ,CAAC;QACvB,yCAAyC;QACzC,OAAO;QACP,QAAQ,CAAC,MAAM,CAAC,mCAAmC,mBAAmB,GAAG,CAAC;QAC1E,gBAAgB;QAChB,kBAAkB;QAClB,QAAQ,CAAC,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC9C,GAAG;KACJ,CAAC,CAAC;AACL,CAAC;AAxGD,wCAwGC;AAED;;GAEG;AACU,QAAA,KAAK,GAAG,cAAc,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * `fixUrlLoader` is a custom loader designed to modify the output of the url-loader.
3
+ * It injects the PUBLIC_PATH from the webpack runtime into the output.
4
+ * The output format is: `export default __webpack_require__.p + "/static/media/ssl.e3019f0e.svg"`
5
+ *
6
+ * `__webpack_require__.p` is a global variable in the webpack container that contains the publicPath.
7
+ * For example, it could be: http://localhost:3000/_next
8
+ *
9
+ * @param {string} content - The original output from the url-loader.
10
+ * @returns {string} The modified output with the injected PUBLIC_PATH.
11
+ */
12
+ export declare function fixUrlLoader(content: string): string;
13
+ export default fixUrlLoader;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fixUrlLoader = void 0;
4
+ /**
5
+ * `fixUrlLoader` is a custom loader designed to modify the output of the url-loader.
6
+ * It injects the PUBLIC_PATH from the webpack runtime into the output.
7
+ * The output format is: `export default __webpack_require__.p + "/static/media/ssl.e3019f0e.svg"`
8
+ *
9
+ * `__webpack_require__.p` is a global variable in the webpack container that contains the publicPath.
10
+ * For example, it could be: http://localhost:3000/_next
11
+ *
12
+ * @param {string} content - The original output from the url-loader.
13
+ * @returns {string} The modified output with the injected PUBLIC_PATH.
14
+ */
15
+ function fixUrlLoader(content) {
16
+ // This regular expression extracts the hostname from the publicPath.
17
+ // For example, it transforms http://localhost:3000/_next/... into http://localhost:3000
18
+ const currentHostnameCode = "__webpack_require__.p.replace(/(.+\\:\\/\\/[^\\/]+){0,1}\\/.*/i, '$1')";
19
+ // Replace the default export path in the content with the modified path that includes the hostname.
20
+ return content.replace('export default "/', `export default ${currentHostnameCode}+"/`);
21
+ }
22
+ exports.fixUrlLoader = fixUrlLoader;
23
+ // Export the fixUrlLoader function as the default export of this module.
24
+ exports.default = fixUrlLoader;
25
+ //# sourceMappingURL=fixUrlLoader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fixUrlLoader.js","sourceRoot":"","sources":["../../../../../packages/nextjs-mf/src/loaders/fixUrlLoader.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;GAUG;AACH,SAAgB,YAAY,CAAC,OAAe;IAC1C,qEAAqE;IACrE,wFAAwF;IACxF,MAAM,mBAAmB,GACvB,wEAAwE,CAAC;IAE3E,oGAAoG;IACpG,OAAO,OAAO,CAAC,OAAO,CACpB,mBAAmB,EACnB,kBAAkB,mBAAmB,KAAK,CAC3C,CAAC;AACJ,CAAC;AAXD,oCAWC;AAED,yEAAyE;AACzE,kBAAe,YAAY,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { RuleSetRuleUnion, Loader } from '@module-federation/utilities';
2
+ /**
3
+ * This function injects a loader into the current module rule.
4
+ * Note: This function mutates the `rule` argument.
5
+ *
6
+ * @param {RuleSetRuleUnion} rule - The current module rule.
7
+ * @param {Loader} [loader={}] - The loader to be injected.
8
+ */
9
+ export declare function injectRuleLoader(rule: RuleSetRuleUnion, loader?: Loader): void;
10
+ /**
11
+ * This function checks if the current module rule has a loader with the provided name.
12
+ *
13
+ * @param {RuleSetRuleUnion} rule - The current module rule.
14
+ * @param {string} loaderName - The name of the loader to check.
15
+ * @returns {boolean} Returns true if the current module rule has a loader with the provided name, otherwise false.
16
+ */
17
+ export declare function hasLoader(rule: RuleSetRuleUnion, loaderName: string): boolean;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasLoader = exports.injectRuleLoader = void 0;
4
+ /**
5
+ * This function injects a loader into the current module rule.
6
+ * Note: This function mutates the `rule` argument.
7
+ *
8
+ * @param {RuleSetRuleUnion} rule - The current module rule.
9
+ * @param {Loader} [loader={}] - The loader to be injected.
10
+ */
11
+ function injectRuleLoader(rule, loader = {}) {
12
+ if (rule !== '...') {
13
+ const _rule = rule;
14
+ if (_rule.loader) {
15
+ _rule.use = [loader, { loader: _rule.loader, options: _rule.options }];
16
+ delete _rule.loader;
17
+ delete _rule.options;
18
+ }
19
+ else if (_rule.use) {
20
+ _rule.use = [loader, ..._rule.use];
21
+ }
22
+ }
23
+ }
24
+ exports.injectRuleLoader = injectRuleLoader;
25
+ /**
26
+ * This function checks if the current module rule has a loader with the provided name.
27
+ *
28
+ * @param {RuleSetRuleUnion} rule - The current module rule.
29
+ * @param {string} loaderName - The name of the loader to check.
30
+ * @returns {boolean} Returns true if the current module rule has a loader with the provided name, otherwise false.
31
+ */
32
+ function hasLoader(rule, loaderName) {
33
+ if (rule !== '...') {
34
+ const _rule = rule;
35
+ if (_rule.loader === loaderName) {
36
+ return true;
37
+ }
38
+ else if (_rule.use && Array.isArray(_rule.use)) {
39
+ for (let i = 0; i < _rule.use.length; i++) {
40
+ const loader = _rule.use[i];
41
+ // check exact name, eg "url-loader" or its path "node_modules/url-loader/dist/cjs.js"
42
+ if (typeof loader !== 'string' &&
43
+ typeof loader !== 'function' &&
44
+ loader.loader &&
45
+ (loader.loader === loaderName ||
46
+ loader.loader.includes(`/${loaderName}/`))) {
47
+ return true;
48
+ }
49
+ else if (typeof loader === 'string') {
50
+ if (loader === loaderName || loader.includes(`/${loaderName}/`)) {
51
+ return true;
52
+ }
53
+ }
54
+ }
55
+ }
56
+ }
57
+ return false;
58
+ }
59
+ exports.hasLoader = hasLoader;
60
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3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