umi 3.5.20 → 4.0.0-beta.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -52
- package/bin/forkedDev.js +4 -0
- package/bin/umi.js +6 -12
- package/client/client/plugin.d.ts +34 -0
- package/client/client/plugin.js +121 -0
- package/client/client/utils.d.ts +6 -0
- package/client/client/utils.js +14 -0
- package/dist/cli/cli.d.ts +5 -0
- package/dist/cli/cli.js +58 -0
- package/dist/cli/dev.d.ts +1 -0
- package/dist/cli/dev.js +26 -0
- package/{lib/utils → dist/cli}/fork.d.ts +0 -0
- package/dist/cli/fork.js +40 -0
- package/{lib → dist/cli}/forkedDev.d.ts +0 -0
- package/dist/cli/forkedDev.js +51 -0
- package/dist/cli/node.d.ts +4 -0
- package/dist/cli/node.js +32 -0
- package/dist/client/plugin.d.ts +34 -0
- package/dist/client/plugin.js +125 -0
- package/dist/client/utils.d.ts +6 -0
- package/dist/client/utils.js +20 -0
- package/dist/constants.d.ts +5 -0
- package/dist/constants.js +13 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +13 -0
- package/dist/pluginUtils.d.ts +1 -0
- package/dist/pluginUtils.js +13 -0
- package/dist/service/cwd.d.ts +1 -0
- package/dist/service/cwd.js +13 -0
- package/dist/service/service.d.ts +8 -0
- package/dist/service/service.js +42 -0
- package/index.d.ts +3 -0
- package/index.esm.js +8 -0
- package/package.json +31 -33
- package/dist/index.esm.js +0 -2
- package/dist/src/ServiceWithBuiltIn.d.ts +0 -5
- package/dist/src/cjs.d.ts +0 -8
- package/dist/src/cli.d.ts +0 -1
- package/dist/src/defineConfig.d.ts +0 -3
- package/dist/src/defineConfig.test.d.ts +0 -1
- package/dist/src/forkedDev.d.ts +0 -1
- package/dist/src/index.d.ts +0 -3
- package/dist/src/initWebpack.d.ts +0 -2
- package/dist/src/plugins/umiAlias.d.ts +0 -3
- package/dist/src/plugins/umiAlias.test.d.ts +0 -1
- package/dist/src/utils/fork.d.ts +0 -6
- package/dist/src/utils/getCwd.d.ts +0 -2
- package/dist/src/utils/getCwd.test.d.ts +0 -1
- package/dist/src/utils/getPkg.d.ts +0 -2
- package/dist/src/utils/getPkg.test.d.ts +0 -1
- package/index.js +0 -6
- package/lib/ServiceWithBuiltIn.d.ts +0 -5
- package/lib/ServiceWithBuiltIn.js +0 -58
- package/lib/cjs.d.ts +0 -8
- package/lib/cjs.js +0 -88
- package/lib/cli.d.ts +0 -1
- package/lib/cli.js +0 -133
- package/lib/defineConfig.d.ts +0 -4
- package/lib/defineConfig.js +0 -23
- package/lib/forkedDev.js +0 -78
- package/lib/index.d.ts +0 -3
- package/lib/index.js +0 -204
- package/lib/initWebpack.d.ts +0 -2
- package/lib/initWebpack.js +0 -109
- package/lib/plugins/umiAlias.d.ts +0 -3
- package/lib/plugins/umiAlias.js +0 -30
- package/lib/utils/fork.js +0 -86
- package/lib/utils/getCwd.d.ts +0 -2
- package/lib/utils/getCwd.js +0 -45
- package/lib/utils/getPkg.d.ts +0 -2
- package/lib/utils/getPkg.js +0 -44
- package/types.d.ts +0 -3
package/README.md
CHANGED
|
@@ -1,54 +1,3 @@
|
|
|
1
|
-
English | [简体中文](https://github.com/umijs/umi/blob/master/README.zh-CN.md)
|
|
2
|
-
|
|
3
1
|
# umi
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
🍙 Extensible enterprise-level front-end application framework.
|
|
8
|
-
|
|
9
|
-
> Please consider following this project's author, [sorrycc](https://github.com/sorrycc), and consider starring the project to show your ❤️ and support.
|
|
10
|
-
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
## Features
|
|
14
|
-
|
|
15
|
-
- 🎉 **Extensible**, Umi implements the complete lifecycle and makes it extensible, and Umi's internal functions are all plugins. Umi also support plugins and presets.
|
|
16
|
-
- 📦 **Out of the Box**, Umi has built-in routing, building, deployment, testing, and so on. It only requires one dependency to get started. Umi also provides an integrated preset for React with rich functionaries.
|
|
17
|
-
- 🐠 **Enterprise**, It has been verified by 3000+ projects in Ant Financial and projects of Alibaba, Youku, Netease, 飞猪, KouBei and other companies.
|
|
18
|
-
- 🚀 **Self Development**, Including micro frontend library, component packaging, documentation tools, request library, hooks library, data flow, etc.
|
|
19
|
-
- 🌴 **Perfect Routing**, Supports both configuration routing and convention routing, while with functional completeness, such as dynamic routing, nested routing, permission routing, and so on.
|
|
20
|
-
- 🚄 **Future Ready**, Umi's community is also exploring new technologies. For example, modern mode, webpack @ 5, automated external, bundler less, etc.
|
|
21
|
-
|
|
22
|
-
## Getting Started
|
|
23
|
-
|
|
24
|
-
Manually,
|
|
25
|
-
|
|
26
|
-
```bash
|
|
27
|
-
# Create directory
|
|
28
|
-
$ mkdir myapp && cd myapp
|
|
29
|
-
|
|
30
|
-
# Install dependency
|
|
31
|
-
$ yarn add umi
|
|
32
|
-
|
|
33
|
-
# Create page
|
|
34
|
-
$ npx umi g page index --typescript --less
|
|
35
|
-
|
|
36
|
-
# Start development
|
|
37
|
-
$ npx umi dev
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
Or [Getting Started with Boilerplate](https://umijs.org/docs/getting-started).
|
|
41
|
-
|
|
42
|
-
## Contributors
|
|
43
|
-
|
|
44
|
-
This project exists thanks to all the people who contribute. [[Contribute](https://umijs.org/docs/contributing)]. <a href="https://github.com/umijs/umi/graphs/contributors"><img src="https://opencollective.com/umi/contributors.svg?width=890&button=false" /></a>
|
|
45
|
-
|
|
46
|
-
## Feedback
|
|
47
|
-
|
|
48
|
-
| Github Issue | 微信群 |
|
|
49
|
-
| --- | --- |
|
|
50
|
-
| [umijs/umi/issues](https://github.com/umijs/umi/issues) | <img src="https://img.alicdn.com/imgextra/i1/O1CN01jmrjUx1yw5LcPFMx0_!!6000000006642-0-tps-430-430.jpg" width="60" /> 关注后回复「umi」 |
|
|
51
|
-
|
|
52
|
-
## LICENSE
|
|
53
|
-
|
|
54
|
-
[MIT](https://github.com/umijs/umi/blob/master/LICENSE)
|
|
3
|
+
See our website [umijs](https://umijs.org) for more information.
|
package/bin/forkedDev.js
ADDED
package/bin/umi.js
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
require('v8-compile-cache');
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const debug = require('@umijs/utils').createDebug('umi:cli');
|
|
11
|
-
debug('Using local install of umi');
|
|
12
|
-
require(localCLI);
|
|
13
|
-
} else {
|
|
14
|
-
require('../lib/cli');
|
|
15
|
-
}
|
|
4
|
+
require('../dist/cli/cli')
|
|
5
|
+
.run()
|
|
6
|
+
.catch((e) => {
|
|
7
|
+
console.error(e);
|
|
8
|
+
process.exit(1);
|
|
9
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export declare enum ApplyPluginsType {
|
|
2
|
+
compose = "compose",
|
|
3
|
+
modify = "modify",
|
|
4
|
+
event = "event"
|
|
5
|
+
}
|
|
6
|
+
interface IPlugin {
|
|
7
|
+
path?: string;
|
|
8
|
+
apply: Record<string, any>;
|
|
9
|
+
}
|
|
10
|
+
export declare class PluginManager {
|
|
11
|
+
opts: {
|
|
12
|
+
validKeys: string[];
|
|
13
|
+
};
|
|
14
|
+
hooks: {
|
|
15
|
+
[key: string]: any;
|
|
16
|
+
};
|
|
17
|
+
constructor(opts: {
|
|
18
|
+
validKeys: string[];
|
|
19
|
+
});
|
|
20
|
+
register(plugin: IPlugin): void;
|
|
21
|
+
getHooks(keyWithDot: string): any;
|
|
22
|
+
applyPlugins({ key, type, initialValue, args, async, }: {
|
|
23
|
+
key: string;
|
|
24
|
+
type: ApplyPluginsType;
|
|
25
|
+
initialValue?: any;
|
|
26
|
+
args?: object;
|
|
27
|
+
async?: boolean;
|
|
28
|
+
}): any;
|
|
29
|
+
static create(opts: {
|
|
30
|
+
validKeys: string[];
|
|
31
|
+
plugins: IPlugin[];
|
|
32
|
+
}): PluginManager;
|
|
33
|
+
}
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,121 @@
|
|
|
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;
|
|
21
|
+
}
|
|
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
|
+
});
|
|
28
|
+
}
|
|
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;
|
|
49
|
+
}
|
|
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
|
+
}
|
|
109
|
+
}
|
|
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
|
+
}
|
|
120
|
+
// plugins meta info (in tmp file)
|
|
121
|
+
// hooks api: usePlugin
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function assert(value, message) {
|
|
2
|
+
if (!value)
|
|
3
|
+
throw new Error(message);
|
|
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);
|
|
11
|
+
}
|
|
12
|
+
export function isPromiseLike(obj) {
|
|
13
|
+
return !!obj && typeof obj === 'object' && typeof obj.then === 'function';
|
|
14
|
+
}
|
package/dist/cli/cli.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
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
|
+
});
|
|
57
|
+
}
|
|
58
|
+
exports.run = run;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function dev(): void;
|
package/dist/cli/dev.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.dev = void 0;
|
|
7
|
+
const fork_1 = __importDefault(require("./fork"));
|
|
8
|
+
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
|
+
});
|
|
25
|
+
}
|
|
26
|
+
exports.dev = dev;
|
|
File without changes
|
package/dist/cli/fork.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const child_process_1 = require("child_process");
|
|
4
|
+
const usedPorts = [];
|
|
5
|
+
function start({ scriptPath }) {
|
|
6
|
+
const execArgv = process.execArgv.slice(0);
|
|
7
|
+
const inspectArgvIndex = execArgv.findIndex((argv) => argv.includes('--inspect-brk'));
|
|
8
|
+
if (inspectArgvIndex > -1) {
|
|
9
|
+
const inspectArgv = execArgv[inspectArgvIndex];
|
|
10
|
+
execArgv.splice(inspectArgvIndex, 1, inspectArgv.replace(/--inspect-brk=(.*)/, (_match, s1) => {
|
|
11
|
+
let port;
|
|
12
|
+
try {
|
|
13
|
+
port = parseInt(s1) + 1;
|
|
14
|
+
}
|
|
15
|
+
catch (e) {
|
|
16
|
+
port = 9230; // node default inspect port plus 1.
|
|
17
|
+
}
|
|
18
|
+
if (usedPorts.includes(port)) {
|
|
19
|
+
port += 1;
|
|
20
|
+
}
|
|
21
|
+
usedPorts.push(port);
|
|
22
|
+
return `--inspect-brk=${port}`;
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
const child = (0, child_process_1.fork)(scriptPath, process.argv.slice(2), { execArgv });
|
|
26
|
+
child.on('message', (data) => {
|
|
27
|
+
var _a;
|
|
28
|
+
const { type, payload } = data || {};
|
|
29
|
+
if (type === 'RESTART') {
|
|
30
|
+
child.kill();
|
|
31
|
+
if (payload === null || payload === void 0 ? void 0 : payload.port) {
|
|
32
|
+
process.env.PORT = payload.port;
|
|
33
|
+
}
|
|
34
|
+
start({ scriptPath });
|
|
35
|
+
}
|
|
36
|
+
(_a = process.send) === null || _a === void 0 ? void 0 : _a.call(process, data);
|
|
37
|
+
});
|
|
38
|
+
return child;
|
|
39
|
+
}
|
|
40
|
+
exports.default = start;
|
|
File without changes
|
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const utils_1 = require("@umijs/utils");
|
|
13
|
+
const constants_1 = require("../constants");
|
|
14
|
+
const service_1 = require("../service/service");
|
|
15
|
+
const node_1 = require("./node");
|
|
16
|
+
(0, node_1.setNodeTitle)(`${constants_1.FRAMEWORK_NAME}-dev`);
|
|
17
|
+
(0, node_1.setNoDeprecation)();
|
|
18
|
+
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
try {
|
|
20
|
+
const args = (0, utils_1.yParser)(process.argv.slice(2));
|
|
21
|
+
const service = new service_1.Service();
|
|
22
|
+
yield service.run2({
|
|
23
|
+
name: constants_1.DEV_COMMAND,
|
|
24
|
+
args,
|
|
25
|
+
});
|
|
26
|
+
let closed = false;
|
|
27
|
+
// kill(2) Ctrl-C
|
|
28
|
+
process.once('SIGINT', () => onSignal('SIGINT'));
|
|
29
|
+
// kill(3) Ctrl-\
|
|
30
|
+
process.once('SIGQUIT', () => onSignal('SIGQUIT'));
|
|
31
|
+
// kill(15) default
|
|
32
|
+
process.once('SIGTERM', () => onSignal('SIGTERM'));
|
|
33
|
+
function onSignal(signal) {
|
|
34
|
+
if (closed)
|
|
35
|
+
return;
|
|
36
|
+
closed = true;
|
|
37
|
+
// 退出时触发插件中的 onExit 事件
|
|
38
|
+
service.applyPlugins({
|
|
39
|
+
key: 'onExit',
|
|
40
|
+
args: {
|
|
41
|
+
signal,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
process.exit(0);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
utils_1.logger.error(e);
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
}))();
|
package/dist/cli/node.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setNoDeprecation = exports.setNodeTitle = exports.checkLocal = exports.checkVersion = void 0;
|
|
4
|
+
const utils_1 = require("@umijs/utils");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
function checkVersion() {
|
|
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}.`);
|
|
10
|
+
process.exit(1);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.checkVersion = checkVersion;
|
|
14
|
+
function checkLocal() {
|
|
15
|
+
if (__filename.includes(`packages/${constants_1.FRAMEWORK_NAME}`)) {
|
|
16
|
+
utils_1.logger.info('@local');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.checkLocal = checkLocal;
|
|
20
|
+
function setNodeTitle(name) {
|
|
21
|
+
if (process.title === 'node') {
|
|
22
|
+
process.title = name || constants_1.FRAMEWORK_NAME;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.setNodeTitle = setNodeTitle;
|
|
26
|
+
function setNoDeprecation() {
|
|
27
|
+
// Use magic to suppress node deprecation warnings
|
|
28
|
+
// See: https://github.com/nodejs/node/blob/master/lib/internal/process/warning.js#L77
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
process.noDeprecation = '1';
|
|
31
|
+
}
|
|
32
|
+
exports.setNoDeprecation = setNoDeprecation;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export declare enum ApplyPluginsType {
|
|
2
|
+
compose = "compose",
|
|
3
|
+
modify = "modify",
|
|
4
|
+
event = "event"
|
|
5
|
+
}
|
|
6
|
+
interface IPlugin {
|
|
7
|
+
path?: string;
|
|
8
|
+
apply: Record<string, any>;
|
|
9
|
+
}
|
|
10
|
+
export declare class PluginManager {
|
|
11
|
+
opts: {
|
|
12
|
+
validKeys: string[];
|
|
13
|
+
};
|
|
14
|
+
hooks: {
|
|
15
|
+
[key: string]: any;
|
|
16
|
+
};
|
|
17
|
+
constructor(opts: {
|
|
18
|
+
validKeys: string[];
|
|
19
|
+
});
|
|
20
|
+
register(plugin: IPlugin): void;
|
|
21
|
+
getHooks(keyWithDot: string): any;
|
|
22
|
+
applyPlugins({ key, type, initialValue, args, async, }: {
|
|
23
|
+
key: string;
|
|
24
|
+
type: ApplyPluginsType;
|
|
25
|
+
initialValue?: any;
|
|
26
|
+
args?: object;
|
|
27
|
+
async?: boolean;
|
|
28
|
+
}): any;
|
|
29
|
+
static create(opts: {
|
|
30
|
+
validKeys: string[];
|
|
31
|
+
plugins: IPlugin[];
|
|
32
|
+
}): PluginManager;
|
|
33
|
+
}
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,125 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.PluginManager = exports.ApplyPluginsType = void 0;
|
|
13
|
+
const utils_1 = require("./utils");
|
|
14
|
+
var ApplyPluginsType;
|
|
15
|
+
(function (ApplyPluginsType) {
|
|
16
|
+
ApplyPluginsType["compose"] = "compose";
|
|
17
|
+
ApplyPluginsType["modify"] = "modify";
|
|
18
|
+
ApplyPluginsType["event"] = "event";
|
|
19
|
+
})(ApplyPluginsType = exports.ApplyPluginsType || (exports.ApplyPluginsType = {}));
|
|
20
|
+
class PluginManager {
|
|
21
|
+
constructor(opts) {
|
|
22
|
+
this.hooks = {};
|
|
23
|
+
this.opts = opts;
|
|
24
|
+
}
|
|
25
|
+
register(plugin) {
|
|
26
|
+
(0, utils_1.assert)(plugin.apply && plugin.path, `plugin register failed, apply and path must supplied`);
|
|
27
|
+
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}.`);
|
|
29
|
+
this.hooks[key] = (this.hooks[key] || []).concat(plugin.apply[key]);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
getHooks(keyWithDot) {
|
|
33
|
+
const [key, ...memberKeys] = keyWithDot.split('.');
|
|
34
|
+
let hooks = this.hooks[key] || [];
|
|
35
|
+
if (memberKeys.length) {
|
|
36
|
+
hooks = hooks
|
|
37
|
+
.map((hook) => {
|
|
38
|
+
try {
|
|
39
|
+
let ret = hook;
|
|
40
|
+
for (const memberKey of memberKeys) {
|
|
41
|
+
ret = ret[memberKey];
|
|
42
|
+
}
|
|
43
|
+
return ret;
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
.filter(Boolean);
|
|
50
|
+
}
|
|
51
|
+
return hooks;
|
|
52
|
+
}
|
|
53
|
+
applyPlugins({ key, type, initialValue, args, async, }) {
|
|
54
|
+
const hooks = this.getHooks(key) || [];
|
|
55
|
+
if (args) {
|
|
56
|
+
(0, utils_1.assert)(typeof args === 'object', `applyPlugins failed, args must be plain object.`);
|
|
57
|
+
}
|
|
58
|
+
switch (type) {
|
|
59
|
+
case ApplyPluginsType.modify:
|
|
60
|
+
if (async) {
|
|
61
|
+
return hooks.reduce((memo, hook) => __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
(0, utils_1.assert)(typeof hook === 'function' ||
|
|
63
|
+
typeof hook === 'object' ||
|
|
64
|
+
(0, utils_1.isPromiseLike)(hook), `applyPlugins failed, all hooks for key ${key} must be function, plain object or Promise.`);
|
|
65
|
+
if ((0, utils_1.isPromiseLike)(memo)) {
|
|
66
|
+
memo = yield memo;
|
|
67
|
+
}
|
|
68
|
+
if (typeof hook === 'function') {
|
|
69
|
+
const ret = hook(memo, args);
|
|
70
|
+
if ((0, utils_1.isPromiseLike)(ret)) {
|
|
71
|
+
return yield ret;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
return ret;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
if ((0, utils_1.isPromiseLike)(hook)) {
|
|
79
|
+
hook = yield hook;
|
|
80
|
+
}
|
|
81
|
+
return Object.assign(Object.assign({}, memo), hook);
|
|
82
|
+
}
|
|
83
|
+
}), (0, utils_1.isPromiseLike)(initialValue)
|
|
84
|
+
? initialValue
|
|
85
|
+
: Promise.resolve(initialValue));
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
return hooks.reduce((memo, hook) => {
|
|
89
|
+
(0, utils_1.assert)(typeof hook === 'function' || typeof hook === 'object', `applyPlugins failed, all hooks for key ${key} must be function or plain object.`);
|
|
90
|
+
if (typeof hook === 'function') {
|
|
91
|
+
return hook(memo, args);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
// TODO: deepmerge?
|
|
95
|
+
return Object.assign(Object.assign({}, memo), hook);
|
|
96
|
+
}
|
|
97
|
+
}, initialValue);
|
|
98
|
+
}
|
|
99
|
+
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
|
+
});
|
|
104
|
+
case ApplyPluginsType.compose:
|
|
105
|
+
return () => {
|
|
106
|
+
return (0, utils_1.compose)({
|
|
107
|
+
fns: hooks.concat(initialValue),
|
|
108
|
+
args,
|
|
109
|
+
})();
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
static create(opts) {
|
|
114
|
+
const pluginManager = new PluginManager({
|
|
115
|
+
validKeys: opts.validKeys,
|
|
116
|
+
});
|
|
117
|
+
opts.plugins.forEach((plugin) => {
|
|
118
|
+
pluginManager.register(plugin);
|
|
119
|
+
});
|
|
120
|
+
return pluginManager;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.PluginManager = PluginManager;
|
|
124
|
+
// plugins meta info (in tmp file)
|
|
125
|
+
// hooks api: usePlugin
|