@umijs/plugins 4.0.0-canary.20230201.2 → 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 +91 -3
  2. package/package.json +3 -3
package/dist/mf.js CHANGED
@@ -94,6 +94,19 @@ function mf(api) {
94
94
  );
95
95
  return config;
96
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
+ });
97
110
  api.onGenerateFiles(() => {
98
111
  api.writeTmpFile({
99
112
  content: `/* infer remote public */;
@@ -117,7 +130,7 @@ function mf(api) {
117
130
  });
118
131
  });
119
132
  function formatRemotes() {
120
- const { remotes = [] } = api.config.mf;
133
+ const { remotes = [] } = api.userConfig.mf;
121
134
  const memo = {};
122
135
  remotes.forEach((remote) => {
123
136
  const aliasName = remote.aliasName || remote.name;
@@ -189,16 +202,21 @@ function mf(api) {
189
202
  return exposes;
190
203
  }
191
204
  function mfName() {
192
- const name = api.config.mf.name;
205
+ const name = api.userConfig.mf.name;
193
206
  if (!name) {
194
207
  api.logger.warn(
195
208
  `module federation name is not defined , "unNamedMF" will be used`
196
209
  );
197
210
  }
211
+ if (!isValidIdentifyName(name)) {
212
+ throw new Error(
213
+ `module federation name '${name}' is not valid javascript identifier.`
214
+ );
215
+ }
198
216
  return name || "unNamedMF";
199
217
  }
200
218
  function getShared() {
201
- const { shared = {} } = api.config.mf;
219
+ const { shared = {} } = api.userConfig.mf;
202
220
  return shared;
203
221
  }
204
222
  function changeUmiEntry(config) {
@@ -226,6 +244,76 @@ function mf(api) {
226
244
  function addMFEntry(config, mfName2, path) {
227
245
  config.entry[mfName2] = path;
228
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
+ }
229
317
  }
230
318
  // Annotate the CommonJS export names for ESM import in node:
231
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.2",
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.2",
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.2"
56
+ "umi": "4.0.0-canary.20230207.1"
57
57
  },
58
58
  "publishConfig": {
59
59
  "access": "public"