@umijs/core 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 +2 -0
- package/compiled/@hapi/joi/index.d.ts +2219 -0
- package/compiled/@hapi/joi/index.js +1 -0
- package/compiled/@hapi/joi/package.json +1 -0
- package/compiled/dotenv/LICENSE +23 -0
- package/compiled/dotenv/index.js +1 -0
- package/compiled/dotenv/package.json +1 -0
- package/compiled/dotenv/types/index.d.ts +59 -0
- package/compiled/just-diff/LICENSE +21 -0
- package/compiled/just-diff/index.d.ts +20 -0
- package/compiled/just-diff/index.js +1 -0
- package/compiled/just-diff/package.json +1 -0
- package/compiled/tapable/LICENSE +21 -0
- package/compiled/tapable/index.js +1 -0
- package/compiled/tapable/package.json +1 -0
- package/compiled/tapable/tapable.d.ts +116 -0
- package/dist/config/config.d.ts +63 -0
- package/dist/config/config.js +183 -0
- package/dist/config/utils.d.ts +8 -0
- package/dist/config/utils.js +15 -0
- package/dist/constants.d.ts +9 -0
- package/dist/constants.js +12 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +21 -0
- package/dist/route/defineRoutes.d.ts +1 -0
- package/dist/route/defineRoutes.js +28 -0
- package/dist/route/route.d.ts +3 -0
- package/dist/route/route.js +19 -0
- package/dist/route/routeUtils.d.ts +7 -0
- package/dist/route/routeUtils.js +21 -0
- package/dist/route/routesConfig.d.ts +5 -0
- package/dist/route/routesConfig.js +37 -0
- package/dist/route/routesConvention.d.ts +4 -0
- package/dist/route/routesConvention.js +73 -0
- package/dist/route/utils.d.ts +7 -0
- package/dist/route/utils.js +26 -0
- package/dist/service/command.d.ts +27 -0
- package/dist/service/command.js +14 -0
- package/dist/service/env.d.ts +4 -0
- package/dist/service/env.js +21 -0
- package/dist/service/generatePlugin.d.ts +4 -0
- package/dist/service/generatePlugin.js +91 -0
- package/dist/service/generator.d.ts +60 -0
- package/dist/service/generator.js +20 -0
- package/dist/service/hook.d.ts +16 -0
- package/dist/service/hook.js +18 -0
- package/dist/service/path.d.ts +13 -0
- package/dist/service/path.js +31 -0
- package/dist/service/plugin.d.ts +56 -0
- package/dist/service/plugin.js +147 -0
- package/dist/service/pluginAPI.d.ts +44 -0
- package/dist/service/pluginAPI.js +146 -0
- package/dist/service/service.d.ts +99 -0
- package/dist/service/service.js +355 -0
- package/dist/service/servicePlugin.d.ts +3 -0
- package/dist/service/servicePlugin.js +14 -0
- package/dist/service/utils.d.ts +2 -0
- package/dist/service/utils.js +12 -0
- package/dist/types.d.ts +108 -0
- package/dist/types.js +42 -0
- package/package.json +42 -21
- package/lib/Config/Config.d.ts +0 -39
- package/lib/Config/Config.js +0 -348
- package/lib/Config/types.d.ts +0 -21
- package/lib/Config/utils/configUtils.d.ts +0 -9
- package/lib/Config/utils/configUtils.js +0 -54
- package/lib/Config/utils/isEqual.d.ts +0 -1
- package/lib/Config/utils/isEqual.js +0 -45
- package/lib/Config/utils/mergeDefault.d.ts +0 -6
- package/lib/Config/utils/mergeDefault.js +0 -41
- package/lib/Html/Html.d.ts +0 -16
- package/lib/Html/Html.js +0 -292
- package/lib/Html/document.ejs +0 -12
- package/lib/Html/types.d.ts +0 -55
- package/lib/Logger/Common.d.ts +0 -13
- package/lib/Logger/Common.js +0 -53
- package/lib/Logger/Logger.d.ts +0 -17
- package/lib/Logger/Logger.js +0 -87
- package/lib/Route/Route.d.ts +0 -32
- package/lib/Route/Route.js +0 -228
- package/lib/Route/getConventionalRoutes.d.ts +0 -10
- package/lib/Route/getConventionalRoutes.js +0 -259
- package/lib/Route/routesToJSON.d.ts +0 -9
- package/lib/Route/routesToJSON.js +0 -140
- package/lib/Route/types.d.ts +0 -11
- package/lib/Service/PluginAPI.d.ts +0 -38
- package/lib/Service/PluginAPI.js +0 -193
- package/lib/Service/Service.d.ts +0 -96
- package/lib/Service/Service.js +0 -694
- package/lib/Service/enums.d.ts +0 -29
- package/lib/Service/enums.js +0 -67
- package/lib/Service/getPaths.d.ts +0 -6
- package/lib/Service/getPaths.js +0 -79
- package/lib/Service/types.d.ts +0 -52
- package/lib/Service/types.js +0 -17
- package/lib/Service/utils/isPromise.d.ts +0 -1
- package/lib/Service/utils/isPromise.js +0 -22
- package/lib/Service/utils/loadDotEnv.d.ts +0 -5
- package/lib/Service/utils/loadDotEnv.js +0 -54
- package/lib/Service/utils/pluginUtils.d.ts +0 -42
- package/lib/Service/utils/pluginUtils.js +0 -201
- package/lib/index.d.ts +0 -14
- package/lib/index.js +0 -81
package/lib/Service/enums.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
export declare enum PluginType {
|
|
2
|
-
preset = "preset",
|
|
3
|
-
plugin = "plugin"
|
|
4
|
-
}
|
|
5
|
-
export declare enum ServiceStage {
|
|
6
|
-
uninitialized = 0,
|
|
7
|
-
constructor = 1,
|
|
8
|
-
init = 2,
|
|
9
|
-
initPresets = 3,
|
|
10
|
-
initPlugins = 4,
|
|
11
|
-
initHooks = 5,
|
|
12
|
-
pluginReady = 6,
|
|
13
|
-
getConfig = 7,
|
|
14
|
-
getPaths = 8,
|
|
15
|
-
run = 9
|
|
16
|
-
}
|
|
17
|
-
export declare enum ConfigChangeType {
|
|
18
|
-
reload = "reload",
|
|
19
|
-
regenerateTmpFiles = "regenerateTmpFiles"
|
|
20
|
-
}
|
|
21
|
-
export declare enum ApplyPluginsType {
|
|
22
|
-
add = "add",
|
|
23
|
-
modify = "modify",
|
|
24
|
-
event = "event"
|
|
25
|
-
}
|
|
26
|
-
export declare enum EnableBy {
|
|
27
|
-
register = "register",
|
|
28
|
-
config = "config"
|
|
29
|
-
}
|
package/lib/Service/enums.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.EnableBy = exports.ApplyPluginsType = exports.ConfigChangeType = exports.ServiceStage = exports.PluginType = void 0;
|
|
7
|
-
|
|
8
|
-
function _react() {
|
|
9
|
-
const data = _interopRequireDefault(require("react"));
|
|
10
|
-
|
|
11
|
-
_react = function _react() {
|
|
12
|
-
return data;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
|
|
20
|
-
var PluginType;
|
|
21
|
-
exports.PluginType = PluginType;
|
|
22
|
-
|
|
23
|
-
(function (PluginType) {
|
|
24
|
-
PluginType["preset"] = "preset";
|
|
25
|
-
PluginType["plugin"] = "plugin";
|
|
26
|
-
})(PluginType || (exports.PluginType = PluginType = {}));
|
|
27
|
-
|
|
28
|
-
var ServiceStage;
|
|
29
|
-
exports.ServiceStage = ServiceStage;
|
|
30
|
-
|
|
31
|
-
(function (ServiceStage) {
|
|
32
|
-
ServiceStage[ServiceStage["uninitialized"] = 0] = "uninitialized";
|
|
33
|
-
ServiceStage[ServiceStage["constructor"] = 1] = "constructor";
|
|
34
|
-
ServiceStage[ServiceStage["init"] = 2] = "init";
|
|
35
|
-
ServiceStage[ServiceStage["initPresets"] = 3] = "initPresets";
|
|
36
|
-
ServiceStage[ServiceStage["initPlugins"] = 4] = "initPlugins";
|
|
37
|
-
ServiceStage[ServiceStage["initHooks"] = 5] = "initHooks";
|
|
38
|
-
ServiceStage[ServiceStage["pluginReady"] = 6] = "pluginReady";
|
|
39
|
-
ServiceStage[ServiceStage["getConfig"] = 7] = "getConfig";
|
|
40
|
-
ServiceStage[ServiceStage["getPaths"] = 8] = "getPaths";
|
|
41
|
-
ServiceStage[ServiceStage["run"] = 9] = "run";
|
|
42
|
-
})(ServiceStage || (exports.ServiceStage = ServiceStage = {}));
|
|
43
|
-
|
|
44
|
-
var ConfigChangeType;
|
|
45
|
-
exports.ConfigChangeType = ConfigChangeType;
|
|
46
|
-
|
|
47
|
-
(function (ConfigChangeType) {
|
|
48
|
-
ConfigChangeType["reload"] = "reload";
|
|
49
|
-
ConfigChangeType["regenerateTmpFiles"] = "regenerateTmpFiles";
|
|
50
|
-
})(ConfigChangeType || (exports.ConfigChangeType = ConfigChangeType = {}));
|
|
51
|
-
|
|
52
|
-
var ApplyPluginsType;
|
|
53
|
-
exports.ApplyPluginsType = ApplyPluginsType;
|
|
54
|
-
|
|
55
|
-
(function (ApplyPluginsType) {
|
|
56
|
-
ApplyPluginsType["add"] = "add";
|
|
57
|
-
ApplyPluginsType["modify"] = "modify";
|
|
58
|
-
ApplyPluginsType["event"] = "event";
|
|
59
|
-
})(ApplyPluginsType || (exports.ApplyPluginsType = ApplyPluginsType = {}));
|
|
60
|
-
|
|
61
|
-
var EnableBy;
|
|
62
|
-
exports.EnableBy = EnableBy;
|
|
63
|
-
|
|
64
|
-
(function (EnableBy) {
|
|
65
|
-
EnableBy["register"] = "register";
|
|
66
|
-
EnableBy["config"] = "config";
|
|
67
|
-
})(EnableBy || (exports.EnableBy = EnableBy = {}));
|
package/lib/Service/getPaths.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = getServicePaths;
|
|
7
|
-
|
|
8
|
-
function _react() {
|
|
9
|
-
const data = _interopRequireDefault(require("react"));
|
|
10
|
-
|
|
11
|
-
_react = function _react() {
|
|
12
|
-
return data;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function _utils() {
|
|
19
|
-
const data = require("@umijs/utils");
|
|
20
|
-
|
|
21
|
-
_utils = function _utils() {
|
|
22
|
-
return data;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
return data;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function _fs() {
|
|
29
|
-
const data = require("fs");
|
|
30
|
-
|
|
31
|
-
_fs = function _fs() {
|
|
32
|
-
return data;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
return data;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function _path() {
|
|
39
|
-
const data = require("path");
|
|
40
|
-
|
|
41
|
-
_path = function _path() {
|
|
42
|
-
return data;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
return data;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
49
|
-
|
|
50
|
-
function isDirectoryAndExist(path) {
|
|
51
|
-
return (0, _fs().existsSync)(path) && (0, _fs().statSync)(path).isDirectory();
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function normalizeWithWinPath(obj) {
|
|
55
|
-
return _utils().lodash.mapValues(obj, value => (0, _utils().winPath)(value));
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function getServicePaths({
|
|
59
|
-
cwd,
|
|
60
|
-
config,
|
|
61
|
-
env
|
|
62
|
-
}) {
|
|
63
|
-
let absSrcPath = cwd;
|
|
64
|
-
|
|
65
|
-
if (isDirectoryAndExist((0, _path().join)(cwd, 'src'))) {
|
|
66
|
-
absSrcPath = (0, _path().join)(cwd, 'src');
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const absPagesPath = config.singular ? (0, _path().join)(absSrcPath, 'page') : (0, _path().join)(absSrcPath, 'pages');
|
|
70
|
-
const tmpDir = ['.umi', env !== 'development' && env].filter(Boolean).join('-');
|
|
71
|
-
return normalizeWithWinPath({
|
|
72
|
-
cwd,
|
|
73
|
-
absNodeModulesPath: (0, _path().join)(cwd, 'node_modules'),
|
|
74
|
-
absOutputPath: (0, _path().join)(cwd, config.outputPath || './dist'),
|
|
75
|
-
absSrcPath,
|
|
76
|
-
absPagesPath,
|
|
77
|
-
absTmpPath: (0, _path().join)(absSrcPath, tmpDir)
|
|
78
|
-
});
|
|
79
|
-
}
|
package/lib/Service/types.d.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import joi from '@umijs/deps/compiled/@hapi/joi';
|
|
2
|
-
import { yargs } from '@umijs/utils';
|
|
3
|
-
import { EnableBy } from './enums';
|
|
4
|
-
export declare type IServicePathKeys = 'cwd' | 'absNodeModulesPath' | 'absOutputPath' | 'absSrcPath' | 'absPagesPath' | 'absTmpPath';
|
|
5
|
-
export declare type IServicePaths = {
|
|
6
|
-
[key in IServicePathKeys]: string;
|
|
7
|
-
};
|
|
8
|
-
export interface IDep {
|
|
9
|
-
[name: string]: string;
|
|
10
|
-
}
|
|
11
|
-
export interface IPackage {
|
|
12
|
-
name?: string;
|
|
13
|
-
dependencies?: IDep;
|
|
14
|
-
devDependencies?: IDep;
|
|
15
|
-
[key: string]: any;
|
|
16
|
-
}
|
|
17
|
-
export interface IPlugin {
|
|
18
|
-
id: string;
|
|
19
|
-
key: string;
|
|
20
|
-
path: string;
|
|
21
|
-
apply: Function;
|
|
22
|
-
config?: IPluginConfig;
|
|
23
|
-
isPreset?: boolean;
|
|
24
|
-
enableBy?: EnableBy | Function;
|
|
25
|
-
}
|
|
26
|
-
export interface IPluginConfig {
|
|
27
|
-
default?: any;
|
|
28
|
-
schema?: {
|
|
29
|
-
(joi: joi.Root): joi.Schema;
|
|
30
|
-
};
|
|
31
|
-
onChange?: string | Function;
|
|
32
|
-
}
|
|
33
|
-
export interface IPreset extends IPlugin {
|
|
34
|
-
}
|
|
35
|
-
export interface IHook {
|
|
36
|
-
key: string;
|
|
37
|
-
fn: Function;
|
|
38
|
-
pluginId?: string;
|
|
39
|
-
before?: string;
|
|
40
|
-
stage?: number;
|
|
41
|
-
}
|
|
42
|
-
export interface ICommand {
|
|
43
|
-
name: string;
|
|
44
|
-
alias?: string;
|
|
45
|
-
description?: string;
|
|
46
|
-
details?: string;
|
|
47
|
-
fn: {
|
|
48
|
-
({ args }: {
|
|
49
|
-
args: yargs.Arguments;
|
|
50
|
-
}): void;
|
|
51
|
-
};
|
|
52
|
-
}
|
package/lib/Service/types.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
function _react() {
|
|
8
|
-
const data = _interopRequireDefault(require("react"));
|
|
9
|
-
|
|
10
|
-
_react = function _react() {
|
|
11
|
-
return data;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
return data;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function isPromise(obj: any): boolean;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = isPromise;
|
|
7
|
-
|
|
8
|
-
function _react() {
|
|
9
|
-
const data = _interopRequireDefault(require("react"));
|
|
10
|
-
|
|
11
|
-
_react = function _react() {
|
|
12
|
-
return data;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
|
|
20
|
-
function isPromise(obj) {
|
|
21
|
-
return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
|
|
22
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = loadDotEnv;
|
|
7
|
-
|
|
8
|
-
function _react() {
|
|
9
|
-
const data = _interopRequireDefault(require("react"));
|
|
10
|
-
|
|
11
|
-
_react = function _react() {
|
|
12
|
-
return data;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function _dotenv() {
|
|
19
|
-
const data = require("@umijs/deps/compiled/dotenv");
|
|
20
|
-
|
|
21
|
-
_dotenv = function _dotenv() {
|
|
22
|
-
return data;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
return data;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function _fs() {
|
|
29
|
-
const data = require("fs");
|
|
30
|
-
|
|
31
|
-
_fs = function _fs() {
|
|
32
|
-
return data;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
return data;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* dotenv wrapper
|
|
42
|
-
* @param envPath string
|
|
43
|
-
*/
|
|
44
|
-
function loadDotEnv(envPath) {
|
|
45
|
-
if ((0, _fs().existsSync)(envPath)) {
|
|
46
|
-
const parsed = (0, _dotenv().parse)((0, _fs().readFileSync)(envPath, 'utf-8')) || {};
|
|
47
|
-
Object.keys(parsed).forEach(key => {
|
|
48
|
-
// eslint-disable-next-line no-prototype-builtins
|
|
49
|
-
if (!process.env.hasOwnProperty(key)) {
|
|
50
|
-
process.env[key] = parsed[key];
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { PluginType } from '../enums';
|
|
2
|
-
import { IPackage, IPlugin } from '../types';
|
|
3
|
-
interface IOpts {
|
|
4
|
-
pkg: IPackage;
|
|
5
|
-
cwd: string;
|
|
6
|
-
}
|
|
7
|
-
interface IResolvePresetsOpts extends IOpts {
|
|
8
|
-
presets: string[];
|
|
9
|
-
userConfigPresets: string[];
|
|
10
|
-
}
|
|
11
|
-
interface IResolvePluginsOpts extends IOpts {
|
|
12
|
-
plugins: string[];
|
|
13
|
-
userConfigPlugins: string[];
|
|
14
|
-
}
|
|
15
|
-
export declare function isPluginOrPreset(type: PluginType, name: string): boolean;
|
|
16
|
-
export declare function pathToObj({ type, path, cwd, }: {
|
|
17
|
-
type: PluginType;
|
|
18
|
-
path: string;
|
|
19
|
-
cwd: string;
|
|
20
|
-
}): {
|
|
21
|
-
id: any;
|
|
22
|
-
key: string;
|
|
23
|
-
path: string;
|
|
24
|
-
apply(): any;
|
|
25
|
-
defaultConfig: null;
|
|
26
|
-
};
|
|
27
|
-
export declare function resolvePresets(opts: IResolvePresetsOpts): {
|
|
28
|
-
id: any;
|
|
29
|
-
key: string;
|
|
30
|
-
path: string;
|
|
31
|
-
apply(): any;
|
|
32
|
-
defaultConfig: null;
|
|
33
|
-
}[];
|
|
34
|
-
export declare function resolvePlugins(opts: IResolvePluginsOpts): {
|
|
35
|
-
id: any;
|
|
36
|
-
key: string;
|
|
37
|
-
path: string;
|
|
38
|
-
apply(): any;
|
|
39
|
-
defaultConfig: null;
|
|
40
|
-
}[];
|
|
41
|
-
export declare function isValidPlugin(plugin: IPlugin): "" | Function;
|
|
42
|
-
export {};
|
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.isPluginOrPreset = isPluginOrPreset;
|
|
7
|
-
exports.pathToObj = pathToObj;
|
|
8
|
-
exports.resolvePresets = resolvePresets;
|
|
9
|
-
exports.resolvePlugins = resolvePlugins;
|
|
10
|
-
exports.isValidPlugin = isValidPlugin;
|
|
11
|
-
|
|
12
|
-
function _react() {
|
|
13
|
-
const data = _interopRequireDefault(require("react"));
|
|
14
|
-
|
|
15
|
-
_react = function _react() {
|
|
16
|
-
return data;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
return data;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function _utils() {
|
|
23
|
-
const data = require("@umijs/utils");
|
|
24
|
-
|
|
25
|
-
_utils = function _utils() {
|
|
26
|
-
return data;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
return data;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function _assert() {
|
|
33
|
-
const data = _interopRequireDefault(require("assert"));
|
|
34
|
-
|
|
35
|
-
_assert = function _assert() {
|
|
36
|
-
return data;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
return data;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function _fs() {
|
|
43
|
-
const data = require("fs");
|
|
44
|
-
|
|
45
|
-
_fs = function _fs() {
|
|
46
|
-
return data;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
return data;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function _path() {
|
|
53
|
-
const data = require("path");
|
|
54
|
-
|
|
55
|
-
_path = function _path() {
|
|
56
|
-
return data;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
return data;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
var _enums = require("../enums");
|
|
63
|
-
|
|
64
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
65
|
-
|
|
66
|
-
const debug = (0, _utils().createDebug)('umi:core:Service:util:plugin');
|
|
67
|
-
const RE = {
|
|
68
|
-
[_enums.PluginType.plugin]: /^(@umijs\/|umi-)plugin-/,
|
|
69
|
-
[_enums.PluginType.preset]: /^(@umijs\/|umi-)preset-/
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
function isPluginOrPreset(type, name) {
|
|
73
|
-
const hasScope = name.charAt(0) === '@';
|
|
74
|
-
const re = RE[type];
|
|
75
|
-
|
|
76
|
-
if (hasScope) {
|
|
77
|
-
return re.test(name.split('/')[1]) || re.test(name);
|
|
78
|
-
} else {
|
|
79
|
-
return re.test(name);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function getPluginsOrPresets(type, opts) {
|
|
84
|
-
const upperCaseType = type.toUpperCase();
|
|
85
|
-
return [// opts
|
|
86
|
-
...(opts[type === _enums.PluginType.preset ? 'presets' : 'plugins'] || []), // env
|
|
87
|
-
...(process.env[`UMI_${upperCaseType}S`] || '').split(',').filter(Boolean), // dependencies
|
|
88
|
-
...Object.keys(opts.pkg.devDependencies || {}).concat(Object.keys(opts.pkg.dependencies || {})).filter(isPluginOrPreset.bind(null, type)), // user config
|
|
89
|
-
...(opts[type === _enums.PluginType.preset ? 'userConfigPresets' : 'userConfigPlugins'] || [])].map(path => {
|
|
90
|
-
if (typeof path !== 'string') {
|
|
91
|
-
throw new Error(`Plugin resolved failed, Please check your plugins config, it must be array of string.\nError Plugin Config: ${JSON.stringify(path)}`);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return _utils().resolve.sync(path, {
|
|
95
|
-
basedir: opts.cwd,
|
|
96
|
-
extensions: ['.js', '.ts']
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
} // e.g.
|
|
100
|
-
// initial-state -> initialState
|
|
101
|
-
// webpack.css-loader -> webpack.cssLoader
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
function nameToKey(name) {
|
|
105
|
-
return name.split('.').map(part => _utils().lodash.camelCase(part)).join('.');
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function pkgNameToKey(pkgName, type) {
|
|
109
|
-
// strip none @umijs scope
|
|
110
|
-
if (pkgName.charAt(0) === '@' && !pkgName.startsWith('@umijs/')) {
|
|
111
|
-
pkgName = pkgName.split('/')[1];
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return nameToKey(pkgName.replace(RE[type], ''));
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function pathToObj({
|
|
118
|
-
type,
|
|
119
|
-
path,
|
|
120
|
-
cwd
|
|
121
|
-
}) {
|
|
122
|
-
let pkg = null;
|
|
123
|
-
let isPkgPlugin = false;
|
|
124
|
-
(0, _assert().default)((0, _fs().existsSync)(path), `${type} ${path} not exists, pathToObj failed`);
|
|
125
|
-
|
|
126
|
-
const pkgJSONPath = _utils().pkgUp.sync({
|
|
127
|
-
cwd: path
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
if (pkgJSONPath) {
|
|
131
|
-
pkg = require(pkgJSONPath);
|
|
132
|
-
isPkgPlugin = (0, _utils().winPath)((0, _path().join)((0, _path().dirname)(pkgJSONPath), pkg.main || 'index.js')) === (0, _utils().winPath)(path);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
let id;
|
|
136
|
-
|
|
137
|
-
if (isPkgPlugin) {
|
|
138
|
-
id = pkg.name;
|
|
139
|
-
} else if ((0, _utils().winPath)(path).startsWith((0, _utils().winPath)(cwd))) {
|
|
140
|
-
id = `./${(0, _utils().winPath)((0, _path().relative)(cwd, path))}`;
|
|
141
|
-
} else if (pkgJSONPath) {
|
|
142
|
-
id = (0, _utils().winPath)((0, _path().join)(pkg.name, (0, _path().relative)((0, _path().dirname)(pkgJSONPath), path)));
|
|
143
|
-
} else {
|
|
144
|
-
id = (0, _utils().winPath)(path);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
id = id.replace('@umijs/preset-built-in/lib/plugins', '@@');
|
|
148
|
-
id = id.replace(/\.js$/, '');
|
|
149
|
-
const key = isPkgPlugin ? pkgNameToKey(pkg.name, type) : nameToKey((0, _path().basename)(path, (0, _path().extname)(path)));
|
|
150
|
-
return {
|
|
151
|
-
id,
|
|
152
|
-
key,
|
|
153
|
-
path: (0, _utils().winPath)(path),
|
|
154
|
-
|
|
155
|
-
apply() {
|
|
156
|
-
// use function to delay require
|
|
157
|
-
try {
|
|
158
|
-
const ret = require(path); // use the default member for es modules
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
return (0, _utils().compatESModuleRequire)(ret);
|
|
162
|
-
} catch (e) {
|
|
163
|
-
throw new Error(`Register ${type} ${path} failed, since ${e.message}`);
|
|
164
|
-
}
|
|
165
|
-
},
|
|
166
|
-
|
|
167
|
-
defaultConfig: null
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
function resolvePresets(opts) {
|
|
172
|
-
const type = _enums.PluginType.preset;
|
|
173
|
-
const presets = [...getPluginsOrPresets(type, opts)];
|
|
174
|
-
debug(`preset paths:`);
|
|
175
|
-
debug(presets);
|
|
176
|
-
return presets.map(path => {
|
|
177
|
-
return pathToObj({
|
|
178
|
-
type,
|
|
179
|
-
path,
|
|
180
|
-
cwd: opts.cwd
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
function resolvePlugins(opts) {
|
|
186
|
-
const type = _enums.PluginType.plugin;
|
|
187
|
-
const plugins = getPluginsOrPresets(type, opts);
|
|
188
|
-
debug(`plugin paths:`);
|
|
189
|
-
debug(plugins);
|
|
190
|
-
return plugins.map(path => {
|
|
191
|
-
return pathToObj({
|
|
192
|
-
type,
|
|
193
|
-
path,
|
|
194
|
-
cwd: opts.cwd
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
function isValidPlugin(plugin) {
|
|
200
|
-
return plugin.id && plugin.key && plugin.apply;
|
|
201
|
-
}
|
package/lib/index.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import Config from './Config/Config';
|
|
2
|
-
import { IConfig } from './Config/types';
|
|
3
|
-
import Html from './Html/Html';
|
|
4
|
-
import { IHTMLTag, IScriptConfig, IStyleConfig } from './Html/types';
|
|
5
|
-
import Logger from './Logger/Logger';
|
|
6
|
-
import Route from './Route/Route';
|
|
7
|
-
import { IRoute } from './Route/types';
|
|
8
|
-
import { PluginType } from './Service/enums';
|
|
9
|
-
import PluginAPI from './Service/PluginAPI';
|
|
10
|
-
import Service, { IServiceOpts } from './Service/Service';
|
|
11
|
-
import { isPluginOrPreset } from './Service/utils/pluginUtils';
|
|
12
|
-
export { Config, Html, Route, Service, PluginAPI, isPluginOrPreset, PluginType, };
|
|
13
|
-
export { IRoute, IConfig, IServiceOpts, IScriptConfig, IStyleConfig, IHTMLTag };
|
|
14
|
-
export { Logger };
|
package/lib/index.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "Config", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function get() {
|
|
9
|
-
return _Config.default;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(exports, "Html", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function get() {
|
|
15
|
-
return _Html.default;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
Object.defineProperty(exports, "Logger", {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: function get() {
|
|
21
|
-
return _Logger.default;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
Object.defineProperty(exports, "Route", {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
get: function get() {
|
|
27
|
-
return _Route.default;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
Object.defineProperty(exports, "PluginType", {
|
|
31
|
-
enumerable: true,
|
|
32
|
-
get: function get() {
|
|
33
|
-
return _enums.PluginType;
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
Object.defineProperty(exports, "PluginAPI", {
|
|
37
|
-
enumerable: true,
|
|
38
|
-
get: function get() {
|
|
39
|
-
return _PluginAPI.default;
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
Object.defineProperty(exports, "Service", {
|
|
43
|
-
enumerable: true,
|
|
44
|
-
get: function get() {
|
|
45
|
-
return _Service.default;
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
Object.defineProperty(exports, "isPluginOrPreset", {
|
|
49
|
-
enumerable: true,
|
|
50
|
-
get: function get() {
|
|
51
|
-
return _pluginUtils.isPluginOrPreset;
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
function _react() {
|
|
56
|
-
const data = _interopRequireDefault(require("react"));
|
|
57
|
-
|
|
58
|
-
_react = function _react() {
|
|
59
|
-
return data;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
return data;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
var _Config = _interopRequireDefault(require("./Config/Config"));
|
|
66
|
-
|
|
67
|
-
var _Html = _interopRequireDefault(require("./Html/Html"));
|
|
68
|
-
|
|
69
|
-
var _Logger = _interopRequireDefault(require("./Logger/Logger"));
|
|
70
|
-
|
|
71
|
-
var _Route = _interopRequireDefault(require("./Route/Route"));
|
|
72
|
-
|
|
73
|
-
var _enums = require("./Service/enums");
|
|
74
|
-
|
|
75
|
-
var _PluginAPI = _interopRequireDefault(require("./Service/PluginAPI"));
|
|
76
|
-
|
|
77
|
-
var _Service = _interopRequireDefault(require("./Service/Service"));
|
|
78
|
-
|
|
79
|
-
var _pluginUtils = require("./Service/utils/pluginUtils");
|
|
80
|
-
|
|
81
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|