@umijs/plugins 4.0.0-rc.2 → 4.0.0-rc.22

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/locale.js CHANGED
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.packageNormalize = void 0;
13
4
  const fs_1 = require("fs");
@@ -19,7 +10,6 @@ const packageNormalize = (packageName) => packageName.replace(/[@\/\-.]/g, '_');
19
10
  exports.packageNormalize = packageNormalize;
20
11
  // TODO: runtime plugin
21
12
  exports.default = (api) => {
22
- var _a;
23
13
  // TODO: antd 的校验考虑 antd 插件
24
14
  let hasAntd = false;
25
15
  try {
@@ -28,15 +18,15 @@ exports.default = (api) => {
28
18
  catch (e) {
29
19
  api.logger.warn('antd is not installed. <SelecLang /> unavailable');
30
20
  }
21
+ const defaultConfig = {
22
+ baseNavigator: true,
23
+ useLocalStorage: true,
24
+ baseSeparator: '-',
25
+ antd: hasAntd,
26
+ };
31
27
  api.describe({
32
28
  key: 'locale',
33
29
  config: {
34
- default: {
35
- baseNavigator: true,
36
- useLocalStorage: true,
37
- baseSeparator: '-',
38
- antd: hasAntd,
39
- },
40
30
  schema(joi) {
41
31
  return joi.object({
42
32
  default: joi.string(),
@@ -52,47 +42,49 @@ exports.default = (api) => {
52
42
  });
53
43
  const reactIntlPkgPath = (0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('react-intl/package')));
54
44
  // polyfill
55
- if ((0, localeUtils_1.isNeedPolyfill)(((_a = api.userConfig) === null || _a === void 0 ? void 0 : _a.targets) || {})) {
56
- api.addEntryImportsAhead(() => [
45
+ api.addEntryImportsAhead(() => (0, localeUtils_1.isNeedPolyfill)(api.config.targets || {})
46
+ ? [
57
47
  {
58
48
  source: require.resolve('intl'),
59
49
  },
60
- ]);
61
- }
62
- const addAntdLocales = (args) => __awaiter(void 0, void 0, void 0, function* () {
63
- var _b;
64
- return yield api.applyPlugins({
50
+ ]
51
+ : []);
52
+ const addAntdLocales = async (args) => {
53
+ var _a;
54
+ return await api.applyPlugins({
65
55
  key: 'addAntdLocales',
66
56
  type: api.ApplyPluginsType.add,
67
57
  initialValue: [
68
- `antd/${((_b = api.config) === null || _b === void 0 ? void 0 : _b.ssr) ? 'lib' : 'es'}/locale/${(0, localeUtils_1.getAntdLocale)(args.lang, args.country)}`,
58
+ `antd/${((_a = api.config) === null || _a === void 0 ? void 0 : _a.ssr) ? 'lib' : 'es'}/locale/${(0, localeUtils_1.getAntdLocale)(args.lang, args.country)}`,
69
59
  ],
70
60
  args,
71
61
  });
72
- });
73
- const getList = (resolveKey) => __awaiter(void 0, void 0, void 0, function* () {
74
- var _c, _d;
62
+ };
63
+ const getList = async (resolveKey) => {
64
+ var _a;
75
65
  const { paths } = api;
76
66
  return (0, localeUtils_1.getLocaleList)({
77
- localeFolder: ((_c = api.config) === null || _c === void 0 ? void 0 : _c.singular) ? 'locale' : 'locales',
78
- separator: (_d = api.config.locale) === null || _d === void 0 ? void 0 : _d.baseSeparator,
67
+ localeFolder: 'locales',
68
+ separator: (_a = api.config.locale) === null || _a === void 0 ? void 0 : _a.baseSeparator,
79
69
  absSrcPath: paths.absSrcPath,
80
70
  absPagesPath: paths.absPagesPath,
81
71
  addAntdLocales,
82
72
  resolveKey,
83
73
  });
84
- });
85
- api.onGenerateFiles(() => __awaiter(void 0, void 0, void 0, function* () {
86
- var _e, _f, _g, _h;
74
+ };
75
+ api.onGenerateFiles(async () => {
76
+ var _a, _b, _c, _d;
87
77
  const localeTpl = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../libs/locale/locale.tpl'), 'utf-8');
88
78
  // moment2dayjs
89
79
  const resolveKey = api.config.moment2dayjs ? 'dayjs' : 'moment';
90
80
  const momentPkgPath = (0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve(`${resolveKey}/package.json`)));
91
81
  const EventEmitterPkg = (0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('event-emitter/package')));
92
- const { baseSeparator, baseNavigator, antd, title, useLocalStorage } = api
93
- .config.locale;
94
- const defaultLocale = ((_e = api.config.locale) === null || _e === void 0 ? void 0 : _e.default) || `zh${baseSeparator}CN`;
95
- const localeList = yield getList(resolveKey);
82
+ const { baseSeparator, baseNavigator, antd, title, useLocalStorage } = {
83
+ ...defaultConfig,
84
+ ...api.config.locale,
85
+ };
86
+ const defaultLocale = ((_a = api.config.locale) === null || _a === void 0 ? void 0 : _a.default) || `zh${baseSeparator}CN`;
87
+ const localeList = await getList(resolveKey);
96
88
  const momentLocales = localeList
97
89
  .map(({ momentLocale }) => momentLocale)
98
90
  .filter((locale) => locale);
@@ -102,7 +94,7 @@ exports.default = (api) => {
102
94
  let MomentLocales = momentLocales;
103
95
  let DefaultMomentLocale = '';
104
96
  // set moment default accounding to locale.default
105
- if (!MomentLocales.length && ((_f = api.config.locale) === null || _f === void 0 ? void 0 : _f.default)) {
97
+ if (!MomentLocales.length && ((_b = api.config.locale) === null || _b === void 0 ? void 0 : _b.default)) {
106
98
  const [lang, country = ''] = defaultLocale.split(baseSeparator);
107
99
  const { momentLocale } = (0, localeUtils_1.getMomentLocale)(lang, country, resolveKey);
108
100
  if (momentLocale) {
@@ -112,9 +104,9 @@ exports.default = (api) => {
112
104
  }
113
105
  let DefaultAntdLocales = [];
114
106
  // set antd default locale
115
- if (!antdLocales.length && ((_g = api.config.locale) === null || _g === void 0 ? void 0 : _g.antd)) {
107
+ if (!antdLocales.length && ((_c = api.config.locale) === null || _c === void 0 ? void 0 : _c.antd)) {
116
108
  const [lang, country = ''] = defaultLocale.split(baseSeparator);
117
- DefaultAntdLocales = plugin_utils_1.lodash.uniq(yield addAntdLocales({
109
+ DefaultAntdLocales = plugin_utils_1.lodash.uniq(await addAntdLocales({
118
110
  lang,
119
111
  country,
120
112
  }));
@@ -139,7 +131,7 @@ exports.default = (api) => {
139
131
  path: 'locale.tsx',
140
132
  });
141
133
  const localeExportsTpl = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../libs/locale/localeExports.tpl'), 'utf-8');
142
- const localeDirName = api.config.singular ? 'locale' : 'locales';
134
+ const localeDirName = 'locales';
143
135
  const localeDirPath = (0, path_1.join)(api.paths.absSrcPath, localeDirName);
144
136
  api.writeTmpFile({
145
137
  path: 'localeExports.ts',
@@ -150,16 +142,20 @@ exports.default = (api) => {
150
142
  UseLocalStorage: !!useLocalStorage,
151
143
  LocaleDir: localeDirName,
152
144
  ExistLocaleDir: (0, fs_1.existsSync)(localeDirPath),
153
- LocaleList: localeList.map((locale) => (Object.assign(Object.assign({}, locale), { antdLocale: locale.antdLocale.map((antdLocale, index) => ({
145
+ LocaleList: localeList.map((locale) => ({
146
+ ...locale,
147
+ antdLocale: locale.antdLocale.map((antdLocale, index) => ({
154
148
  locale: antdLocale,
155
149
  index: index,
156
- })), paths: locale.paths.map((path, index) => ({
150
+ })),
151
+ paths: locale.paths.map((path, index) => ({
157
152
  path,
158
153
  index,
159
- })) }))),
154
+ })),
155
+ })),
160
156
  Antd: !!antd,
161
157
  DefaultLocale: JSON.stringify(defaultLocale),
162
- warningPkgPath: (0, plugin_utils_1.winPath)(require.resolve('warning/package')),
158
+ warningPkgPath: (0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('warning/package'))),
163
159
  reactIntlPkgPath,
164
160
  }),
165
161
  });
@@ -179,25 +175,25 @@ exports.default = (api) => {
179
175
  Antd: !!antd,
180
176
  LocaleList: localeList,
181
177
  ShowSelectLang: localeList.length > 1 && !!antd,
182
- antdFiles: ((_h = api.config) === null || _h === void 0 ? void 0 : _h.ssr) ? 'lib' : 'es',
178
+ antdFiles: ((_d = api.config) === null || _d === void 0 ? void 0 : _d.ssr) ? 'lib' : 'es',
183
179
  }),
184
180
  });
185
181
  // index.ts
186
182
  api.writeTmpFile({
187
183
  path: 'index.ts',
188
184
  content: `
189
- export { useIntl, formatMessage, FormattedMessage } from './localeExports.ts';
185
+ export { setLocale, getLocale, useIntl, injectIntl, formatMessage, FormattedMessage } from './localeExports.ts';
190
186
  export { SelectLang } from './SelectLang.tsx';
191
187
  `,
192
188
  });
193
- }));
189
+ });
194
190
  // Runtime Plugin
195
191
  api.addRuntimePlugin(() => [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })]);
196
192
  api.addRuntimePluginKey(() => ['locale']);
197
193
  // watch locale files
198
- api.addTmpGenerateWatcherPaths(() => __awaiter(void 0, void 0, void 0, function* () {
194
+ api.addTmpGenerateWatcherPaths(async () => {
199
195
  const resolveKey = api.config.moment2dayjs ? 'dayjs' : 'moment';
200
- const localeList = yield getList(resolveKey);
196
+ const localeList = await getList(resolveKey);
201
197
  return (0, localeUtils_1.exactLocalePaths)(localeList);
202
- }));
198
+ });
203
199
  };
package/dist/model.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -18,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
18
22
  __setModuleDefault(result, mod);
19
23
  return result;
20
24
  };
21
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
- return new (P || (P = Promise))(function (resolve, reject) {
24
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
- step((generator = generator.apply(thisArg, _arguments || [])).next());
28
- });
29
- };
30
25
  Object.defineProperty(exports, "__esModule", { value: true });
31
26
  const t = __importStar(require("@umijs/bundler-utils/compiled/babel/types"));
32
27
  const fs_1 = require("fs");
@@ -45,17 +40,8 @@ exports.default = (api) => {
45
40
  },
46
41
  enableBy: api.EnableBy.config,
47
42
  });
48
- api.modifyAppData((memo) => __awaiter(void 0, void 0, void 0, function* () {
49
- const models = yield getAllModels(api);
50
- memo.pluginModel = {
51
- models,
52
- };
53
- return memo;
54
- }));
55
- api.onGenerateFiles((args) => __awaiter(void 0, void 0, void 0, function* () {
56
- const models = args.isFirstTime
57
- ? api.appData.pluginModel.models
58
- : yield getAllModels(api);
43
+ api.onGenerateFiles(async () => {
44
+ const models = await getAllModels(api);
59
45
  // model.ts
60
46
  api.writeTmpFile({
61
47
  path: 'model.ts',
@@ -90,7 +76,7 @@ export function dataflowProvider(container, opts) {
90
76
  }
91
77
  `,
92
78
  });
93
- }));
79
+ });
94
80
  api.addTmpGenerateWatcherPaths(() => {
95
81
  return [(0, path_1.join)(api.paths.absSrcPath, 'models')];
96
82
  });
@@ -98,19 +84,18 @@ export function dataflowProvider(container, opts) {
98
84
  return [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })];
99
85
  });
100
86
  };
101
- function getAllModels(api) {
102
- return __awaiter(this, void 0, void 0, function* () {
103
- const extraModels = yield api.applyPlugins({
104
- key: 'addExtraModels',
105
- type: api.ApplyPluginsType.add,
106
- initialValue: [],
107
- });
108
- return new modelUtils_1.ModelUtils(api, {
109
- astTest({ node }) {
110
- return t.isArrowFunctionExpression(node) || t.isFunctionDeclaration(node);
111
- },
112
- }).getAllModels({
113
- extraModels: [...extraModels, ...(api.config.model.extraModels || [])],
114
- });
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 || [])],
115
100
  });
116
101
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const utils_1 = require("@umijs/utils");
4
3
  const path_1 = require("path");
4
+ const plugin_utils_1 = require("umi/plugin-utils");
5
5
  /*
6
6
  As long as moment2dayjs is registered, moment will be replaced by dayjs.
7
7
  The presets that can adapt to antd is registered by default.
@@ -81,11 +81,11 @@ dayjs.extend({{.}});
81
81
 
82
82
  dayjs.extend(antdPlugin);
83
83
  `;
84
- const dayjsAntdPluginPath = require.resolve('antd-dayjs-webpack-plugin/src/antd-plugin');
85
- const dayjsPath = (0, path_1.dirname)(require.resolve('dayjs/package.json'));
84
+ const dayjsAntdPluginPath = (0, plugin_utils_1.winPath)(require.resolve('antd-dayjs-webpack-plugin/src/antd-plugin'));
85
+ const dayjsPath = (0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('dayjs/package.json')));
86
86
  api.writeTmpFile({
87
87
  path: 'runtime.tsx',
88
- content: utils_1.Mustache.render(runtimeTpl, {
88
+ content: plugin_utils_1.Mustache.render(runtimeTpl, {
89
89
  plugins,
90
90
  dayjsPath,
91
91
  dayjsAntdPluginPath,
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isMasterEnable = void 0;
4
4
  const fs_1 = require("fs");
5
5
  const path_1 = require("path");
6
+ const plugin_utils_1 = require("umi/plugin-utils");
6
7
  const withTmpPath_1 = require("../utils/withTmpPath");
7
8
  const constants_1 = require("./constants");
8
9
  function isMasterEnable(opts) {
@@ -22,22 +23,30 @@ exports.default = (api) => {
22
23
  api.addRuntimePlugin(() => {
23
24
  return [(0, withTmpPath_1.withTmpPath)({ api, path: 'masterRuntimePlugin.tsx' })];
24
25
  });
25
- 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) }) })));
26
- // 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
+ }));
27
37
  api.modifyRoutes((memo) => {
28
38
  Object.keys(memo).forEach((id) => {
39
+ var _a;
29
40
  const route = memo[id];
30
41
  if (route.microApp) {
31
42
  const appName = route.microApp;
32
- // TODO: config base
33
- const base = '/';
34
- // TODO: config masterHistoryType
35
- 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';
36
45
  const routeProps = route.microAppProps || {};
37
46
  const normalizedRouteProps = JSON.stringify(routeProps).replace(/"/g, "'");
38
47
  route.file = `(async () => {
39
48
  const { getMicroAppRouteComponent } = await import('@@/plugin-qiankun-master/getMicroAppRouteComponent');
40
- return getMicroAppRouteComponent({ appName: '${appName}', base: '${base}', masterHistoryType: '${masterHistoryType}', routeProps: ${normalizedRouteProps} })
49
+ return getMicroAppRouteComponent({ appName: '${appName}', base: '${base}', routePath: '${route.path}', masterHistoryType: '${masterHistoryType}', routeProps: ${normalizedRouteProps} })
41
50
  })()`;
42
51
  }
43
52
  });
@@ -64,7 +73,11 @@ exports.default = (api) => {
64
73
  api.writeTmpFile({
65
74
  path: 'masterOptions.ts',
66
75
  content: `
67
- 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
+ })};
68
81
  export const getMasterOptions = () => options;
69
82
  export const setMasterOptions = (newOpts) => options = ({ ...options, ...newOpts });
70
83
  `,
@@ -90,7 +103,6 @@ export const setMasterOptions = (newOpts) => options = ({ ...options, ...newOpts
90
103
  path: file.replace(/\.tpl$/, ''),
91
104
  tpl: getFileContent(file),
92
105
  context: {
93
- runtimeHistory: api.config.runtimeHistory,
94
106
  dynamicRoot: false,
95
107
  hasModelPlugin: api.isPluginEnable('model'),
96
108
  // dynamicRoot:
@@ -99,16 +111,25 @@ export const setMasterOptions = (newOpts) => options = ({ ...options, ...newOpts
99
111
  });
100
112
  }
101
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
+ }
102
118
  api.writeTmpFile({
103
119
  path: file.replace(/\.tpl$/, ''),
104
- content: getFileContent(file)
120
+ content: content
105
121
  .replace('__USE_MODEL__', api.isPluginEnable('model')
106
122
  ? `import { useModel } from '@@/plugin-model'`
107
123
  : `const useModel = null;`)
108
- .replace(/from 'qiankun'/g, `from '${(0, path_1.dirname)(require.resolve('qiankun/package'))}'`)
109
- .replace(/from 'lodash\//g, `from '${(0, path_1.dirname)(require.resolve('lodash/package'))}/`),
124
+ .replace(/from 'lodash\//g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('lodash/package')))}/`),
110
125
  });
111
126
  }
112
127
  });
128
+ api.writeTmpFile({
129
+ path: 'index.ts',
130
+ content: `
131
+ export { MicroApp } from './MicroApp';
132
+ `,
133
+ });
113
134
  });
114
135
  };
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const assert_1 = __importDefault(require("assert"));
7
7
  const fs_1 = require("fs");
8
8
  const path_1 = require("path");
9
+ const plugin_utils_1 = require("umi/plugin-utils");
9
10
  const withTmpPath_1 = require("../utils/withTmpPath");
10
11
  const constants_1 = require("./constants");
11
12
  // BREAK CHANGE: 需要手动配置 slave: {},不能留空
@@ -29,20 +30,32 @@ exports.default = (api) => {
29
30
  key: 'addExtraModels',
30
31
  fn() {
31
32
  return [
32
- `@@/plugin-qiankun-slave/qiankunModel#{"namespace":"${constants_1.qiankunStateFromMasterModelNamespace}"}`,
33
+ (0, withTmpPath_1.withTmpPath)({
34
+ api,
35
+ path: `qiankunModel.ts#{"namespace":"${constants_1.qiankunStateFromMasterModelNamespace}"}`,
36
+ }),
33
37
  ];
34
38
  },
35
39
  });
36
40
  api.modifyDefaultConfig((memo) => {
37
- var _a, _b, _c;
38
- const initialSlaveOptions = Object.assign(Object.assign({ devSourceMap: true }, JSON.parse(process.env.INITIAL_QIANKUN_SLAVE_OPTIONS || '{}')), (memo.qiankun || {}).slave);
39
- 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,
40
49
  // 默认开启 runtimePublicPath,避免出现 dynamic import 场景子应用资源地址出问题
41
- runtimePublicPath: true,
42
- // TODO: runtimeHistory
43
- runtimeHistory: {}, qiankun: Object.assign(Object.assign({}, memo.qiankun), { slave: initialSlaveOptions }) });
50
+ runtimePublicPath: true,
51
+ qiankun: {
52
+ ...memo.qiankun,
53
+ slave: initialSlaveOptions,
54
+ },
55
+ };
44
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;
45
- if (!shouldNotModifyDefaultBase) {
57
+ const historyType = ((_d = api.userConfig.history) === null || _d === void 0 ? void 0 : _d.type) || 'browser';
58
+ if (!shouldNotModifyDefaultBase && historyType !== 'hash') {
46
59
  // @ts-ignore
47
60
  modifiedDefaultConfig.base = `/${api.pkg.name}`;
48
61
  }
@@ -52,22 +65,23 @@ exports.default = (api) => {
52
65
  var _a, _b;
53
66
  // mfsu 场景默认给子应用增加 mfName 配置,从而避免冲突
54
67
  if (config.mfsu !== false) {
55
- config.mfsu = Object.assign(Object.assign({}, config.mfsu), { mfName: ((_a = config.mfsu) === null || _a === void 0 ? void 0 : _a.mfName) ||
56
- `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
+ };
57
73
  }
58
74
  return config;
59
75
  });
60
- // api.modifyPublicPathStr((publicPathStr) => {
61
- // const { runtimePublicPath } = api.config;
62
- // const { shouldNotModifyRuntimePublicPath } = (api.config.qiankun || {})
63
- // .slave!;
64
- // if (runtimePublicPath === true && !shouldNotModifyRuntimePublicPath) {
65
- // return `window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__ || "${
66
- // api.config.publicPath || '/'
67
- // }"`;
68
- // }
69
- // return publicPathStr;
70
- // });
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
+ });
71
85
  api.chainWebpack((config) => {
72
86
  (0, assert_1.default)(api.pkg.name, 'You should have name in package.json.');
73
87
  const { shouldNotAddLibraryChunkName } = (api.config.qiankun || {}).slave;
@@ -112,30 +126,39 @@ if (!window.__POWERED_BY_QIANKUN__) {
112
126
  function getFileContent(file) {
113
127
  return (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../../libs/qiankun/slave', file), 'utf-8');
114
128
  }
115
- api.onGenerateFiles(() => {
116
- // api.writeTmpFile({
117
- // path: 'slaveOptions.ts',
118
- // content: `
119
- // let options = ${JSON.stringify((api.config.qiankun || {}).slave || {})};
120
- // export const getSlaveOptions = () => options;
121
- // export const setSlaveOptions = (newOpts) => options = ({ ...options, ...newOpts });
122
- // `,
123
- // });
124
- [
125
- 'qiankunModel.ts',
126
- 'connectMaster.tsx',
127
- 'slaveRuntimePlugin.ts',
128
- 'lifecycles.ts',
129
- ].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
+ });
130
155
  api.writeTmpFile({
131
- path: file.replace(/\.tpl$/, ''),
132
- content: getFileContent(file)
133
- .replace('__USE_MODEL__', api.isPluginEnable('model')
134
- ? `import { useModel } from '@@/plugin/model'`
135
- : `const useModel = null;`)
136
- .replace(/from 'qiankun'/g, `from '${(0, path_1.dirname)(require.resolve('qiankun/package'))}'`)
137
- .replace(/from 'lodash\//g, `from '${(0, path_1.dirname)(require.resolve('lodash/package'))}/`),
156
+ path: 'index.ts',
157
+ content: `
158
+ export { connectMaster } from './connectMaster';
159
+ `,
138
160
  });
139
- });
161
+ },
162
+ before: 'model',
140
163
  });
141
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
  },