@umijs/plugins 4.0.7 → 4.0.10

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/dva.js CHANGED
@@ -1,84 +1,103 @@
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;
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
24
10
  };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getAllModels = exports.getModelUtil = void 0;
27
- const t = __importStar(require("@umijs/bundler-utils/compiled/babel/types"));
28
- const utils_1 = require("@umijs/utils");
29
- const path_1 = require("path");
30
- const plugin_utils_1 = require("umi/plugin-utils");
31
- const modelUtils_1 = require("./utils/modelUtils");
32
- const withTmpPath_1 = require("./utils/withTmpPath");
33
- exports.default = (api) => {
34
- const pkgPath = (0, path_1.join)(__dirname, '../libs/dva.ts');
35
- api.describe({
36
- config: {
37
- schema(Joi) {
38
- return Joi.object({
39
- extraModels: Joi.array().items(Joi.string()),
40
- immer: Joi.object(),
41
- });
42
- },
43
- },
44
- enableBy: api.EnableBy.config,
45
- });
46
- api.modifyAppData((memo) => {
47
- const models = getAllModels(api);
48
- memo.pluginDva = {
49
- pkgPath,
50
- models,
51
- };
52
- return memo;
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+
22
+ // src/dva.ts
23
+ var dva_exports = {};
24
+ __export(dva_exports, {
25
+ default: () => dva_default,
26
+ getAllModels: () => getAllModels,
27
+ getModelUtil: () => getModelUtil
28
+ });
29
+ module.exports = __toCommonJS(dva_exports);
30
+ var t = __toESM(require("@umijs/bundler-utils/compiled/babel/types"));
31
+ var import_utils = require("@umijs/utils");
32
+ var import_path = require("path");
33
+ var import_umi = require("umi");
34
+ var import_plugin_utils = require("umi/plugin-utils");
35
+ var import_modelUtils = require("./utils/modelUtils");
36
+ var import_withTmpPath = require("./utils/withTmpPath");
37
+ var dva_default = (api) => {
38
+ const pkgPath = (0, import_path.join)(__dirname, "../libs/dva.ts");
39
+ api.describe({
40
+ config: {
41
+ schema(Joi) {
42
+ return Joi.alternatives().try(Joi.object({
43
+ extraModels: Joi.array().items(Joi.string()),
44
+ immer: Joi.object()
45
+ }), Joi.boolean().invalid(true));
46
+ }
47
+ },
48
+ enableBy: api.EnableBy.config
49
+ });
50
+ api.modifyAppData((memo) => {
51
+ const models = getAllModels(api);
52
+ memo.pluginDva = {
53
+ pkgPath,
54
+ models
55
+ };
56
+ return memo;
57
+ });
58
+ api.modifyConfig((memo) => {
59
+ memo.alias["dva$"] = pkgPath;
60
+ return memo;
61
+ });
62
+ api.onGenerateFiles((args) => {
63
+ var _a, _b, _c, _d, _e, _f;
64
+ const models = args.isFirstTime ? api.appData.pluginDva.models : getAllModels(api);
65
+ api.writeTmpFile({
66
+ path: "models.ts",
67
+ content: import_modelUtils.ModelUtils.getModelsContent(models)
53
68
  });
54
- api.modifyConfig((memo) => {
55
- // import from dva
56
- memo.alias['dva$'] = pkgPath;
57
- return memo;
69
+ api.writeTmpFile({
70
+ path: import_umi.RUNTIME_TYPE_FILE_NAME,
71
+ content: `
72
+ export interface IRuntimeConfig {
73
+ dva?: {
74
+ config?: {
75
+ initialState?: Record<string, any>;
76
+ onError?: any;
77
+ onStateChange?: any;
78
+ onAction?: any;
79
+ onHmr?: any;
80
+ onReducer?: any;
81
+ onEffect?: any;
82
+ extraReducers?: any;
83
+ extraEnhancers?: any;
84
+ [key: string]: any;
85
+ },
86
+ plugins?: string[];
87
+ }
88
+ }
89
+ `
58
90
  });
59
- api.onGenerateFiles((args) => {
60
- var _a, _b, _c, _d, _e, _f;
61
- const models = args.isFirstTime
62
- ? api.appData.pluginDva.models
63
- : getAllModels(api);
64
- // models.ts
65
- api.writeTmpFile({
66
- path: 'models.ts',
67
- content: modelUtils_1.ModelUtils.getModelsContent(models),
68
- });
69
- // dva.tsx
70
- api.writeTmpFile({
71
- path: 'dva.tsx',
72
- tpl: `
91
+ api.writeTmpFile({
92
+ path: "dva.tsx",
93
+ tpl: `
73
94
  // It's faked dva
74
95
  // aliased to @umijs/plugins/templates/dva
75
96
  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
- : ''}
97
+ import createLoading from '${(0, import_utils.winPath)(require.resolve("dva-loading"))}';
98
+ ${((_a = api.config.dva) == null ? void 0 : _a.immer) ? `
99
+ import dvaImmer, { enableES5, enableAllPlugins } from '${(0, import_utils.winPath)(require.resolve("dva-immer"))}';
100
+ ` : ""}
82
101
  import React, { useRef } from 'react';
83
102
  import { history, ApplyPluginsType, useAppData } from 'umi';
84
103
  import { models } from './models';
@@ -111,9 +130,9 @@ export function RootContainer(props: any) {
111
130
  );
112
131
  dvaApp = app.current;
113
132
  app.current.use(createLoading());
114
- ${((_b = api.config.dva) === null || _b === void 0 ? void 0 : _b.immer) ? `app.current.use(dvaImmer());` : ''}
115
- ${((_d = (_c = api.config.dva) === null || _c === void 0 ? void 0 : _c.immer) === null || _d === void 0 ? void 0 : _d.enableES5) ? `enableES5();` : ''}
116
- ${((_f = (_e = api.config.dva) === null || _e === void 0 ? void 0 : _e.immer) === null || _f === void 0 ? void 0 : _f.enableAllPlugins) ? `enableAllPlugins();` : ''}
133
+ ${((_b = api.config.dva) == null ? void 0 : _b.immer) ? `app.current.use(dvaImmer());` : ""}
134
+ ${((_d = (_c = api.config.dva) == null ? void 0 : _c.immer) == null ? void 0 : _d.enableES5) ? `enableES5();` : ""}
135
+ ${((_f = (_e = api.config.dva) == null ? void 0 : _e.immer) == null ? void 0 : _f.enableAllPlugins) ? `enableAllPlugins();` : ""}
117
136
  (runtimeDva.plugins || []).forEach((p) => {
118
137
  app.current.use(p);
119
138
  });
@@ -132,82 +151,77 @@ export function getDvaApp() {
132
151
  return dvaApp;
133
152
  }
134
153
  `,
135
- context: {},
136
- });
137
- // runtime.tsx
138
- api.writeTmpFile({
139
- path: 'runtime.tsx',
140
- content: `
154
+ context: {}
155
+ });
156
+ api.writeTmpFile({
157
+ path: "runtime.tsx",
158
+ content: `
141
159
  import React from 'react';
142
160
  import { RootContainer } from './dva';
143
161
 
144
162
  export function dataflowProvider(container, opts) {
145
163
  return React.createElement(RootContainer, opts, container);
146
164
  }
147
- `,
148
- });
149
- // index.ts for export
150
- api.writeTmpFile({
151
- path: 'index.ts',
152
- content: `
165
+ `
166
+ });
167
+ api.writeTmpFile({
168
+ path: "index.ts",
169
+ content: `
153
170
  export { connect, useDispatch, useStore, useSelector } from 'dva';
154
171
  export { getDvaApp } from './dva';
155
- `,
156
- });
157
- });
158
- api.addTmpGenerateWatcherPaths(() => {
159
- return [(0, path_1.join)(api.paths.absSrcPath, 'models')];
160
- });
161
- api.addRuntimePlugin(() => {
162
- return [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })];
163
- });
164
- api.addRuntimePluginKey(() => ['dva']);
165
- // dva list model
166
- api.registerCommand({
167
- name: 'dva',
168
- fn() {
169
- api.logger.info(plugin_utils_1.chalk.green.bold('dva models'));
170
- api.appData.pluginDva.models.forEach((model) => {
171
- api.logger.info(` - ${(0, path_1.relative)(api.cwd, model.file)}`);
172
- });
173
- },
172
+ `
174
173
  });
174
+ });
175
+ api.addTmpGenerateWatcherPaths(() => {
176
+ return [(0, import_path.join)(api.paths.absSrcPath, "models")];
177
+ });
178
+ api.addRuntimePlugin(() => {
179
+ return [(0, import_withTmpPath.withTmpPath)({ api, path: "runtime.tsx" })];
180
+ });
181
+ api.addRuntimePluginKey(() => ["dva"]);
182
+ api.registerCommand({
183
+ name: "dva",
184
+ fn() {
185
+ api.logger.info(import_plugin_utils.chalk.green.bold("dva models"));
186
+ api.appData.pluginDva.models.forEach((model) => {
187
+ api.logger.info(` - ${(0, import_path.relative)(api.cwd, model.file)}`);
188
+ });
189
+ }
190
+ });
175
191
  };
176
192
  function getModelUtil(api) {
177
- return new modelUtils_1.ModelUtils(api, {
178
- contentTest(content) {
179
- return content.startsWith('// @dva-model');
180
- },
181
- astTest({ node, content }) {
182
- if (isModelObject(node)) {
183
- return true;
184
- }
185
- else if (content.includes('dva-model-extend') &&
186
- t.isCallExpression(node) &&
187
- node.arguments.length === 2 &&
188
- isModelObject(node.arguments[1])) {
189
- return true;
190
- }
191
- return false;
192
- },
193
- });
193
+ return new import_modelUtils.ModelUtils(api, {
194
+ contentTest(content) {
195
+ return content.startsWith("// @dva-model");
196
+ },
197
+ astTest({ node, content }) {
198
+ if (isModelObject(node)) {
199
+ return true;
200
+ } else if (content.includes("dva-model-extend") && t.isCallExpression(node) && node.arguments.length === 2 && isModelObject(node.arguments[1])) {
201
+ return true;
202
+ }
203
+ return false;
204
+ }
205
+ });
194
206
  }
195
- exports.getModelUtil = getModelUtil;
196
207
  function getAllModels(api) {
197
- return getModelUtil(api).getAllModels({
198
- extraModels: [...(api.config.dva.extraModels || [])],
199
- });
208
+ return getModelUtil(api).getAllModels({
209
+ extraModels: [...api.config.dva.extraModels || []]
210
+ });
200
211
  }
201
- exports.getAllModels = getAllModels;
202
212
  function isModelObject(node) {
203
- return (t.isObjectExpression(node) &&
204
- node.properties.some((property) => {
205
- return [
206
- 'state',
207
- 'reducers',
208
- 'subscriptions',
209
- 'effects',
210
- 'namespace',
211
- ].includes(property.key.name);
212
- }));
213
+ return t.isObjectExpression(node) && node.properties.some((property) => {
214
+ return [
215
+ "state",
216
+ "reducers",
217
+ "subscriptions",
218
+ "effects",
219
+ "namespace"
220
+ ].includes(property.key.name);
221
+ });
213
222
  }
223
+ // Annotate the CommonJS export names for ESM import in node:
224
+ 0 && (module.exports = {
225
+ getAllModels,
226
+ getModelUtil
227
+ });
package/dist/icons.js CHANGED
@@ -1,5 +1,29 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = (api) => {
4
- api;
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
5
8
  };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/icons.ts
20
+ var icons_exports = {};
21
+ __export(icons_exports, {
22
+ default: () => icons_default
23
+ });
24
+ module.exports = __toCommonJS(icons_exports);
25
+ var icons_default = (api) => {
26
+ api;
27
+ };
28
+ // Annotate the CommonJS export names for ESM import in node:
29
+ 0 && (module.exports = {});
@@ -1,42 +1,62 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const withTmpPath_1 = require("./utils/withTmpPath");
4
- exports.default = (api) => {
5
- api.describe({
6
- config: {
7
- schema(Joi) {
8
- return Joi.object({
9
- loading: Joi.string(),
10
- });
11
- },
12
- },
13
- enableBy: api.EnableBy.config,
14
- });
15
- api.register({
16
- key: 'addExtraModels',
17
- fn: () => [
18
- (0, withTmpPath_1.withTmpPath)({
19
- api,
20
- path: '@@initialState.ts#{"namespace":"@@initialState"}',
21
- }),
22
- ],
23
- });
24
- api.addRuntimePluginKey(() => ['getInitialState']);
25
- api.addRuntimePlugin(() => {
26
- return [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })];
27
- });
28
- api.onGenerateFiles(() => {
29
- var _a;
30
- const { loading } = api.config.initialState;
31
- // Provider.tsx
32
- api.writeTmpFile({
33
- path: 'Provider.tsx',
34
- content: `
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/initial-state.ts
20
+ var initial_state_exports = {};
21
+ __export(initial_state_exports, {
22
+ default: () => initial_state_default
23
+ });
24
+ module.exports = __toCommonJS(initial_state_exports);
25
+ var import_umi = require("umi");
26
+ var import_withTmpPath = require("./utils/withTmpPath");
27
+ var initial_state_default = (api) => {
28
+ api.describe({
29
+ config: {
30
+ schema(Joi) {
31
+ return Joi.alternatives().try(Joi.object({
32
+ loading: Joi.string()
33
+ }), Joi.boolean().invalid(true));
34
+ }
35
+ },
36
+ enableBy: api.EnableBy.config
37
+ });
38
+ api.register({
39
+ key: "addExtraModels",
40
+ fn: () => [
41
+ (0, import_withTmpPath.withTmpPath)({
42
+ api,
43
+ path: '@@initialState.ts#{"namespace":"@@initialState"}'
44
+ })
45
+ ]
46
+ });
47
+ api.addRuntimePluginKey(() => ["getInitialState"]);
48
+ api.addRuntimePlugin(() => {
49
+ return [(0, import_withTmpPath.withTmpPath)({ api, path: "runtime.tsx" })];
50
+ });
51
+ api.onGenerateFiles(() => {
52
+ var _a;
53
+ const { loading } = api.config.initialState;
54
+ api.writeTmpFile({
55
+ path: "Provider.tsx",
56
+ content: `
35
57
  import React from 'react';
36
58
  import { useModel } from '@@/plugin-model';
37
- ${loading
38
- ? `import Loading from '${loading}'`
39
- : `function Loading() { return <div />; }`}
59
+ ${loading ? `import Loading from '${loading}'` : `function Loading() { return <div />; }`}
40
60
  export default function InitialStateProvider(props: any) {
41
61
  const appLoaded = React.useRef(false);
42
62
  const { loading = false } = useModel("@@initialState") || {};
@@ -50,13 +70,11 @@ export default function InitialStateProvider(props: any) {
50
70
  }
51
71
  return props.children;
52
72
  }
53
- `,
54
- });
55
- // @@initialState.ts
56
- api.writeTmpFile({
57
- path: '@@initialState.ts',
58
- content: ((_a = api.appData.appJS) === null || _a === void 0 ? void 0 : _a.exports.includes('getInitialState'))
59
- ? `
73
+ `
74
+ });
75
+ api.writeTmpFile({
76
+ path: "@@initialState.ts",
77
+ content: ((_a = api.appData.appJS) == null ? void 0 : _a.exports.includes("getInitialState")) ? `
60
78
  import { useState, useEffect, useCallback } from 'react';
61
79
  import { getInitialState } from '@/app';
62
80
 
@@ -104,21 +122,29 @@ export default () => {
104
122
  setInitialState,
105
123
  };
106
124
  }
107
- `
108
- : `
125
+ ` : `
109
126
  export default () => ({ loading: false, refresh: () => {} })
110
- `,
111
- });
112
- // runtime.tsx
113
- api.writeTmpFile({
114
- path: 'runtime.tsx',
115
- content: `
127
+ `
128
+ });
129
+ api.writeTmpFile({
130
+ path: "runtime.tsx",
131
+ content: `
116
132
  import React from 'react';
117
133
  import Provider from './Provider';
118
134
  export function dataflowProvider(container) {
119
135
  return <Provider>{ container }</Provider>;
120
136
  }
121
- `,
122
- });
137
+ `
138
+ });
139
+ api.writeTmpFile({
140
+ path: import_umi.RUNTIME_TYPE_FILE_NAME,
141
+ content: `
142
+ export interface IRuntimeConfig {
143
+ getInitialState?: () => Promise<Record<string, any>>
144
+ }
145
+ `
123
146
  });
147
+ });
124
148
  };
149
+ // Annotate the CommonJS export names for ESM import in node:
150
+ 0 && (module.exports = {});