@umijs/plugins 4.0.9 → 4.0.12

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
@@ -19,7 +19,7 @@ var __copyProps = (to, from, except, desc) => {
19
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
20
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
21
 
22
- // access.ts
22
+ // src/access.ts
23
23
  var access_exports = {};
24
24
  __export(access_exports, {
25
25
  default: () => access_default
package/dist/analytics.js CHANGED
@@ -16,7 +16,7 @@ var __copyProps = (to, from, except, desc) => {
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
- // analytics.ts
19
+ // src/analytics.ts
20
20
  var analytics_exports = {};
21
21
  __export(analytics_exports, {
22
22
  default: () => analytics_default
package/dist/antd.js CHANGED
@@ -33,7 +33,7 @@ var __copyProps = (to, from, except, desc) => {
33
33
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
34
34
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
35
35
 
36
- // antd.ts
36
+ // src/antd.ts
37
37
  var antd_exports = {};
38
38
  __export(antd_exports, {
39
39
  default: () => antd_default
package/dist/dva.js CHANGED
@@ -19,7 +19,7 @@ var __copyProps = (to, from, except, desc) => {
19
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
20
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
21
 
22
- // dva.ts
22
+ // src/dva.ts
23
23
  var dva_exports = {};
24
24
  __export(dva_exports, {
25
25
  default: () => dva_default,
@@ -30,6 +30,7 @@ module.exports = __toCommonJS(dva_exports);
30
30
  var t = __toESM(require("@umijs/bundler-utils/compiled/babel/types"));
31
31
  var import_utils = require("@umijs/utils");
32
32
  var import_path = require("path");
33
+ var import_umi = require("umi");
33
34
  var import_plugin_utils = require("umi/plugin-utils");
34
35
  var import_modelUtils = require("./utils/modelUtils");
35
36
  var import_withTmpPath = require("./utils/withTmpPath");
@@ -65,6 +66,28 @@ var dva_default = (api) => {
65
66
  path: "models.ts",
66
67
  content: import_modelUtils.ModelUtils.getModelsContent(models)
67
68
  });
69
+ api.writeTmpFile({
70
+ path: import_umi.RUNTIME_TYPE_FILE_NAME,
71
+ content: `
72
+ export interface IRuntimeConfig {
73
+ dva?: {
74
+ config?: {
75
+ initialState?: Record<string, any>;
76
+ onError?: any;
77
+ onStateChange?: any;
78
+ onAction?: any;
79
+ onHmr?: any;
80
+ onReducer?: any;
81
+ onEffect?: any;
82
+ extraReducers?: any;
83
+ extraEnhancers?: any;
84
+ [key: string]: any;
85
+ },
86
+ plugins?: string[];
87
+ }
88
+ }
89
+ `
90
+ });
68
91
  api.writeTmpFile({
69
92
  path: "dva.tsx",
70
93
  tpl: `
package/dist/icons.js CHANGED
@@ -16,7 +16,7 @@ var __copyProps = (to, from, except, desc) => {
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
- // icons.ts
19
+ // src/icons.ts
20
20
  var icons_exports = {};
21
21
  __export(icons_exports, {
22
22
  default: () => icons_default
@@ -16,12 +16,13 @@ var __copyProps = (to, from, except, desc) => {
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
- // initial-state.ts
19
+ // src/initial-state.ts
20
20
  var initial_state_exports = {};
21
21
  __export(initial_state_exports, {
22
22
  default: () => initial_state_default
23
23
  });
24
24
  module.exports = __toCommonJS(initial_state_exports);
25
+ var import_umi = require("umi");
25
26
  var import_withTmpPath = require("./utils/withTmpPath");
26
27
  var initial_state_default = (api) => {
27
28
  api.describe({
@@ -132,6 +133,14 @@ import React from 'react';
132
133
  import Provider from './Provider';
133
134
  export function dataflowProvider(container) {
134
135
  return <Provider>{ container }</Provider>;
136
+ }
137
+ `
138
+ });
139
+ api.writeTmpFile({
140
+ path: import_umi.RUNTIME_TYPE_FILE_NAME,
141
+ content: `
142
+ export interface IRuntimeConfig {
143
+ getInitialState?: () => Promise<Record<string, any>>
135
144
  }
136
145
  `
137
146
  });
package/dist/layout.js CHANGED
@@ -19,7 +19,7 @@ var __copyProps = (to, from, except, desc) => {
19
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
20
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
21
 
22
- // layout.ts
22
+ // src/layout.ts
23
23
  var layout_exports = {};
24
24
  __export(layout_exports, {
25
25
  default: () => layout_default
@@ -28,6 +28,7 @@ module.exports = __toCommonJS(layout_exports);
28
28
  var allIcons = __toESM(require("@ant-design/icons"));
29
29
  var import_fs = require("fs");
30
30
  var import_path = require("path");
31
+ var import_umi = require("umi");
31
32
  var import_plugin_utils = require("umi/plugin-utils");
32
33
  var import_withTmpPath = require("./utils/withTmpPath");
33
34
  var layout_default = (api) => {
@@ -247,20 +248,49 @@ const { formatMessage } = useIntl();
247
248
  api.writeTmpFile({
248
249
  path: "types.d.ts",
249
250
  content: `
250
- import type { ProLayoutProps } from "${pkgPath || "@ant-design/pro-layout"}";
251
+ import type { ProLayoutProps, HeaderProps } from "${pkgPath || "@ant-design/pro-layout"}";
251
252
  ${hasInitialStatePlugin ? `import type InitialStateType from '@@/plugin-initialState/@@initialState';
252
253
  type InitDataType = ReturnType<typeof InitialStateType>;
253
254
  ` : "type InitDataType = any;"}
254
255
 
255
- export type RunTimeLayoutConfig = (
256
- initData: InitDataType,
257
- ) => ProLayoutProps & {
258
- childrenRender?: (dom: JSX.Element, props: ProLayoutProps) => React.ReactNode,
259
- noAccessible?: JSX.Element,
260
- notFound?: JSX.Element,
256
+ import type { IConfigFromPlugins } from '@@/core/pluginConfig';
257
+
258
+ export type RunTimeLayoutConfig = (initData: InitDataType) => Omit<
259
+ ProLayoutProps,
260
+ 'rightContentRender'
261
+ > & {
262
+ childrenRender?: (dom: JSX.Element, props: ProLayoutProps) => React.ReactNode;
263
+ unAccessible?: JSX.Element;
264
+ noFound?: JSX.Element;
265
+ logout?: (initialState: InitDataType['initialState']) => Promise<void> | void;
266
+ rightContentRender?: (
267
+ headerProps: HeaderProps,
268
+ dom: JSX.Element,
269
+ props: {
270
+ userConfig: IConfigFromPlugins['layout'];
271
+ runtimeConfig: RunTimeLayoutConfig;
272
+ loading: InitDataType['loading'];
273
+ initialState: InitDataType['initialState'];
274
+ setInitialState: InitDataType['setInitialState'];
275
+ },
276
+ ) => JSX.Element;
277
+ rightRender?: (
278
+ initialState: InitDataType['initialState'],
279
+ setInitialState: InitDataType['setInitialState'],
280
+ runtimeConfig: RunTimeLayoutConfig,
281
+ ) => JSX.Element;
261
282
  };
262
283
  `
263
284
  });
285
+ api.writeTmpFile({
286
+ path: import_umi.RUNTIME_TYPE_FILE_NAME,
287
+ content: `
288
+ import type { RunTimeLayoutConfig } from './types.d';
289
+ export interface IRuntimeConfig {
290
+ layout?: RunTimeLayoutConfig
291
+ }
292
+ `
293
+ });
264
294
  const iconsMap = Object.keys(api.appData.routes).reduce((memo, id) => {
265
295
  const { icon } = api.appData.routes[id];
266
296
  if (icon) {
@@ -560,11 +590,13 @@ const Exception: React.FC<{
560
590
  route?: IRoute;
561
591
  notFound?: React.ReactNode;
562
592
  noAccessible?: React.ReactNode;
593
+ unAccessible?: React.ReactNode;
594
+ noFound?: React.ReactNode;
563
595
  }> = (props) => (
564
596
  // render custom 404
565
- (!props.route && props.notFound) ||
597
+ (!props.route && (props.noFound || props.notFound)) ||
566
598
  // render custom 403
567
- (props.route.unaccessible && props.noAccessible) ||
599
+ (props.route.unaccessible && (props.unAccessible || props.noAccessible)) ||
568
600
  // render default exception
569
601
  ((!props.route || props.route.unaccessible) && (
570
602
  <Result
package/dist/locale.js CHANGED
@@ -36,7 +36,7 @@ var __copyProps = (to, from, except, desc) => {
36
36
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
37
37
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
38
 
39
- // locale.ts
39
+ // src/locale.ts
40
40
  var locale_exports = {};
41
41
  __export(locale_exports, {
42
42
  default: () => locale_default,
@@ -202,8 +202,8 @@ var locale_default = (api) => {
202
202
  api.writeTmpFile({
203
203
  path: "index.ts",
204
204
  content: `
205
- export { addLocale, setLocale, getLocale, getIntl, useIntl, injectIntl, formatMessage, FormattedMessage, getAllLocales } from './localeExports.ts';
206
- export { SelectLang } from './SelectLang.tsx';
205
+ export { addLocale, setLocale, getLocale, getIntl, useIntl, injectIntl, formatMessage, FormattedMessage, getAllLocales, FormattedDate, FormattedDateParts, FormattedDisplayName, FormattedHTMLMessage, FormattedList, FormattedNumber, FormattedNumberParts, FormattedPlural, FormattedRelativeTime, FormattedTime, FormattedTimeParts, IntlProvider, RawIntlProvider } from './localeExports';
206
+ export { SelectLang } from './SelectLang';
207
207
  `
208
208
  });
209
209
  });
package/dist/mf.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import type { IApi } from 'umi';
2
+ export default function mf(api: IApi): void;
package/dist/mf.js ADDED
@@ -0,0 +1,197 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/mf.ts
20
+ var mf_exports = {};
21
+ __export(mf_exports, {
22
+ default: () => mf
23
+ });
24
+ module.exports = __toCommonJS(mf_exports);
25
+ var import_fs = require("fs");
26
+ var import_path = require("path");
27
+ var import_plugin_utils = require("umi/plugin-utils");
28
+ var { isEmpty } = import_plugin_utils.lodash;
29
+ var mfSetupPathFileName = "_mf_setup-public-path.js";
30
+ var mfAsyncEntryFileName = "asyncEntry.ts";
31
+ function mf(api) {
32
+ api.describe({
33
+ key: "mf",
34
+ config: {
35
+ schema(Joi) {
36
+ return Joi.object({
37
+ name: Joi.string(),
38
+ remotes: Joi.array().items(Joi.object({
39
+ aliasName: Joi.string(),
40
+ name: Joi.string().required(),
41
+ entry: Joi.string(),
42
+ entries: Joi.object(),
43
+ keyResolver: Joi.string()
44
+ })),
45
+ shared: Joi.object(),
46
+ library: Joi.object()
47
+ });
48
+ }
49
+ },
50
+ enableBy: api.EnableBy.config
51
+ });
52
+ api.modifyWebpackConfig(async (config, { webpack }) => {
53
+ const exposes = await constructExposes();
54
+ const remotes = formatRemotes();
55
+ const shared = getShared();
56
+ if (isEmpty(remotes) && isEmpty(exposes)) {
57
+ api.logger.warn("ModuleFederation exposes and remotes are empty, plugin will not work");
58
+ return config;
59
+ }
60
+ if (!isEmpty(remotes)) {
61
+ if (!api.config.mfsu) {
62
+ changeUmiEntry(config);
63
+ }
64
+ }
65
+ let name = "_";
66
+ if (!isEmpty(exposes)) {
67
+ name = mfName();
68
+ addMFEntry(config, name, (0, import_path.join)(api.paths.absTmpPath, "plugin-mf", mfSetupPathFileName));
69
+ }
70
+ const mfConfig = {
71
+ name,
72
+ remotes,
73
+ filename: "remote.js",
74
+ exposes,
75
+ shared,
76
+ library: api.config.mf.library
77
+ };
78
+ const { ModuleFederationPlugin } = webpack.container;
79
+ config.plugins.push(new ModuleFederationPlugin(mfConfig));
80
+ api.logger.debug(`ModuleFederationPlugin is enabled with config ${JSON.stringify(mfConfig)}`);
81
+ return config;
82
+ });
83
+ api.onGenerateFiles(() => {
84
+ api.writeTmpFile({
85
+ content: `/* infer remote public */;
86
+ __webpack_public_path__ = document.currentScript.src + '/../';`,
87
+ path: mfSetupPathFileName
88
+ });
89
+ if (api.env === "development" && api.config.mfsu) {
90
+ return;
91
+ }
92
+ api.writeTmpFile({
93
+ content: `import('${(0, import_plugin_utils.winPath)((0, import_path.join)(api.paths.absTmpPath, "umi.ts"))}')`,
94
+ path: mfAsyncEntryFileName
95
+ });
96
+ });
97
+ function formatRemotes() {
98
+ const { remotes = [] } = api.config.mf;
99
+ const memo = {};
100
+ remotes.forEach((remote) => {
101
+ const aliasName = remote.aliasName || remote.name;
102
+ const r = formatRemote(remote);
103
+ if (memo[aliasName]) {
104
+ return api.logger.error(`${aliasName} already set as ${memo[aliasName]}, new value ${r} will be ignored`);
105
+ }
106
+ memo[aliasName] = r;
107
+ });
108
+ return memo;
109
+ }
110
+ function formatRemote(remote) {
111
+ if (remote.entry) {
112
+ return `${remote.name}@${remote.entry}`;
113
+ }
114
+ if (remote.entries && remote.keyResolver) {
115
+ const dynamicUrl = `promise new Promise(resolve => {
116
+ const entries = ${JSON.stringify(remote.entries)};
117
+ const key = ${remote.keyResolver};
118
+
119
+ const remoteUrlWithVersion = entries[key];
120
+ const script = document.createElement('script')
121
+ script.src = remoteUrlWithVersion
122
+ script.onload = () => {
123
+ // the injected script has loaded and is available on window
124
+ // we can now resolve this Promise
125
+ const proxy = {
126
+ get: (request) => window.${remote.name}.get(request),
127
+ init: (arg) => {
128
+ try {
129
+ return window.${remote.name}.init(arg)
130
+ } catch(e) {
131
+ console.log('remote container already initialized')
132
+ }
133
+ }
134
+ }
135
+ resolve(proxy)
136
+ }
137
+ // inject this script with the src set to the versioned remoteEntry.js
138
+ document.head.appendChild(script);
139
+ })
140
+ `;
141
+ return dynamicUrl;
142
+ } else {
143
+ api.logger.error("you should provider entry or entries and keyResolver");
144
+ throw Error("Wrong MF#remotes config");
145
+ }
146
+ }
147
+ async function constructExposes() {
148
+ const exposes = {};
149
+ const exposesPath = (0, import_path.join)(api.paths.absSrcPath, "exposes");
150
+ if (!(0, import_fs.existsSync)(exposesPath)) {
151
+ return exposes;
152
+ }
153
+ const dir = (0, import_fs.opendirSync)(exposesPath);
154
+ for await (const dirent of dir) {
155
+ if (dirent.isDirectory()) {
156
+ exposes["./" + dirent.name] = (0, import_plugin_utils.winPath)((0, import_path.join)(api.paths.absSrcPath, "exposes", dirent.name));
157
+ } else {
158
+ api.logger.warn(`${dirent.name} is not a directory, ignore in ModuleFederation expose`);
159
+ }
160
+ }
161
+ return exposes;
162
+ }
163
+ function mfName() {
164
+ const name = api.config.mf.name;
165
+ if (!name) {
166
+ api.logger.warn(`module federation name is not defined , "unNamedMF" will be used`);
167
+ }
168
+ return name || "unNamedMF";
169
+ }
170
+ function getShared() {
171
+ const { shared = {} } = api.config.mf;
172
+ return shared;
173
+ }
174
+ function changeUmiEntry(config) {
175
+ const { entry } = config;
176
+ const asyncEntryPath = (0, import_plugin_utils.winPath)((0, import_path.join)(api.paths.absTmpPath, "plugin-mf", mfAsyncEntryFileName));
177
+ if (entry.umi) {
178
+ if (typeof entry.umi === "string") {
179
+ entry.umi = asyncEntryPath;
180
+ } else if (Array.isArray(entry.umi)) {
181
+ const i = entry.umi.findIndex((f) => f.endsWith("umi.ts"));
182
+ if (i >= 0) {
183
+ entry.umi[i] = asyncEntryPath;
184
+ } else {
185
+ api.logger.info(`umi.ts not found in entry.umi ${JSON.stringify(entry.umi)}`);
186
+ }
187
+ }
188
+ } else {
189
+ api.logger.warn("umi entry not found");
190
+ }
191
+ }
192
+ function addMFEntry(config, mfName2, path) {
193
+ config.entry[mfName2] = path;
194
+ }
195
+ }
196
+ // Annotate the CommonJS export names for ESM import in node:
197
+ 0 && (module.exports = {});
package/dist/model.js CHANGED
@@ -19,7 +19,7 @@ var __copyProps = (to, from, except, desc) => {
19
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
20
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
21
 
22
- // model.ts
22
+ // src/model.ts
23
23
  var model_exports = {};
24
24
  __export(model_exports, {
25
25
  default: () => model_default
@@ -19,7 +19,7 @@ var __copyProps = (to, from, except, desc) => {
19
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
20
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
21
 
22
- // moment2dayjs.ts
22
+ // src/moment2dayjs.ts
23
23
  var moment2dayjs_exports = {};
24
24
  __export(moment2dayjs_exports, {
25
25
  default: () => moment2dayjs_default
@@ -16,7 +16,7 @@ var __copyProps = (to, from, except, desc) => {
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
- // constants.ts
19
+ // src/qiankun/constants.ts
20
20
  var constants_exports = {};
21
21
  __export(constants_exports, {
22
22
  MODEL_EXPORT_NAME: () => MODEL_EXPORT_NAME,
@@ -36,7 +36,7 @@ var __copyProps = (to, from, except, desc) => {
36
36
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
37
37
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
38
 
39
- // master.ts
39
+ // src/qiankun/master.ts
40
40
  var master_exports = {};
41
41
  __export(master_exports, {
42
42
  default: () => master_default,
@@ -45,6 +45,7 @@ __export(master_exports, {
45
45
  module.exports = __toCommonJS(master_exports);
46
46
  var import_fs = require("fs");
47
47
  var import_path = require("path");
48
+ var import_umi = require("umi");
48
49
  var import_plugin_utils = require("umi/plugin-utils");
49
50
  var import_withTmpPath = require("../utils/withTmpPath");
50
51
  var import_constants = require("./constants");
@@ -103,6 +104,21 @@ var master_default = (api) => {
103
104
  }
104
105
  api.onGenerateFiles(() => {
105
106
  var _a;
107
+ api.writeTmpFile({
108
+ path: import_umi.RUNTIME_TYPE_FILE_NAME,
109
+ content: `
110
+ import { MasterOptions } from './types'
111
+ type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };
112
+ type XOR<T, U> = (Without<T, U> & U) | (Without<U, T> & T);
113
+ interface Config {
114
+ master?: MasterOptions;
115
+ }
116
+ export interface IRuntimeConfig {
117
+ qiankun?: XOR<MasterOptions, Config>;
118
+ ${import_constants.MODEL_EXPORT_NAME}?: () => Record<string, any>;
119
+ }
120
+ `
121
+ });
106
122
  api.writeTmpFile({
107
123
  path: "masterOptions.ts",
108
124
  content: `
@@ -36,7 +36,7 @@ var __copyProps = (to, from, except, desc) => {
36
36
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
37
37
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
38
 
39
- // slave.ts
39
+ // src/qiankun/slave.ts
40
40
  var slave_exports = {};
41
41
  __export(slave_exports, {
42
42
  default: () => slave_default
@@ -45,6 +45,7 @@ module.exports = __toCommonJS(slave_exports);
45
45
  var import_assert = __toESM(require("assert"));
46
46
  var import_fs = require("fs");
47
47
  var import_path = require("path");
48
+ var import_umi = require("umi");
48
49
  var import_plugin_utils = require("umi/plugin-utils");
49
50
  var import_withTmpPath = require("../utils/withTmpPath");
50
51
  var import_constants = require("./constants");
@@ -75,6 +76,30 @@ var slave_default = (api) => {
75
76
  ];
76
77
  }
77
78
  });
79
+ api.onGenerateFiles(() => {
80
+ api.writeTmpFile({
81
+ path: import_umi.RUNTIME_TYPE_FILE_NAME,
82
+ content: `
83
+ interface LifeCycles {
84
+ bootstrap?: (props?: any) => Promise<any>;
85
+ mount?: (props?: any) => Promise<any>;
86
+ unmount?: (props?: any) => Promise<any>;
87
+ update?: (props?: any) => Promise<any>;
88
+ }
89
+ type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };
90
+ type XOR<T, U> = (Without<T, U> & U) | (Without<U, T> & T);
91
+ interface SlaveOption extends LifeCycles {
92
+ enable?: boolean;
93
+ }
94
+ interface Config {
95
+ slave?: SlaveOption;
96
+ }
97
+ export interface IRuntimeConfig {
98
+ qiankun?: XOR<Config, LifeCycles>
99
+ }
100
+ `
101
+ });
102
+ });
78
103
  api.modifyDefaultConfig((memo) => {
79
104
  var _a, _b, _c;
80
105
  const initialSlaveOptions = __spreadValues(__spreadValues({
package/dist/qiankun.js CHANGED
@@ -19,7 +19,7 @@ var __copyProps = (to, from, except, desc) => {
19
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
20
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
21
 
22
- // qiankun.ts
22
+ // src/qiankun.ts
23
23
  var qiankun_exports = {};
24
24
  __export(qiankun_exports, {
25
25
  default: () => qiankun_default
package/dist/request.js CHANGED
@@ -19,13 +19,14 @@ var __copyProps = (to, from, except, desc) => {
19
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
20
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
21
 
22
- // request.ts
22
+ // src/request.ts
23
23
  var request_exports = {};
24
24
  __export(request_exports, {
25
25
  default: () => request_default
26
26
  });
27
27
  module.exports = __toCommonJS(request_exports);
28
28
  var import_path = require("path");
29
+ var import_umi = require("umi");
29
30
  var import_plugin_utils = require("umi/plugin-utils");
30
31
  var request_default = (api) => {
31
32
  api.describe({
@@ -153,7 +154,7 @@ interface IErrorHandler {
153
154
  }
154
155
  type IRequestInterceptorAxios = (config: RequestOptions) => RequestOptions;
155
156
  type IRequestInterceptorUmiRequest = (url: string, config : RequestOptions) => { url: string, options: RequestOptions };
156
- type IRequestInterceptor = IRequestInterceptorAxios;
157
+ type IRequestInterceptor = IRequestInterceptorAxios | IRequestInterceptorUmiRequest;
157
158
  type IErrorInterceptor = (error: Error) => Promise<Error>;
158
159
  type IResponseInterceptor = <T = any>(response : AxiosResponse<T>) => AxiosResponse<T> ;
159
160
  type IRequestInterceptorTuple = [IRequestInterceptor , IErrorInterceptor] | [ IRequestInterceptor ] | IRequestInterceptor
@@ -344,6 +345,15 @@ export {
344
345
  } from './request';
345
346
  `
346
347
  });
348
+ api.writeTmpFile({
349
+ path: import_umi.RUNTIME_TYPE_FILE_NAME,
350
+ content: `
351
+ import type { RequestConfig } from './types.d'
352
+ export type IRuntimeConfig = {
353
+ request?: RequestConfig
354
+ };
355
+ `
356
+ });
347
357
  });
348
358
  };
349
359
  // Annotate the CommonJS export names for ESM import in node:
@@ -16,7 +16,7 @@ var __copyProps = (to, from, except, desc) => {
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
- // tailwindcss.ts
19
+ // src/tailwindcss.ts
20
20
  var tailwindcss_exports = {};
21
21
  __export(tailwindcss_exports, {
22
22
  default: () => tailwindcss_default
@@ -40,15 +40,19 @@ var tailwindcss_default = (api) => {
40
40
  const inputPath = (0, import_path.join)(api.cwd, "tailwind.css");
41
41
  const generatedPath = (0, import_path.join)(api.paths.absTmpPath, outputPath);
42
42
  const binPath = (0, import_path.join)(api.cwd, "node_modules/.bin/tailwind");
43
+ const configPath = (0, import_path.join)(process.env.APP_ROOT || api.cwd, "tailwind.config.js");
43
44
  return new Promise((resolve) => {
44
45
  tailwind = (0, import_plugin_utils.crossSpawn)(`${binPath}`, [
46
+ "-c",
47
+ configPath,
45
48
  "-i",
46
49
  inputPath,
47
50
  "-o",
48
51
  generatedPath,
49
52
  api.env === "development" ? "--watch" : ""
50
53
  ], {
51
- stdio: "inherit"
54
+ stdio: "inherit",
55
+ cwd: process.env.APP_ROOT || api.cwd
52
56
  });
53
57
  tailwind.on("error", (m) => {
54
58
  api.logger.error("tailwindcss service encounter an error: " + m);
package/dist/unocss.js CHANGED
@@ -16,7 +16,7 @@ var __copyProps = (to, from, except, desc) => {
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
- // unocss.ts
19
+ // src/unocss.ts
20
20
  var unocss_exports = {};
21
21
  __export(unocss_exports, {
22
22
  default: () => unocss_default
@@ -19,7 +19,7 @@ var __copyProps = (to, from, except, desc) => {
19
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
20
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
21
 
22
- // astUtils.ts
22
+ // src/utils/astUtils.ts
23
23
  var astUtils_exports = {};
24
24
  __export(astUtils_exports, {
25
25
  getIdentifierDeclaration: () => getIdentifierDeclaration
@@ -16,7 +16,7 @@ var __copyProps = (to, from, except, desc) => {
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
- // localeUtils.ts
19
+ // src/utils/localeUtils.ts
20
20
  var localeUtils_exports = {};
21
21
  __export(localeUtils_exports, {
22
22
  exactLocalePaths: () => exactLocalePaths,
@@ -19,7 +19,7 @@ var __copyProps = (to, from, except, desc) => {
19
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
20
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
21
 
22
- // modelUtils.ts
22
+ // src/utils/modelUtils.ts
23
23
  var modelUtils_exports = {};
24
24
  __export(modelUtils_exports, {
25
25
  Model: () => Model,
@@ -16,7 +16,7 @@ var __copyProps = (to, from, except, desc) => {
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
- // resolveProjectDep.ts
19
+ // src/utils/resolveProjectDep.ts
20
20
  var resolveProjectDep_exports = {};
21
21
  __export(resolveProjectDep_exports, {
22
22
  resolveProjectDep: () => resolveProjectDep
@@ -16,7 +16,7 @@ var __copyProps = (to, from, except, desc) => {
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
- // withTmpPath.ts
19
+ // src/utils/withTmpPath.ts
20
20
  var withTmpPath_exports = {};
21
21
  __export(withTmpPath_exports, {
22
22
  withTmpPath: () => withTmpPath
@@ -262,6 +262,9 @@ http://j.mp/37Fkd5Q
262
262
  );
263
263
  firstWaring = false;
264
264
  }
265
+ if (!g_intl) {
266
+ setIntl(getLocale());
267
+ }
265
268
  return g_intl.formatMessage(descriptor, values);
266
269
  };
267
270
 
@@ -100,13 +100,18 @@ export function patchMicroAppRoute(
100
100
  const recursiveSearch = (
101
101
  routes: IRouteProps[],
102
102
  path: string,
103
- ): IRouteProps | null => {
103
+ parentPath: string,
104
+ ): [IRouteProps, IRouteProps[], number, string] | null => {
104
105
  for (let i = 0; i < routes.length; i++) {
105
106
  if (routes[i].path === path) {
106
- return routes[i];
107
+ return [routes[i], routes, i, parentPath];
107
108
  }
108
109
  if (routes[i].children && routes[i].children?.length) {
109
- const found = recursiveSearch(routes[i].children || [], path);
110
+ const found = recursiveSearch(
111
+ routes[i].children || [],
112
+ path,
113
+ routes[i].path,
114
+ );
110
115
  if (found) {
111
116
  return found;
112
117
  }
@@ -116,23 +121,48 @@ const recursiveSearch = (
116
121
  };
117
122
 
118
123
  export function insertRoute(routes: IRouteProps[], microAppRoute: IRouteProps) {
119
- const found = recursiveSearch(routes, microAppRoute.insert);
124
+ const mod =
125
+ microAppRoute.appendChildTo || microAppRoute.insert
126
+ ? 'appendChildTo'
127
+ : microAppRoute.insertBefore
128
+ ? 'insertBefore'
129
+ : undefined;
130
+ const target =
131
+ microAppRoute.appendChildTo ||
132
+ microAppRoute.insert ||
133
+ microAppRoute.insertBefore;
134
+ const [found, foundParentRoutes = [], index = 0, parentPath] =
135
+ recursiveSearch(routes, target, '/') || [];
120
136
  if (found) {
121
- if (
122
- !microAppRoute.path ||
123
- !found.path ||
124
- !microAppRoute.path.startsWith(found.path)
125
- ) {
126
- throw new Error(
127
- `[plugin-qiankun]: path "${microAppRoute.path}" need to starts with "${found.path}"`,
128
- );
137
+ switch (mod) {
138
+ case 'appendChildTo':
139
+ if (
140
+ !microAppRoute.path ||
141
+ !found.path ||
142
+ !microAppRoute.path.startsWith(found.path)
143
+ ) {
144
+ throw new Error(
145
+ `[plugin-qiankun]: path "${microAppRoute.path}" need to starts with "${found.path}"`,
146
+ );
147
+ }
148
+ found.exact = false;
149
+ found.children = found.children || [];
150
+ found.children.push(microAppRoute);
151
+ break;
152
+ case 'insertBefore':
153
+ if (
154
+ !microAppRoute.path ||
155
+ !found.path ||
156
+ !microAppRoute.path.startsWith(parentPath)
157
+ ) {
158
+ throw new Error(
159
+ `[plugin-qiankun]: path "${microAppRoute.path}" need to starts with "${parentPath}"`,
160
+ );
161
+ }
162
+ foundParentRoutes.splice(index, 0, microAppRoute);
163
+ break;
129
164
  }
130
- found.exact = false;
131
- found.children = found.children || [];
132
- found.children.push(microAppRoute);
133
165
  } else {
134
- throw new Error(
135
- `[plugin-qiankun]: path "${microAppRoute.insert}" not found`,
136
- );
166
+ throw new Error(`[plugin-qiankun]: path "${target}" not found`);
137
167
  }
138
168
  }
@@ -24,7 +24,9 @@ async function getMasterRuntime() {
24
24
 
25
25
  // modify route with "microApp" attribute to use real component
26
26
  function patchMicroAppRouteComponent(routes: any[]) {
27
- const insertRoutes = microAppRuntimeRoutes.filter((r) => r.insert);
27
+ const insertRoutes = microAppRuntimeRoutes.filter(
28
+ (r) => r.insert || r.insertBefore || r.appendChildTo,
29
+ );
28
30
  // 先处理 insert 配置
29
31
  insertRoutes.forEach((route) => {
30
32
  insertRoute(routes, route);
@@ -60,7 +62,13 @@ function patchMicroAppRouteComponent(routes: any[]) {
60
62
  };
61
63
 
62
64
  patchRoute(microAppRoute);
63
- !microAppRoute.insert && rootRoutes.unshift(microAppRoute);
65
+ if (
66
+ !microAppRoute.insert &&
67
+ !microAppRoute.insertBefore &&
68
+ !microAppRoute.appendChildTo
69
+ ) {
70
+ rootRoutes.unshift(microAppRoute);
71
+ }
64
72
  });
65
73
  }
66
74
  }
@@ -13,7 +13,7 @@ export type App = {
13
13
  // 取 entry 时是否需要开启跨域 credentials
14
14
  credentials?: boolean;
15
15
  props?: any;
16
- } & Pick<BaseIConfig, 'mountElementId'>;
16
+ } & Partial<Pick<BaseIConfig, 'mountElementId'>>;
17
17
 
18
18
  export type MicroAppRoute = {
19
19
  path: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/plugins",
3
- "version": "4.0.9",
3
+ "version": "4.0.12",
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",
@@ -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": "^7.0.1-beta.28",
28
- "@umijs/bundler-utils": "4.0.9",
28
+ "@umijs/bundler-utils": "4.0.12",
29
29
  "antd-dayjs-webpack-plugin": "^1.0.6",
30
30
  "axios": "^0.27.2",
31
31
  "babel-plugin-import": "^1.13.5",
@@ -44,7 +44,7 @@
44
44
  "warning": "^4.0.3"
45
45
  },
46
46
  "devDependencies": {
47
- "umi": "4.0.9"
47
+ "umi": "4.0.12"
48
48
  },
49
49
  "publishConfig": {
50
50
  "access": "public"