@yumerijs/core 3.0.5 → 3.0.6
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/core.d.ts +2 -0
- package/dist/core.js +5 -3
- package/package.json +1 -1
package/dist/core.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export interface Plugin {
|
|
|
15
15
|
apply?: (ctx: Context, config: Config) => Promise<void> | void;
|
|
16
16
|
disable?: (ctx: Context) => Promise<void> | void;
|
|
17
17
|
depend?: Array<string>;
|
|
18
|
+
optional?: Array<string>;
|
|
18
19
|
provide?: Array<string>;
|
|
19
20
|
render?: string;
|
|
20
21
|
config?: Schema<any>;
|
|
@@ -25,6 +26,7 @@ type PluginModuleLike = Plugin | PluginConstructor | ((ctx: Context, config: Con
|
|
|
25
26
|
apply?: ((ctx: Context, config: Config) => Promise<void> | void);
|
|
26
27
|
disable?: (ctx: Context) => Promise<void> | void;
|
|
27
28
|
depend?: Array<string>;
|
|
29
|
+
optional?: Array<string>;
|
|
28
30
|
provide?: Array<string>;
|
|
29
31
|
render?: string;
|
|
30
32
|
config?: Schema<any>;
|
package/dist/core.js
CHANGED
|
@@ -20,6 +20,8 @@ function mergePluginMeta(target, source) {
|
|
|
20
20
|
return target;
|
|
21
21
|
if (target.depend == null && Array.isArray(source.depend))
|
|
22
22
|
target.depend = source.depend;
|
|
23
|
+
if (target.optional == null && Array.isArray(source.optional))
|
|
24
|
+
target.optional = source.optional;
|
|
23
25
|
if (target.provide == null && Array.isArray(source.provide))
|
|
24
26
|
target.provide = source.provide;
|
|
25
27
|
if (target.render == null && typeof source.render === 'string')
|
|
@@ -175,9 +177,9 @@ export class Core {
|
|
|
175
177
|
const plugin = resolvePluginModule(module, context, config);
|
|
176
178
|
const shortName = this.getShortPluginName(context.pluginname);
|
|
177
179
|
context.module = plugin;
|
|
178
|
-
//
|
|
179
|
-
const
|
|
180
|
-
for (const name of
|
|
180
|
+
// 自动依赖注入:必需依赖始终由 loader 保证,optional 仅在已提供时注入。
|
|
181
|
+
const dependencies = [...(plugin.depend || []), ...(plugin.optional || [])];
|
|
182
|
+
for (const name of dependencies) {
|
|
181
183
|
const component = this.getComponent(name);
|
|
182
184
|
if (component) {
|
|
183
185
|
context.inject(name, component);
|