@umijs/plugins 4.0.47 → 4.0.48

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.
package/dist/access.js CHANGED
@@ -51,7 +51,7 @@ var access_default = (api) => {
51
51
  path: "runtime.tsx",
52
52
  content: `
53
53
  import React from 'react';${hasAccessFile ? `
54
- import accessFactory from '@/access'
54
+ import accessFactory from '@/access';
55
55
  import { useModel } from '@@/plugin-model';
56
56
  ` : ""}
57
57
  import { AccessContext } from './context';
@@ -166,10 +166,23 @@ export const useAccessMarkedRoutes = (routes: IRoute[]) => {
166
166
  api.writeTmpFile({
167
167
  path: "context.ts",
168
168
  content: `
169
- import React from 'react';
169
+ import React from 'react';${hasAccessFile ? `
170
+ import { AccessInstance } from './types.d';
171
+
172
+ export const AccessContext = React.createContext<AccessInstance>(null);
173
+ ` : `
170
174
  export const AccessContext = React.createContext<any>(null);
175
+ `}
171
176
  `
172
177
  });
178
+ api.writeTmpFile({
179
+ path: "types.d.ts",
180
+ content: hasAccessFile ? `
181
+ import accessFactory from '@/access';
182
+
183
+ export type AccessInstance = ReturnType<typeof accessFactory>;
184
+ ` : "export {}"
185
+ });
173
186
  });
174
187
  api.addRuntimePlugin(() => {
175
188
  return [(0, import_withTmpPath.withTmpPath)({ api, path: "runtime.tsx" })];
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,7 +202,7 @@ 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`
@@ -197,7 +211,7 @@ function mf(api) {
197
211
  return name || "unNamedMF";
198
212
  }
199
213
  function getShared() {
200
- const { shared = {} } = api.config.mf;
214
+ const { shared = {} } = api.userConfig.mf;
201
215
  return shared;
202
216
  }
203
217
  function changeUmiEntry(config) {
@@ -28,6 +28,7 @@ __export(react_query_exports, {
28
28
  default: () => react_query_default
29
29
  });
30
30
  module.exports = __toCommonJS(react_query_exports);
31
+ var import_utils = require("@umijs/utils");
31
32
  var import_path = require("path");
32
33
  var import_resolveProjectDep = require("./utils/resolveProjectDep");
33
34
  var import_withTmpPath = require("./utils/withTmpPath");
@@ -45,18 +46,19 @@ var react_query_default = (api) => {
45
46
  enableBy: api.EnableBy.config
46
47
  });
47
48
  let pkgPath;
48
- const defaultPkgPath = (0, import_path.dirname)(
49
- require.resolve("@tanstack/react-query/package.json")
49
+ const defaultPkgPath = (0, import_utils.winPath)(
50
+ (0, import_path.dirname)(require.resolve("@tanstack/react-query/package.json"))
50
51
  );
51
- const devtoolPkgPath = (0, import_path.dirname)(
52
- require.resolve("@tanstack/react-query-devtools/package.json")
52
+ const devtoolPkgPath = (0, import_utils.winPath)(
53
+ (0, import_path.dirname)(require.resolve("@tanstack/react-query-devtools/package.json"))
53
54
  );
54
55
  try {
55
- pkgPath = (0, import_resolveProjectDep.resolveProjectDep)({
56
+ const localQueryPath = (0, import_resolveProjectDep.resolveProjectDep)({
56
57
  pkg: api.pkg,
57
58
  cwd: api.cwd,
58
59
  dep: "@tanstack/react-query"
59
- }) || defaultPkgPath;
60
+ });
61
+ pkgPath = localQueryPath ? (0, import_utils.winPath)(localQueryPath) : defaultPkgPath;
60
62
  } catch (e) {
61
63
  throw new Error(`[reactQuery] package resolve failed, ${e.message}`);
62
64
  }
@@ -28,6 +28,7 @@ __export(styled_components_exports, {
28
28
  default: () => styled_components_default
29
29
  });
30
30
  module.exports = __toCommonJS(styled_components_exports);
31
+ var import_utils = require("@umijs/utils");
31
32
  var import_path = require("path");
32
33
  var import_withTmpPath = require("./utils/withTmpPath");
33
34
  var styled_components_default = (api) => {
@@ -62,7 +63,9 @@ var styled_components_default = (api) => {
62
63
  api.writeTmpFile({
63
64
  path: "index.tsx",
64
65
  content: `
65
- import styled, { ThemeProvider, createGlobalStyle, css, keyframes, StyleSheetManager, useTheme } from '${libPath}';
66
+ import styled, { ThemeProvider, createGlobalStyle, css, keyframes, StyleSheetManager, useTheme } from '${(0, import_utils.winPath)(
67
+ libPath
68
+ )}';
66
69
  export { styled, ThemeProvider, createGlobalStyle, css, keyframes, StyleSheetManager, useTheme };
67
70
  `
68
71
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/plugins",
3
- "version": "4.0.47",
3
+ "version": "4.0.48",
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,8 +29,8 @@
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.47",
33
- "@umijs/valtio": "^1.0.2",
32
+ "@umijs/bundler-utils": "4.0.48",
33
+ "@umijs/valtio": "^1.0.3",
34
34
  "antd-dayjs-webpack-plugin": "^1.0.6",
35
35
  "axios": "^0.27.2",
36
36
  "babel-plugin-import": "^1.13.6",
@@ -53,7 +53,7 @@
53
53
  },
54
54
  "devDependencies": {
55
55
  "antd": "^4.24.1",
56
- "umi": "4.0.47"
56
+ "umi": "4.0.48"
57
57
  },
58
58
  "publishConfig": {
59
59
  "access": "public"