@umijs/plugins 4.0.0-canary.20230201.1 → 4.0.0-canary.20230207.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/mf.js +93 -4
  2. package/package.json +3 -3
package/dist/mf.js CHANGED
@@ -76,10 +76,11 @@ function mf(api) {
76
76
  (0, import_path.join)(api.paths.absTmpPath, "plugin-mf", mfSetupPathFileName)
77
77
  );
78
78
  }
79
+ const useHash = api.config.hash && api.env !== "development";
79
80
  const mfConfig = {
80
81
  name,
81
82
  remotes,
82
- filename: api.config.hash ? "remote.[contenthash:8].js" : "remote.js",
83
+ filename: useHash ? "remote.[contenthash:8].js" : "remote.js",
83
84
  exposes,
84
85
  shared,
85
86
  library: api.config.mf.library
@@ -93,6 +94,19 @@ function mf(api) {
93
94
  );
94
95
  return config;
95
96
  });
97
+ api.modifyDefaultConfig(async (memo) => {
98
+ if (memo.mfsu) {
99
+ const exposes = await constructExposes();
100
+ if (!isEmpty(exposes)) {
101
+ memo.mfsu.remoteName = mfName();
102
+ memo.mfsu.mfName = `mf_${memo.mfsu.remoteName}`;
103
+ }
104
+ const remotes = formatRemotes();
105
+ memo.mfsu.remoteAliases = Object.keys(remotes);
106
+ memo.mfsu.shared = getShared();
107
+ }
108
+ return memo;
109
+ });
96
110
  api.onGenerateFiles(() => {
97
111
  api.writeTmpFile({
98
112
  content: `/* infer remote public */;
@@ -116,7 +130,7 @@ function mf(api) {
116
130
  });
117
131
  });
118
132
  function formatRemotes() {
119
- const { remotes = [] } = api.config.mf;
133
+ const { remotes = [] } = api.userConfig.mf;
120
134
  const memo = {};
121
135
  remotes.forEach((remote) => {
122
136
  const aliasName = remote.aliasName || remote.name;
@@ -188,16 +202,21 @@ function mf(api) {
188
202
  return exposes;
189
203
  }
190
204
  function mfName() {
191
- const name = api.config.mf.name;
205
+ const name = api.userConfig.mf.name;
192
206
  if (!name) {
193
207
  api.logger.warn(
194
208
  `module federation name is not defined , "unNamedMF" will be used`
195
209
  );
196
210
  }
211
+ if (!isValidIdentifyName(name)) {
212
+ throw new Error(
213
+ `module federation name '${name}' is not valid javascript identifier.`
214
+ );
215
+ }
197
216
  return name || "unNamedMF";
198
217
  }
199
218
  function getShared() {
200
- const { shared = {} } = api.config.mf;
219
+ const { shared = {} } = api.userConfig.mf;
201
220
  return shared;
202
221
  }
203
222
  function changeUmiEntry(config) {
@@ -225,6 +244,76 @@ function mf(api) {
225
244
  function addMFEntry(config, mfName2, path) {
226
245
  config.entry[mfName2] = path;
227
246
  }
247
+ function isValidIdentifyName(name) {
248
+ const reservedKeywords = [
249
+ "abstract",
250
+ "await",
251
+ "boolean",
252
+ "break",
253
+ "byte",
254
+ "case",
255
+ "catch",
256
+ "char",
257
+ "class",
258
+ "const",
259
+ "continue",
260
+ "debugger",
261
+ "default",
262
+ "delete",
263
+ "do",
264
+ "double",
265
+ "else",
266
+ "enum",
267
+ "export",
268
+ "extends",
269
+ "false",
270
+ "final",
271
+ "finally",
272
+ "float",
273
+ "for",
274
+ "function",
275
+ "goto",
276
+ "if",
277
+ "implements",
278
+ "import",
279
+ "in",
280
+ "instanceof",
281
+ "int",
282
+ "interface",
283
+ "let",
284
+ "long",
285
+ "native",
286
+ "new",
287
+ "null",
288
+ "package",
289
+ "private",
290
+ "protected",
291
+ "public",
292
+ "return",
293
+ "short",
294
+ "static",
295
+ "super",
296
+ "switch",
297
+ "synchronized",
298
+ "this",
299
+ "throw",
300
+ "transient",
301
+ "true",
302
+ "try",
303
+ "typeof",
304
+ "var",
305
+ "void",
306
+ "volatile",
307
+ "while",
308
+ "with",
309
+ "yield"
310
+ ];
311
+ const regexIdentifierName = /^(?:[$_\p{ID_Start}])(?:[$_\u200C\u200D\p{ID_Continue}])*$/u;
312
+ if (reservedKeywords.includes(name) || !regexIdentifierName.test(name)) {
313
+ return false;
314
+ }
315
+ return true;
316
+ }
228
317
  }
229
318
  // Annotate the CommonJS export names for ESM import in node:
230
319
  0 && (module.exports = {});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/plugins",
3
- "version": "4.0.0-canary.20230201.1",
3
+ "version": "4.0.0-canary.20230207.1",
4
4
  "description": "@umijs/plugins",
5
5
  "homepage": "https://github.com/umijs/umi/tree/master/packages/plugins#readme",
6
6
  "bugs": "https://github.com/umijs/umi/issues",
@@ -29,7 +29,7 @@
29
29
  "@ant-design/pro-components": "^2.0.1",
30
30
  "@tanstack/react-query": "^4.22.0",
31
31
  "@tanstack/react-query-devtools": "^4.22.0",
32
- "@umijs/bundler-utils": "4.0.0-canary.20230201.1",
32
+ "@umijs/bundler-utils": "4.0.0-canary.20230207.1",
33
33
  "@umijs/valtio": "^1.0.3",
34
34
  "antd-dayjs-webpack-plugin": "^1.0.6",
35
35
  "axios": "^0.27.2",
@@ -53,7 +53,7 @@
53
53
  },
54
54
  "devDependencies": {
55
55
  "antd": "^4.24.1",
56
- "umi": "4.0.0-canary.20230201.1"
56
+ "umi": "4.0.0-canary.20230207.1"
57
57
  },
58
58
  "publishConfig": {
59
59
  "access": "public"