@umijs/core 3.5.17 → 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.
Files changed (84) hide show
  1. package/README.md +2 -0
  2. package/dist/config/config.d.ts +63 -0
  3. package/dist/config/config.js +178 -0
  4. package/dist/config/utils.d.ts +8 -0
  5. package/dist/config/utils.js +15 -0
  6. package/dist/constants.d.ts +9 -0
  7. package/dist/constants.js +12 -0
  8. package/dist/index.d.ts +5 -0
  9. package/dist/index.js +19 -0
  10. package/dist/route/defineRoutes.d.ts +1 -0
  11. package/dist/route/defineRoutes.js +28 -0
  12. package/dist/route/route.d.ts +2 -0
  13. package/dist/route/route.js +18 -0
  14. package/dist/route/routeUtils.d.ts +7 -0
  15. package/dist/route/routeUtils.js +21 -0
  16. package/dist/route/routesConfig.d.ts +0 -0
  17. package/dist/route/routesConfig.js +1 -0
  18. package/dist/route/routesConvention.d.ts +3 -0
  19. package/dist/route/routesConvention.js +73 -0
  20. package/dist/route/utils.d.ts +7 -0
  21. package/dist/route/utils.js +26 -0
  22. package/dist/service/command.d.ts +27 -0
  23. package/dist/service/command.js +14 -0
  24. package/dist/service/env.d.ts +4 -0
  25. package/dist/service/env.js +21 -0
  26. package/dist/service/hook.d.ts +16 -0
  27. package/dist/service/hook.js +18 -0
  28. package/dist/service/path.d.ts +13 -0
  29. package/dist/service/path.js +31 -0
  30. package/dist/service/plugin.d.ts +53 -0
  31. package/dist/service/plugin.js +137 -0
  32. package/dist/service/pluginAPI.d.ts +35 -0
  33. package/dist/service/pluginAPI.js +120 -0
  34. package/dist/service/service.d.ts +91 -0
  35. package/dist/service/service.js +361 -0
  36. package/dist/service/servicePlugin.d.ts +3 -0
  37. package/dist/service/servicePlugin.js +14 -0
  38. package/dist/service/utils.d.ts +2 -0
  39. package/dist/service/utils.js +12 -0
  40. package/dist/types.d.ts +108 -0
  41. package/dist/types.js +42 -0
  42. package/package.json +35 -15
  43. package/lib/Config/Config.d.ts +0 -39
  44. package/lib/Config/Config.js +0 -348
  45. package/lib/Config/types.d.ts +0 -21
  46. package/lib/Config/utils/configUtils.d.ts +0 -9
  47. package/lib/Config/utils/configUtils.js +0 -54
  48. package/lib/Config/utils/isEqual.d.ts +0 -1
  49. package/lib/Config/utils/isEqual.js +0 -45
  50. package/lib/Config/utils/mergeDefault.d.ts +0 -6
  51. package/lib/Config/utils/mergeDefault.js +0 -41
  52. package/lib/Html/Html.d.ts +0 -16
  53. package/lib/Html/Html.js +0 -292
  54. package/lib/Html/document.ejs +0 -12
  55. package/lib/Html/types.d.ts +0 -55
  56. package/lib/Logger/Common.d.ts +0 -13
  57. package/lib/Logger/Common.js +0 -53
  58. package/lib/Logger/Logger.d.ts +0 -17
  59. package/lib/Logger/Logger.js +0 -87
  60. package/lib/Route/Route.d.ts +0 -32
  61. package/lib/Route/Route.js +0 -228
  62. package/lib/Route/getConventionalRoutes.d.ts +0 -10
  63. package/lib/Route/getConventionalRoutes.js +0 -259
  64. package/lib/Route/routesToJSON.d.ts +0 -9
  65. package/lib/Route/routesToJSON.js +0 -140
  66. package/lib/Route/types.d.ts +0 -11
  67. package/lib/Service/PluginAPI.d.ts +0 -38
  68. package/lib/Service/PluginAPI.js +0 -193
  69. package/lib/Service/Service.d.ts +0 -96
  70. package/lib/Service/Service.js +0 -694
  71. package/lib/Service/enums.d.ts +0 -29
  72. package/lib/Service/enums.js +0 -67
  73. package/lib/Service/getPaths.d.ts +0 -6
  74. package/lib/Service/getPaths.js +0 -79
  75. package/lib/Service/types.d.ts +0 -52
  76. package/lib/Service/types.js +0 -17
  77. package/lib/Service/utils/isPromise.d.ts +0 -1
  78. package/lib/Service/utils/isPromise.js +0 -22
  79. package/lib/Service/utils/loadDotEnv.d.ts +0 -5
  80. package/lib/Service/utils/loadDotEnv.js +0 -54
  81. package/lib/Service/utils/pluginUtils.d.ts +0 -42
  82. package/lib/Service/utils/pluginUtils.js +0 -201
  83. package/lib/index.d.ts +0 -14
  84. package/lib/index.js +0 -81
@@ -1,193 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = 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 utils() {
19
- const data = _interopRequireWildcard(require("@umijs/utils"));
20
-
21
- utils = function utils() {
22
- return data;
23
- };
24
-
25
- return data;
26
- }
27
-
28
- function _assert() {
29
- const data = _interopRequireDefault(require("assert"));
30
-
31
- _assert = function _assert() {
32
- return data;
33
- };
34
-
35
- return data;
36
- }
37
-
38
- var _Html = _interopRequireDefault(require("../Html/Html"));
39
-
40
- var _Logger = _interopRequireDefault(require("../Logger/Logger"));
41
-
42
- var _enums = require("./enums");
43
-
44
- var _pluginUtils = require("./utils/pluginUtils");
45
-
46
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
47
-
48
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
49
-
50
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
51
-
52
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
53
-
54
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
55
-
56
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
57
-
58
- class PluginAPI {
59
- constructor(opts) {
60
- this.id = void 0;
61
- this.key = void 0;
62
- this.service = void 0;
63
- this.Html = void 0;
64
- this.utils = void 0;
65
- this.logger = void 0;
66
- this.id = opts.id;
67
- this.key = opts.key;
68
- this.service = opts.service;
69
- this.utils = utils();
70
- this.Html = _Html.default;
71
- this.logger = new _Logger.default(`umi:plugin:${this.id || this.key}`);
72
- } // TODO: reversed keys
73
-
74
-
75
- describe({
76
- id,
77
- key,
78
- config,
79
- enableBy
80
- } = {}) {
81
- const plugins = this.service.plugins; // this.id and this.key is generated automatically
82
- // so we need to diff first
83
-
84
- if (id && this.id !== id) {
85
- if (plugins[id]) {
86
- const name = plugins[id].isPreset ? 'preset' : 'plugin';
87
- throw new Error(`api.describe() failed, ${name} ${id} is already registered by ${plugins[id].path}.`);
88
- }
89
-
90
- plugins[id] = plugins[this.id];
91
- plugins[id].id = id;
92
- delete plugins[this.id];
93
- this.id = id;
94
- }
95
-
96
- if (key && this.key !== key) {
97
- this.key = key;
98
- plugins[this.id].key = key;
99
- }
100
-
101
- if (config) {
102
- plugins[this.id].config = config;
103
- }
104
-
105
- plugins[this.id].enableBy = enableBy || _enums.EnableBy.register;
106
- }
107
-
108
- register(hook) {
109
- (0, _assert().default)(hook.key && typeof hook.key === 'string', `api.register() failed, hook.key must supplied and should be string, but got ${hook.key}.`);
110
- (0, _assert().default)(hook.fn && typeof hook.fn === 'function', `api.register() failed, hook.fn must supplied and should be function, but got ${hook.fn}.`);
111
- this.service.hooksByPluginId[this.id] = (this.service.hooksByPluginId[this.id] || []).concat(hook);
112
- }
113
-
114
- registerCommand(command) {
115
- const name = command.name,
116
- alias = command.alias;
117
- (0, _assert().default)(!this.service.commands[name], `api.registerCommand() failed, the command ${name} is exists.`);
118
- this.service.commands[name] = command;
119
-
120
- if (alias) {
121
- this.service.commands[alias] = name;
122
- }
123
- }
124
-
125
- registerPresets(presets) {
126
- (0, _assert().default)(this.service.stage === _enums.ServiceStage.initPresets, `api.registerPresets() failed, it should only used in presets.`);
127
- (0, _assert().default)(Array.isArray(presets), `api.registerPresets() failed, presets must be Array.`);
128
- const extraPresets = presets.map(preset => {
129
- return (0, _pluginUtils.isValidPlugin)(preset) ? preset : (0, _pluginUtils.pathToObj)({
130
- type: _enums.PluginType.preset,
131
- path: preset,
132
- cwd: this.service.cwd
133
- });
134
- }); // 插到最前面,下个 while 循环优先执行
135
-
136
- this.service._extraPresets.splice(0, 0, ...extraPresets);
137
- } // 在 preset 初始化阶段放后面,在插件注册阶段放前面
138
-
139
-
140
- registerPlugins(plugins) {
141
- (0, _assert().default)(this.service.stage === _enums.ServiceStage.initPresets || this.service.stage === _enums.ServiceStage.initPlugins, `api.registerPlugins() failed, it should only be used in registering stage.`);
142
- (0, _assert().default)(Array.isArray(plugins), `api.registerPlugins() failed, plugins must be Array.`);
143
- const extraPlugins = plugins.map(plugin => {
144
- return (0, _pluginUtils.isValidPlugin)(plugin) ? plugin : (0, _pluginUtils.pathToObj)({
145
- type: _enums.PluginType.plugin,
146
- path: plugin,
147
- cwd: this.service.cwd
148
- });
149
- });
150
-
151
- if (this.service.stage === _enums.ServiceStage.initPresets) {
152
- this.service._extraPlugins.push(...extraPlugins);
153
- } else {
154
- this.service._extraPlugins.splice(0, 0, ...extraPlugins);
155
- }
156
- }
157
-
158
- registerMethod({
159
- name,
160
- fn,
161
- exitsError = true
162
- }) {
163
- if (this.service.pluginMethods[name]) {
164
- if (exitsError) {
165
- throw new Error(`api.registerMethod() failed, method ${name} is already exist.`);
166
- } else {
167
- return;
168
- }
169
- }
170
-
171
- this.service.pluginMethods[name] = fn || // 这里不能用 arrow function,this 需指向执行此方法的 PluginAPI
172
- // 否则 pluginId 会不会,导致不能正确 skip plugin
173
- function (fn) {
174
- const hook = _objectSpread({
175
- key: name
176
- }, utils().lodash.isPlainObject(fn) ? fn : {
177
- fn
178
- }); // @ts-ignore
179
-
180
-
181
- this.register(hook);
182
- };
183
- }
184
-
185
- skipPlugins(pluginIds) {
186
- pluginIds.forEach(pluginId => {
187
- this.service.skipPluginIds.add(pluginId);
188
- });
189
- }
190
-
191
- }
192
-
193
- exports.default = PluginAPI;
@@ -1,96 +0,0 @@
1
- /// <reference types="node" />
2
- import { BabelRegister, NodeEnv } from '@umijs/utils';
3
- import { EventEmitter } from 'events';
4
- import Config from '../Config/Config';
5
- import { ApplyPluginsType, ConfigChangeType, EnableBy, ServiceStage } from './enums';
6
- import PluginAPI from './PluginAPI';
7
- import { ICommand, IHook, IPackage, IPlugin, IPreset } from './types';
8
- export interface IServiceOpts {
9
- cwd: string;
10
- pkg?: IPackage;
11
- presets?: string[];
12
- plugins?: string[];
13
- configFiles?: string[];
14
- env?: NodeEnv;
15
- }
16
- interface IConfig {
17
- presets?: string[];
18
- plugins?: string[];
19
- [key: string]: any;
20
- }
21
- export default class Service extends EventEmitter {
22
- cwd: string;
23
- pkg: IPackage;
24
- skipPluginIds: Set<string>;
25
- stage: ServiceStage;
26
- commands: {
27
- [name: string]: ICommand | string;
28
- };
29
- plugins: {
30
- [id: string]: IPlugin;
31
- };
32
- pluginMethods: {
33
- [name: string]: Function;
34
- };
35
- initialPresets: IPreset[];
36
- initialPlugins: IPlugin[];
37
- _extraPresets: IPreset[];
38
- _extraPlugins: IPlugin[];
39
- userConfig: IConfig;
40
- configInstance: Config;
41
- config: IConfig | null;
42
- babelRegister: BabelRegister;
43
- hooksByPluginId: {
44
- [id: string]: IHook[];
45
- };
46
- hooks: {
47
- [key: string]: IHook[];
48
- };
49
- paths: {
50
- cwd?: string;
51
- absNodeModulesPath?: string;
52
- absSrcPath?: string;
53
- absPagesPath?: string;
54
- absOutputPath?: string;
55
- absTmpPath?: string;
56
- };
57
- env: string | undefined;
58
- ApplyPluginsType: typeof ApplyPluginsType;
59
- EnableBy: typeof EnableBy;
60
- ConfigChangeType: typeof ConfigChangeType;
61
- ServiceStage: typeof ServiceStage;
62
- args: any;
63
- constructor(opts: IServiceOpts);
64
- setStage(stage: ServiceStage): void;
65
- resolvePackage(): any;
66
- loadEnv(): void;
67
- init(): Promise<void>;
68
- initPresetsAndPlugins(): Promise<void>;
69
- getPluginAPI(opts: any): PluginAPI;
70
- applyAPI(opts: {
71
- apply: Function;
72
- api: PluginAPI;
73
- }): Promise<any>;
74
- initPreset(preset: IPreset): Promise<void>;
75
- initPlugin(plugin: IPlugin): Promise<void>;
76
- getPluginOptsWithKey(key: string): any;
77
- registerPlugin(plugin: IPlugin): void;
78
- isPluginEnable(pluginId: string): any;
79
- hasPlugins(pluginIds: string[]): boolean;
80
- hasPresets(presetIds: string[]): boolean;
81
- applyPlugins(opts: {
82
- key: string;
83
- type: ApplyPluginsType;
84
- initialValue?: any;
85
- args?: any;
86
- }): Promise<any>;
87
- run({ name, args }: {
88
- name: string;
89
- args?: any;
90
- }): Promise<void>;
91
- runCommand({ name, args }: {
92
- name: string;
93
- args?: any;
94
- }): Promise<void>;
95
- }
96
- export {};