@umijs/plugins 4.0.0-rc.18 → 4.0.0-rc.20

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
@@ -24,9 +24,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  const allIcons = __importStar(require("@ant-design/icons"));
27
+ const fs_1 = require("fs");
27
28
  const path_1 = require("path");
28
29
  const plugin_utils_1 = require("umi/plugin-utils");
29
- const resolveProjectDep_1 = require("./utils/resolveProjectDep");
30
30
  const withTmpPath_1 = require("./utils/withTmpPath");
31
31
  exports.default = (api) => {
32
32
  api.describe({
@@ -39,11 +39,28 @@ exports.default = (api) => {
39
39
  },
40
40
  enableBy: api.EnableBy.config,
41
41
  });
42
- const pkgPath = (0, resolveProjectDep_1.resolveProjectDep)({
43
- pkg: api.pkg,
44
- cwd: api.cwd,
45
- dep: '@ant-design/pro-layout',
46
- }) || (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();
47
64
  api.modifyAppData((memo) => {
48
65
  const version = require(`${pkgPath}/package.json`).version;
49
66
  memo.pluginLayout = {
@@ -53,8 +70,11 @@ exports.default = (api) => {
53
70
  return memo;
54
71
  });
55
72
  api.modifyConfig((memo) => {
56
- // import from @ant-design/pro-layout
57
- 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
+ }
58
78
  return memo;
59
79
  });
60
80
  api.onGenerateFiles(() => {
@@ -65,9 +85,9 @@ exports.default = (api) => {
65
85
  content: `
66
86
  import { Link, useLocation, useNavigate, Outlet, useAppData, useRouteData, matchRoutes } from 'umi';
67
87
  import { useMemo } from 'react';
68
- import ProLayout, {
69
- PageLoading,
70
- } from '@ant-design/pro-layout';
88
+ import {
89
+ ProLayout,
90
+ } from "${pkgHasDep || '@ant-design/pro-layout'}";
71
91
  import './Layout.less';
72
92
  import Logo from './Logo';
73
93
  import Exception from './Exception';
@@ -34,16 +34,14 @@ exports.default = (api) => {
34
34
  },
35
35
  },
36
36
  }));
37
- // TODO: modify routes
38
37
  api.modifyRoutes((memo) => {
39
38
  Object.keys(memo).forEach((id) => {
39
+ var _a;
40
40
  const route = memo[id];
41
41
  if (route.microApp) {
42
42
  const appName = route.microApp;
43
- // TODO: config base
44
- const base = '/';
45
- // TODO: config masterHistoryType
46
- const masterHistoryType = 'browser';
43
+ const base = api.config.base || '/';
44
+ const masterHistoryType = ((_a = api.config.history) === null || _a === void 0 ? void 0 : _a.type) || 'browser';
47
45
  const routeProps = route.microAppProps || {};
48
46
  const normalizedRouteProps = JSON.stringify(routeProps).replace(/"/g, "'");
49
47
  route.file = `(async () => {
@@ -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-rc.18",
3
+ "version": "4.0.0-rc.20",
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-rc.18",
28
+ "@umijs/bundler-utils": "4.0.0-rc.20",
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-rc.18"
47
+ "umi": "4.0.0-rc.20"
48
48
  },
49
49
  "publishConfig": {
50
50
  "access": "public"