@umijs/plugins 4.0.0-canary.20220516.3 → 4.0.0-canary.20220525.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/layout.js CHANGED
@@ -22,15 +22,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
25
  Object.defineProperty(exports, "__esModule", { value: true });
29
26
  const allIcons = __importStar(require("@ant-design/icons"));
30
- const assert_1 = __importDefault(require("assert"));
27
+ const fs_1 = require("fs");
31
28
  const path_1 = require("path");
32
29
  const plugin_utils_1 = require("umi/plugin-utils");
33
- const resolveProjectDep_1 = require("./utils/resolveProjectDep");
34
30
  const withTmpPath_1 = require("./utils/withTmpPath");
35
31
  exports.default = (api) => {
36
32
  api.describe({
@@ -43,11 +39,28 @@ exports.default = (api) => {
43
39
  },
44
40
  enableBy: api.EnableBy.config,
45
41
  });
46
- const pkgPath = (0, resolveProjectDep_1.resolveProjectDep)({
47
- pkg: api.pkg,
48
- cwd: api.cwd,
49
- dep: '@ant-design/pro-layout',
50
- }) || (0, path_1.dirname)(require.resolve('@ant-design/pro-layout/package.json'));
42
+ /**
43
+ * 优先去找 '@alipay/tech-ui',保证稳定性
44
+ */
45
+ const depList = ['@alipay/tech-ui', '@ant-design/pro-layout'];
46
+ const pkgHasDep = depList.find((dep) => {
47
+ var _a, _b;
48
+ const { pkg } = api;
49
+ if (((_a = pkg.dependencies) === null || _a === void 0 ? void 0 : _a[dep]) || ((_b = pkg.devDependencies) === null || _b === void 0 ? void 0 : _b[dep])) {
50
+ return true;
51
+ }
52
+ return false;
53
+ });
54
+ const getPkgPath = () => {
55
+ // 如果 layout 和 techui至少有一个在,找到他们的地址
56
+ if (pkgHasDep &&
57
+ (0, fs_1.existsSync)((0, path_1.join)(api.cwd, 'node_modules', pkgHasDep, 'package.json'))) {
58
+ return (0, path_1.join)(api.cwd, 'node_modules', pkgHasDep);
59
+ }
60
+ // 如果项目中没有去找插件以来的
61
+ return (0, path_1.dirname)(require.resolve('@ant-design/pro-layout/package.json'));
62
+ };
63
+ const pkgPath = getPkgPath();
51
64
  api.modifyAppData((memo) => {
52
65
  const version = require(`${pkgPath}/package.json`).version;
53
66
  memo.pluginLayout = {
@@ -57,8 +70,11 @@ exports.default = (api) => {
57
70
  return memo;
58
71
  });
59
72
  api.modifyConfig((memo) => {
60
- // import from @ant-design/pro-layout
61
- memo.alias['@ant-design/pro-layout'] = pkgPath;
73
+ // 只在没有自行依赖 @ant-design/pro-layout 或 @alipay/tech-ui 时
74
+ // 才使用插件中提供的 @ant-design/pro-layout
75
+ if (!pkgHasDep) {
76
+ memo.alias['@ant-design/pro-layout'] = pkgPath;
77
+ }
62
78
  return memo;
63
79
  });
64
80
  api.onGenerateFiles(() => {
@@ -69,9 +85,9 @@ exports.default = (api) => {
69
85
  content: `
70
86
  import { Link, useLocation, useNavigate, Outlet, useAppData, useRouteData, matchRoutes } from 'umi';
71
87
  import { useMemo } from 'react';
72
- import ProLayout, {
73
- PageLoading,
74
- } from '@ant-design/pro-layout';
88
+ import {
89
+ ProLayout,
90
+ } from "${pkgHasDep || '@ant-design/pro-layout'}";
75
91
  import './Layout.less';
76
92
  import Logo from './Logo';
77
93
  import Exception from './Exception';
@@ -191,9 +207,6 @@ const { formatMessage } = useIntl();
191
207
  const { icon } = api.appData.routes[id];
192
208
  if (icon) {
193
209
  const upperIcon = plugin_utils_1.lodash.upperFirst(plugin_utils_1.lodash.camelCase(icon));
194
- (0, assert_1.default)(
195
- // @ts-ignore
196
- allIcons[upperIcon] || allIcons[`${upperIcon}Outlined`], `Icon ${upperIcon} is not found`);
197
210
  // @ts-ignore
198
211
  if (allIcons[upperIcon]) {
199
212
  memo[upperIcon] = true;
@@ -238,7 +251,9 @@ export function patchRoutes({ routes }) {
238
251
  const { icon } = routes[key];
239
252
  if (icon && typeof icon === 'string') {
240
253
  const upperIcon = formatIcon(icon);
241
- routes[key].icon = React.createElement(icons[upperIcon] || icons[upperIcon + 'Outlined']);
254
+ if (icons[upperIcon] || icons[upperIcon + 'Outlined']) {
255
+ routes[key].icon = React.createElement(icons[upperIcon] || icons[upperIcon + 'Outlined']);
256
+ }
242
257
  }
243
258
  });
244
259
  }
@@ -74,8 +74,8 @@ exports.default = (api) => {
74
74
  return config;
75
75
  });
76
76
  api.addHTMLHeadScripts(() => {
77
- var _a;
78
- const dontModify = (_a = api.config.qiankun) === null || _a === void 0 ? void 0 : _a.shouldNotModifyRuntimePublicPath;
77
+ var _a, _b;
78
+ const dontModify = (_b = (_a = api.config.qiankun) === null || _a === void 0 ? void 0 : _a.slave) === null || _b === void 0 ? void 0 : _b.shouldNotModifyRuntimePublicPath;
79
79
  return dontModify
80
80
  ? []
81
81
  : [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/plugins",
3
- "version": "4.0.0-canary.20220516.3",
3
+ "version": "4.0.0-canary.20220525.1",
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.38.0",
28
- "@umijs/bundler-utils": "4.0.0-canary.20220516.3",
28
+ "@umijs/bundler-utils": "4.0.0-canary.20220525.1",
29
29
  "antd-dayjs-webpack-plugin": "^1.0.6",
30
30
  "axios": "^0.27.2",
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-canary.20220516.3"
47
+ "umi": "4.0.0-canary.20220525.1"
48
48
  },
49
49
  "publishConfig": {
50
50
  "access": "public"