@umijs/plugins 4.0.0-rc.6 → 4.0.0-rc.7

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/antd.js CHANGED
@@ -5,11 +5,16 @@ const plugin_utils_1 = require("umi/plugin-utils");
5
5
  const resolveProjectDep_1 = require("./utils/resolveProjectDep");
6
6
  const withTmpPath_1 = require("./utils/withTmpPath");
7
7
  exports.default = (api) => {
8
- const pkgPath = (0, resolveProjectDep_1.resolveProjectDep)({
9
- pkg: api.pkg,
10
- cwd: api.cwd,
11
- dep: 'antd',
12
- }) || (0, path_1.dirname)(require.resolve('antd/package.json'));
8
+ let pkgPath;
9
+ try {
10
+ pkgPath =
11
+ (0, resolveProjectDep_1.resolveProjectDep)({
12
+ pkg: api.pkg,
13
+ cwd: api.cwd,
14
+ dep: 'antd',
15
+ }) || (0, path_1.dirname)(require.resolve('antd/package.json'));
16
+ }
17
+ catch (e) { }
13
18
  api.describe({
14
19
  config: {
15
20
  schema(Joi) {
@@ -27,7 +32,13 @@ exports.default = (api) => {
27
32
  },
28
33
  enableBy: api.EnableBy.config,
29
34
  });
35
+ function checkPkgPath() {
36
+ if (!pkgPath) {
37
+ throw new Error(`Can't find antd package. Please install antd first.`);
38
+ }
39
+ }
30
40
  api.modifyAppData((memo) => {
41
+ checkPkgPath();
31
42
  const version = require(`${pkgPath}/package.json`).version;
32
43
  memo.antd = {
33
44
  pkgPath,
@@ -36,6 +47,7 @@ exports.default = (api) => {
36
47
  return memo;
37
48
  });
38
49
  api.modifyConfig((memo) => {
50
+ checkPkgPath();
39
51
  // antd import
40
52
  memo.alias.antd = pkgPath;
41
53
  // moment > dayjs
package/dist/dva.js CHANGED
@@ -29,6 +29,7 @@ const path_1 = require("path");
29
29
  const plugin_utils_1 = require("umi/plugin-utils");
30
30
  const modelUtils_1 = require("./utils/modelUtils");
31
31
  const withTmpPath_1 = require("./utils/withTmpPath");
32
+ const utils_1 = require("@umijs/utils");
32
33
  exports.default = (api) => {
33
34
  const pkgPath = (0, path_1.join)(__dirname, '../libs/dva.ts');
34
35
  api.describe({
@@ -36,6 +37,7 @@ exports.default = (api) => {
36
37
  schema(Joi) {
37
38
  return Joi.object({
38
39
  extraModels: Joi.array().items(Joi.string()),
40
+ immer: Joi.object(),
39
41
  });
40
42
  },
41
43
  },
@@ -55,6 +57,7 @@ exports.default = (api) => {
55
57
  return memo;
56
58
  });
57
59
  api.onGenerateFiles((args) => {
60
+ var _a, _b, _c, _d, _e, _f;
58
61
  const models = args.isFirstTime
59
62
  ? api.appData.pluginDva.models
60
63
  : getAllModels(api);
@@ -70,6 +73,12 @@ exports.default = (api) => {
70
73
  // It's faked dva
71
74
  // aliased to @umijs/plugins/templates/dva
72
75
  import { create, Provider } from 'dva';
76
+ import createLoading from '${(0, utils_1.winPath)(require.resolve('dva-loading'))}';
77
+ ${((_a = api.config.dva) === null || _a === void 0 ? void 0 : _a.immer)
78
+ ? `
79
+ import dvaImmer, { enableES5, enableAllPlugins } from '${(0, utils_1.winPath)(require.resolve('dva-immer'))}';
80
+ `
81
+ : ''}
73
82
  import React, { useRef } from 'react';
74
83
  import { history } from 'umi';
75
84
  import { models } from './models';
@@ -91,6 +100,10 @@ export function RootContainer(props: any) {
91
100
  },
92
101
  },
93
102
  );
103
+ app.current.use(createLoading());
104
+ ${((_b = api.config.dva) === null || _b === void 0 ? void 0 : _b.immer) ? `app.current.use(dvaImmer());` : ''}
105
+ ${((_d = (_c = api.config.dva) === null || _c === void 0 ? void 0 : _c.immer) === null || _d === void 0 ? void 0 : _d.enableES5) ? `enableES5();` : ''}
106
+ ${((_f = (_e = api.config.dva) === null || _e === void 0 ? void 0 : _e.immer) === null || _f === void 0 ? void 0 : _f.enableAllPlugins) ? `enableAllPlugins();` : ''}
94
107
  for (const id of Object.keys(models)) {
95
108
  app.current.model(models[id].model);
96
109
  }
package/dist/locale.js CHANGED
@@ -28,15 +28,15 @@ exports.default = (api) => {
28
28
  catch (e) {
29
29
  api.logger.warn('antd is not installed. <SelecLang /> unavailable');
30
30
  }
31
+ const defaultConfig = {
32
+ baseNavigator: true,
33
+ useLocalStorage: true,
34
+ baseSeparator: '-',
35
+ antd: hasAntd,
36
+ };
31
37
  api.describe({
32
38
  key: 'locale',
33
39
  config: {
34
- default: {
35
- baseNavigator: true,
36
- useLocalStorage: true,
37
- baseSeparator: '-',
38
- antd: hasAntd,
39
- },
40
40
  schema(joi) {
41
41
  return joi.object({
42
42
  default: joi.string(),
@@ -89,8 +89,7 @@ exports.default = (api) => {
89
89
  const resolveKey = api.config.moment2dayjs ? 'dayjs' : 'moment';
90
90
  const momentPkgPath = (0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve(`${resolveKey}/package.json`)));
91
91
  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;
92
+ const { baseSeparator, baseNavigator, antd, title, useLocalStorage } = Object.assign(Object.assign({}, defaultConfig), api.config.locale);
94
93
  const defaultLocale = ((_e = api.config.locale) === null || _e === void 0 ? void 0 : _e.default) || `zh${baseSeparator}CN`;
95
94
  const localeList = yield getList(resolveKey);
96
95
  const momentLocales = localeList
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const plugin_utils_1 = require("umi/plugin-utils");
4
3
  const path_1 = require("path");
4
+ const plugin_utils_1 = require("umi/plugin-utils");
5
5
  exports.default = (api) => {
6
6
  api.describe({
7
7
  key: 'tailwindcss',
@@ -14,7 +14,7 @@ exports.default = (api) => {
14
14
  });
15
15
  let tailwind = null;
16
16
  const outputPath = 'plugin-tailwindcss/tailwind.css';
17
- api.onStart(() => {
17
+ api.onBeforeCompiler(() => {
18
18
  const inputPath = (0, path_1.join)(api.cwd, 'tailwind.css');
19
19
  const generatedPath = (0, path_1.join)(api.paths.absTmpPath, outputPath);
20
20
  const binPath = (0, path_1.join)(api.cwd, 'node_modules/.bin/tailwind');
package/dist/unocss.js CHANGED
@@ -1,34 +1,8 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = 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);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
2
  Object.defineProperty(exports, "__esModule", { value: true });
29
3
  const child_process_1 = require("child_process");
30
- const fs = __importStar(require("fs"));
31
- const path_1 = __importDefault(require("path"));
4
+ const fs_1 = require("fs");
5
+ const path_1 = require("path");
32
6
  const plugin_utils_1 = require("umi/plugin-utils");
33
7
  exports.default = (api) => {
34
8
  api.describe({
@@ -42,20 +16,24 @@ exports.default = (api) => {
42
16
  },
43
17
  enableBy: api.EnableBy.config,
44
18
  });
45
- api.onStart(() => {
19
+ const outputPath = 'uno.css';
20
+ api.onBeforeCompiler(() => {
46
21
  /** 由于 @unocss/cli 对设置文件进行了检查,因此加入需要 unocss.config.ts 设置的提示
47
22
  * https://github.com/antfu/unocss/blob/main/packages/cli/src/index.ts#L93 */
48
- if (!fs.existsSync(path_1.default.resolve(api.paths.cwd, 'unocss.config.ts')))
49
- plugin_utils_1.logger.warn('请在项目目录中添加 unocss.config.ts 文件,并配置需要的 unocss presets,否则插件将没有效果!');
50
- const generatedPath = path_1.default.resolve(api.paths.absTmpPath, 'uno.css');
51
- const binPath = path_1.default.resolve(api.cwd, 'node_modules/.bin/unocss');
23
+ if (!(0, fs_1.existsSync)((0, path_1.join)(api.paths.cwd, 'unocss.config.ts')))
24
+ api.logger.warn('请在项目目录中添加 unocss.config.ts 文件,并配置需要的 unocss presets,否则插件将没有效果!');
25
+ const generatedPath = (0, path_1.join)(api.paths.absTmpPath, outputPath);
26
+ const binPath = (0, path_1.join)(api.cwd, 'node_modules/.bin/unocss');
52
27
  const watchDirs = api.config.unocss.watch;
53
28
  /** 透过子进程建立 unocss 服务,将生成的 css 写入 generatedPath */
54
- const unocss = (0, child_process_1.exec)(`${binPath} ${watchDirs.join(' ')} --out-file ${generatedPath} --watch`, { cwd: api.cwd });
29
+ const unocss = (0, child_process_1.exec)(`${binPath} ${watchDirs.join(' ')} --out-file ${generatedPath} ${api.env === 'development' ? '--watch' : ''}`, { cwd: api.cwd });
55
30
  unocss.on('error', (m) => {
56
31
  api.logger.error('unocss service encounter an error: ' + m);
57
32
  });
58
- /** 将生成的 css 文件加入到 import 中 */
59
- api.addEntryImports(() => [{ source: generatedPath }]);
33
+ });
34
+ /** 将生成的 css 文件加入到 import 中 */
35
+ api.addEntryImports(() => {
36
+ const generatedPath = (0, plugin_utils_1.winPath)((0, path_1.join)(api.paths.absTmpPath, outputPath));
37
+ return [{ source: generatedPath }];
60
38
  });
61
39
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/plugins",
3
- "version": "4.0.0-rc.6",
3
+ "version": "4.0.0-rc.7",
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",
@@ -18,18 +18,21 @@
18
18
  "scripts": {
19
19
  "build": "pnpm tsc",
20
20
  "build:deps": "pnpm esno ../../scripts/bundleDeps.ts",
21
- "dev": "pnpm build -- --watch"
21
+ "dev": "pnpm build -- --watch",
22
+ "test": "jest -c ../../jest.turbo.config.ts"
22
23
  },
23
24
  "dependencies": {
24
25
  "@ahooksjs/use-request": "^2.0.0",
25
26
  "@ant-design/icons": "^4.7.0",
26
27
  "@ant-design/pro-layout": "^7.0.1-beta.3",
27
- "@umijs/bundler-utils": "4.0.0-rc.6",
28
+ "@umijs/bundler-utils": "4.0.0-rc.7",
28
29
  "antd-dayjs-webpack-plugin": "^1.0.6",
29
30
  "axios": "^0.26.1",
30
31
  "babel-plugin-import": "^1.13.3",
31
- "dayjs": "^1.10.8",
32
+ "dayjs": "^1.11.0",
32
33
  "dva-core": "^2.0.4",
34
+ "dva-immer": "^1.0.0",
35
+ "dva-loading": "^3.0.22",
33
36
  "event-emitter": "~0.3.5",
34
37
  "fast-deep-equal": "3.1.3",
35
38
  "lodash": "^4.17.21",
@@ -41,7 +44,7 @@
41
44
  "warning": "^4.0.3"
42
45
  },
43
46
  "devDependencies": {
44
- "umi": "4.0.0-rc.6"
47
+ "umi": "4.0.0-rc.7"
45
48
  },
46
49
  "publishConfig": {
47
50
  "access": "public"