umi 4.0.0-canary.20220429.3 → 4.0.0-canary.20220506.2
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/dist/cli/cli.d.ts +5 -0
- package/dist/cli/cli.js +47 -0
- package/dist/cli/dev.d.ts +1 -0
- package/dist/cli/dev.js +26 -0
- package/dist/cli/fork.d.ts +6 -0
- package/dist/cli/fork.js +40 -0
- package/dist/cli/forkedDev.d.ts +1 -0
- package/dist/cli/forkedDev.js +42 -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 +124 -0
- package/dist/client/utils.d.ts +6 -0
- package/dist/client/utils.js +20 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.js +12 -0
- package/dist/defineConfig.d.ts +5 -0
- package/dist/defineConfig.js +7 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +22 -0
- package/dist/pluginUtils.d.ts +5 -0
- package/dist/pluginUtils.js +39 -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 +39 -0
- package/dist/test.d.ts +117 -0
- package/dist/test.js +51 -0
- package/package.json +10 -10
package/dist/cli/cli.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.run = void 0;
|
|
4
|
+
const utils_1 = require("@umijs/utils");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
const service_1 = require("../service/service");
|
|
7
|
+
const dev_1 = require("./dev");
|
|
8
|
+
const node_1 = require("./node");
|
|
9
|
+
async function run(opts) {
|
|
10
|
+
(0, node_1.checkVersion)();
|
|
11
|
+
(0, node_1.checkLocal)();
|
|
12
|
+
(0, node_1.setNodeTitle)();
|
|
13
|
+
(0, node_1.setNoDeprecation)();
|
|
14
|
+
const args = (0, utils_1.yParser)(process.argv.slice(2), {
|
|
15
|
+
alias: {
|
|
16
|
+
version: ['v'],
|
|
17
|
+
help: ['h'],
|
|
18
|
+
},
|
|
19
|
+
boolean: ['version'],
|
|
20
|
+
});
|
|
21
|
+
const command = args._[0];
|
|
22
|
+
if ([constants_1.DEV_COMMAND, 'setup'].includes(command)) {
|
|
23
|
+
process.env.NODE_ENV = 'development';
|
|
24
|
+
}
|
|
25
|
+
else if (command === 'build') {
|
|
26
|
+
process.env.NODE_ENV = 'production';
|
|
27
|
+
}
|
|
28
|
+
if (opts === null || opts === void 0 ? void 0 : opts.presets) {
|
|
29
|
+
process.env.UMI_PRESETS = opts.presets.join(',');
|
|
30
|
+
}
|
|
31
|
+
if (command === constants_1.DEV_COMMAND) {
|
|
32
|
+
(0, dev_1.dev)();
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
try {
|
|
36
|
+
await new service_1.Service().run2({
|
|
37
|
+
name: args._[0],
|
|
38
|
+
args,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
utils_1.logger.error(e);
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
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;
|
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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("@umijs/utils");
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
const service_1 = require("../service/service");
|
|
6
|
+
const node_1 = require("./node");
|
|
7
|
+
(0, node_1.setNodeTitle)(`${constants_1.FRAMEWORK_NAME}-dev`);
|
|
8
|
+
(0, node_1.setNoDeprecation)();
|
|
9
|
+
(async () => {
|
|
10
|
+
try {
|
|
11
|
+
const args = (0, utils_1.yParser)(process.argv.slice(2));
|
|
12
|
+
const service = new service_1.Service();
|
|
13
|
+
await service.run2({
|
|
14
|
+
name: constants_1.DEV_COMMAND,
|
|
15
|
+
args,
|
|
16
|
+
});
|
|
17
|
+
let closed = false;
|
|
18
|
+
// kill(2) Ctrl-C
|
|
19
|
+
process.once('SIGINT', () => onSignal('SIGINT'));
|
|
20
|
+
// kill(3) Ctrl-\
|
|
21
|
+
process.once('SIGQUIT', () => onSignal('SIGQUIT'));
|
|
22
|
+
// kill(15) default
|
|
23
|
+
process.once('SIGTERM', () => onSignal('SIGTERM'));
|
|
24
|
+
function onSignal(signal) {
|
|
25
|
+
if (closed)
|
|
26
|
+
return;
|
|
27
|
+
closed = true;
|
|
28
|
+
// 退出时触发插件中的 onExit 事件
|
|
29
|
+
service.applyPlugins({
|
|
30
|
+
key: 'onExit',
|
|
31
|
+
args: {
|
|
32
|
+
signal,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
process.exit(0);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
utils_1.logger.error(e);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
})();
|
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 === 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
|
+
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,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PluginManager = exports.ApplyPluginsType = void 0;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
var ApplyPluginsType;
|
|
6
|
+
(function (ApplyPluginsType) {
|
|
7
|
+
ApplyPluginsType["compose"] = "compose";
|
|
8
|
+
ApplyPluginsType["modify"] = "modify";
|
|
9
|
+
ApplyPluginsType["event"] = "event";
|
|
10
|
+
})(ApplyPluginsType = exports.ApplyPluginsType || (exports.ApplyPluginsType = {}));
|
|
11
|
+
class PluginManager {
|
|
12
|
+
constructor(opts) {
|
|
13
|
+
this.hooks = {};
|
|
14
|
+
this.opts = opts;
|
|
15
|
+
}
|
|
16
|
+
register(plugin) {
|
|
17
|
+
(0, utils_1.assert)(plugin.apply && plugin.path, `plugin register failed, apply and path must supplied`);
|
|
18
|
+
Object.keys(plugin.apply).forEach((key) => {
|
|
19
|
+
(0, utils_1.assert)(this.opts.validKeys.indexOf(key) > -1, `register failed, invalid key ${key} from plugin ${plugin.path}.`);
|
|
20
|
+
this.hooks[key] = (this.hooks[key] || []).concat(plugin.apply[key]);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
getHooks(keyWithDot) {
|
|
24
|
+
const [key, ...memberKeys] = keyWithDot.split('.');
|
|
25
|
+
let hooks = this.hooks[key] || [];
|
|
26
|
+
if (memberKeys.length) {
|
|
27
|
+
hooks = hooks
|
|
28
|
+
.map((hook) => {
|
|
29
|
+
try {
|
|
30
|
+
let ret = hook;
|
|
31
|
+
for (const memberKey of memberKeys) {
|
|
32
|
+
ret = ret[memberKey];
|
|
33
|
+
}
|
|
34
|
+
return ret;
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
.filter(Boolean);
|
|
41
|
+
}
|
|
42
|
+
return hooks;
|
|
43
|
+
}
|
|
44
|
+
applyPlugins({ key, type, initialValue, args, async, }) {
|
|
45
|
+
const hooks = this.getHooks(key) || [];
|
|
46
|
+
if (args) {
|
|
47
|
+
(0, utils_1.assert)(typeof args === 'object', `applyPlugins failed, args must be plain object.`);
|
|
48
|
+
}
|
|
49
|
+
if (async) {
|
|
50
|
+
(0, utils_1.assert)(type === ApplyPluginsType.modify || type === ApplyPluginsType.event, `async only works with modify and event type.`);
|
|
51
|
+
}
|
|
52
|
+
switch (type) {
|
|
53
|
+
case ApplyPluginsType.modify:
|
|
54
|
+
if (async) {
|
|
55
|
+
return hooks.reduce(async (memo, hook) => {
|
|
56
|
+
(0, utils_1.assert)(typeof hook === 'function' ||
|
|
57
|
+
typeof hook === 'object' ||
|
|
58
|
+
(0, utils_1.isPromiseLike)(hook), `applyPlugins failed, all hooks for key ${key} must be function, plain object or Promise.`);
|
|
59
|
+
if ((0, utils_1.isPromiseLike)(memo)) {
|
|
60
|
+
memo = await memo;
|
|
61
|
+
}
|
|
62
|
+
if (typeof hook === 'function') {
|
|
63
|
+
const ret = hook(memo, args);
|
|
64
|
+
if ((0, utils_1.isPromiseLike)(ret)) {
|
|
65
|
+
return await ret;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
return ret;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
if ((0, utils_1.isPromiseLike)(hook)) {
|
|
73
|
+
hook = await hook;
|
|
74
|
+
}
|
|
75
|
+
return { ...memo, ...hook };
|
|
76
|
+
}
|
|
77
|
+
}, (0, utils_1.isPromiseLike)(initialValue)
|
|
78
|
+
? initialValue
|
|
79
|
+
: Promise.resolve(initialValue));
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
return hooks.reduce((memo, hook) => {
|
|
83
|
+
(0, utils_1.assert)(typeof hook === 'function' || typeof hook === 'object', `applyPlugins failed, all hooks for key ${key} must be function or plain object.`);
|
|
84
|
+
if (typeof hook === 'function') {
|
|
85
|
+
return hook(memo, args);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
// TODO: deepmerge?
|
|
89
|
+
return { ...memo, ...hook };
|
|
90
|
+
}
|
|
91
|
+
}, initialValue);
|
|
92
|
+
}
|
|
93
|
+
case ApplyPluginsType.event:
|
|
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
|
+
})();
|
|
103
|
+
case ApplyPluginsType.compose:
|
|
104
|
+
return () => {
|
|
105
|
+
return (0, utils_1.compose)({
|
|
106
|
+
fns: hooks.concat(initialValue),
|
|
107
|
+
args,
|
|
108
|
+
})();
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
static create(opts) {
|
|
113
|
+
const pluginManager = new PluginManager({
|
|
114
|
+
validKeys: opts.validKeys,
|
|
115
|
+
});
|
|
116
|
+
opts.plugins.forEach((plugin) => {
|
|
117
|
+
pluginManager.register(plugin);
|
|
118
|
+
});
|
|
119
|
+
return pluginManager;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
exports.PluginManager = PluginManager;
|
|
123
|
+
// plugins meta info (in tmp file)
|
|
124
|
+
// hooks api: usePlugin
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isPromiseLike = exports.compose = exports.assert = void 0;
|
|
4
|
+
function assert(value, message) {
|
|
5
|
+
if (!value)
|
|
6
|
+
throw new Error(message);
|
|
7
|
+
}
|
|
8
|
+
exports.assert = assert;
|
|
9
|
+
function compose({ fns, args, }) {
|
|
10
|
+
if (fns.length === 1) {
|
|
11
|
+
return fns[0];
|
|
12
|
+
}
|
|
13
|
+
const last = fns.pop();
|
|
14
|
+
return fns.reduce((a, b) => () => b(a, args), last);
|
|
15
|
+
}
|
|
16
|
+
exports.compose = compose;
|
|
17
|
+
function isPromiseLike(obj) {
|
|
18
|
+
return !!obj && typeof obj === 'object' && typeof obj.then === 'function';
|
|
19
|
+
}
|
|
20
|
+
exports.isPromiseLike = isPromiseLike;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FRAMEWORK_NAME = exports.DEFAULT_CONFIG_FILES = exports.DEV_COMMAND = exports.MIN_NODE_VERSION = void 0;
|
|
4
|
+
exports.MIN_NODE_VERSION = 14;
|
|
5
|
+
exports.DEV_COMMAND = 'dev';
|
|
6
|
+
exports.DEFAULT_CONFIG_FILES = [
|
|
7
|
+
'.umirc.ts',
|
|
8
|
+
'.umirc.js',
|
|
9
|
+
'config/config.ts',
|
|
10
|
+
'config/config.js',
|
|
11
|
+
];
|
|
12
|
+
exports.FRAMEWORK_NAME = 'umi';
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
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.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; } });
|
|
20
|
+
var defineConfig_1 = require("./defineConfig");
|
|
21
|
+
Object.defineProperty(exports, "defineConfig", { enumerable: true, get: function () { return defineConfig_1.defineConfig; } });
|
|
22
|
+
__exportStar(require("./service/service"), exports);
|
|
@@ -0,0 +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';
|
|
4
|
+
export * from '@umijs/utils';
|
|
5
|
+
export { httpProxyMiddleware, express };
|
|
@@ -0,0 +1,39 @@
|
|
|
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 __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
|
+
};
|
|
25
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
|
+
};
|
|
28
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
29
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
30
|
+
};
|
|
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; } });
|
|
39
|
+
__exportStar(require("@umijs/utils"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getCwd(): string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCwd = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
function getCwd() {
|
|
6
|
+
const cwd = process.cwd();
|
|
7
|
+
const appRoot = process.env.APP_ROOT;
|
|
8
|
+
if (appRoot) {
|
|
9
|
+
return (0, path_1.isAbsolute)(appRoot) ? appRoot : (0, path_1.join)(cwd, appRoot);
|
|
10
|
+
}
|
|
11
|
+
return cwd;
|
|
12
|
+
}
|
|
13
|
+
exports.getCwd = getCwd;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Service = void 0;
|
|
4
|
+
const core_1 = require("@umijs/core");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const constants_1 = require("../constants");
|
|
8
|
+
const cwd_1 = require("./cwd");
|
|
9
|
+
class Service extends core_1.Service {
|
|
10
|
+
constructor(opts) {
|
|
11
|
+
process.env.UMI_DIR = (0, path_1.dirname)(require.resolve('../../package'));
|
|
12
|
+
const cwd = (0, cwd_1.getCwd)();
|
|
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: [
|
|
21
|
+
(0, fs_1.existsSync)((0, path_1.join)(cwd, 'plugin.ts')) && (0, path_1.join)(cwd, 'plugin.ts'),
|
|
22
|
+
(0, fs_1.existsSync)((0, path_1.join)(cwd, 'plugin.js')) && (0, path_1.join)(cwd, 'plugin.js'),
|
|
23
|
+
].filter(Boolean),
|
|
24
|
+
});
|
|
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
|
+
}
|
|
38
|
+
}
|
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "umi",
|
|
3
|
-
"version": "4.0.0-canary.
|
|
3
|
+
"version": "4.0.0-canary.20220506.2",
|
|
4
4
|
"description": "umi",
|
|
5
5
|
"homepage": "https://github.com/umijs/umi-next/tree/master/packages/umi#readme",
|
|
6
6
|
"bugs": "https://github.com/umijs/umi-next/issues",
|
|
@@ -37,15 +37,15 @@
|
|
|
37
37
|
"test": "umi-scripts jest-turbo"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@umijs/bundler-utils": "4.0.0-canary.
|
|
41
|
-
"@umijs/bundler-webpack": "4.0.0-canary.
|
|
42
|
-
"@umijs/core": "4.0.0-canary.
|
|
43
|
-
"@umijs/lint": "4.0.0-canary.
|
|
44
|
-
"@umijs/preset-umi": "4.0.0-canary.
|
|
45
|
-
"@umijs/renderer-react": "4.0.0-canary.
|
|
46
|
-
"@umijs/server": "4.0.0-canary.
|
|
47
|
-
"@umijs/test": "4.0.0-canary.
|
|
48
|
-
"@umijs/utils": "4.0.0-canary.
|
|
40
|
+
"@umijs/bundler-utils": "4.0.0-canary.20220506.2",
|
|
41
|
+
"@umijs/bundler-webpack": "4.0.0-canary.20220506.2",
|
|
42
|
+
"@umijs/core": "4.0.0-canary.20220506.2",
|
|
43
|
+
"@umijs/lint": "4.0.0-canary.20220506.2",
|
|
44
|
+
"@umijs/preset-umi": "4.0.0-canary.20220506.2",
|
|
45
|
+
"@umijs/renderer-react": "4.0.0-canary.20220506.2",
|
|
46
|
+
"@umijs/server": "4.0.0-canary.20220506.2",
|
|
47
|
+
"@umijs/test": "4.0.0-canary.20220506.2",
|
|
48
|
+
"@umijs/utils": "4.0.0-canary.20220506.2",
|
|
49
49
|
"prettier-plugin-organize-imports": "^2.3.4",
|
|
50
50
|
"prettier-plugin-packagejson": "^2.2.17"
|
|
51
51
|
},
|