@umijs/core 3.5.20 → 4.0.0-beta.1
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/dist/config/config.d.ts +63 -0
- package/dist/config/config.js +178 -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 +5 -0
- package/dist/index.js +19 -0
- package/dist/route/defineRoutes.d.ts +1 -0
- package/dist/route/defineRoutes.js +28 -0
- package/dist/route/route.d.ts +2 -0
- package/dist/route/route.js +18 -0
- package/dist/route/routeUtils.d.ts +7 -0
- package/dist/route/routeUtils.js +21 -0
- package/dist/route/routesConfig.d.ts +0 -0
- package/dist/route/routesConfig.js +1 -0
- package/dist/route/routesConvention.d.ts +3 -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/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 +53 -0
- package/dist/service/plugin.js +137 -0
- package/dist/service/pluginAPI.d.ts +35 -0
- package/dist/service/pluginAPI.js +120 -0
- package/dist/service/service.d.ts +91 -0
- package/dist/service/service.js +361 -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 +35 -15
- 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
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPaths = void 0;
|
|
4
|
+
const utils_1 = require("@umijs/utils");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const types_1 = require("../types");
|
|
8
|
+
function winJoin(...args) {
|
|
9
|
+
return (0, utils_1.winPath)((0, path_1.join)(...args));
|
|
10
|
+
}
|
|
11
|
+
function getPaths(opts) {
|
|
12
|
+
const cwd = opts.cwd;
|
|
13
|
+
const src = winJoin(cwd, 'src');
|
|
14
|
+
const absSrcPath = (0, fs_1.existsSync)(src) && (0, fs_1.statSync)(src).isDirectory() ? src : cwd;
|
|
15
|
+
const absPagesPath = winJoin(absSrcPath, 'pages');
|
|
16
|
+
const tmp = opts.env === types_1.Env.development
|
|
17
|
+
? `.${opts.prefix}`
|
|
18
|
+
: `.${opts.prefix}-${opts.env}`;
|
|
19
|
+
const absTmpPath = winJoin(absSrcPath, tmp);
|
|
20
|
+
const absNodeModulesPath = winJoin(cwd, 'node_modules');
|
|
21
|
+
const absOutputPath = winJoin(cwd, 'dist');
|
|
22
|
+
return {
|
|
23
|
+
cwd,
|
|
24
|
+
absSrcPath,
|
|
25
|
+
absPagesPath,
|
|
26
|
+
absTmpPath,
|
|
27
|
+
absNodeModulesPath,
|
|
28
|
+
absOutputPath,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
exports.getPaths = getPaths;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { EnableBy, IPluginConfig } from '../types';
|
|
2
|
+
declare type PluginType = 'plugin' | 'preset';
|
|
3
|
+
interface IOpts {
|
|
4
|
+
path: string;
|
|
5
|
+
cwd: string;
|
|
6
|
+
type: PluginType;
|
|
7
|
+
}
|
|
8
|
+
export interface IPluginObject {
|
|
9
|
+
id: string;
|
|
10
|
+
key: string;
|
|
11
|
+
apply?: Function;
|
|
12
|
+
config?: IPluginConfig;
|
|
13
|
+
enableBy?: EnableBy | (() => boolean);
|
|
14
|
+
}
|
|
15
|
+
export declare class Plugin {
|
|
16
|
+
private cwd;
|
|
17
|
+
type: PluginType;
|
|
18
|
+
path: string;
|
|
19
|
+
id: string;
|
|
20
|
+
key: string;
|
|
21
|
+
apply: Function;
|
|
22
|
+
config: IPluginConfig;
|
|
23
|
+
enableBy: EnableBy | (() => boolean);
|
|
24
|
+
constructor(opts: IOpts);
|
|
25
|
+
merge(opts: {
|
|
26
|
+
key?: string;
|
|
27
|
+
config?: IPluginConfig;
|
|
28
|
+
enableBy?: EnableBy | (() => boolean);
|
|
29
|
+
}): void;
|
|
30
|
+
getId(opts: {
|
|
31
|
+
pkg: any;
|
|
32
|
+
isPkgEntry: boolean;
|
|
33
|
+
pkgJSONPath: string | null;
|
|
34
|
+
}): any;
|
|
35
|
+
getKey(opts: {
|
|
36
|
+
pkg: any;
|
|
37
|
+
isPkgEntry: boolean;
|
|
38
|
+
}): string;
|
|
39
|
+
static isPluginOrPreset(type: 'plugin' | 'preset', name: string): boolean;
|
|
40
|
+
static stripNoneUmiScope(name: string): string;
|
|
41
|
+
static getPluginsAndPresets(opts: {
|
|
42
|
+
cwd: string;
|
|
43
|
+
pkg: any;
|
|
44
|
+
userConfig: any;
|
|
45
|
+
plugins?: string[];
|
|
46
|
+
presets?: string[];
|
|
47
|
+
prefix: string;
|
|
48
|
+
}): {
|
|
49
|
+
presets: Plugin[];
|
|
50
|
+
plugins: Plugin[];
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,137 @@
|
|
|
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.Plugin = void 0;
|
|
7
|
+
const utils_1 = require("@umijs/utils");
|
|
8
|
+
const assert_1 = __importDefault(require("assert"));
|
|
9
|
+
const fs_1 = require("fs");
|
|
10
|
+
const path_1 = require("path");
|
|
11
|
+
const types_1 = require("../types");
|
|
12
|
+
const RE = {
|
|
13
|
+
plugin: /^(@umijs\/|umi-)plugin-/,
|
|
14
|
+
preset: /^(@umijs\/|umi-)preset-/,
|
|
15
|
+
};
|
|
16
|
+
class Plugin {
|
|
17
|
+
constructor(opts) {
|
|
18
|
+
this.config = {};
|
|
19
|
+
this.enableBy = types_1.EnableBy.register;
|
|
20
|
+
this.type = opts.type;
|
|
21
|
+
this.path = (0, utils_1.winPath)(opts.path);
|
|
22
|
+
this.cwd = opts.cwd;
|
|
23
|
+
(0, assert_1.default)((0, fs_1.existsSync)(this.path), `Invalid ${this.type} ${this.path}, it's not exists.`);
|
|
24
|
+
let pkg = null;
|
|
25
|
+
// path is the package entry
|
|
26
|
+
let isPkgEntry = false;
|
|
27
|
+
const pkgJSONPath = utils_1.pkgUp.sync({ cwd: this.path });
|
|
28
|
+
if (pkgJSONPath) {
|
|
29
|
+
pkg = require(pkgJSONPath);
|
|
30
|
+
isPkgEntry =
|
|
31
|
+
(0, utils_1.winPath)((0, path_1.join)((0, path_1.dirname)(pkgJSONPath), pkg.main || 'index.js')) ===
|
|
32
|
+
(0, utils_1.winPath)(this.path);
|
|
33
|
+
}
|
|
34
|
+
this.id = this.getId({ pkg, isPkgEntry, pkgJSONPath });
|
|
35
|
+
this.key = this.getKey({ pkg, isPkgEntry });
|
|
36
|
+
this.apply = () => {
|
|
37
|
+
try {
|
|
38
|
+
const ret = require(this.path);
|
|
39
|
+
// use the default member for es modules
|
|
40
|
+
return ret.__esModule ? ret.default : ret;
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
throw new Error(`Register ${this.type} ${this.path} failed, since ${e.message}`);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
merge(opts) {
|
|
48
|
+
if (opts.key)
|
|
49
|
+
this.key = opts.key;
|
|
50
|
+
if (opts.config)
|
|
51
|
+
this.config = opts.config;
|
|
52
|
+
if (opts.enableBy)
|
|
53
|
+
this.enableBy = opts.enableBy;
|
|
54
|
+
}
|
|
55
|
+
getId(opts) {
|
|
56
|
+
let id;
|
|
57
|
+
if (opts.isPkgEntry) {
|
|
58
|
+
id = opts.pkg.name;
|
|
59
|
+
}
|
|
60
|
+
else if ((0, utils_1.winPath)(this.path).startsWith((0, utils_1.winPath)(this.cwd))) {
|
|
61
|
+
id = `./${(0, utils_1.winPath)((0, path_1.relative)(this.cwd, this.path))}`;
|
|
62
|
+
}
|
|
63
|
+
else if (opts.pkgJSONPath) {
|
|
64
|
+
id = (0, utils_1.winPath)((0, path_1.join)(opts.pkg.name, (0, path_1.relative)((0, path_1.dirname)(opts.pkgJSONPath), this.path)));
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
id = (0, utils_1.winPath)(this.path);
|
|
68
|
+
}
|
|
69
|
+
id = id.replace('@umijs/preset-built-in/lib/plugins', '@@');
|
|
70
|
+
id = id.replace(/\.js$/, '');
|
|
71
|
+
return id;
|
|
72
|
+
}
|
|
73
|
+
getKey(opts) {
|
|
74
|
+
// e.g.
|
|
75
|
+
// initial-state -> initialState
|
|
76
|
+
// webpack.css-loader -> webpack.cssLoader
|
|
77
|
+
function nameToKey(name) {
|
|
78
|
+
return name
|
|
79
|
+
.split('.')
|
|
80
|
+
.map((part) => utils_1.lodash.camelCase(part))
|
|
81
|
+
.join('.');
|
|
82
|
+
}
|
|
83
|
+
return nameToKey(opts.isPkgEntry
|
|
84
|
+
? Plugin.stripNoneUmiScope(opts.pkg.name).replace(RE[this.type], '')
|
|
85
|
+
: (0, path_1.basename)(this.path, (0, path_1.extname)(this.path)));
|
|
86
|
+
}
|
|
87
|
+
static isPluginOrPreset(type, name) {
|
|
88
|
+
return RE[type].test(Plugin.stripNoneUmiScope(name));
|
|
89
|
+
}
|
|
90
|
+
static stripNoneUmiScope(name) {
|
|
91
|
+
if (name.charAt(0) === '@' && !name.startsWith('@umijs/')) {
|
|
92
|
+
name = name.split('/')[1];
|
|
93
|
+
}
|
|
94
|
+
return name;
|
|
95
|
+
}
|
|
96
|
+
static getPluginsAndPresets(opts) {
|
|
97
|
+
function get(type) {
|
|
98
|
+
const types = `${type}s`;
|
|
99
|
+
return [
|
|
100
|
+
// opts
|
|
101
|
+
...(opts[types] || []),
|
|
102
|
+
// env
|
|
103
|
+
...(process.env[`${opts.prefix}_${types}`.toUpperCase()] || '')
|
|
104
|
+
.split(',')
|
|
105
|
+
.filter(Boolean),
|
|
106
|
+
// dependencies
|
|
107
|
+
...Object.keys(opts.pkg.devDependencies || {})
|
|
108
|
+
.concat(Object.keys(opts.pkg.dependencies || {}))
|
|
109
|
+
.filter(Plugin.isPluginOrPreset.bind(null, type)),
|
|
110
|
+
// user config
|
|
111
|
+
...(opts.userConfig[types] || []),
|
|
112
|
+
].map((path) => {
|
|
113
|
+
(0, assert_1.default)(typeof path === 'string', `Invalid plugin ${path}, it must be string.`);
|
|
114
|
+
let resolved;
|
|
115
|
+
try {
|
|
116
|
+
resolved = utils_1.resolve.sync(path, {
|
|
117
|
+
basedir: opts.cwd,
|
|
118
|
+
extensions: ['.tsx', '.ts', '.mjs', '.jsx', '.js'],
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
catch (_e) {
|
|
122
|
+
throw new Error(`Invalid plugin ${path}, can not be resolved.`);
|
|
123
|
+
}
|
|
124
|
+
return new Plugin({
|
|
125
|
+
path: resolved,
|
|
126
|
+
type,
|
|
127
|
+
cwd: opts.cwd,
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
presets: get('preset'),
|
|
133
|
+
plugins: get('plugin'),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
exports.Plugin = Plugin;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { EnableBy, IPluginConfig } from '../types';
|
|
2
|
+
import { IOpts as ICommandOpts } from './command';
|
|
3
|
+
import { IOpts as IHookOpts } from './hook';
|
|
4
|
+
import { Plugin } from './plugin';
|
|
5
|
+
import { Service } from './service';
|
|
6
|
+
export declare class PluginAPI {
|
|
7
|
+
service: Service;
|
|
8
|
+
plugin: Plugin;
|
|
9
|
+
constructor(opts: {
|
|
10
|
+
service: Service;
|
|
11
|
+
plugin: Plugin;
|
|
12
|
+
});
|
|
13
|
+
describe(opts: {
|
|
14
|
+
key?: string;
|
|
15
|
+
config?: IPluginConfig;
|
|
16
|
+
enableBy?: EnableBy | (() => boolean);
|
|
17
|
+
}): void;
|
|
18
|
+
registerCommand(opts: Omit<ICommandOpts, 'plugin'> & {
|
|
19
|
+
alias?: string | string[];
|
|
20
|
+
}): void;
|
|
21
|
+
register(opts: Omit<IHookOpts, 'plugin'>): void;
|
|
22
|
+
registerMethod(opts: {
|
|
23
|
+
name: string;
|
|
24
|
+
fn?: Function;
|
|
25
|
+
}): void;
|
|
26
|
+
registerPresets(source: Plugin[], presets: any[]): void;
|
|
27
|
+
registerPlugins(source: Plugin[], plugins: any[]): void;
|
|
28
|
+
skipPlugins(ids: string[]): void;
|
|
29
|
+
static proxyPluginAPI(opts: {
|
|
30
|
+
pluginAPI: PluginAPI;
|
|
31
|
+
service: Service;
|
|
32
|
+
serviceProps: string[];
|
|
33
|
+
staticProps: Record<string, any>;
|
|
34
|
+
}): PluginAPI;
|
|
35
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
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.PluginAPI = void 0;
|
|
7
|
+
const utils_1 = require("@umijs/utils");
|
|
8
|
+
const assert_1 = __importDefault(require("assert"));
|
|
9
|
+
const types_1 = require("../types");
|
|
10
|
+
const command_1 = require("./command");
|
|
11
|
+
const hook_1 = require("./hook");
|
|
12
|
+
const plugin_1 = require("./plugin");
|
|
13
|
+
const utils_2 = require("./utils");
|
|
14
|
+
class PluginAPI {
|
|
15
|
+
constructor(opts) {
|
|
16
|
+
this.service = opts.service;
|
|
17
|
+
this.plugin = opts.plugin;
|
|
18
|
+
// TODO
|
|
19
|
+
// logger
|
|
20
|
+
}
|
|
21
|
+
describe(opts) {
|
|
22
|
+
this.plugin.merge(opts);
|
|
23
|
+
}
|
|
24
|
+
registerCommand(opts) {
|
|
25
|
+
const { alias } = opts;
|
|
26
|
+
delete opts.alias;
|
|
27
|
+
const registerCommand = (commandOpts) => {
|
|
28
|
+
var _a;
|
|
29
|
+
const { name } = commandOpts;
|
|
30
|
+
(0, assert_1.default)(!this.service.commands[name], `api.registerCommand() failed, the command ${name} is exists from ${(_a = this.service.commands[name]) === null || _a === void 0 ? void 0 : _a.plugin.id}.`);
|
|
31
|
+
this.service.commands[name] = new command_1.Command(Object.assign(Object.assign({}, commandOpts), { plugin: this.plugin }));
|
|
32
|
+
};
|
|
33
|
+
registerCommand(opts);
|
|
34
|
+
if (alias) {
|
|
35
|
+
const aliases = (0, utils_2.makeArray)(alias);
|
|
36
|
+
aliases.forEach((alias) => {
|
|
37
|
+
registerCommand(Object.assign(Object.assign({}, opts), { name: alias }));
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
register(opts) {
|
|
42
|
+
var _a, _b;
|
|
43
|
+
(_a = this.service.hooks)[_b = opts.key] || (_a[_b] = []);
|
|
44
|
+
this.service.hooks[opts.key].push(new hook_1.Hook(Object.assign(Object.assign({}, opts), { plugin: this.plugin })));
|
|
45
|
+
}
|
|
46
|
+
registerMethod(opts) {
|
|
47
|
+
(0, assert_1.default)(!this.service.pluginMethods[opts.name], `api.registerMethod() failed, method ${opts.name} is already exist.`);
|
|
48
|
+
this.service.pluginMethods[opts.name] = {
|
|
49
|
+
plugin: this.plugin,
|
|
50
|
+
fn: opts.fn ||
|
|
51
|
+
((fn) => {
|
|
52
|
+
this.register(Object.assign({ key: opts.name }, (utils_1.lodash.isPlainObject(fn) ? fn : { fn })));
|
|
53
|
+
}),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
registerPresets(source, presets) {
|
|
57
|
+
(0, assert_1.default)(this.service.stage === types_1.ServiceStage.initPresets, `api.registerPresets() failed, it should only used in presets.`);
|
|
58
|
+
source.splice(0, 0, ...presets.map((preset) => {
|
|
59
|
+
return new plugin_1.Plugin({
|
|
60
|
+
path: preset,
|
|
61
|
+
cwd: this.service.cwd,
|
|
62
|
+
type: types_1.PluginType.plugin,
|
|
63
|
+
});
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
66
|
+
registerPlugins(source, plugins) {
|
|
67
|
+
(0, assert_1.default)(this.service.stage === types_1.ServiceStage.initPresets ||
|
|
68
|
+
this.service.stage === types_1.ServiceStage.initPlugins, `api.registerPlugins() failed, it should only be used in registering stage.`);
|
|
69
|
+
const mappedPlugins = plugins.map((plugin) => {
|
|
70
|
+
if (utils_1.lodash.isPlainObject(plugin)) {
|
|
71
|
+
(0, assert_1.default)(plugin.id && plugin.key, `Invalid plugin object, id and key must supplied.`);
|
|
72
|
+
plugin.type = types_1.PluginType.plugin;
|
|
73
|
+
plugin.enableBy = plugin.enableBy || types_1.EnableBy.register;
|
|
74
|
+
plugin.apply = plugin.apply || (() => () => { });
|
|
75
|
+
plugin.config = plugin.config || {};
|
|
76
|
+
return plugin;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
return new plugin_1.Plugin({
|
|
80
|
+
path: plugin,
|
|
81
|
+
cwd: this.service.cwd,
|
|
82
|
+
type: types_1.PluginType.plugin,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
if (this.service.stage === types_1.ServiceStage.initPresets) {
|
|
87
|
+
source.push(...mappedPlugins);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
source.splice(0, 0, ...mappedPlugins);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
skipPlugins(ids) {
|
|
94
|
+
ids.forEach((id) => {
|
|
95
|
+
this.service.skipPluginIds.add(id);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
static proxyPluginAPI(opts) {
|
|
99
|
+
return new Proxy(opts.pluginAPI, {
|
|
100
|
+
get: (target, prop) => {
|
|
101
|
+
if (opts.service.pluginMethods[prop]) {
|
|
102
|
+
return opts.service.pluginMethods[prop].fn;
|
|
103
|
+
}
|
|
104
|
+
if (opts.serviceProps.includes(prop)) {
|
|
105
|
+
// @ts-ignore
|
|
106
|
+
const serviceProp = opts.service[prop];
|
|
107
|
+
return typeof serviceProp === 'function'
|
|
108
|
+
? serviceProp.bind(opts.service)
|
|
109
|
+
: serviceProp;
|
|
110
|
+
}
|
|
111
|
+
if (prop in opts.staticProps) {
|
|
112
|
+
return opts.staticProps[prop];
|
|
113
|
+
}
|
|
114
|
+
// @ts-ignore
|
|
115
|
+
return target[prop];
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.PluginAPI = PluginAPI;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { yParser } from '@umijs/utils';
|
|
2
|
+
import { Config } from '../config/config';
|
|
3
|
+
import { ApplyPluginsType, ConfigChangeType, EnableBy, Env, IEvent, IModify, ServiceStage } from '../types';
|
|
4
|
+
import { Command } from './command';
|
|
5
|
+
import { Hook } from './hook';
|
|
6
|
+
import { Plugin } from './plugin';
|
|
7
|
+
interface IOpts {
|
|
8
|
+
cwd: string;
|
|
9
|
+
env: Env;
|
|
10
|
+
plugins?: string[];
|
|
11
|
+
presets?: string[];
|
|
12
|
+
frameworkName?: string;
|
|
13
|
+
defaultConfigFiles?: string[];
|
|
14
|
+
}
|
|
15
|
+
export declare class Service {
|
|
16
|
+
private opts;
|
|
17
|
+
appData: Record<string, any>;
|
|
18
|
+
args: yParser.Arguments;
|
|
19
|
+
commands: Record<string, Command>;
|
|
20
|
+
config: Record<string, any>;
|
|
21
|
+
configSchemas: Record<string, any>;
|
|
22
|
+
configDefaults: Record<string, any>;
|
|
23
|
+
configOnChanges: Record<string, any>;
|
|
24
|
+
cwd: string;
|
|
25
|
+
env: Env;
|
|
26
|
+
hooks: Record<string, Hook[]>;
|
|
27
|
+
name: string;
|
|
28
|
+
paths: {
|
|
29
|
+
cwd?: string;
|
|
30
|
+
absSrcPath?: string;
|
|
31
|
+
absPagesPath?: string;
|
|
32
|
+
absTmpPath?: string;
|
|
33
|
+
absNodeModulesPath?: string;
|
|
34
|
+
absOutputPath?: string;
|
|
35
|
+
};
|
|
36
|
+
plugins: Record<string, Plugin>;
|
|
37
|
+
pluginMethods: Record<string, {
|
|
38
|
+
plugin: Plugin;
|
|
39
|
+
fn: Function;
|
|
40
|
+
}>;
|
|
41
|
+
skipPluginIds: Set<string>;
|
|
42
|
+
stage: ServiceStage;
|
|
43
|
+
userConfig: Record<string, any>;
|
|
44
|
+
configManager: Config | null;
|
|
45
|
+
pkg: Record<string, string | Record<string, any>>;
|
|
46
|
+
constructor(opts: IOpts);
|
|
47
|
+
applyPlugins<T>(opts: {
|
|
48
|
+
key: string;
|
|
49
|
+
type?: ApplyPluginsType;
|
|
50
|
+
initialValue?: any;
|
|
51
|
+
args?: any;
|
|
52
|
+
}): Promise<T>;
|
|
53
|
+
run(opts: {
|
|
54
|
+
name: string;
|
|
55
|
+
args?: any;
|
|
56
|
+
}): Promise<void>;
|
|
57
|
+
initPreset(opts: {
|
|
58
|
+
preset: Plugin;
|
|
59
|
+
presets: Plugin[];
|
|
60
|
+
plugins: Plugin[];
|
|
61
|
+
}): Promise<void>;
|
|
62
|
+
initPlugin(opts: {
|
|
63
|
+
plugin: Plugin;
|
|
64
|
+
presets?: Plugin[];
|
|
65
|
+
plugins: Plugin[];
|
|
66
|
+
}): Promise<any>;
|
|
67
|
+
isPluginEnable(hook: Hook): boolean;
|
|
68
|
+
}
|
|
69
|
+
export interface IServicePluginAPI {
|
|
70
|
+
appData: typeof Service.prototype.appData;
|
|
71
|
+
applyPlugins: typeof Service.prototype.applyPlugins;
|
|
72
|
+
args: typeof Service.prototype.args;
|
|
73
|
+
config: typeof Service.prototype.config;
|
|
74
|
+
cwd: typeof Service.prototype.cwd;
|
|
75
|
+
pkg: typeof Service.prototype.pkg;
|
|
76
|
+
name: typeof Service.prototype.name;
|
|
77
|
+
paths: Required<typeof Service.prototype.paths>;
|
|
78
|
+
userConfig: typeof Service.prototype.userConfig;
|
|
79
|
+
onCheck: IEvent<null>;
|
|
80
|
+
onStart: IEvent<null>;
|
|
81
|
+
modifyAppData: IModify<typeof Service.prototype.appData, null>;
|
|
82
|
+
modifyConfig: IModify<typeof Service.prototype.config, null>;
|
|
83
|
+
modifyDefaultConfig: IModify<typeof Service.prototype.config, null>;
|
|
84
|
+
modifyPaths: IModify<typeof Service.prototype.paths, null>;
|
|
85
|
+
ApplyPluginsType: typeof ApplyPluginsType;
|
|
86
|
+
ConfigChangeType: typeof ConfigChangeType;
|
|
87
|
+
EnableBy: typeof EnableBy;
|
|
88
|
+
ServiceStage: typeof ServiceStage;
|
|
89
|
+
registerPlugins: (plugins: (Plugin | {})[]) => void;
|
|
90
|
+
}
|
|
91
|
+
export {};
|