@umijs/plugins 4.0.0-rc.14 → 4.0.0-rc.15

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
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -24,7 +15,7 @@ exports.default = (api) => {
24
15
  },
25
16
  enableBy: api.EnableBy.config,
26
17
  });
27
- api.onGenerateFiles(() => __awaiter(void 0, void 0, void 0, function* () {
18
+ api.onGenerateFiles(async () => {
28
19
  // allow enable access without access file
29
20
  const hasAccessFile = ['js', 'jsx', 'ts', 'tsx'].some((ext) => fs_1.default.existsSync((0, path_1.join)(api.paths.absSrcPath, `access.${ext}`)));
30
21
  // runtime.tsx
@@ -137,7 +128,7 @@ import React from 'react';
137
128
  export const AccessContext = React.createContext<any>(null);
138
129
  `,
139
130
  });
140
- }));
131
+ });
141
132
  api.addRuntimePlugin(() => {
142
133
  return [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })];
143
134
  });
package/dist/antd.js CHANGED
@@ -57,12 +57,18 @@ exports.default = (api) => {
57
57
  // dark mode & compact mode
58
58
  if (memo.antd.dark || memo.antd.compact) {
59
59
  const { getThemeVariables } = require('antd/dist/theme');
60
- memo.theme = Object.assign(Object.assign({}, getThemeVariables(memo.antd)), memo.theme);
60
+ memo.theme = {
61
+ ...getThemeVariables(memo.antd),
62
+ ...memo.theme,
63
+ };
61
64
  }
62
65
  return memo;
63
66
  });
64
67
  api.modifyConfig((memo) => {
65
- memo.theme = Object.assign({ 'root-entry-name': 'default' }, memo.theme);
68
+ memo.theme = {
69
+ 'root-entry-name': 'default',
70
+ ...memo.theme,
71
+ };
66
72
  return memo;
67
73
  });
68
74
  // babel-plugin-import
package/dist/dva.js CHANGED
@@ -180,6 +180,7 @@ function getModelUtil(api) {
180
180
  exports.getModelUtil = getModelUtil;
181
181
  function getAllModels(api) {
182
182
  return getModelUtil(api).getAllModels({
183
+ extraModelsPre: [],
183
184
  extraModels: [...(api.config.dva.extraModels || [])],
184
185
  });
185
186
  }
@@ -13,7 +13,7 @@ exports.default = (api) => {
13
13
  enableBy: api.EnableBy.config,
14
14
  });
15
15
  api.register({
16
- key: 'addExtraModels',
16
+ key: 'addExtraModelsPre',
17
17
  fn: () => [(0, withTmpPath_1.withTmpPath)({ api, path: '@@initialState.ts' })],
18
18
  });
19
19
  api.addRuntimePluginKey(() => ['getInitialState']);
package/dist/layout.js CHANGED
@@ -39,7 +39,7 @@ exports.default = (api) => {
39
39
  schema(joi) {
40
40
  return joi.object();
41
41
  },
42
- // onChange: api.ConfigChangeType.regenerateTmpFiles,
42
+ onChange: api.ConfigChangeType.regenerateTmpFiles,
43
43
  },
44
44
  enableBy: api.EnableBy.config,
45
45
  });
package/dist/locale.js CHANGED
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.packageNormalize = void 0;
13
4
  const fs_1 = require("fs");
@@ -58,9 +49,9 @@ exports.default = (api) => {
58
49
  },
59
50
  ]
60
51
  : []);
61
- const addAntdLocales = (args) => __awaiter(void 0, void 0, void 0, function* () {
52
+ const addAntdLocales = async (args) => {
62
53
  var _a;
63
- return yield api.applyPlugins({
54
+ return await api.applyPlugins({
64
55
  key: 'addAntdLocales',
65
56
  type: api.ApplyPluginsType.add,
66
57
  initialValue: [
@@ -68,29 +59,32 @@ exports.default = (api) => {
68
59
  ],
69
60
  args,
70
61
  });
71
- });
72
- const getList = (resolveKey) => __awaiter(void 0, void 0, void 0, function* () {
73
- var _b;
62
+ };
63
+ const getList = async (resolveKey) => {
64
+ var _a;
74
65
  const { paths } = api;
75
66
  return (0, localeUtils_1.getLocaleList)({
76
67
  localeFolder: 'locales',
77
- separator: (_b = api.config.locale) === null || _b === void 0 ? void 0 : _b.baseSeparator,
68
+ separator: (_a = api.config.locale) === null || _a === void 0 ? void 0 : _a.baseSeparator,
78
69
  absSrcPath: paths.absSrcPath,
79
70
  absPagesPath: paths.absPagesPath,
80
71
  addAntdLocales,
81
72
  resolveKey,
82
73
  });
83
- });
84
- api.onGenerateFiles(() => __awaiter(void 0, void 0, void 0, function* () {
85
- var _c, _d, _e, _f;
74
+ };
75
+ api.onGenerateFiles(async () => {
76
+ var _a, _b, _c, _d;
86
77
  const localeTpl = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../libs/locale/locale.tpl'), 'utf-8');
87
78
  // moment2dayjs
88
79
  const resolveKey = api.config.moment2dayjs ? 'dayjs' : 'moment';
89
80
  const momentPkgPath = (0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve(`${resolveKey}/package.json`)));
90
81
  const EventEmitterPkg = (0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('event-emitter/package')));
91
- const { baseSeparator, baseNavigator, antd, title, useLocalStorage } = Object.assign(Object.assign({}, defaultConfig), api.config.locale);
92
- const defaultLocale = ((_c = api.config.locale) === null || _c === void 0 ? void 0 : _c.default) || `zh${baseSeparator}CN`;
93
- const localeList = yield getList(resolveKey);
82
+ const { baseSeparator, baseNavigator, antd, title, useLocalStorage } = {
83
+ ...defaultConfig,
84
+ ...api.config.locale,
85
+ };
86
+ const defaultLocale = ((_a = api.config.locale) === null || _a === void 0 ? void 0 : _a.default) || `zh${baseSeparator}CN`;
87
+ const localeList = await getList(resolveKey);
94
88
  const momentLocales = localeList
95
89
  .map(({ momentLocale }) => momentLocale)
96
90
  .filter((locale) => locale);
@@ -100,7 +94,7 @@ exports.default = (api) => {
100
94
  let MomentLocales = momentLocales;
101
95
  let DefaultMomentLocale = '';
102
96
  // set moment default accounding to locale.default
103
- if (!MomentLocales.length && ((_d = api.config.locale) === null || _d === void 0 ? void 0 : _d.default)) {
97
+ if (!MomentLocales.length && ((_b = api.config.locale) === null || _b === void 0 ? void 0 : _b.default)) {
104
98
  const [lang, country = ''] = defaultLocale.split(baseSeparator);
105
99
  const { momentLocale } = (0, localeUtils_1.getMomentLocale)(lang, country, resolveKey);
106
100
  if (momentLocale) {
@@ -110,9 +104,9 @@ exports.default = (api) => {
110
104
  }
111
105
  let DefaultAntdLocales = [];
112
106
  // set antd default locale
113
- if (!antdLocales.length && ((_e = api.config.locale) === null || _e === void 0 ? void 0 : _e.antd)) {
107
+ if (!antdLocales.length && ((_c = api.config.locale) === null || _c === void 0 ? void 0 : _c.antd)) {
114
108
  const [lang, country = ''] = defaultLocale.split(baseSeparator);
115
- DefaultAntdLocales = plugin_utils_1.lodash.uniq(yield addAntdLocales({
109
+ DefaultAntdLocales = plugin_utils_1.lodash.uniq(await addAntdLocales({
116
110
  lang,
117
111
  country,
118
112
  }));
@@ -148,13 +142,17 @@ exports.default = (api) => {
148
142
  UseLocalStorage: !!useLocalStorage,
149
143
  LocaleDir: localeDirName,
150
144
  ExistLocaleDir: (0, fs_1.existsSync)(localeDirPath),
151
- LocaleList: localeList.map((locale) => (Object.assign(Object.assign({}, locale), { antdLocale: locale.antdLocale.map((antdLocale, index) => ({
145
+ LocaleList: localeList.map((locale) => ({
146
+ ...locale,
147
+ antdLocale: locale.antdLocale.map((antdLocale, index) => ({
152
148
  locale: antdLocale,
153
149
  index: index,
154
- })), paths: locale.paths.map((path, index) => ({
150
+ })),
151
+ paths: locale.paths.map((path, index) => ({
155
152
  path,
156
153
  index,
157
- })) }))),
154
+ })),
155
+ })),
158
156
  Antd: !!antd,
159
157
  DefaultLocale: JSON.stringify(defaultLocale),
160
158
  warningPkgPath: (0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('warning/package'))),
@@ -177,7 +175,7 @@ exports.default = (api) => {
177
175
  Antd: !!antd,
178
176
  LocaleList: localeList,
179
177
  ShowSelectLang: localeList.length > 1 && !!antd,
180
- antdFiles: ((_f = api.config) === null || _f === void 0 ? void 0 : _f.ssr) ? 'lib' : 'es',
178
+ antdFiles: ((_d = api.config) === null || _d === void 0 ? void 0 : _d.ssr) ? 'lib' : 'es',
181
179
  }),
182
180
  });
183
181
  // index.ts
@@ -188,14 +186,14 @@ export { setLocale, getLocale, useIntl, injectIntl, formatMessage, FormattedMess
188
186
  export { SelectLang } from './SelectLang.tsx';
189
187
  `,
190
188
  });
191
- }));
189
+ });
192
190
  // Runtime Plugin
193
191
  api.addRuntimePlugin(() => [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })]);
194
192
  api.addRuntimePluginKey(() => ['locale']);
195
193
  // watch locale files
196
- api.addTmpGenerateWatcherPaths(() => __awaiter(void 0, void 0, void 0, function* () {
194
+ api.addTmpGenerateWatcherPaths(async () => {
197
195
  const resolveKey = api.config.moment2dayjs ? 'dayjs' : 'moment';
198
- const localeList = yield getList(resolveKey);
196
+ const localeList = await getList(resolveKey);
199
197
  return (0, localeUtils_1.exactLocalePaths)(localeList);
200
- }));
198
+ });
201
199
  };
package/dist/model.js CHANGED
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
25
  Object.defineProperty(exports, "__esModule", { value: true });
35
26
  const t = __importStar(require("@umijs/bundler-utils/compiled/babel/types"));
36
27
  const fs_1 = require("fs");
@@ -49,17 +40,17 @@ exports.default = (api) => {
49
40
  },
50
41
  enableBy: api.EnableBy.config,
51
42
  });
52
- api.modifyAppData((memo) => __awaiter(void 0, void 0, void 0, function* () {
53
- const models = yield getAllModels(api);
43
+ api.modifyAppData(async (memo) => {
44
+ const models = await getAllModels(api);
54
45
  memo.pluginModel = {
55
46
  models,
56
47
  };
57
48
  return memo;
58
- }));
59
- api.onGenerateFiles((args) => __awaiter(void 0, void 0, void 0, function* () {
49
+ });
50
+ api.onGenerateFiles(async (args) => {
60
51
  const models = args.isFirstTime
61
52
  ? api.appData.pluginModel.models
62
- : yield getAllModels(api);
53
+ : await getAllModels(api);
63
54
  // model.ts
64
55
  api.writeTmpFile({
65
56
  path: 'model.ts',
@@ -94,7 +85,7 @@ export function dataflowProvider(container, opts) {
94
85
  }
95
86
  `,
96
87
  });
97
- }));
88
+ });
98
89
  api.addTmpGenerateWatcherPaths(() => {
99
90
  return [(0, path_1.join)(api.paths.absSrcPath, 'models')];
100
91
  });
@@ -102,19 +93,26 @@ export function dataflowProvider(container, opts) {
102
93
  return [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })];
103
94
  });
104
95
  };
105
- function getAllModels(api) {
106
- return __awaiter(this, void 0, void 0, function* () {
107
- const extraModels = yield api.applyPlugins({
108
- key: 'addExtraModels',
109
- type: api.ApplyPluginsType.add,
110
- initialValue: [],
111
- });
112
- return new modelUtils_1.ModelUtils(api, {
113
- astTest({ node }) {
114
- return t.isArrowFunctionExpression(node) || t.isFunctionDeclaration(node);
115
- },
116
- }).getAllModels({
117
- extraModels: [...extraModels, ...(api.config.model.extraModels || [])],
118
- });
96
+ async function getAllModels(api) {
97
+ const extraModelsPre = await api.applyPlugins({
98
+ key: 'addExtraModelsPre',
99
+ type: api.ApplyPluginsType.add,
100
+ initialValue: [],
101
+ });
102
+ const extraModels = await api.applyPlugins({
103
+ key: 'addExtraModels',
104
+ type: api.ApplyPluginsType.add,
105
+ initialValue: [],
106
+ });
107
+ return new modelUtils_1.ModelUtils(api, {
108
+ astTest({ node }) {
109
+ return t.isArrowFunctionExpression(node) || t.isFunctionDeclaration(node);
110
+ },
111
+ }).getAllModels({
112
+ extraModelsPre: [
113
+ ...extraModelsPre,
114
+ ...(api.config.model.extraModelsPre || []),
115
+ ],
116
+ extraModels: [...extraModels, ...(api.config.model.extraModels || [])],
119
117
  });
120
118
  }
@@ -23,7 +23,17 @@ exports.default = (api) => {
23
23
  api.addRuntimePlugin(() => {
24
24
  return [(0, withTmpPath_1.withTmpPath)({ api, path: 'masterRuntimePlugin.tsx' })];
25
25
  });
26
- api.modifyDefaultConfig((config) => (Object.assign(Object.assign({}, config), { mountElementId: constants_1.defaultMasterRootId, qiankun: Object.assign(Object.assign({}, config.qiankun), { master: Object.assign(Object.assign({}, JSON.parse(process.env.INITIAL_QIANKUN_MASTER_OPTIONS || '{}')), (config.qiankun || {}).master) }) })));
26
+ api.modifyDefaultConfig((config) => ({
27
+ ...config,
28
+ mountElementId: constants_1.defaultMasterRootId,
29
+ qiankun: {
30
+ ...config.qiankun,
31
+ master: {
32
+ ...JSON.parse(process.env.INITIAL_QIANKUN_MASTER_OPTIONS || '{}'),
33
+ ...(config.qiankun || {}).master,
34
+ },
35
+ },
36
+ }));
27
37
  // TODO: modify routes
28
38
  api.modifyRoutes((memo) => {
29
39
  Object.keys(memo).forEach((id) => {
@@ -65,7 +75,11 @@ exports.default = (api) => {
65
75
  api.writeTmpFile({
66
76
  path: 'masterOptions.ts',
67
77
  content: `
68
- let options = ${JSON.stringify(Object.assign({ masterHistoryType: ((_a = api.config.history) === null || _a === void 0 ? void 0 : _a.type) || constants_1.defaultHistoryType, base: api.config.base || '/' }, api.config.qiankun.master))};
78
+ let options = ${JSON.stringify({
79
+ masterHistoryType: ((_a = api.config.history) === null || _a === void 0 ? void 0 : _a.type) || constants_1.defaultHistoryType,
80
+ base: api.config.base || '/',
81
+ ...api.config.qiankun.master,
82
+ })};
69
83
  export const getMasterOptions = () => options;
70
84
  export const setMasterOptions = (newOpts) => options = ({ ...options, ...newOpts });
71
85
  `,
@@ -36,10 +36,20 @@ exports.default = (api) => {
36
36
  });
37
37
  api.modifyDefaultConfig((memo) => {
38
38
  var _a, _b, _c, _d;
39
- const initialSlaveOptions = Object.assign(Object.assign({ devSourceMap: true }, JSON.parse(process.env.INITIAL_QIANKUN_SLAVE_OPTIONS || '{}')), (memo.qiankun || {}).slave);
40
- const modifiedDefaultConfig = Object.assign(Object.assign({}, memo), {
39
+ const initialSlaveOptions = {
40
+ devSourceMap: true,
41
+ ...JSON.parse(process.env.INITIAL_QIANKUN_SLAVE_OPTIONS || '{}'),
42
+ ...(memo.qiankun || {}).slave,
43
+ };
44
+ const modifiedDefaultConfig = {
45
+ ...memo,
41
46
  // 默认开启 runtimePublicPath,避免出现 dynamic import 场景子应用资源地址出问题
42
- runtimePublicPath: true, qiankun: Object.assign(Object.assign({}, memo.qiankun), { slave: initialSlaveOptions }) });
47
+ runtimePublicPath: true,
48
+ qiankun: {
49
+ ...memo.qiankun,
50
+ slave: initialSlaveOptions,
51
+ },
52
+ };
43
53
  const shouldNotModifyDefaultBase = (_c = (_b = (_a = api.userConfig.qiankun) === null || _a === void 0 ? void 0 : _a.slave) === null || _b === void 0 ? void 0 : _b.shouldNotModifyDefaultBase) !== null && _c !== void 0 ? _c : initialSlaveOptions.shouldNotModifyDefaultBase;
44
54
  const historyType = ((_d = api.userConfig.history) === null || _d === void 0 ? void 0 : _d.type) || 'browser';
45
55
  if (!shouldNotModifyDefaultBase && historyType !== 'hash') {
@@ -52,8 +62,11 @@ exports.default = (api) => {
52
62
  var _a, _b;
53
63
  // mfsu 场景默认给子应用增加 mfName 配置,从而避免冲突
54
64
  if (config.mfsu !== false) {
55
- config.mfsu = Object.assign(Object.assign({}, config.mfsu), { mfName: ((_a = config.mfsu) === null || _a === void 0 ? void 0 : _a.mfName) ||
56
- `mf_${(_b = api.pkg.name) === null || _b === void 0 ? void 0 : _b.replace(/^@/, '').replace(/\W/g, '_')}` });
65
+ config.mfsu = {
66
+ ...config.mfsu,
67
+ mfName: ((_a = config.mfsu) === null || _a === void 0 ? void 0 : _a.mfName) ||
68
+ `mf_${(_b = api.pkg.name) === null || _b === void 0 ? void 0 : _b.replace(/^@/, '').replace(/\W/g, '_')}`,
69
+ };
57
70
  }
58
71
  return config;
59
72
  });
package/dist/request.js CHANGED
@@ -291,6 +291,12 @@ export type {
291
291
  formatResult,
292
292
  }),
293
293
  });
294
+ api.writeTmpFile({
295
+ path: 'types.d.ts',
296
+ content: `
297
+ export type { RequestConfig } from './request';
298
+ `,
299
+ });
294
300
  api.writeTmpFile({
295
301
  path: 'index.ts',
296
302
  content: `
@@ -299,10 +305,6 @@ export {
299
305
  UseRequestProvider,
300
306
  request,
301
307
  } from './request';
302
-
303
- export type {
304
- RequestConfig
305
- } from './request';
306
308
  `,
307
309
  });
308
310
  });
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.isNeedPolyfill = exports.exactLocalePaths = exports.getLocaleList = exports.getAntdLocale = exports.getMomentLocale = void 0;
13
4
  const fs_1 = require("fs");
@@ -55,7 +46,7 @@ const modulesHasLocale = (localePath) => {
55
46
  return false;
56
47
  }
57
48
  };
58
- const getLocaleList = (opts) => __awaiter(void 0, void 0, void 0, function* () {
49
+ const getLocaleList = async (opts) => {
59
50
  const { localeFolder, separator = '-', absSrcPath = '', absPagesPath = '', addAntdLocales, resolveKey = 'moment', } = opts;
60
51
  const localeFileMath = new RegExp(`^([a-z]{2})${separator}?([A-Z]{2})?\.(js|json|ts)$`);
61
52
  const localeFiles = plugin_utils_1.glob
@@ -80,11 +71,11 @@ const getLocaleList = (opts) => __awaiter(void 0, void 0, void 0, function* () {
80
71
  };
81
72
  });
82
73
  const groups = plugin_utils_1.lodash.groupBy(localeFiles, 'name');
83
- const promises = Object.keys(groups).map((name) => __awaiter(void 0, void 0, void 0, function* () {
74
+ const promises = Object.keys(groups).map(async (name) => {
84
75
  const [lang, country = ''] = name.split(separator);
85
76
  const { momentLocale } = (0, exports.getMomentLocale)(lang, country, resolveKey);
86
77
  const antdLocale = plugin_utils_1.lodash
87
- .uniq(yield addAntdLocales({ lang, country }))
78
+ .uniq(await addAntdLocales({ lang, country }))
88
79
  .filter((localePath) => modulesHasLocale(localePath));
89
80
  return {
90
81
  lang,
@@ -97,9 +88,9 @@ const getLocaleList = (opts) => __awaiter(void 0, void 0, void 0, function* () {
97
88
  paths: groups[name].map((item) => (0, plugin_utils_1.winPath)(item.path)),
98
89
  momentLocale,
99
90
  };
100
- }));
91
+ });
101
92
  return Promise.all(promises);
102
- });
93
+ };
103
94
  exports.getLocaleList = getLocaleList;
104
95
  const exactLocalePaths = (data) => {
105
96
  return plugin_utils_1.lodash.flatten(data.map((item) => item.paths));
@@ -20,6 +20,7 @@ export declare class ModelUtils {
20
20
  count: number;
21
21
  constructor(api: IApi | null, opts: IOpts);
22
22
  getAllModels(opts: {
23
+ extraModelsPre: string[];
23
24
  extraModels: string[];
24
25
  }): Model[];
25
26
  getModels(opts: {
@@ -62,6 +62,7 @@ class ModelUtils {
62
62
  // reset count
63
63
  this.count = 1;
64
64
  return [
65
+ ...opts.extraModelsPre,
65
66
  ...this.getModels({
66
67
  base: (0, path_1.join)(this.api.paths.absSrcPath, 'models'),
67
68
  pattern: '**/*.{ts,tsx,js,jsx}',
@@ -139,6 +139,13 @@ export const MicroApp = forwardRef(
139
139
  setComponentError(null);
140
140
  setLoading(true);
141
141
  const configuration = {
142
+ fetch(url) {
143
+ return window.fetch(url, {
144
+ headers: {
145
+ accept: 'text/html',
146
+ },
147
+ });
148
+ },
142
149
  globalContext: window,
143
150
  ...globalSettings,
144
151
  ...settingsFromProps,
@@ -1,5 +1,4 @@
1
1
  // @ts-nocheck
2
- /* eslint-disable */
3
2
  __USE_MODEL__;
4
3
  import React from 'react';
5
4
 
@@ -1,5 +1,4 @@
1
1
  // @ts-nocheck
2
- /* eslint-disable */
3
2
  import { getPluginManager } from '@@/core/plugin';
4
3
  import ReactDOM from 'react-dom';
5
4
  import { ApplyPluginsType } from 'umi';
@@ -22,7 +21,7 @@ let render = noop;
22
21
  let hasMountedAtLeastOnce = false;
23
22
 
24
23
  export default () => defer.promise;
25
- export const clientRenderOptsStack: any[] = [];
24
+ export const contextOptsStack: any[] = [];
26
25
 
27
26
  // function normalizeHistory(
28
27
  // history?: 'string' | Record<string, any>,
@@ -79,10 +78,7 @@ export function genMount(mountElementId: string) {
79
78
  // 默认开启
80
79
  // 如果需要手动控制 loading,通过主应用配置 props.autoSetLoading false 可以关闭
81
80
  callback: () => {
82
- if (
83
- props?.autoSetLoading &&
84
- typeof props?.setLoading === 'function'
85
- ) {
81
+ if (props.autoSetLoading && typeof props.setLoading === 'function') {
86
82
  props.setLoading(false);
87
83
  }
88
84
 
@@ -94,9 +90,11 @@ export function genMount(mountElementId: string) {
94
90
  // 支持通过 props 注入 container 来限定子应用 mountElementId 的查找范围
95
91
  // 避免多个子应用出现在同一主应用时出现 mount 冲突
96
92
  rootElement:
97
- props?.container?.querySelector(`#${mountElementId}`) ||
93
+ props.container?.querySelector(`#${mountElementId}`) ||
98
94
  mountElementId,
99
95
 
96
+ basename: props.base,
97
+
100
98
  // 当存在同一个 umi 子应用在同一个页面被多实例渲染的场景时(比如一个页面里,同时展示了这个子应用的多个路由页面)
101
99
  // mount 钩子会被调用多次,但是具体什么时候对应的实例开始 render 则是不定的,即它调用 applyPlugins('modifyClientRenderOpts') 的时机是不确定的
102
100
  // 为了保证每次 applyPlugins('modifyClientRenderOpts') 调用是生成正确的 history,我们需要这里通过闭包上下文维持 mount 调用时的一些配置信息
@@ -111,7 +109,7 @@ export function genMount(mountElementId: string) {
111
109
  // },
112
110
  };
113
111
 
114
- clientRenderOptsStack.push(clientRenderOpts);
112
+ contextOptsStack.push(clientRenderOpts);
115
113
  }
116
114
 
117
115
  // 第一次 mount defer 被 resolve 后umi 会自动触发 render,非第一次 mount 则需手动触发
@@ -1,5 +1,4 @@
1
1
  // @ts-nocheck
2
- /* eslint-disable */
3
2
  import { useState } from 'react';
4
3
 
5
4
  let initState: any;
@@ -1,21 +1,15 @@
1
1
  // @ts-nocheck
2
- /* eslint-disable */
3
- import qiankunRender from './lifecycles';
2
+ import qiankunRender, { contextOptsStack } from './lifecycles';
4
3
 
5
4
  export function render(oldRender: any) {
6
5
  return qiankunRender().then(oldRender);
7
6
  }
8
7
 
9
- // export function modifyClientRenderOpts(memo: any) {
10
- // // 每次应用 render 的时候会调 modifyClientRenderOpts,这时尝试从队列中取 render 的配置
11
- // const clientRenderOpts = clientRenderOptsStack.shift();
12
- // if (clientRenderOpts) {
13
- // const history = clientRenderOpts.getHistory();
14
- // delete clientRenderOpts.getHistory;
15
- // clientRenderOpts.history = history;
16
- // }
17
- // return {
18
- // ...memo,
19
- // ...clientRenderOpts,
20
- // };
21
- // }
8
+ export function modifyContextOpts(memo: any) {
9
+ // 每次应用 render 的时候会调 modifyClientRenderOpts,这时尝试从队列中取 render 的配置
10
+ const clientRenderOpts = contextOptsStack.shift();
11
+ return {
12
+ ...memo,
13
+ ...clientRenderOpts,
14
+ };
15
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/plugins",
3
- "version": "4.0.0-rc.14",
3
+ "version": "4.0.0-rc.15",
4
4
  "description": "@umijs/plugins",
5
5
  "homepage": "https://github.com/umijs/umi-next/tree/master/packages/plugins#readme",
6
6
  "bugs": "https://github.com/umijs/umi-next/issues",
@@ -25,7 +25,7 @@
25
25
  "@ahooksjs/use-request": "^2.0.0",
26
26
  "@ant-design/icons": "^4.7.0",
27
27
  "@ant-design/pro-layout": "^6.35.1",
28
- "@umijs/bundler-utils": "4.0.0-rc.14",
28
+ "@umijs/bundler-utils": "4.0.0-rc.15",
29
29
  "antd-dayjs-webpack-plugin": "^1.0.6",
30
30
  "axios": "^0.26.1",
31
31
  "babel-plugin-import": "^1.13.3",
@@ -44,7 +44,7 @@
44
44
  "warning": "^4.0.3"
45
45
  },
46
46
  "devDependencies": {
47
- "umi": "4.0.0-rc.14"
47
+ "umi": "4.0.0-rc.15"
48
48
  },
49
49
  "publishConfig": {
50
50
  "access": "public"