@umijs/plugins 4.0.0-canary.20220729.1 → 4.0.0-canary.20220810.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.
package/dist/dva.js CHANGED
@@ -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: `
@@ -22,6 +22,7 @@ __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
@@ -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) => {
@@ -251,15 +252,16 @@ const { formatMessage } = useIntl();
251
252
  ${hasInitialStatePlugin ? `import type InitialStateType from '@@/plugin-initialState/@@initialState';
252
253
  type InitDataType = ReturnType<typeof InitialStateType>;
253
254
  ` : "type InitDataType = any;"}
254
- import { IConfigFromPlugins } from '@@/core/pluginConfig';
255
-
255
+
256
+ import type { IConfigFromPlugins } from '@@/core/pluginConfig';
257
+
256
258
  export type RunTimeLayoutConfig = (initData: InitDataType) => Omit<
257
259
  ProLayoutProps,
258
260
  'rightContentRender'
259
261
  > & {
260
262
  childrenRender?: (dom: JSX.Element, props: ProLayoutProps) => React.ReactNode;
261
- noAccessible?: JSX.Element;
262
- notFound?: JSX.Element;
263
+ unAccessible?: JSX.Element;
264
+ noFound?: JSX.Element;
263
265
  logout?: (initialState: InitDataType['initialState']) => Promise<void> | void;
264
266
  rightContentRender?: (
265
267
  headerProps: HeaderProps,
@@ -280,6 +282,15 @@ const { formatMessage } = useIntl();
280
282
  };
281
283
  `
282
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
+ });
283
294
  const iconsMap = Object.keys(api.appData.routes).reduce((memo, id) => {
284
295
  const { icon } = api.appData.routes[id];
285
296
  if (icon) {
@@ -579,11 +590,13 @@ const Exception: React.FC<{
579
590
  route?: IRoute;
580
591
  notFound?: React.ReactNode;
581
592
  noAccessible?: React.ReactNode;
593
+ unAccessible?: React.ReactNode;
594
+ noFound?: React.ReactNode;
582
595
  }> = (props) => (
583
596
  // render custom 404
584
- (!props.route && props.notFound) ||
597
+ (!props.route && (props.noFound || props.notFound)) ||
585
598
  // render custom 403
586
- (props.route.unaccessible && props.noAccessible) ||
599
+ (props.route.unaccessible && (props.unAccessible || props.noAccessible)) ||
587
600
  // render default exception
588
601
  ((!props.route || props.route.unaccessible) && (
589
602
  <Result
package/dist/locale.js CHANGED
@@ -202,7 +202,7 @@ 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';
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
206
  export { SelectLang } from './SelectLang';
207
207
  `
208
208
  });
@@ -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: `
@@ -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/request.js CHANGED
@@ -26,6 +26,7 @@ __export(request_exports, {
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({
@@ -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:
@@ -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);
@@ -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.0-canary.20220729.1",
3
+ "version": "4.0.0-canary.20220810.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",
@@ -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.0-canary.20220729.1",
28
+ "@umijs/bundler-utils": "4.0.0-canary.20220810.1",
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.0-canary.20220729.1"
47
+ "umi": "4.0.0-canary.20220810.1"
48
48
  },
49
49
  "publishConfig": {
50
50
  "access": "public"