@umijs/plugins 4.0.0-rc.9 → 4.0.2

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/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,8 @@ 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);
54
- memo.pluginModel = {
55
- models,
56
- };
57
- return memo;
58
- }));
59
- api.onGenerateFiles((args) => __awaiter(void 0, void 0, void 0, function* () {
60
- const models = args.isFirstTime
61
- ? api.appData.pluginModel.models
62
- : yield getAllModels(api);
43
+ api.onGenerateFiles(async () => {
44
+ const models = await getAllModels(api);
63
45
  // model.ts
64
46
  api.writeTmpFile({
65
47
  path: 'model.ts',
@@ -94,7 +76,7 @@ export function dataflowProvider(container, opts) {
94
76
  }
95
77
  `,
96
78
  });
97
- }));
79
+ });
98
80
  api.addTmpGenerateWatcherPaths(() => {
99
81
  return [(0, path_1.join)(api.paths.absSrcPath, 'models')];
100
82
  });
@@ -102,19 +84,18 @@ export function dataflowProvider(container, opts) {
102
84
  return [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })];
103
85
  });
104
86
  };
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
- });
87
+ async function getAllModels(api) {
88
+ const extraModels = await api.applyPlugins({
89
+ key: 'addExtraModels',
90
+ type: api.ApplyPluginsType.add,
91
+ initialValue: [],
92
+ });
93
+ return new modelUtils_1.ModelUtils(api, {
94
+ astTest({ node }) {
95
+ return t.isArrowFunctionExpression(node) || t.isFunctionDeclaration(node);
96
+ },
97
+ }).getAllModels({
98
+ sort: {},
99
+ extraModels: [...extraModels, ...(api.config.model.extraModels || [])],
119
100
  });
120
101
  }
@@ -23,22 +23,30 @@ 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) }) })));
27
- // TODO: modify routes
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
+ }));
28
37
  api.modifyRoutes((memo) => {
29
38
  Object.keys(memo).forEach((id) => {
39
+ var _a;
30
40
  const route = memo[id];
31
41
  if (route.microApp) {
32
42
  const appName = route.microApp;
33
- // TODO: config base
34
- const base = '/';
35
- // TODO: config masterHistoryType
36
- 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';
37
45
  const routeProps = route.microAppProps || {};
38
46
  const normalizedRouteProps = JSON.stringify(routeProps).replace(/"/g, "'");
39
47
  route.file = `(async () => {
40
48
  const { getMicroAppRouteComponent } = await import('@@/plugin-qiankun-master/getMicroAppRouteComponent');
41
- return getMicroAppRouteComponent({ appName: '${appName}', base: '${base}', masterHistoryType: '${masterHistoryType}', routeProps: ${normalizedRouteProps} })
49
+ return getMicroAppRouteComponent({ appName: '${appName}', base: '${base}', routePath: '${route.path}', masterHistoryType: '${masterHistoryType}', routeProps: ${normalizedRouteProps} })
42
50
  })()`;
43
51
  }
44
52
  });
@@ -65,7 +73,11 @@ exports.default = (api) => {
65
73
  api.writeTmpFile({
66
74
  path: 'masterOptions.ts',
67
75
  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))};
76
+ let options = ${JSON.stringify({
77
+ masterHistoryType: ((_a = api.config.history) === null || _a === void 0 ? void 0 : _a.type) || constants_1.defaultHistoryType,
78
+ base: api.config.base || '/',
79
+ ...api.config.qiankun.master,
80
+ })};
69
81
  export const getMasterOptions = () => options;
70
82
  export const setMasterOptions = (newOpts) => options = ({ ...options, ...newOpts });
71
83
  `,
@@ -91,7 +103,6 @@ export const setMasterOptions = (newOpts) => options = ({ ...options, ...newOpts
91
103
  path: file.replace(/\.tpl$/, ''),
92
104
  tpl: getFileContent(file),
93
105
  context: {
94
- runtimeHistory: api.config.runtimeHistory,
95
106
  dynamicRoot: false,
96
107
  hasModelPlugin: api.isPluginEnable('model'),
97
108
  // dynamicRoot:
@@ -100,16 +111,25 @@ export const setMasterOptions = (newOpts) => options = ({ ...options, ...newOpts
100
111
  });
101
112
  }
102
113
  else {
114
+ let content = getFileContent(file);
115
+ if (!api.config.qiankun.externalQiankun) {
116
+ content = content.replace(/from 'qiankun'/g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('qiankun/package')))}'`);
117
+ }
103
118
  api.writeTmpFile({
104
119
  path: file.replace(/\.tpl$/, ''),
105
- content: getFileContent(file)
120
+ content: content
106
121
  .replace('__USE_MODEL__', api.isPluginEnable('model')
107
122
  ? `import { useModel } from '@@/plugin-model'`
108
123
  : `const useModel = null;`)
109
- .replace(/from 'qiankun'/g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('qiankun/package')))}'`)
110
124
  .replace(/from 'lodash\//g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('lodash/package')))}/`),
111
125
  });
112
126
  }
113
127
  });
128
+ api.writeTmpFile({
129
+ path: 'index.ts',
130
+ content: `
131
+ export { MicroApp } from './MicroApp';
132
+ `,
133
+ });
114
134
  });
115
135
  };
@@ -30,20 +30,32 @@ exports.default = (api) => {
30
30
  key: 'addExtraModels',
31
31
  fn() {
32
32
  return [
33
- `@@/plugin-qiankun-slave/qiankunModel#{"namespace":"${constants_1.qiankunStateFromMasterModelNamespace}"}`,
33
+ (0, withTmpPath_1.withTmpPath)({
34
+ api,
35
+ path: `qiankunModel.ts#{"namespace":"${constants_1.qiankunStateFromMasterModelNamespace}"}`,
36
+ }),
34
37
  ];
35
38
  },
36
39
  });
37
40
  api.modifyDefaultConfig((memo) => {
38
- var _a, _b, _c;
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), {
41
+ var _a, _b, _c, _d;
42
+ const initialSlaveOptions = {
43
+ devSourceMap: true,
44
+ ...JSON.parse(process.env.INITIAL_QIANKUN_SLAVE_OPTIONS || '{}'),
45
+ ...(memo.qiankun || {}).slave,
46
+ };
47
+ const modifiedDefaultConfig = {
48
+ ...memo,
41
49
  // 默认开启 runtimePublicPath,避免出现 dynamic import 场景子应用资源地址出问题
42
- runtimePublicPath: true,
43
- // TODO: runtimeHistory
44
- runtimeHistory: {}, qiankun: Object.assign(Object.assign({}, memo.qiankun), { slave: initialSlaveOptions }) });
50
+ runtimePublicPath: true,
51
+ qiankun: {
52
+ ...memo.qiankun,
53
+ slave: initialSlaveOptions,
54
+ },
55
+ };
45
56
  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;
46
- if (!shouldNotModifyDefaultBase) {
57
+ const historyType = ((_d = api.userConfig.history) === null || _d === void 0 ? void 0 : _d.type) || 'browser';
58
+ if (!shouldNotModifyDefaultBase && historyType !== 'hash') {
47
59
  // @ts-ignore
48
60
  modifiedDefaultConfig.base = `/${api.pkg.name}`;
49
61
  }
@@ -53,22 +65,23 @@ exports.default = (api) => {
53
65
  var _a, _b;
54
66
  // mfsu 场景默认给子应用增加 mfName 配置,从而避免冲突
55
67
  if (config.mfsu !== false) {
56
- config.mfsu = Object.assign(Object.assign({}, config.mfsu), { mfName: ((_a = config.mfsu) === null || _a === void 0 ? void 0 : _a.mfName) ||
57
- `mf_${(_b = api.pkg.name) === null || _b === void 0 ? void 0 : _b.replace(/^@/, '').replace(/\W/g, '_')}` });
68
+ config.mfsu = {
69
+ ...config.mfsu,
70
+ mfName: ((_a = config.mfsu) === null || _a === void 0 ? void 0 : _a.mfName) ||
71
+ `mf_${(_b = api.pkg.name) === null || _b === void 0 ? void 0 : _b.replace(/^@/, '').replace(/\W/g, '_')}`,
72
+ };
58
73
  }
59
74
  return config;
60
75
  });
61
- // api.modifyPublicPathStr((publicPathStr) => {
62
- // const { runtimePublicPath } = api.config;
63
- // const { shouldNotModifyRuntimePublicPath } = (api.config.qiankun || {})
64
- // .slave!;
65
- // if (runtimePublicPath === true && !shouldNotModifyRuntimePublicPath) {
66
- // return `window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__ || "${
67
- // api.config.publicPath || '/'
68
- // }"`;
69
- // }
70
- // return publicPathStr;
71
- // });
76
+ api.addHTMLHeadScripts(() => {
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
+ return dontModify
80
+ ? []
81
+ : [
82
+ `window.publicPath = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__ || "${api.config.publicPath || '/'}";`,
83
+ ];
84
+ });
72
85
  api.chainWebpack((config) => {
73
86
  (0, assert_1.default)(api.pkg.name, 'You should have name in package.json.');
74
87
  const { shouldNotAddLibraryChunkName } = (api.config.qiankun || {}).slave;
@@ -113,30 +126,39 @@ if (!window.__POWERED_BY_QIANKUN__) {
113
126
  function getFileContent(file) {
114
127
  return (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../../libs/qiankun/slave', file), 'utf-8');
115
128
  }
116
- api.onGenerateFiles(() => {
117
- // api.writeTmpFile({
118
- // path: 'slaveOptions.ts',
119
- // content: `
120
- // let options = ${JSON.stringify((api.config.qiankun || {}).slave || {})};
121
- // export const getSlaveOptions = () => options;
122
- // export const setSlaveOptions = (newOpts) => options = ({ ...options, ...newOpts });
123
- // `,
124
- // });
125
- [
126
- 'qiankunModel.ts',
127
- 'connectMaster.tsx',
128
- 'slaveRuntimePlugin.ts',
129
- 'lifecycles.ts',
130
- ].forEach((file) => {
129
+ api.onGenerateFiles({
130
+ fn() {
131
+ // api.writeTmpFile({
132
+ // path: 'slaveOptions.ts',
133
+ // content: `
134
+ // let options = ${JSON.stringify((api.config.qiankun || {}).slave || {})};
135
+ // export const getSlaveOptions = () => options;
136
+ // export const setSlaveOptions = (newOpts) => options = ({ ...options, ...newOpts });
137
+ // `,
138
+ // });
139
+ [
140
+ 'qiankunModel.ts',
141
+ 'connectMaster.tsx',
142
+ 'slaveRuntimePlugin.ts',
143
+ 'lifecycles.ts',
144
+ ].forEach((file) => {
145
+ api.writeTmpFile({
146
+ path: file.replace(/\.tpl$/, ''),
147
+ content: getFileContent(file)
148
+ .replace('__USE_MODEL__', api.isPluginEnable('model')
149
+ ? `import { useModel } from '@@/plugin-model'`
150
+ : `const useModel = null;`)
151
+ .replace(/from 'qiankun'/g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('qiankun/package')))}'`)
152
+ .replace(/from 'lodash\//g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('lodash/package')))}/`),
153
+ });
154
+ });
131
155
  api.writeTmpFile({
132
- path: file.replace(/\.tpl$/, ''),
133
- content: getFileContent(file)
134
- .replace('__USE_MODEL__', api.isPluginEnable('model')
135
- ? `import { useModel } from '@@/plugin/model'`
136
- : `const useModel = null;`)
137
- .replace(/from 'qiankun'/g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('qiankun/package')))}'`)
138
- .replace(/from 'lodash\//g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('lodash/package')))}/`),
156
+ path: 'index.ts',
157
+ content: `
158
+ export { connectMaster } from './connectMaster';
159
+ `,
139
160
  });
140
- });
161
+ },
162
+ before: 'model',
141
163
  });
142
164
  };
package/dist/qiankun.js CHANGED
@@ -7,6 +7,7 @@ exports.default = (api) => {
7
7
  return joi.object().keys({
8
8
  slave: joi.object(),
9
9
  master: joi.object(),
10
+ externalQiankun: joi.boolean(),
10
11
  });
11
12
  },
12
13
  },