umi 4.0.0-rc.12 → 4.0.0-rc.13

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,3 +1,14 @@
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
+ };
1
12
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
13
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
14
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -7,6 +18,33 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
18
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
19
  });
9
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
+ };
10
48
  import { assert, compose, isPromiseLike } from './utils';
11
49
  export var ApplyPluginsType;
12
50
  (function (ApplyPluginsType) {
@@ -14,27 +52,29 @@ export var ApplyPluginsType;
14
52
  ApplyPluginsType["modify"] = "modify";
15
53
  ApplyPluginsType["event"] = "event";
16
54
  })(ApplyPluginsType || (ApplyPluginsType = {}));
17
- export class PluginManager {
18
- constructor(opts) {
55
+ var PluginManager = /** @class */ (function () {
56
+ function PluginManager(opts) {
19
57
  this.hooks = {};
20
58
  this.opts = opts;
21
59
  }
22
- register(plugin) {
23
- assert(plugin.apply && plugin.path, `plugin register failed, apply and path must supplied`);
24
- Object.keys(plugin.apply).forEach((key) => {
25
- assert(this.opts.validKeys.indexOf(key) > -1, `register failed, invalid key ${key} from plugin ${plugin.path}.`);
26
- this.hooks[key] = (this.hooks[key] || []).concat(plugin.apply[key]);
60
+ PluginManager.prototype.register = function (plugin) {
61
+ var _this = this;
62
+ assert(plugin.apply && plugin.path, "plugin register failed, apply and path must supplied");
63
+ Object.keys(plugin.apply).forEach(function (key) {
64
+ assert(_this.opts.validKeys.indexOf(key) > -1, "register failed, invalid key ".concat(key, " from plugin ").concat(plugin.path, "."));
65
+ _this.hooks[key] = (_this.hooks[key] || []).concat(plugin.apply[key]);
27
66
  });
28
- }
29
- getHooks(keyWithDot) {
30
- const [key, ...memberKeys] = keyWithDot.split('.');
31
- let hooks = this.hooks[key] || [];
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] || [];
32
71
  if (memberKeys.length) {
33
72
  hooks = hooks
34
- .map((hook) => {
73
+ .map(function (hook) {
35
74
  try {
36
- let ret = hook;
37
- for (const memberKey of memberKeys) {
75
+ var ret = hook;
76
+ for (var _i = 0, memberKeys_1 = memberKeys; _i < memberKeys_1.length; _i++) {
77
+ var memberKey = memberKeys_1[_i];
38
78
  ret = ret[memberKey];
39
79
  }
40
80
  return ret;
@@ -46,84 +86,112 @@ export class PluginManager {
46
86
  .filter(Boolean);
47
87
  }
48
88
  return hooks;
49
- }
50
- applyPlugins({ key, type, initialValue, args, async, }) {
51
- const hooks = this.getHooks(key) || [];
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) || [];
52
94
  if (args) {
53
- assert(typeof args === 'object', `applyPlugins failed, args must be plain object.`);
95
+ assert(typeof args === 'object', "applyPlugins failed, args must be plain object.");
54
96
  }
55
97
  if (async) {
56
- assert(type === ApplyPluginsType.modify || type === ApplyPluginsType.event, `async only works with modify and event type.`);
98
+ assert(type === ApplyPluginsType.modify || type === ApplyPluginsType.event, "async only works with modify and event type.");
57
99
  }
58
100
  switch (type) {
59
101
  case ApplyPluginsType.modify:
60
102
  if (async) {
61
- return hooks.reduce((memo, hook) => __awaiter(this, void 0, void 0, function* () {
62
- assert(typeof hook === 'function' ||
63
- typeof hook === 'object' ||
64
- isPromiseLike(hook), `applyPlugins failed, all hooks for key ${key} must be function, plain object or Promise.`);
65
- if (isPromiseLike(memo)) {
66
- memo = yield memo;
67
- }
68
- if (typeof hook === 'function') {
69
- const ret = hook(memo, args);
70
- if (isPromiseLike(ret)) {
71
- return yield ret;
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*/];
72
132
  }
73
- else {
74
- return ret;
75
- }
76
- }
77
- else {
78
- if (isPromiseLike(hook)) {
79
- hook = yield hook;
80
- }
81
- return Object.assign(Object.assign({}, memo), hook);
82
- }
83
- }), isPromiseLike(initialValue)
133
+ });
134
+ }); }, isPromiseLike(initialValue)
84
135
  ? initialValue
85
136
  : Promise.resolve(initialValue));
86
137
  }
87
138
  else {
88
- return hooks.reduce((memo, hook) => {
89
- assert(typeof hook === 'function' || typeof hook === 'object', `applyPlugins failed, all hooks for key ${key} must be function or plain object.`);
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."));
90
141
  if (typeof hook === 'function') {
91
142
  return hook(memo, args);
92
143
  }
93
144
  else {
94
145
  // TODO: deepmerge?
95
- return Object.assign(Object.assign({}, memo), hook);
146
+ return __assign(__assign({}, memo), hook);
96
147
  }
97
148
  }, initialValue);
98
149
  }
99
150
  case ApplyPluginsType.event:
100
- return (() => __awaiter(this, void 0, void 0, function* () {
101
- for (const hook of hooks) {
102
- assert(typeof hook === 'function', `applyPlugins failed, all hooks for key ${key} must be function.`);
103
- const ret = hook(args);
104
- if (async && isPromiseLike(ret)) {
105
- yield ret;
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*/];
106
172
  }
107
- }
108
- }))();
173
+ });
174
+ }); })();
109
175
  case ApplyPluginsType.compose:
110
- return () => {
176
+ return function () {
111
177
  return compose({
112
178
  fns: hooks.concat(initialValue),
113
- args,
179
+ args: args,
114
180
  })();
115
181
  };
116
182
  }
117
- }
118
- static create(opts) {
119
- const pluginManager = new PluginManager({
183
+ };
184
+ PluginManager.create = function (opts) {
185
+ var pluginManager = new PluginManager({
120
186
  validKeys: opts.validKeys,
121
187
  });
122
- opts.plugins.forEach((plugin) => {
188
+ opts.plugins.forEach(function (plugin) {
123
189
  pluginManager.register(plugin);
124
190
  });
125
191
  return pluginManager;
126
- }
127
- }
192
+ };
193
+ return PluginManager;
194
+ }());
195
+ export { PluginManager };
128
196
  // plugins meta info (in tmp file)
129
197
  // hooks api: usePlugin
@@ -2,12 +2,13 @@ export function assert(value, message) {
2
2
  if (!value)
3
3
  throw new Error(message);
4
4
  }
5
- export function compose({ fns, args, }) {
5
+ export function compose(_a) {
6
+ var fns = _a.fns, args = _a.args;
6
7
  if (fns.length === 1) {
7
8
  return fns[0];
8
9
  }
9
- const last = fns.pop();
10
- return fns.reduce((a, b) => () => b(a, args), last);
10
+ var last = fns.pop();
11
+ return fns.reduce(function (a, b) { return function () { return b(a, args); }; }, last);
11
12
  }
12
13
  export function isPromiseLike(obj) {
13
14
  return !!obj && typeof obj === 'object' && typeof obj.then === 'function';
package/dist/cli/node.js CHANGED
@@ -5,8 +5,8 @@ const utils_1 = require("@umijs/utils");
5
5
  const constants_1 = require("../constants");
6
6
  function checkVersion() {
7
7
  const v = parseInt(process.version.slice(1));
8
- if (v < constants_1.MIN_NODE_VERSION || v === constants_1.EXCLUDE_NODE_VERSION) {
9
- utils_1.logger.error(`Your node version ${v} is not supported, please upgrade to ${constants_1.MIN_NODE_VERSION} or above except ${constants_1.EXCLUDE_NODE_VERSION}.`);
8
+ if (v < constants_1.MIN_NODE_VERSION || v === 15 || v === 17) {
9
+ utils_1.logger.error(`Your node version ${v} is not supported, please upgrade to ${constants_1.MIN_NODE_VERSION} or above except 15 or 17.`);
10
10
  process.exit(1);
11
11
  }
12
12
  }
@@ -1,5 +1,4 @@
1
1
  export declare const MIN_NODE_VERSION = 14;
2
- export declare const EXCLUDE_NODE_VERSION = 15;
3
2
  export declare const DEV_COMMAND = "dev";
4
3
  export declare const DEFAULT_CONFIG_FILES: string[];
5
4
  export declare const FRAMEWORK_NAME = "umi";
package/dist/constants.js CHANGED
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FRAMEWORK_NAME = exports.DEFAULT_CONFIG_FILES = exports.DEV_COMMAND = exports.EXCLUDE_NODE_VERSION = exports.MIN_NODE_VERSION = void 0;
3
+ exports.FRAMEWORK_NAME = exports.DEFAULT_CONFIG_FILES = exports.DEV_COMMAND = exports.MIN_NODE_VERSION = void 0;
4
4
  exports.MIN_NODE_VERSION = 14;
5
- exports.EXCLUDE_NODE_VERSION = 15;
6
5
  exports.DEV_COMMAND = 'dev';
7
6
  exports.DEFAULT_CONFIG_FILES = [
8
7
  '.umirc.ts',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "umi",
3
- "version": "4.0.0-rc.12",
3
+ "version": "4.0.0-rc.13",
4
4
  "description": "umi",
5
5
  "homepage": "https://github.com/umijs/umi-next/tree/master/packages/umi#readme",
6
6
  "bugs": "https://github.com/umijs/umi-next/issues",
@@ -37,14 +37,14 @@
37
37
  "test": "jest -c ../../jest.turbo.config.ts"
38
38
  },
39
39
  "dependencies": {
40
- "@umijs/bundler-utils": "4.0.0-rc.12",
41
- "@umijs/bundler-webpack": "4.0.0-rc.12",
42
- "@umijs/core": "4.0.0-rc.12",
43
- "@umijs/lint": "4.0.0-rc.12",
44
- "@umijs/preset-umi": "4.0.0-rc.12",
45
- "@umijs/renderer-react": "4.0.0-rc.12",
46
- "@umijs/test": "4.0.0-rc.12",
47
- "@umijs/utils": "4.0.0-rc.12",
40
+ "@umijs/bundler-utils": "4.0.0-rc.13",
41
+ "@umijs/bundler-webpack": "4.0.0-rc.13",
42
+ "@umijs/core": "4.0.0-rc.13",
43
+ "@umijs/lint": "4.0.0-rc.13",
44
+ "@umijs/preset-umi": "4.0.0-rc.13",
45
+ "@umijs/renderer-react": "4.0.0-rc.13",
46
+ "@umijs/test": "4.0.0-rc.13",
47
+ "@umijs/utils": "4.0.0-rc.13",
48
48
  "prettier-plugin-organize-imports": "^2.3.4",
49
49
  "prettier-plugin-packagejson": "^2.2.17"
50
50
  },