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