@umijs/plugins 4.0.7 → 4.0.8

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,80 @@
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;
53
- });
54
- api.modifyConfig((memo) => {
55
- // import from dva
56
- memo.alias['dva$'] = pkgPath;
57
- return memo;
58
- });
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),
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
+ // 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_plugin_utils = require("umi/plugin-utils");
34
+ var import_modelUtils = require("./utils/modelUtils");
35
+ var import_withTmpPath = require("./utils/withTmpPath");
36
+ var dva_default = (api) => {
37
+ const pkgPath = (0, import_path.join)(__dirname, "../libs/dva.ts");
38
+ api.describe({
39
+ config: {
40
+ schema(Joi) {
41
+ return Joi.object({
42
+ extraModels: Joi.array().items(Joi.string()),
43
+ immer: Joi.object()
68
44
  });
69
- // dva.tsx
70
- api.writeTmpFile({
71
- path: 'dva.tsx',
72
- tpl: `
45
+ }
46
+ },
47
+ enableBy: api.EnableBy.config
48
+ });
49
+ api.modifyAppData((memo) => {
50
+ const models = getAllModels(api);
51
+ memo.pluginDva = {
52
+ pkgPath,
53
+ models
54
+ };
55
+ return memo;
56
+ });
57
+ api.modifyConfig((memo) => {
58
+ memo.alias["dva$"] = pkgPath;
59
+ return memo;
60
+ });
61
+ api.onGenerateFiles((args) => {
62
+ var _a, _b, _c, _d, _e, _f;
63
+ const models = args.isFirstTime ? api.appData.pluginDva.models : getAllModels(api);
64
+ api.writeTmpFile({
65
+ path: "models.ts",
66
+ content: import_modelUtils.ModelUtils.getModelsContent(models)
67
+ });
68
+ api.writeTmpFile({
69
+ path: "dva.tsx",
70
+ tpl: `
73
71
  // It's faked dva
74
72
  // aliased to @umijs/plugins/templates/dva
75
73
  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
- : ''}
74
+ import createLoading from '${(0, import_utils.winPath)(require.resolve("dva-loading"))}';
75
+ ${((_a = api.config.dva) == null ? void 0 : _a.immer) ? `
76
+ import dvaImmer, { enableES5, enableAllPlugins } from '${(0, import_utils.winPath)(require.resolve("dva-immer"))}';
77
+ ` : ""}
82
78
  import React, { useRef } from 'react';
83
79
  import { history, ApplyPluginsType, useAppData } from 'umi';
84
80
  import { models } from './models';
@@ -111,9 +107,9 @@ export function RootContainer(props: any) {
111
107
  );
112
108
  dvaApp = app.current;
113
109
  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();` : ''}
110
+ ${((_b = api.config.dva) == null ? void 0 : _b.immer) ? `app.current.use(dvaImmer());` : ""}
111
+ ${((_d = (_c = api.config.dva) == null ? void 0 : _c.immer) == null ? void 0 : _d.enableES5) ? `enableES5();` : ""}
112
+ ${((_f = (_e = api.config.dva) == null ? void 0 : _e.immer) == null ? void 0 : _f.enableAllPlugins) ? `enableAllPlugins();` : ""}
117
113
  (runtimeDva.plugins || []).forEach((p) => {
118
114
  app.current.use(p);
119
115
  });
@@ -132,82 +128,77 @@ export function getDvaApp() {
132
128
  return dvaApp;
133
129
  }
134
130
  `,
135
- context: {},
136
- });
137
- // runtime.tsx
138
- api.writeTmpFile({
139
- path: 'runtime.tsx',
140
- content: `
131
+ context: {}
132
+ });
133
+ api.writeTmpFile({
134
+ path: "runtime.tsx",
135
+ content: `
141
136
  import React from 'react';
142
137
  import { RootContainer } from './dva';
143
138
 
144
139
  export function dataflowProvider(container, opts) {
145
140
  return React.createElement(RootContainer, opts, container);
146
141
  }
147
- `,
148
- });
149
- // index.ts for export
150
- api.writeTmpFile({
151
- path: 'index.ts',
152
- content: `
142
+ `
143
+ });
144
+ api.writeTmpFile({
145
+ path: "index.ts",
146
+ content: `
153
147
  export { connect, useDispatch, useStore, useSelector } from 'dva';
154
148
  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
- },
149
+ `
174
150
  });
151
+ });
152
+ api.addTmpGenerateWatcherPaths(() => {
153
+ return [(0, import_path.join)(api.paths.absSrcPath, "models")];
154
+ });
155
+ api.addRuntimePlugin(() => {
156
+ return [(0, import_withTmpPath.withTmpPath)({ api, path: "runtime.tsx" })];
157
+ });
158
+ api.addRuntimePluginKey(() => ["dva"]);
159
+ api.registerCommand({
160
+ name: "dva",
161
+ fn() {
162
+ api.logger.info(import_plugin_utils.chalk.green.bold("dva models"));
163
+ api.appData.pluginDva.models.forEach((model) => {
164
+ api.logger.info(` - ${(0, import_path.relative)(api.cwd, model.file)}`);
165
+ });
166
+ }
167
+ });
175
168
  };
176
169
  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
- });
170
+ return new import_modelUtils.ModelUtils(api, {
171
+ contentTest(content) {
172
+ return content.startsWith("// @dva-model");
173
+ },
174
+ astTest({ node, content }) {
175
+ if (isModelObject(node)) {
176
+ return true;
177
+ } else if (content.includes("dva-model-extend") && t.isCallExpression(node) && node.arguments.length === 2 && isModelObject(node.arguments[1])) {
178
+ return true;
179
+ }
180
+ return false;
181
+ }
182
+ });
194
183
  }
195
- exports.getModelUtil = getModelUtil;
196
184
  function getAllModels(api) {
197
- return getModelUtil(api).getAllModels({
198
- extraModels: [...(api.config.dva.extraModels || [])],
199
- });
185
+ return getModelUtil(api).getAllModels({
186
+ extraModels: [...api.config.dva.extraModels || []]
187
+ });
200
188
  }
201
- exports.getAllModels = getAllModels;
202
189
  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
- }));
190
+ return t.isObjectExpression(node) && node.properties.some((property) => {
191
+ return [
192
+ "state",
193
+ "reducers",
194
+ "subscriptions",
195
+ "effects",
196
+ "namespace"
197
+ ].includes(property.key.name);
198
+ });
213
199
  }
200
+ // Annotate the CommonJS export names for ESM import in node:
201
+ 0 && (module.exports = {
202
+ getAllModels,
203
+ getModelUtil
204
+ });
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
+ // 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,61 @@
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
+ // 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_withTmpPath = require("./utils/withTmpPath");
26
+ var initial_state_default = (api) => {
27
+ api.describe({
28
+ config: {
29
+ schema(Joi) {
30
+ return Joi.object({
31
+ loading: Joi.string()
32
+ });
33
+ }
34
+ },
35
+ enableBy: api.EnableBy.config
36
+ });
37
+ api.register({
38
+ key: "addExtraModels",
39
+ fn: () => [
40
+ (0, import_withTmpPath.withTmpPath)({
41
+ api,
42
+ path: '@@initialState.ts#{"namespace":"@@initialState"}'
43
+ })
44
+ ]
45
+ });
46
+ api.addRuntimePluginKey(() => ["getInitialState"]);
47
+ api.addRuntimePlugin(() => {
48
+ return [(0, import_withTmpPath.withTmpPath)({ api, path: "runtime.tsx" })];
49
+ });
50
+ api.onGenerateFiles(() => {
51
+ var _a;
52
+ const { loading } = api.config.initialState;
53
+ api.writeTmpFile({
54
+ path: "Provider.tsx",
55
+ content: `
35
56
  import React from 'react';
36
57
  import { useModel } from '@@/plugin-model';
37
- ${loading
38
- ? `import Loading from '${loading}'`
39
- : `function Loading() { return <div />; }`}
58
+ ${loading ? `import Loading from '${loading}'` : `function Loading() { return <div />; }`}
40
59
  export default function InitialStateProvider(props: any) {
41
60
  const appLoaded = React.useRef(false);
42
61
  const { loading = false } = useModel("@@initialState") || {};
@@ -50,13 +69,11 @@ export default function InitialStateProvider(props: any) {
50
69
  }
51
70
  return props.children;
52
71
  }
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
- ? `
72
+ `
73
+ });
74
+ api.writeTmpFile({
75
+ path: "@@initialState.ts",
76
+ content: ((_a = api.appData.appJS) == null ? void 0 : _a.exports.includes("getInitialState")) ? `
60
77
  import { useState, useEffect, useCallback } from 'react';
61
78
  import { getInitialState } from '@/app';
62
79
 
@@ -104,21 +121,21 @@ export default () => {
104
121
  setInitialState,
105
122
  };
106
123
  }
107
- `
108
- : `
124
+ ` : `
109
125
  export default () => ({ loading: false, refresh: () => {} })
110
- `,
111
- });
112
- // runtime.tsx
113
- api.writeTmpFile({
114
- path: 'runtime.tsx',
115
- content: `
126
+ `
127
+ });
128
+ api.writeTmpFile({
129
+ path: "runtime.tsx",
130
+ content: `
116
131
  import React from 'react';
117
132
  import Provider from './Provider';
118
133
  export function dataflowProvider(container) {
119
134
  return <Provider>{ container }</Provider>;
120
135
  }
121
- `,
122
- });
136
+ `
123
137
  });
138
+ });
124
139
  };
140
+ // Annotate the CommonJS export names for ESM import in node:
141
+ 0 && (module.exports = {});