Skip to content

Commit 3b8aa58

Browse files
author
Ovidiu Barabula
committed
feat(core): provide dependencies subscriber to plugins
1 parent f274864 commit 3b8aa58

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/plugin-manager/installable.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,35 @@ describe('Installable', () => {
8484
});
8585

8686

87+
it('calls dependencies installer subscriber when dependencies are passed', async () => {
88+
const installable = {
89+
dependencies: {
90+
dependencies: {
91+
myDependencyPackage: '^1.0.0',
92+
},
93+
devDependencies: {
94+
myDevDependencyPackage: '^1.0.0',
95+
},
96+
},
97+
hook,
98+
name,
99+
taskFn,
100+
};
101+
let called = false;
102+
const configuredPlugin = Installable(installable);
103+
const configSubscriberStub = async () => Promise.resolve(true);
104+
const taskSubscribersStub = { hook: taskName => taskName };
105+
const depsInstallerSubscriberStub = () => called = true;
106+
107+
await configuredPlugin.install(
108+
taskSubscribersStub,
109+
configSubscriberStub,
110+
depsInstallerSubscriberStub,
111+
);
112+
expect(called).to.be.true;
113+
});
114+
115+
87116
it('doesn\'t call configuration subscriber when questionnaire is not available passed', async () => {
88117
const installable = {
89118
hook,

src/plugin-manager/installable.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import * as path from 'path';
1212
import ConfigManager, { Config, IConfigManager } from '../config-manager';
1313
import ConfigManagerProxy from '../config-manager/config-manager-proxy';
1414
import { ConfigQuestionnaire, QuestionnaireSubscriber } from '../config-wizard';
15+
import { DependenciesSubscriber } from '../dependencies-manager';
16+
import { DependenciesManifest } from '../dependencies-manager/dependencies-installer';
1517
import { TaskSubscriber } from '../task-manager';
1618
import Logger, { ILogger } from '../util/logger';
1719
import { AnyFunction, AnyObject, getPrefix, isObject } from '../util/utility-functions';
@@ -23,6 +25,7 @@ export interface InstallableObject {
2325
taskFn: AnyFunction;
2426
hook: string;
2527
name: string;
28+
dependencies?: DependenciesManifest;
2629
description?: string;
2730
configDefaults?: Config;
2831
configQuestionnaire?: ConfigQuestionnaire;
@@ -81,7 +84,7 @@ export async function getUtilitiesProvider(name: string): Promise<PluginProvider
8184
// TODO: Will have to make ConfigManager a Singleton
8285
const configManager: IConfigManager = await ConfigManager();
8386
// Create logger instance with plugin's name as the channel
84-
const logger: ILogger = Logger.getInstance()(name);
87+
const logger: ILogger = Logger.getInstance()(`task ${chalk.hex('#7AC0DA')(name)}`);
8588

8689
// Instantiate a config manager proxy with access to the plugin's configuration
8790
const config: IConfigManager = ConfigManagerProxy(configManager, getPrefix(name));
@@ -145,6 +148,7 @@ export async function provideUtilities(taskFn: AnyFunction, name: string): Promi
145148
* Installable plugin factory
146149
* @param configDefaults Configuration defaults object
147150
* @param configQuestionnaire Configuration questionnaire object
151+
* @param dependencies Dependencies manifest object
148152
* @param description Task description
149153
* @param hook Task registration hook
150154
* @param name Task name
@@ -162,6 +166,7 @@ function Installable(plugin: Plugin | InstallableObject): Plugin {
162166
const {
163167
configDefaults,
164168
configQuestionnaire,
169+
dependencies,
165170
description,
166171
hook,
167172
name,
@@ -186,10 +191,12 @@ function Installable(plugin: Plugin | InstallableObject): Plugin {
186191
* Task plugin installer function
187192
* @param taskSubscribers Hook subscribers object
188193
* @param configSubscriber Configuration questionnaire subscriber
194+
* @param dependenciesSubscriber Dependencies installer subscriber
189195
*/
190196
async function install(
191197
taskSubscribers: TaskSubscriber,
192198
configSubscriber: QuestionnaireSubscriber,
199+
dependenciesSubscriber: DependenciesSubscriber,
193200
): Promise<void> {
194201
// Register Gulp task
195202
gulp.task(name, await provideUtilities(taskFn, name));
@@ -203,6 +210,11 @@ function Installable(plugin: Plugin | InstallableObject): Plugin {
203210
) {
204211
await configSubscriber(configDefaults, configQuestionnaire);
205212
}
213+
214+
// Register plugin dependencies, if available
215+
if (typeof dependencies !== 'undefined') {
216+
await dependenciesSubscriber(dependencies, name);
217+
}
206218
}
207219

208220

0 commit comments

Comments
 (0)