umi 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.
@@ -1,197 +1,270 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
- return new (P || (P = Promise))(function (resolve, reject) {
15
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
- step((generator = generator.apply(thisArg, _arguments || [])).next());
19
- });
20
- };
21
- var __generator = (this && this.__generator) || function (thisArg, body) {
22
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
- function verb(n) { return function (v) { return step([n, v]); }; }
25
- function step(op) {
26
- if (f) throw new TypeError("Generator is already executing.");
27
- while (_) try {
28
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
- if (y = 0, t) op = [op[0] & 2, t.value];
30
- switch (op[0]) {
31
- case 0: case 1: t = op; break;
32
- case 4: _.label++; return { value: op[1], done: false };
33
- case 5: _.label++; y = op[1]; op = [0]; continue;
34
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
- default:
36
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
- if (t[2]) _.ops.pop();
41
- _.trys.pop(); continue;
42
- }
43
- op = body.call(thisArg, _);
44
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
- }
47
- };
48
- import { assert, compose, isPromiseLike } from './utils';
1
+ import _objectSpread from "@babel/runtime/helpers/objectSpread2";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
+ import _typeof from "@babel/runtime/helpers/typeof";
4
+ import _createForOfIteratorHelper from "@babel/runtime/helpers/createForOfIteratorHelper";
5
+ import _toArray from "@babel/runtime/helpers/toArray";
6
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
7
+ import _createClass from "@babel/runtime/helpers/createClass";
8
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
9
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
10
+ import { assert, compose, isPromiseLike } from "./utils";
49
11
  export var ApplyPluginsType;
12
+
50
13
  (function (ApplyPluginsType) {
51
- ApplyPluginsType["compose"] = "compose";
52
- ApplyPluginsType["modify"] = "modify";
53
- ApplyPluginsType["event"] = "event";
14
+ ApplyPluginsType["compose"] = "compose";
15
+ ApplyPluginsType["modify"] = "modify";
16
+ ApplyPluginsType["event"] = "event";
54
17
  })(ApplyPluginsType || (ApplyPluginsType = {}));
55
- var PluginManager = /** @class */ (function () {
56
- function PluginManager(opts) {
57
- this.hooks = {};
58
- this.opts = opts;
18
+
19
+ export var PluginManager = /*#__PURE__*/function () {
20
+ function PluginManager(opts) {
21
+ _classCallCheck(this, PluginManager);
22
+
23
+ _defineProperty(this, "opts", void 0);
24
+
25
+ _defineProperty(this, "hooks", {});
26
+
27
+ this.opts = opts;
28
+ }
29
+
30
+ _createClass(PluginManager, [{
31
+ key: "register",
32
+ value: function register(plugin) {
33
+ var _this = this;
34
+
35
+ assert(plugin.apply, "plugin register failed, apply must supplied");
36
+ Object.keys(plugin.apply).forEach(function (key) {
37
+ assert(_this.opts.validKeys.indexOf(key) > -1, "register failed, invalid key ".concat(key, " ").concat(plugin.path ? "from plugin ".concat(plugin.path) : '', "."));
38
+ _this.hooks[key] = (_this.hooks[key] || []).concat(plugin.apply[key]);
39
+ });
59
40
  }
60
- PluginManager.prototype.register = function (plugin) {
61
- var _this = this;
62
- assert(plugin.apply, "plugin register failed, apply must supplied");
63
- Object.keys(plugin.apply).forEach(function (key) {
64
- assert(_this.opts.validKeys.indexOf(key) > -1, "register failed, invalid key ".concat(key, " ").concat(plugin.path ? "from plugin ".concat(plugin.path) : '', "."));
65
- _this.hooks[key] = (_this.hooks[key] || []).concat(plugin.apply[key]);
66
- });
67
- };
68
- PluginManager.prototype.getHooks = function (keyWithDot) {
69
- var _a = keyWithDot.split('.'), key = _a[0], memberKeys = _a.slice(1);
70
- var hooks = this.hooks[key] || [];
71
- if (memberKeys.length) {
72
- hooks = hooks
73
- .map(function (hook) {
74
- try {
75
- var ret = hook;
76
- for (var _i = 0, memberKeys_1 = memberKeys; _i < memberKeys_1.length; _i++) {
77
- var memberKey = memberKeys_1[_i];
78
- ret = ret[memberKey];
79
- }
80
- return ret;
81
- }
82
- catch (e) {
83
- return null;
84
- }
85
- })
86
- .filter(Boolean);
87
- }
88
- return hooks;
89
- };
90
- PluginManager.prototype.applyPlugins = function (_a) {
91
- var _this = this;
92
- var key = _a.key, type = _a.type, initialValue = _a.initialValue, args = _a.args, async = _a.async;
93
- var hooks = this.getHooks(key) || [];
94
- if (args) {
95
- assert(typeof args === 'object', "applyPlugins failed, args must be plain object.");
96
- }
97
- if (async) {
98
- assert(type === ApplyPluginsType.modify || type === ApplyPluginsType.event, "async only works with modify and event type.");
99
- }
100
- switch (type) {
101
- case ApplyPluginsType.modify:
102
- if (async) {
103
- return hooks.reduce(function (memo, hook) { return __awaiter(_this, void 0, void 0, function () {
104
- var ret;
105
- return __generator(this, function (_a) {
106
- switch (_a.label) {
107
- case 0:
108
- assert(typeof hook === 'function' ||
109
- typeof hook === 'object' ||
110
- isPromiseLike(hook), "applyPlugins failed, all hooks for key ".concat(key, " must be function, plain object or Promise."));
111
- if (!isPromiseLike(memo)) return [3 /*break*/, 2];
112
- return [4 /*yield*/, memo];
113
- case 1:
114
- memo = _a.sent();
115
- _a.label = 2;
116
- case 2:
117
- if (!(typeof hook === 'function')) return [3 /*break*/, 6];
118
- ret = hook(memo, args);
119
- if (!isPromiseLike(ret)) return [3 /*break*/, 4];
120
- return [4 /*yield*/, ret];
121
- case 3: return [2 /*return*/, _a.sent()];
122
- case 4: return [2 /*return*/, ret];
123
- case 5: return [3 /*break*/, 9];
124
- case 6:
125
- if (!isPromiseLike(hook)) return [3 /*break*/, 8];
126
- return [4 /*yield*/, hook];
127
- case 7:
128
- hook = _a.sent();
129
- _a.label = 8;
130
- case 8: return [2 /*return*/, __assign(__assign({}, memo), hook)];
131
- case 9: return [2 /*return*/];
132
- }
133
- });
134
- }); }, isPromiseLike(initialValue)
135
- ? initialValue
136
- : Promise.resolve(initialValue));
137
- }
138
- else {
139
- return hooks.reduce(function (memo, hook) {
140
- assert(typeof hook === 'function' || typeof hook === 'object', "applyPlugins failed, all hooks for key ".concat(key, " must be function or plain object."));
141
- if (typeof hook === 'function') {
142
- return hook(memo, args);
41
+ }, {
42
+ key: "getHooks",
43
+ value: function getHooks(keyWithDot) {
44
+ var _keyWithDot$split = keyWithDot.split('.'),
45
+ _keyWithDot$split2 = _toArray(_keyWithDot$split),
46
+ key = _keyWithDot$split2[0],
47
+ memberKeys = _keyWithDot$split2.slice(1);
48
+
49
+ var hooks = this.hooks[key] || [];
50
+
51
+ if (memberKeys.length) {
52
+ hooks = hooks.map(function (hook) {
53
+ try {
54
+ var ret = hook;
55
+
56
+ var _iterator = _createForOfIteratorHelper(memberKeys),
57
+ _step;
58
+
59
+ try {
60
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
61
+ var memberKey = _step.value;
62
+ ret = ret[memberKey];
63
+ }
64
+ } catch (err) {
65
+ _iterator.e(err);
66
+ } finally {
67
+ _iterator.f();
68
+ }
69
+
70
+ return ret;
71
+ } catch (e) {
72
+ return null;
73
+ }
74
+ }).filter(Boolean);
75
+ }
76
+
77
+ return hooks;
78
+ }
79
+ }, {
80
+ key: "applyPlugins",
81
+ value: function applyPlugins(_ref) {
82
+ var key = _ref.key,
83
+ type = _ref.type,
84
+ initialValue = _ref.initialValue,
85
+ args = _ref.args,
86
+ async = _ref.async;
87
+ var hooks = this.getHooks(key) || [];
88
+
89
+ if (args) {
90
+ assert(_typeof(args) === 'object', "applyPlugins failed, args must be plain object.");
91
+ }
92
+
93
+ if (async) {
94
+ assert(type === ApplyPluginsType.modify || type === ApplyPluginsType.event, "async only works with modify and event type.");
95
+ }
96
+
97
+ switch (type) {
98
+ case ApplyPluginsType.modify:
99
+ if (async) {
100
+ return hooks.reduce( /*#__PURE__*/function () {
101
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(memo, hook) {
102
+ var ret;
103
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
104
+ while (1) {
105
+ switch (_context.prev = _context.next) {
106
+ case 0:
107
+ assert(typeof hook === 'function' || _typeof(hook) === 'object' || isPromiseLike(hook), "applyPlugins failed, all hooks for key ".concat(key, " must be function, plain object or Promise."));
108
+
109
+ if (!isPromiseLike(memo)) {
110
+ _context.next = 5;
111
+ break;
143
112
  }
144
- else {
145
- // TODO: deepmerge?
146
- return __assign(__assign({}, memo), hook);
113
+
114
+ _context.next = 4;
115
+ return memo;
116
+
117
+ case 4:
118
+ memo = _context.sent;
119
+
120
+ case 5:
121
+ if (!(typeof hook === 'function')) {
122
+ _context.next = 16;
123
+ break;
147
124
  }
148
- }, initialValue);
149
- }
150
- case ApplyPluginsType.event:
151
- return (function () { return __awaiter(_this, void 0, void 0, function () {
152
- var _i, hooks_1, hook, ret;
153
- return __generator(this, function (_a) {
154
- switch (_a.label) {
155
- case 0:
156
- _i = 0, hooks_1 = hooks;
157
- _a.label = 1;
158
- case 1:
159
- if (!(_i < hooks_1.length)) return [3 /*break*/, 4];
160
- hook = hooks_1[_i];
161
- assert(typeof hook === 'function', "applyPlugins failed, all hooks for key ".concat(key, " must be function."));
162
- ret = hook(args);
163
- if (!(async && isPromiseLike(ret))) return [3 /*break*/, 3];
164
- return [4 /*yield*/, ret];
165
- case 2:
166
- _a.sent();
167
- _a.label = 3;
168
- case 3:
169
- _i++;
170
- return [3 /*break*/, 1];
171
- case 4: return [2 /*return*/];
125
+
126
+ ret = hook(memo, args);
127
+
128
+ if (!isPromiseLike(ret)) {
129
+ _context.next = 13;
130
+ break;
131
+ }
132
+
133
+ _context.next = 10;
134
+ return ret;
135
+
136
+ case 10:
137
+ return _context.abrupt("return", _context.sent);
138
+
139
+ case 13:
140
+ return _context.abrupt("return", ret);
141
+
142
+ case 14:
143
+ _context.next = 21;
144
+ break;
145
+
146
+ case 16:
147
+ if (!isPromiseLike(hook)) {
148
+ _context.next = 20;
149
+ break;
172
150
  }
173
- });
174
- }); })();
175
- case ApplyPluginsType.compose:
176
- return function () {
177
- return compose({
178
- fns: hooks.concat(initialValue),
179
- args: args,
180
- })();
181
- };
182
- }
183
- };
184
- PluginManager.create = function (opts) {
185
- var pluginManager = new PluginManager({
186
- validKeys: opts.validKeys,
187
- });
188
- opts.plugins.forEach(function (plugin) {
189
- pluginManager.register(plugin);
190
- });
191
- return pluginManager;
192
- };
193
- return PluginManager;
194
- }());
195
- export { PluginManager };
196
- // plugins meta info (in tmp file)
197
- // hooks api: usePlugin
151
+
152
+ _context.next = 19;
153
+ return hook;
154
+
155
+ case 19:
156
+ hook = _context.sent;
157
+
158
+ case 20:
159
+ return _context.abrupt("return", _objectSpread(_objectSpread({}, memo), hook));
160
+
161
+ case 21:
162
+ case "end":
163
+ return _context.stop();
164
+ }
165
+ }
166
+ }, _callee);
167
+ }));
168
+
169
+ return function (_x, _x2) {
170
+ return _ref2.apply(this, arguments);
171
+ };
172
+ }(), isPromiseLike(initialValue) ? initialValue : Promise.resolve(initialValue));
173
+ } else {
174
+ return hooks.reduce(function (memo, hook) {
175
+ assert(typeof hook === 'function' || _typeof(hook) === 'object', "applyPlugins failed, all hooks for key ".concat(key, " must be function or plain object."));
176
+
177
+ if (typeof hook === 'function') {
178
+ return hook(memo, args);
179
+ } else {
180
+ // TODO: deepmerge?
181
+ return _objectSpread(_objectSpread({}, memo), hook);
182
+ }
183
+ }, initialValue);
184
+ }
185
+
186
+ case ApplyPluginsType.event:
187
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
188
+ var _iterator2, _step2, hook, ret;
189
+
190
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
191
+ while (1) {
192
+ switch (_context2.prev = _context2.next) {
193
+ case 0:
194
+ _iterator2 = _createForOfIteratorHelper(hooks);
195
+ _context2.prev = 1;
196
+
197
+ _iterator2.s();
198
+
199
+ case 3:
200
+ if ((_step2 = _iterator2.n()).done) {
201
+ _context2.next = 12;
202
+ break;
203
+ }
204
+
205
+ hook = _step2.value;
206
+ assert(typeof hook === 'function', "applyPlugins failed, all hooks for key ".concat(key, " must be function."));
207
+ ret = hook(args);
208
+
209
+ if (!(async && isPromiseLike(ret))) {
210
+ _context2.next = 10;
211
+ break;
212
+ }
213
+
214
+ _context2.next = 10;
215
+ return ret;
216
+
217
+ case 10:
218
+ _context2.next = 3;
219
+ break;
220
+
221
+ case 12:
222
+ _context2.next = 17;
223
+ break;
224
+
225
+ case 14:
226
+ _context2.prev = 14;
227
+ _context2.t0 = _context2["catch"](1);
228
+
229
+ _iterator2.e(_context2.t0);
230
+
231
+ case 17:
232
+ _context2.prev = 17;
233
+
234
+ _iterator2.f();
235
+
236
+ return _context2.finish(17);
237
+
238
+ case 20:
239
+ case "end":
240
+ return _context2.stop();
241
+ }
242
+ }
243
+ }, _callee2, null, [[1, 14, 17, 20]]);
244
+ }))();
245
+
246
+ case ApplyPluginsType.compose:
247
+ return function () {
248
+ return compose({
249
+ fns: hooks.concat(initialValue),
250
+ args: args
251
+ })();
252
+ };
253
+ }
254
+ }
255
+ }], [{
256
+ key: "create",
257
+ value: function create(opts) {
258
+ var pluginManager = new PluginManager({
259
+ validKeys: opts.validKeys
260
+ });
261
+ opts.plugins.forEach(function (plugin) {
262
+ pluginManager.register(plugin);
263
+ });
264
+ return pluginManager;
265
+ }
266
+ }]);
267
+
268
+ return PluginManager;
269
+ }(); // plugins meta info (in tmp file)
270
+ // hooks api: usePlugin
@@ -1,15 +1,22 @@
1
+ import _typeof from "@babel/runtime/helpers/typeof";
1
2
  export function assert(value, message) {
2
- if (!value)
3
- throw new Error(message);
3
+ if (!value) throw new Error(message);
4
4
  }
5
- export function compose(_a) {
6
- var fns = _a.fns, args = _a.args;
7
- if (fns.length === 1) {
8
- return fns[0];
9
- }
10
- var last = fns.pop();
11
- return fns.reduce(function (a, b) { return function () { return b(a, args); }; }, last);
5
+ export function compose(_ref) {
6
+ var fns = _ref.fns,
7
+ args = _ref.args;
8
+
9
+ if (fns.length === 1) {
10
+ return fns[0];
11
+ }
12
+
13
+ var last = fns.pop();
14
+ return fns.reduce(function (a, b) {
15
+ return function () {
16
+ return b(a, args);
17
+ };
18
+ }, last);
12
19
  }
13
20
  export function isPromiseLike(obj) {
14
- return !!obj && typeof obj === 'object' && typeof obj.then === 'function';
15
- }
21
+ return !!obj && _typeof(obj) === 'object' && typeof obj.then === 'function';
22
+ }
package/dist/cli/cli.js CHANGED
@@ -1,48 +1,69 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.run = void 0;
4
- const utils_1 = require("@umijs/utils");
5
- const constants_1 = require("../constants");
6
- const service_1 = require("../service/service");
7
- const dev_1 = require("./dev");
8
- const node_1 = require("./node");
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/cli/cli.ts
20
+ var cli_exports = {};
21
+ __export(cli_exports, {
22
+ run: () => run
23
+ });
24
+ module.exports = __toCommonJS(cli_exports);
25
+ var import_utils = require("@umijs/utils");
26
+ var import_constants = require("../constants");
27
+ var import_service = require("../service/service");
28
+ var import_dev = require("./dev");
29
+ var import_node = require("./node");
9
30
  async function run(opts) {
10
- (0, node_1.checkVersion)();
11
- (0, node_1.checkLocal)();
12
- (0, node_1.setNodeTitle)();
13
- (0, node_1.setNoDeprecation)();
14
- const args = (0, utils_1.yParser)(process.argv.slice(2), {
15
- alias: {
16
- version: ['v'],
17
- help: ['h'],
18
- },
19
- boolean: ['version'],
20
- });
21
- const command = args._[0];
22
- if ([constants_1.DEV_COMMAND, 'setup'].includes(command)) {
23
- process.env.NODE_ENV = 'development';
24
- }
25
- else if (command === 'build') {
26
- process.env.NODE_ENV = 'production';
27
- }
28
- if (opts === null || opts === void 0 ? void 0 : opts.presets) {
29
- process.env.UMI_PRESETS = opts.presets.join(',');
30
- }
31
- if (command === constants_1.DEV_COMMAND) {
32
- (0, dev_1.dev)();
33
- }
34
- else {
35
- try {
36
- await new service_1.Service().run2({
37
- name: args._[0],
38
- args,
39
- });
40
- }
41
- catch (e) {
42
- utils_1.logger.fatal(e);
43
- utils_1.printHelp.exit();
44
- process.exit(1);
45
- }
31
+ (0, import_node.checkVersion)();
32
+ (0, import_node.checkLocal)();
33
+ (0, import_node.setNodeTitle)();
34
+ (0, import_node.setNoDeprecation)();
35
+ const args = (0, import_utils.yParser)(process.argv.slice(2), {
36
+ alias: {
37
+ version: ["v"],
38
+ help: ["h"]
39
+ },
40
+ boolean: ["version"]
41
+ });
42
+ const command = args._[0];
43
+ if ([import_constants.DEV_COMMAND, "setup"].includes(command)) {
44
+ process.env.NODE_ENV = "development";
45
+ } else if (command === "build") {
46
+ process.env.NODE_ENV = "production";
47
+ }
48
+ if (opts == null ? void 0 : opts.presets) {
49
+ process.env.UMI_PRESETS = opts.presets.join(",");
50
+ }
51
+ if (command === import_constants.DEV_COMMAND) {
52
+ (0, import_dev.dev)();
53
+ } else {
54
+ try {
55
+ await new import_service.Service().run2({
56
+ name: args._[0],
57
+ args
58
+ });
59
+ } catch (e) {
60
+ import_utils.logger.fatal(e);
61
+ import_utils.printHelp.exit();
62
+ process.exit(1);
46
63
  }
64
+ }
47
65
  }
48
- exports.run = run;
66
+ // Annotate the CommonJS export names for ESM import in node:
67
+ 0 && (module.exports = {
68
+ run
69
+ });