Skip to content

Commit

Permalink
feat(plugins): Switch from /plugin-manifest.js to /plugin-manifest.js…
Browse files Browse the repository at this point in the history
…on (spinnaker#7905)

BREAKING CHANGE: Switch plugin-manifest to json to match the json output from gate's /plugins/deck/plugin-manifest.json

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and Yun Zhang committed Mar 28, 2021
1 parent c2392fe commit cd8ff2b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
14 changes: 9 additions & 5 deletions app/scripts/modules/core/src/plugins/plugin.registry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { IStageTypeConfig } from 'core/domain';
import { API } from '../api';
import { IDeckPlugin, IPluginManifest, IPluginMetaData, PluginRegistry } from './plugin.registry';
import { Registry } from 'core/registry';
import { mock } from 'angular';

type TestPluginRegistry = PluginRegistry & {
load(pluginManifestData: IPluginManifest): Promise<any>;
Expand Down Expand Up @@ -34,11 +35,14 @@ describe('PluginRegistry', () => {
});
});

it('loadPluginManifestFromDeck() should import() from /plugin-manifest.js', async () => {
loadModuleFromUrlSpy.and.callFake(() => Promise.resolve({ plugins: [] }));
await pluginRegistry.loadPluginManifestFromDeck();
expect(loadModuleFromUrlSpy).toHaveBeenCalledWith('/plugin-manifest.js');
});
it(
'loadPluginManifestFromDeck() should fetch /plugin-manifest.json from deck assets',
mock.inject(async ($http: any) => {
const spy = spyOn($http, 'get').and.callFake(() => Promise.resolve({ data: [] }));
await pluginRegistry.loadPluginManifestFromDeck();
expect(spy).toHaveBeenCalledWith('/plugin-manifest.json');
}),
);

it('loadPluginManifestFromGate() should fetch from gate /plugins/deck/plugin-manifest.json', async () => {
const spy = jasmine.createSpy('get', () => Promise.resolve([])).and.callThrough();
Expand Down
14 changes: 5 additions & 9 deletions app/scripts/modules/core/src/plugins/plugin.registry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { API } from 'core/api';
import { Registry } from 'core/registry';
import { IStageTypeConfig } from 'core/domain';
import { $http } from 'ngimport';

export interface IDeckPlugin {
stages?: IStageTypeConfig[];
Expand Down Expand Up @@ -91,15 +92,10 @@ export class PluginRegistry {
/** Loads plugin manifest file served as a custom deck asset */
public loadPluginManifestFromDeck() {
const source = 'deck';
const uri = '/plugin-manifest.js';
const loadPromise = this.loadModuleFromUrl(uri)
.then((pluginManifest: IPluginManifest) => {
if (!pluginManifest || !pluginManifest.plugins) {
throw new Error(`Expected plugin-manifest.js to contain an export named 'plugins' but it did not.`);
}
return pluginManifest.plugins;
})
.catch(error => {
const uri = '/plugin-manifest.json';
const loadPromise = Promise.resolve($http.get<IPluginMetaData[]>(uri))
.then(response => response.data)
.catch((error: any) => {
console.error(`Failed to load ${uri} from ${source}`);
throw error;
});
Expand Down
2 changes: 0 additions & 2 deletions plugin-manifest.js

This file was deleted.

1 change: 1 addition & 0 deletions plugin-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
4 changes: 2 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ function configure(env, webpackOpts) {
to: `./styleguide.html`,
},
{
from: `./plugin-manifest.js`,
to: `./plugin-manifest.js`,
from: `./plugin-manifest.json`,
to: `./plugin-manifest.json`,
},
]),
new HtmlWebpackPlugin({
Expand Down

0 comments on commit cd8ff2b

Please sign in to comment.