umi 4.0.0-rc.2 → 4.0.0-rc.22

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 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]);
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,76 +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.");
96
+ }
97
+ if (async) {
98
+ assert(type === ApplyPluginsType.modify || type === ApplyPluginsType.event, "async only works with modify and event type.");
54
99
  }
55
100
  switch (type) {
56
101
  case ApplyPluginsType.modify:
57
102
  if (async) {
58
- return hooks.reduce((memo, hook) => __awaiter(this, void 0, void 0, function* () {
59
- assert(typeof hook === 'function' ||
60
- typeof hook === 'object' ||
61
- isPromiseLike(hook), `applyPlugins failed, all hooks for key ${key} must be function, plain object or Promise.`);
62
- if (isPromiseLike(memo)) {
63
- memo = yield memo;
64
- }
65
- if (typeof hook === 'function') {
66
- const ret = hook(memo, args);
67
- if (isPromiseLike(ret)) {
68
- 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*/];
69
132
  }
70
- else {
71
- return ret;
72
- }
73
- }
74
- else {
75
- if (isPromiseLike(hook)) {
76
- hook = yield hook;
77
- }
78
- return Object.assign(Object.assign({}, memo), hook);
79
- }
80
- }), isPromiseLike(initialValue)
133
+ });
134
+ }); }, isPromiseLike(initialValue)
81
135
  ? initialValue
82
136
  : Promise.resolve(initialValue));
83
137
  }
84
138
  else {
85
- return hooks.reduce((memo, hook) => {
86
- 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."));
87
141
  if (typeof hook === 'function') {
88
142
  return hook(memo, args);
89
143
  }
90
144
  else {
91
145
  // TODO: deepmerge?
92
- return Object.assign(Object.assign({}, memo), hook);
146
+ return __assign(__assign({}, memo), hook);
93
147
  }
94
148
  }, initialValue);
95
149
  }
96
150
  case ApplyPluginsType.event:
97
- return hooks.forEach((hook) => {
98
- assert(typeof hook === 'function', `applyPlugins failed, all hooks for key ${key} must be function.`);
99
- hook(args);
100
- });
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*/];
172
+ }
173
+ });
174
+ }); })();
101
175
  case ApplyPluginsType.compose:
102
- return () => {
176
+ return function () {
103
177
  return compose({
104
178
  fns: hooks.concat(initialValue),
105
- args,
179
+ args: args,
106
180
  })();
107
181
  };
108
182
  }
109
- }
110
- static create(opts) {
111
- const pluginManager = new PluginManager({
183
+ };
184
+ PluginManager.create = function (opts) {
185
+ var pluginManager = new PluginManager({
112
186
  validKeys: opts.validKeys,
113
187
  });
114
- opts.plugins.forEach((plugin) => {
188
+ opts.plugins.forEach(function (plugin) {
115
189
  pluginManager.register(plugin);
116
190
  });
117
191
  return pluginManager;
118
- }
119
- }
192
+ };
193
+ return PluginManager;
194
+ }());
195
+ export { PluginManager };
120
196
  // plugins meta info (in tmp file)
121
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/cli.js CHANGED
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.run = void 0;
13
4
  const utils_1 = require("@umijs/utils");
@@ -15,44 +6,44 @@ const constants_1 = require("../constants");
15
6
  const service_1 = require("../service/service");
16
7
  const dev_1 = require("./dev");
17
8
  const node_1 = require("./node");
18
- function run(opts) {
19
- return __awaiter(this, void 0, void 0, function* () {
20
- (0, node_1.checkVersion)();
21
- (0, node_1.checkLocal)();
22
- (0, node_1.setNodeTitle)();
23
- (0, node_1.setNoDeprecation)();
24
- const args = (0, utils_1.yParser)(process.argv.slice(2), {
25
- alias: {
26
- version: ['v'],
27
- help: ['h'],
28
- },
29
- boolean: ['version'],
30
- });
31
- const command = args._[0];
32
- if ([constants_1.DEV_COMMAND, 'setup'].includes(command)) {
33
- process.env.NODE_ENV = 'development';
34
- }
35
- else if (command === 'build') {
36
- process.env.NODE_ENV = 'production';
37
- }
38
- if (opts === null || opts === void 0 ? void 0 : opts.presets) {
39
- process.env.UMI_PRESETS = opts.presets.join(',');
40
- }
41
- if (command === constants_1.DEV_COMMAND) {
42
- (0, dev_1.dev)();
9
+ const printHelp_1 = require("./printHelp");
10
+ async function run(opts) {
11
+ (0, node_1.checkVersion)();
12
+ (0, node_1.checkLocal)();
13
+ (0, node_1.setNodeTitle)();
14
+ (0, node_1.setNoDeprecation)();
15
+ const args = (0, utils_1.yParser)(process.argv.slice(2), {
16
+ alias: {
17
+ version: ['v'],
18
+ help: ['h'],
19
+ },
20
+ boolean: ['version'],
21
+ });
22
+ const command = args._[0];
23
+ if ([constants_1.DEV_COMMAND, 'setup'].includes(command)) {
24
+ process.env.NODE_ENV = 'development';
25
+ }
26
+ else if (command === 'build') {
27
+ process.env.NODE_ENV = 'production';
28
+ }
29
+ if (opts === null || opts === void 0 ? void 0 : opts.presets) {
30
+ process.env.UMI_PRESETS = opts.presets.join(',');
31
+ }
32
+ if (command === constants_1.DEV_COMMAND) {
33
+ (0, dev_1.dev)();
34
+ }
35
+ else {
36
+ try {
37
+ await new service_1.Service().run2({
38
+ name: args._[0],
39
+ args,
40
+ });
43
41
  }
44
- else {
45
- try {
46
- yield new service_1.Service().run2({
47
- name: args._[0],
48
- args,
49
- });
50
- }
51
- catch (e) {
52
- utils_1.logger.error(e);
53
- process.exit(1);
54
- }
42
+ catch (e) {
43
+ utils_1.logger.fatal(e);
44
+ (0, printHelp_1.printHelp)();
45
+ process.exit(1);
55
46
  }
56
- });
47
+ }
57
48
  }
58
49
  exports.run = run;
@@ -1,25 +1,17 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  const utils_1 = require("@umijs/utils");
13
4
  const constants_1 = require("../constants");
14
5
  const service_1 = require("../service/service");
15
6
  const node_1 = require("./node");
7
+ const printHelp_1 = require("./printHelp");
16
8
  (0, node_1.setNodeTitle)(`${constants_1.FRAMEWORK_NAME}-dev`);
17
9
  (0, node_1.setNoDeprecation)();
18
- (() => __awaiter(void 0, void 0, void 0, function* () {
10
+ (async () => {
19
11
  try {
20
12
  const args = (0, utils_1.yParser)(process.argv.slice(2));
21
13
  const service = new service_1.Service();
22
- yield service.run2({
14
+ await service.run2({
23
15
  name: constants_1.DEV_COMMAND,
24
16
  args,
25
17
  });
@@ -45,7 +37,8 @@ const node_1 = require("./node");
45
37
  }
46
38
  }
47
39
  catch (e) {
48
- utils_1.logger.error(e);
40
+ utils_1.logger.fatal(e);
41
+ (0, printHelp_1.printHelp)();
49
42
  process.exit(1);
50
43
  }
51
- }))();
44
+ })();
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
  }
@@ -0,0 +1 @@
1
+ export declare function printHelp(): void;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.printHelp = void 0;
4
+ const utils_1 = require("@umijs/utils");
5
+ function printHelp() {
6
+ utils_1.logger.fatal('A complete log of this run can be found in:');
7
+ utils_1.logger.fatal(utils_1.logger.getLatestLogFilePath());
8
+ utils_1.logger.fatal('Consider reporting a GitHub issue on https://github.com/umijs/umi-next/issues');
9
+ }
10
+ exports.printHelp = printHelp;
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.PluginManager = exports.ApplyPluginsType = void 0;
13
4
  const utils_1 = require("./utils");
@@ -23,9 +14,9 @@ class PluginManager {
23
14
  this.opts = opts;
24
15
  }
25
16
  register(plugin) {
26
- (0, utils_1.assert)(plugin.apply && plugin.path, `plugin register failed, apply and path must supplied`);
17
+ (0, utils_1.assert)(plugin.apply, `plugin register failed, apply must supplied`);
27
18
  Object.keys(plugin.apply).forEach((key) => {
28
- (0, utils_1.assert)(this.opts.validKeys.indexOf(key) > -1, `register failed, invalid key ${key} from plugin ${plugin.path}.`);
19
+ (0, utils_1.assert)(this.opts.validKeys.indexOf(key) > -1, `register failed, invalid key ${key} ${plugin.path ? `from plugin ${plugin.path}` : ''}.`);
29
20
  this.hooks[key] = (this.hooks[key] || []).concat(plugin.apply[key]);
30
21
  });
31
22
  }
@@ -55,20 +46,23 @@ class PluginManager {
55
46
  if (args) {
56
47
  (0, utils_1.assert)(typeof args === 'object', `applyPlugins failed, args must be plain object.`);
57
48
  }
49
+ if (async) {
50
+ (0, utils_1.assert)(type === ApplyPluginsType.modify || type === ApplyPluginsType.event, `async only works with modify and event type.`);
51
+ }
58
52
  switch (type) {
59
53
  case ApplyPluginsType.modify:
60
54
  if (async) {
61
- return hooks.reduce((memo, hook) => __awaiter(this, void 0, void 0, function* () {
55
+ return hooks.reduce(async (memo, hook) => {
62
56
  (0, utils_1.assert)(typeof hook === 'function' ||
63
57
  typeof hook === 'object' ||
64
58
  (0, utils_1.isPromiseLike)(hook), `applyPlugins failed, all hooks for key ${key} must be function, plain object or Promise.`);
65
59
  if ((0, utils_1.isPromiseLike)(memo)) {
66
- memo = yield memo;
60
+ memo = await memo;
67
61
  }
68
62
  if (typeof hook === 'function') {
69
63
  const ret = hook(memo, args);
70
64
  if ((0, utils_1.isPromiseLike)(ret)) {
71
- return yield ret;
65
+ return await ret;
72
66
  }
73
67
  else {
74
68
  return ret;
@@ -76,11 +70,11 @@ class PluginManager {
76
70
  }
77
71
  else {
78
72
  if ((0, utils_1.isPromiseLike)(hook)) {
79
- hook = yield hook;
73
+ hook = await hook;
80
74
  }
81
- return Object.assign(Object.assign({}, memo), hook);
75
+ return { ...memo, ...hook };
82
76
  }
83
- }), (0, utils_1.isPromiseLike)(initialValue)
77
+ }, (0, utils_1.isPromiseLike)(initialValue)
84
78
  ? initialValue
85
79
  : Promise.resolve(initialValue));
86
80
  }
@@ -92,15 +86,20 @@ class PluginManager {
92
86
  }
93
87
  else {
94
88
  // TODO: deepmerge?
95
- return Object.assign(Object.assign({}, memo), hook);
89
+ return { ...memo, ...hook };
96
90
  }
97
91
  }, initialValue);
98
92
  }
99
93
  case ApplyPluginsType.event:
100
- return hooks.forEach((hook) => {
101
- (0, utils_1.assert)(typeof hook === 'function', `applyPlugins failed, all hooks for key ${key} must be function.`);
102
- hook(args);
103
- });
94
+ return (async () => {
95
+ for (const hook of hooks) {
96
+ (0, utils_1.assert)(typeof hook === 'function', `applyPlugins failed, all hooks for key ${key} must be function.`);
97
+ const ret = hook(args);
98
+ if (async && (0, utils_1.isPromiseLike)(ret)) {
99
+ await ret;
100
+ }
101
+ }
102
+ })();
104
103
  case ApplyPluginsType.compose:
105
104
  return () => {
106
105
  return (0, utils_1.compose)({
@@ -1,5 +1,4 @@
1
- export declare const MIN_NODE_VERSION = 16;
2
- export declare const EXCLUDE_NODE_VERSION = 15;
1
+ export declare const MIN_NODE_VERSION = 14;
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;
4
- exports.MIN_NODE_VERSION = 16;
5
- exports.EXCLUDE_NODE_VERSION = 15;
3
+ exports.FRAMEWORK_NAME = exports.DEFAULT_CONFIG_FILES = exports.DEV_COMMAND = exports.MIN_NODE_VERSION = void 0;
4
+ exports.MIN_NODE_VERSION = 14;
6
5
  exports.DEV_COMMAND = 'dev';
7
6
  exports.DEFAULT_CONFIG_FILES = [
8
7
  '.umirc.ts',
@@ -1 +1,5 @@
1
- export declare function defineConfig(config: any): any;
1
+ import { IConfigFromPlugins } from '@@/core/pluginConfig';
2
+ import type { IConfig } from '@umijs/preset-umi';
3
+ declare type ConfigType = IConfigFromPlugins & IConfig;
4
+ export declare function defineConfig(config: ConfigType): ConfigType;
5
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { RequestHandler } from '@umijs/bundler-webpack/compiled/express';
2
+ declare type MockDeclare = string | number | null | undefined | boolean | Record<string, any> | RequestHandler;
3
+ export declare function defineMock(mockData: {
4
+ [key: string]: MockDeclare;
5
+ }): {
6
+ [key: string]: MockDeclare;
7
+ };
8
+ export {};
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defineMock = void 0;
4
+ function defineMock(mockData) {
5
+ return mockData;
6
+ }
7
+ exports.defineMock = defineMock;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import { IServicePluginAPI, PluginAPI } from '@umijs/core';
2
+ export { run } from './cli/cli';
2
3
  export { defineConfig } from './defineConfig';
4
+ export { defineMock } from './defineMock';
3
5
  export * from './service/service';
4
6
  export declare type IApi = PluginAPI & IServicePluginAPI;
package/dist/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -10,7 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
15
  };
12
16
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.defineConfig = void 0;
17
+ exports.defineMock = exports.defineConfig = exports.run = void 0;
18
+ var cli_1 = require("./cli/cli");
19
+ Object.defineProperty(exports, "run", { enumerable: true, get: function () { return cli_1.run; } });
14
20
  var defineConfig_1 = require("./defineConfig");
15
21
  Object.defineProperty(exports, "defineConfig", { enumerable: true, get: function () { return defineConfig_1.defineConfig; } });
22
+ var defineMock_1 = require("./defineMock");
23
+ Object.defineProperty(exports, "defineMock", { enumerable: true, get: function () { return defineMock_1.defineMock; } });
16
24
  __exportStar(require("./service/service"), exports);
@@ -1 +1,5 @@
1
+ import express from '@umijs/bundler-utils/compiled/express';
2
+ import * as httpProxyMiddleware from '@umijs/bundler-webpack/compiled/http-proxy-middleware';
3
+ export { createServerRoutes } from '@umijs/server';
1
4
  export * from '@umijs/utils';
5
+ export { httpProxyMiddleware, express };
@@ -1,13 +1,39 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
8
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
+ };
9
25
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
26
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
27
  };
28
+ var __importDefault = (this && this.__importDefault) || function (mod) {
29
+ return (mod && mod.__esModule) ? mod : { "default": mod };
30
+ };
12
31
  Object.defineProperty(exports, "__esModule", { value: true });
32
+ exports.express = exports.httpProxyMiddleware = exports.createServerRoutes = void 0;
33
+ const express_1 = __importDefault(require("@umijs/bundler-utils/compiled/express"));
34
+ exports.express = express_1.default;
35
+ const httpProxyMiddleware = __importStar(require("@umijs/bundler-webpack/compiled/http-proxy-middleware"));
36
+ exports.httpProxyMiddleware = httpProxyMiddleware;
37
+ var server_1 = require("@umijs/server");
38
+ Object.defineProperty(exports, "createServerRoutes", { enumerable: true, get: function () { return server_1.createServerRoutes; } });
13
39
  __exportStar(require("@umijs/utils"), exports);
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.Service = void 0;
13
4
  const core_1 = require("@umijs/core");
@@ -19,24 +10,30 @@ class Service extends core_1.Service {
19
10
  constructor(opts) {
20
11
  process.env.UMI_DIR = (0, path_1.dirname)(require.resolve('../../package'));
21
12
  const cwd = (0, cwd_1.getCwd)();
22
- super(Object.assign(Object.assign({}, opts), { env: process.env.NODE_ENV, cwd, defaultConfigFiles: constants_1.DEFAULT_CONFIG_FILES, frameworkName: constants_1.FRAMEWORK_NAME, presets: [require.resolve('@umijs/preset-umi'), ...((opts === null || opts === void 0 ? void 0 : opts.presets) || [])], plugins: [
13
+ super({
14
+ ...opts,
15
+ env: process.env.NODE_ENV,
16
+ cwd,
17
+ defaultConfigFiles: constants_1.DEFAULT_CONFIG_FILES,
18
+ frameworkName: constants_1.FRAMEWORK_NAME,
19
+ presets: [require.resolve('@umijs/preset-umi'), ...((opts === null || opts === void 0 ? void 0 : opts.presets) || [])],
20
+ plugins: [
23
21
  (0, fs_1.existsSync)((0, path_1.join)(cwd, 'plugin.ts')) && (0, path_1.join)(cwd, 'plugin.ts'),
24
22
  (0, fs_1.existsSync)((0, path_1.join)(cwd, 'plugin.js')) && (0, path_1.join)(cwd, 'plugin.js'),
25
- ].filter(Boolean) }));
26
- }
27
- run2(opts) {
28
- return __awaiter(this, void 0, void 0, function* () {
29
- let name = opts.name;
30
- if ((opts === null || opts === void 0 ? void 0 : opts.args.version) || name === 'v') {
31
- name = 'version';
32
- }
33
- else if ((opts === null || opts === void 0 ? void 0 : opts.args.help) || !name || name === 'h') {
34
- name = 'help';
35
- }
36
- // TODO
37
- // initWebpack
38
- return yield this.run(Object.assign(Object.assign({}, opts), { name }));
23
+ ].filter(Boolean),
39
24
  });
40
25
  }
26
+ async run2(opts) {
27
+ let name = opts.name;
28
+ if ((opts === null || opts === void 0 ? void 0 : opts.args.version) || name === 'v') {
29
+ name = 'version';
30
+ }
31
+ else if ((opts === null || opts === void 0 ? void 0 : opts.args.help) || !name || name === 'h') {
32
+ name = 'help';
33
+ }
34
+ // TODO
35
+ // initWebpack
36
+ return await this.run({ ...opts, name });
37
+ }
41
38
  }
42
39
  exports.Service = Service;
package/dist/test.d.ts ADDED
@@ -0,0 +1,117 @@
1
+ import { Config } from '@umijs/test';
2
+ export * from '@umijs/test';
3
+ export declare function configUmiAlias(config: Config.InitialOptions): Promise<Partial<{
4
+ automock: boolean;
5
+ bail: number | boolean;
6
+ cache: boolean;
7
+ cacheDirectory: string;
8
+ ci: boolean;
9
+ clearMocks: boolean;
10
+ changedFilesWithAncestor: boolean;
11
+ changedSince: string;
12
+ collectCoverage: boolean;
13
+ collectCoverageFrom: string[];
14
+ collectCoverageOnlyFrom: {
15
+ [key: string]: boolean;
16
+ };
17
+ coverageDirectory: string;
18
+ coveragePathIgnorePatterns: string[];
19
+ coverageProvider: "babel" | "v8";
20
+ coverageReporters: Config.CoverageReporters;
21
+ coverageThreshold: {
22
+ [path: string]: Config.CoverageThresholdValue;
23
+ global: Config.CoverageThresholdValue;
24
+ };
25
+ dependencyExtractor: string;
26
+ detectLeaks: boolean;
27
+ detectOpenHandles: boolean;
28
+ displayName: string | Config.DisplayName;
29
+ expand: boolean;
30
+ extensionsToTreatAsEsm: string[];
31
+ extraGlobals: string[];
32
+ filter: string;
33
+ findRelatedTests: boolean;
34
+ forceCoverageMatch: string[];
35
+ forceExit: boolean;
36
+ json: boolean;
37
+ globals: Config.ConfigGlobals;
38
+ globalSetup: string | null | undefined;
39
+ globalTeardown: string | null | undefined;
40
+ haste: Config.HasteConfig;
41
+ injectGlobals: boolean;
42
+ reporters: (string | Config.ReporterConfig)[];
43
+ logHeapUsage: boolean;
44
+ lastCommit: boolean;
45
+ listTests: boolean;
46
+ maxConcurrency: number;
47
+ maxWorkers: string | number;
48
+ moduleDirectories: string[];
49
+ moduleFileExtensions: string[];
50
+ moduleLoader: string;
51
+ moduleNameMapper: {
52
+ [key: string]: string | string[];
53
+ };
54
+ modulePathIgnorePatterns: string[];
55
+ modulePaths: string[];
56
+ name: string;
57
+ noStackTrace: boolean;
58
+ notify: boolean;
59
+ notifyMode: string;
60
+ onlyChanged: boolean;
61
+ onlyFailures: boolean;
62
+ outputFile: string;
63
+ passWithNoTests: boolean;
64
+ preprocessorIgnorePatterns: string[];
65
+ preset: string | null | undefined;
66
+ prettierPath: string | null | undefined;
67
+ projects: (string | Config.InitialProjectOptions)[];
68
+ replname: string | null | undefined;
69
+ resetMocks: boolean;
70
+ resetModules: boolean;
71
+ resolver: string | null | undefined;
72
+ restoreMocks: boolean;
73
+ rootDir: string;
74
+ roots: string[];
75
+ runner: string;
76
+ runTestsByPath: boolean;
77
+ scriptPreprocessor: string;
78
+ setupFiles: string[];
79
+ setupTestFrameworkScriptFile: string;
80
+ setupFilesAfterEnv: string[];
81
+ silent: boolean;
82
+ skipFilter: boolean;
83
+ skipNodeResolution: boolean;
84
+ slowTestThreshold: number;
85
+ snapshotResolver: string;
86
+ snapshotSerializers: string[];
87
+ snapshotFormat: Config.PrettyFormatOptions;
88
+ errorOnDeprecated: boolean;
89
+ testEnvironment: string;
90
+ testEnvironmentOptions: Record<string, unknown>;
91
+ testFailureExitCode: string | number;
92
+ testLocationInResults: boolean;
93
+ testMatch: string[];
94
+ testNamePattern: string;
95
+ testPathDirs: string[];
96
+ testPathIgnorePatterns: string[];
97
+ testRegex: string | string[];
98
+ testResultsProcessor: string;
99
+ testRunner: string;
100
+ testSequencer: string;
101
+ testURL: string;
102
+ testTimeout: number;
103
+ timers: "real" | "fake" | "modern" | "legacy";
104
+ transform: {
105
+ [regex: string]: string | Config.TransformerConfig;
106
+ };
107
+ transformIgnorePatterns: string[];
108
+ watchPathIgnorePatterns: string[];
109
+ unmockedModulePathPatterns: string[];
110
+ updateSnapshot: boolean;
111
+ useStderr: boolean;
112
+ verbose?: boolean | undefined;
113
+ watch: boolean;
114
+ watchAll: boolean;
115
+ watchman: boolean;
116
+ watchPlugins: (string | [string, Record<string, unknown>])[];
117
+ }>>;
package/dist/test.js ADDED
@@ -0,0 +1,51 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.configUmiAlias = void 0;
18
+ const fs_1 = require("fs");
19
+ const service_1 = require("./service/service");
20
+ __exportStar(require("@umijs/test"), exports);
21
+ function getAliasPathWithKey(alias, key) {
22
+ const thePath = alias[key];
23
+ if (alias[thePath]) {
24
+ return getAliasPathWithKey(alias, thePath);
25
+ }
26
+ return thePath;
27
+ }
28
+ let service;
29
+ async function configUmiAlias(config) {
30
+ if (!service) {
31
+ service = new service_1.Service();
32
+ await service.run2({
33
+ name: 'setup',
34
+ args: { quiet: true },
35
+ });
36
+ }
37
+ config.moduleNameMapper || (config.moduleNameMapper = {});
38
+ const { alias } = service.config;
39
+ for (const key of Object.keys(alias)) {
40
+ const aliasPath = getAliasPathWithKey(alias, key);
41
+ if ((0, fs_1.existsSync)(aliasPath) && (0, fs_1.statSync)(aliasPath).isDirectory()) {
42
+ config.moduleNameMapper[`^${key}/(.*)$`] = `${aliasPath}/$1`;
43
+ config.moduleNameMapper[`^${key}$`] = aliasPath;
44
+ }
45
+ else {
46
+ config.moduleNameMapper[`^${key}$`] = aliasPath;
47
+ }
48
+ }
49
+ return config;
50
+ }
51
+ exports.configUmiAlias = configUmiAlias;
package/eslint.js ADDED
@@ -0,0 +1,7 @@
1
+ try {
2
+ require.resolve('@umijs/lint/package.json');
3
+ } catch (err) {
4
+ throw new Error('@umijs/lint is not built-in, please install it manually before run umi lint.');
5
+ }
6
+
7
+ module.exports = process.env.LEGACY_ESLINT ? require('@umijs/lint/dist/config/eslint/legacy') : require('@umijs/lint/dist/config/eslint');
package/index.d.ts CHANGED
@@ -1,3 +1,10 @@
1
+ // @ts-ignore
1
2
  export * from '@@/exports';
2
- export type { IApi } from '@umijs/preset-umi';
3
+ export type {
4
+ IApi,
5
+ webpack,
6
+ IRoute,
7
+ UmiApiRequest,
8
+ UmiApiResponse,
9
+ } from '@umijs/preset-umi';
3
10
  export * from './dist';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "umi",
3
- "version": "4.0.0-rc.2",
3
+ "version": "4.0.0-rc.22",
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",
@@ -22,19 +22,36 @@
22
22
  "bin",
23
23
  "plugin.js",
24
24
  "plugin-utils.d.ts",
25
- "plugin-utils.js"
25
+ "plugin-utils.js",
26
+ "prettier.js",
27
+ "test.d.ts",
28
+ "test.js",
29
+ "eslint.js",
30
+ "stylelint.js"
26
31
  ],
27
32
  "scripts": {
28
33
  "build": "pnpm tsc",
29
34
  "build:client": "pnpm tsc --project ./tsconfig.client.json",
30
- "build:deps": "pnpm esno ../../scripts/bundleDeps.ts",
31
- "dev": "pnpm build -- --watch"
35
+ "build:deps": "umi-scripts bundleDeps",
36
+ "dev": "pnpm build -- --watch",
37
+ "dev:client": "pnpm build:client -- --watch",
38
+ "test": "umi-scripts jest-turbo"
32
39
  },
33
40
  "dependencies": {
34
- "@umijs/core": "4.0.0-rc.2",
35
- "@umijs/preset-umi": "4.0.0-rc.2",
36
- "@umijs/renderer-react": "4.0.0-rc.2",
37
- "@umijs/utils": "4.0.0-rc.2"
41
+ "@umijs/bundler-utils": "4.0.0-rc.22",
42
+ "@umijs/bundler-webpack": "4.0.0-rc.22",
43
+ "@umijs/core": "4.0.0-rc.22",
44
+ "@umijs/lint": "4.0.0-rc.22",
45
+ "@umijs/preset-umi": "4.0.0-rc.22",
46
+ "@umijs/renderer-react": "4.0.0-rc.22",
47
+ "@umijs/server": "4.0.0-rc.22",
48
+ "@umijs/test": "4.0.0-rc.22",
49
+ "@umijs/utils": "4.0.0-rc.22",
50
+ "prettier-plugin-organize-imports": "^2.3.4",
51
+ "prettier-plugin-packagejson": "^2.2.17"
52
+ },
53
+ "engines": {
54
+ "node": ">=14"
38
55
  },
39
56
  "publishConfig": {
40
57
  "access": "public"
package/prettier.js ADDED
@@ -0,0 +1,12 @@
1
+ module.exports = {
2
+ printWidth: 80,
3
+ singleQuote: true,
4
+ trailingComma: 'all',
5
+ proseWrap: 'never',
6
+ endOfLine: 'lf',
7
+ overrides: [{ files: '.prettierrc', options: { parser: 'json' } }],
8
+ plugins: [
9
+ require.resolve('prettier-plugin-packagejson'),
10
+ require.resolve('prettier-plugin-organize-imports'),
11
+ ],
12
+ };
package/stylelint.js ADDED
@@ -0,0 +1,7 @@
1
+ try {
2
+ require.resolve('@umijs/lint/package.json');
3
+ } catch (err) {
4
+ throw new Error('@umijs/lint is not built-in, please install it manually before run umi lint.');
5
+ }
6
+
7
+ module.exports = require('@umijs/lint/dist/config/stylelint');
package/test.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/test';
package/test.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/test');