Skip to content

Commit

Permalink
Revert "feat(plugins): Switch from /plugin-manifest.js to /plugin-man…
Browse files Browse the repository at this point in the history
…ifest.json (#7905)" (#7943)

This reverts commit dba6bf1.
  • Loading branch information
plumpy authored Feb 24, 2020
1 parent dba6bf1 commit 2c1308e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
14 changes: 5 additions & 9 deletions app/scripts/modules/core/src/plugins/plugin.registry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ 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 @@ -35,14 +34,11 @@ describe('PluginRegistry', () => {
});
});

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('loadPluginManifestFromDeck() should import() from /plugin-manifest.js', async () => {
loadModuleFromUrlSpy.and.callFake(() => Promise.resolve({ plugins: [] }));
await pluginRegistry.loadPluginManifestFromDeck();
expect(loadModuleFromUrlSpy).toHaveBeenCalledWith('/plugin-manifest.js');
});

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: 9 additions & 5 deletions app/scripts/modules/core/src/plugins/plugin.registry.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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 @@ -92,10 +91,15 @@ export class PluginRegistry {
/** Loads plugin manifest file served as a custom deck asset */
public loadPluginManifestFromDeck() {
const source = 'deck';
const uri = '/plugin-manifest.json';
const loadPromise = Promise.resolve($http.get<IPluginMetaData[]>(uri))
.then(response => response.data)
.catch((error: any) => {
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 => {
console.error(`Failed to load ${uri} from ${source}`);
throw error;
});
Expand Down
2 changes: 2 additions & 0 deletions plugin-manifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const plugins = [];
export { plugins };
1 change: 0 additions & 1 deletion plugin-manifest.json

This file was deleted.

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.json`,
to: `./plugin-manifest.json`,
from: `./plugin-manifest.js`,
to: `./plugin-manifest.js`,
},
]),
new HtmlWebpackPlugin({
Expand Down

0 comments on commit 2c1308e

Please sign in to comment.