umi 4.0.0-beta.8 → 4.0.0-canary-20240513.3

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.
Files changed (59) hide show
  1. package/LICENSE +21 -0
  2. package/bin/forkedDev.js +1 -1
  3. package/bin/umi.js +20 -1
  4. package/client/client/plugin.js +213 -116
  5. package/client/client/utils.js +16 -10
  6. package/dist/cli/cli.d.ts +0 -1
  7. package/dist/cli/cli.js +68 -56
  8. package/dist/cli/dev.js +49 -23
  9. package/dist/cli/fork.js +86 -36
  10. package/dist/cli/forkedDev.d.ts +0 -1
  11. package/dist/cli/forkedDev.js +35 -50
  12. package/dist/constants.d.ts +2 -2
  13. package/dist/constants.js +45 -12
  14. package/dist/defineConfig.d.ts +10 -0
  15. package/dist/defineConfig.js +31 -0
  16. package/dist/defineMock.d.ts +8 -0
  17. package/dist/defineMock.js +31 -0
  18. package/dist/index.d.ts +5 -4
  19. package/dist/index.js +39 -26
  20. package/dist/pluginUtils.d.ts +5 -0
  21. package/dist/pluginUtils.js +48 -0
  22. package/dist/service/cwd.js +35 -11
  23. package/dist/service/requireHook.d.ts +1 -0
  24. package/dist/service/requireHook.js +14 -0
  25. package/dist/service/service.d.ts +0 -1
  26. package/dist/service/service.js +69 -40
  27. package/dist/test-setup.d.ts +1 -0
  28. package/dist/test-setup.js +3 -0
  29. package/dist/test.d.ts +119 -0
  30. package/dist/test.js +82 -0
  31. package/eslint.js +7 -0
  32. package/index.d.ts +10 -3
  33. package/package.json +45 -27
  34. package/plugin-utils.d.ts +1 -0
  35. package/plugin-utils.js +1 -0
  36. package/plugin.js +1 -0
  37. package/prettier.js +13 -0
  38. package/stylelint.js +7 -0
  39. package/test-setup.js +1 -0
  40. package/test.d.ts +1 -0
  41. package/test.js +1 -0
  42. package/dist/cli/cli.d.ts.map +0 -1
  43. package/dist/cli/dev.d.ts.map +0 -1
  44. package/dist/cli/fork.d.ts.map +0 -1
  45. package/dist/cli/forkedDev.d.ts.map +0 -1
  46. package/dist/cli/node.d.ts +0 -4
  47. package/dist/cli/node.d.ts.map +0 -1
  48. package/dist/cli/node.js +0 -32
  49. package/dist/client/plugin.d.ts +0 -34
  50. package/dist/client/plugin.d.ts.map +0 -1
  51. package/dist/client/plugin.js +0 -125
  52. package/dist/client/utils.d.ts +0 -6
  53. package/dist/client/utils.d.ts.map +0 -1
  54. package/dist/client/utils.js +0 -20
  55. package/dist/constants.d.ts.map +0 -1
  56. package/dist/index.d.ts.map +0 -1
  57. package/dist/service/cwd.d.ts.map +0 -1
  58. package/dist/service/service.d.ts.map +0 -1
  59. package/index.esm.js +0 -2
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017-present ChenCheng (sorrycc@gmail.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/bin/forkedDev.js CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- require('v8-compile-cache');
3
+ // require('v8-compile-cache');
4
4
  require('../dist/cli/forkedDev');
package/bin/umi.js CHANGED
@@ -1,6 +1,25 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- require('v8-compile-cache');
3
+ // disable since it's conflicted with typescript cjs + dynamic import
4
+ // require('v8-compile-cache');
5
+
6
+ // patch console for debug
7
+ // ref: https://remysharp.com/2014/05/23/where-is-that-console-log
8
+ if (process.env.DEBUG_CONSOLE) {
9
+ ['log', 'warn', 'error'].forEach((method) => {
10
+ const old = console[method];
11
+ console[method] = function () {
12
+ let stack = new Error().stack.split(/\n/);
13
+ // Chrome includes a single "Error" line, FF doesn't.
14
+ if (stack[0].indexOf('Error') === 0) {
15
+ stack = stack.slice(1);
16
+ }
17
+ const args = [].slice.apply(arguments).concat([stack[1].trim()]);
18
+ return old.apply(console, args);
19
+ };
20
+ });
21
+ }
22
+
4
23
  require('../dist/cli/cli')
5
24
  .run()
6
25
  .catch((e) => {
@@ -1,121 +1,218 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { assert, compose, isPromiseLike } from './utils';
11
- export var ApplyPluginsType;
12
- (function (ApplyPluginsType) {
13
- ApplyPluginsType["compose"] = "compose";
14
- ApplyPluginsType["modify"] = "modify";
15
- ApplyPluginsType["event"] = "event";
16
- })(ApplyPluginsType || (ApplyPluginsType = {}));
17
- export class PluginManager {
18
- constructor(opts) {
19
- this.hooks = {};
20
- this.opts = opts;
1
+ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
4
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
5
+ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
6
+ import _toArray from "@babel/runtime/helpers/esm/toArray";
7
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
8
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
9
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
10
+ import { assert, compose, isPromiseLike } from "./utils";
11
+ export var ApplyPluginsType = /*#__PURE__*/function (ApplyPluginsType) {
12
+ ApplyPluginsType["compose"] = "compose";
13
+ ApplyPluginsType["modify"] = "modify";
14
+ ApplyPluginsType["event"] = "event";
15
+ return ApplyPluginsType;
16
+ }({});
17
+ export var PluginManager = /*#__PURE__*/function () {
18
+ function PluginManager(opts) {
19
+ _classCallCheck(this, PluginManager);
20
+ _defineProperty(this, "opts", void 0);
21
+ _defineProperty(this, "hooks", {});
22
+ this.opts = opts;
23
+ }
24
+ _createClass(PluginManager, [{
25
+ key: "register",
26
+ value: function register(plugin) {
27
+ var _this = this;
28
+ assert(plugin.apply, "plugin register failed, apply must supplied");
29
+ Object.keys(plugin.apply).forEach(function (key) {
30
+ assert(_this.opts.validKeys.indexOf(key) > -1, "register failed, invalid key ".concat(key, " ").concat(plugin.path ? "from plugin ".concat(plugin.path) : '', "."));
31
+ _this.hooks[key] = (_this.hooks[key] || []).concat(plugin.apply[key]);
32
+ });
21
33
  }
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]);
27
- });
34
+ }, {
35
+ key: "getHooks",
36
+ value: function getHooks(keyWithDot) {
37
+ var _keyWithDot$split = keyWithDot.split('.'),
38
+ _keyWithDot$split2 = _toArray(_keyWithDot$split),
39
+ key = _keyWithDot$split2[0],
40
+ memberKeys = _keyWithDot$split2.slice(1);
41
+ var hooks = this.hooks[key] || [];
42
+ if (memberKeys.length) {
43
+ hooks = hooks.map(function (hook) {
44
+ try {
45
+ var ret = hook;
46
+ var _iterator = _createForOfIteratorHelper(memberKeys),
47
+ _step;
48
+ try {
49
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
50
+ var memberKey = _step.value;
51
+ ret = ret[memberKey];
52
+ }
53
+ } catch (err) {
54
+ _iterator.e(err);
55
+ } finally {
56
+ _iterator.f();
57
+ }
58
+ return ret;
59
+ } catch (e) {
60
+ return null;
61
+ }
62
+ }).filter(Boolean);
63
+ }
64
+ return hooks;
28
65
  }
29
- getHooks(keyWithDot) {
30
- const [key, ...memberKeys] = keyWithDot.split('.');
31
- let hooks = this.hooks[key] || [];
32
- if (memberKeys.length) {
33
- hooks = hooks
34
- .map((hook) => {
35
- try {
36
- let ret = hook;
37
- for (const memberKey of memberKeys) {
38
- ret = ret[memberKey];
39
- }
40
- return ret;
41
- }
42
- catch (e) {
43
- return null;
44
- }
45
- })
46
- .filter(Boolean);
47
- }
48
- return hooks;
66
+ }, {
67
+ key: "applyPlugins",
68
+ value: function applyPlugins(_ref) {
69
+ var key = _ref.key,
70
+ type = _ref.type,
71
+ initialValue = _ref.initialValue,
72
+ args = _ref.args,
73
+ async = _ref.async;
74
+ var hooks = this.getHooks(key) || [];
75
+ if (args) {
76
+ assert(_typeof(args) === 'object', "applyPlugins failed, args must be plain object.");
77
+ }
78
+ if (async) {
79
+ assert(type === ApplyPluginsType.modify || type === ApplyPluginsType.event, "async only works with modify and event type.");
80
+ }
81
+ switch (type) {
82
+ case ApplyPluginsType.modify:
83
+ if (async) {
84
+ return hooks.reduce( /*#__PURE__*/function () {
85
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(memo, hook) {
86
+ var ret;
87
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
88
+ while (1) switch (_context.prev = _context.next) {
89
+ case 0:
90
+ assert(typeof hook === 'function' || _typeof(hook) === 'object' || isPromiseLike(hook), "applyPlugins failed, all hooks for key ".concat(key, " must be function, plain object or Promise."));
91
+ if (!isPromiseLike(memo)) {
92
+ _context.next = 5;
93
+ break;
94
+ }
95
+ _context.next = 4;
96
+ return memo;
97
+ case 4:
98
+ memo = _context.sent;
99
+ case 5:
100
+ if (!(typeof hook === 'function')) {
101
+ _context.next = 16;
102
+ break;
103
+ }
104
+ ret = hook(memo, args);
105
+ if (!isPromiseLike(ret)) {
106
+ _context.next = 13;
107
+ break;
108
+ }
109
+ _context.next = 10;
110
+ return ret;
111
+ case 10:
112
+ return _context.abrupt("return", _context.sent);
113
+ case 13:
114
+ return _context.abrupt("return", ret);
115
+ case 14:
116
+ _context.next = 21;
117
+ break;
118
+ case 16:
119
+ if (!isPromiseLike(hook)) {
120
+ _context.next = 20;
121
+ break;
122
+ }
123
+ _context.next = 19;
124
+ return hook;
125
+ case 19:
126
+ hook = _context.sent;
127
+ case 20:
128
+ return _context.abrupt("return", _objectSpread(_objectSpread({}, memo), hook));
129
+ case 21:
130
+ case "end":
131
+ return _context.stop();
132
+ }
133
+ }, _callee);
134
+ }));
135
+ return function (_x, _x2) {
136
+ return _ref2.apply(this, arguments);
137
+ };
138
+ }(), isPromiseLike(initialValue) ? initialValue : Promise.resolve(initialValue));
139
+ } else {
140
+ return hooks.reduce(function (memo, hook) {
141
+ assert(typeof hook === 'function' || _typeof(hook) === 'object', "applyPlugins failed, all hooks for key ".concat(key, " must be function or plain object."));
142
+ if (typeof hook === 'function') {
143
+ return hook(memo, args);
144
+ } else {
145
+ // TODO: deepmerge?
146
+ return _objectSpread(_objectSpread({}, memo), hook);
147
+ }
148
+ }, initialValue);
149
+ }
150
+ case ApplyPluginsType.event:
151
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
152
+ var _iterator2, _step2, hook, ret;
153
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
154
+ while (1) switch (_context2.prev = _context2.next) {
155
+ case 0:
156
+ _iterator2 = _createForOfIteratorHelper(hooks);
157
+ _context2.prev = 1;
158
+ _iterator2.s();
159
+ case 3:
160
+ if ((_step2 = _iterator2.n()).done) {
161
+ _context2.next = 12;
162
+ break;
163
+ }
164
+ hook = _step2.value;
165
+ assert(typeof hook === 'function', "applyPlugins failed, all hooks for key ".concat(key, " must be function."));
166
+ ret = hook(args);
167
+ if (!(async && isPromiseLike(ret))) {
168
+ _context2.next = 10;
169
+ break;
170
+ }
171
+ _context2.next = 10;
172
+ return ret;
173
+ case 10:
174
+ _context2.next = 3;
175
+ break;
176
+ case 12:
177
+ _context2.next = 17;
178
+ break;
179
+ case 14:
180
+ _context2.prev = 14;
181
+ _context2.t0 = _context2["catch"](1);
182
+ _iterator2.e(_context2.t0);
183
+ case 17:
184
+ _context2.prev = 17;
185
+ _iterator2.f();
186
+ return _context2.finish(17);
187
+ case 20:
188
+ case "end":
189
+ return _context2.stop();
190
+ }
191
+ }, _callee2, null, [[1, 14, 17, 20]]);
192
+ }))();
193
+ case ApplyPluginsType.compose:
194
+ return function () {
195
+ return compose({
196
+ fns: hooks.concat(initialValue),
197
+ args: args
198
+ })();
199
+ };
200
+ }
49
201
  }
50
- applyPlugins({ key, type, initialValue, args, async, }) {
51
- const hooks = this.getHooks(key) || [];
52
- if (args) {
53
- assert(typeof args === 'object', `applyPlugins failed, args must be plain object.`);
54
- }
55
- switch (type) {
56
- case ApplyPluginsType.modify:
57
- 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;
69
- }
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)
81
- ? initialValue
82
- : Promise.resolve(initialValue));
83
- }
84
- 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.`);
87
- if (typeof hook === 'function') {
88
- return hook(memo, args);
89
- }
90
- else {
91
- // TODO: deepmerge?
92
- return Object.assign(Object.assign({}, memo), hook);
93
- }
94
- }, initialValue);
95
- }
96
- 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
- });
101
- case ApplyPluginsType.compose:
102
- return () => {
103
- return compose({
104
- fns: hooks.concat(initialValue),
105
- args,
106
- })();
107
- };
108
- }
202
+ }], [{
203
+ key: "create",
204
+ value: function create(opts) {
205
+ var pluginManager = new PluginManager({
206
+ validKeys: opts.validKeys
207
+ });
208
+ opts.plugins.forEach(function (plugin) {
209
+ pluginManager.register(plugin);
210
+ });
211
+ return pluginManager;
109
212
  }
110
- static create(opts) {
111
- const pluginManager = new PluginManager({
112
- validKeys: opts.validKeys,
113
- });
114
- opts.plugins.forEach((plugin) => {
115
- pluginManager.register(plugin);
116
- });
117
- return pluginManager;
118
- }
119
- }
213
+ }]);
214
+ return PluginManager;
215
+ }();
216
+
120
217
  // plugins meta info (in tmp file)
121
- // hooks api: usePlugin
218
+ // hooks api: usePlugin
@@ -1,14 +1,20 @@
1
+ import _typeof from "@babel/runtime/helpers/esm/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({ fns, args, }) {
6
- if (fns.length === 1) {
7
- return fns[0];
8
- }
9
- const last = fns.pop();
10
- return fns.reduce((a, b) => () => b(a, args), last);
5
+ export function compose(_ref) {
6
+ var fns = _ref.fns,
7
+ args = _ref.args;
8
+ if (fns.length === 1) {
9
+ return fns[0];
10
+ }
11
+ var last = fns.pop();
12
+ return fns.reduce(function (a, b) {
13
+ return function () {
14
+ return b(a, args);
15
+ };
16
+ }, last);
11
17
  }
12
18
  export function isPromiseLike(obj) {
13
- return !!obj && typeof obj === 'object' && typeof obj.then === 'function';
14
- }
19
+ return !!obj && _typeof(obj) === 'object' && typeof obj.then === 'function';
20
+ }
package/dist/cli/cli.d.ts CHANGED
@@ -3,4 +3,3 @@ interface IOpts {
3
3
  }
4
4
  export declare function run(opts?: IOpts): Promise<void>;
5
5
  export {};
6
- //# sourceMappingURL=cli.d.ts.map
package/dist/cli/cli.js CHANGED
@@ -1,58 +1,70 @@
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
- });
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 });
10
8
  };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.run = void 0;
13
- const utils_1 = require("@umijs/utils");
14
- const constants_1 = require("../constants");
15
- const service_1 = require("../service/service");
16
- const dev_1 = require("./dev");
17
- 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)();
43
- }
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
- }
55
- }
56
- });
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
+ (0, import_utils.catchUnhandledRejection)();
30
+ async function run(opts) {
31
+ (0, import_utils.checkVersion)(import_constants.MIN_NODE_VERSION);
32
+ (0, import_utils.checkLocal)();
33
+ (0, import_utils.setNodeTitle)(import_constants.FRAMEWORK_NAME);
34
+ (0, import_utils.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
+ const FEATURE_COMMANDS = ["mfsu", "setup", "deadcode"];
44
+ if ([import_constants.DEV_COMMAND, ...FEATURE_COMMANDS].includes(command)) {
45
+ process.env.NODE_ENV = "development";
46
+ } else if (command === "build") {
47
+ process.env.NODE_ENV = "production";
48
+ }
49
+ if (opts == null ? void 0 : opts.presets) {
50
+ process.env[`${import_constants.FRAMEWORK_NAME}_PRESETS`.toUpperCase()] = opts.presets.join(",");
51
+ }
52
+ if (command === import_constants.DEV_COMMAND) {
53
+ (0, import_dev.dev)();
54
+ } else {
55
+ try {
56
+ await new import_service.Service().run2({
57
+ name: args._[0],
58
+ args
59
+ });
60
+ } catch (e) {
61
+ import_utils.logger.fatal(e);
62
+ import_utils.printHelp.exit();
63
+ process.exit(1);
64
+ }
65
+ }
57
66
  }
58
- exports.run = run;
67
+ // Annotate the CommonJS export names for ESM import in node:
68
+ 0 && (module.exports = {
69
+ run
70
+ });
package/dist/cli/dev.js CHANGED
@@ -1,26 +1,52 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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 });
4
10
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.dev = void 0;
7
- const fork_1 = __importDefault(require("./fork"));
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(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/cli/dev.ts
30
+ var dev_exports = {};
31
+ __export(dev_exports, {
32
+ dev: () => dev
33
+ });
34
+ module.exports = __toCommonJS(dev_exports);
35
+ var import_fork = __toESM(require("./fork"));
8
36
  function dev() {
9
- const child = (0, fork_1.default)({
10
- scriptPath: require.resolve('../../bin/forkedDev'),
11
- });
12
- // ref:
13
- // http://nodejs.cn/api/process/signal_events.html
14
- // https://lisk.io/blog/development/why-we-stopped-using-npm-start-child-processes
15
- process.on('SIGINT', () => {
16
- child.kill('SIGINT');
17
- // ref:
18
- // https://github.com/umijs/umi/issues/6009
19
- process.exit(0);
20
- });
21
- process.on('SIGTERM', () => {
22
- child.kill('SIGTERM');
23
- process.exit(1);
24
- });
37
+ const child = (0, import_fork.default)({
38
+ scriptPath: require.resolve("../../bin/forkedDev")
39
+ });
40
+ process.on("SIGINT", () => {
41
+ child.kill("SIGINT");
42
+ process.exit(0);
43
+ });
44
+ process.on("SIGTERM", () => {
45
+ child.kill("SIGTERM");
46
+ process.exit(1);
47
+ });
25
48
  }
26
- exports.dev = dev;
49
+ // Annotate the CommonJS export names for ESM import in node:
50
+ 0 && (module.exports = {
51
+ dev
52
+ });