From 2c1308e2704cb5917a29e7a316857f261919af3d Mon Sep 17 00:00:00 2001 From: Michael Plump Date: Mon, 24 Feb 2020 16:09:58 -0500 Subject: [PATCH] Revert "feat(plugins): Switch from /plugin-manifest.js to /plugin-manifest.json (#7905)" (#7943) This reverts commit dba6bf14bd9173f769881acaff7298af1dcb4add. --- .../core/src/plugins/plugin.registry.spec.ts | 14 +++++--------- .../modules/core/src/plugins/plugin.registry.ts | 14 +++++++++----- plugin-manifest.js | 2 ++ plugin-manifest.json | 1 - webpack.config.js | 4 ++-- 5 files changed, 18 insertions(+), 17 deletions(-) create mode 100644 plugin-manifest.js delete mode 100644 plugin-manifest.json diff --git a/app/scripts/modules/core/src/plugins/plugin.registry.spec.ts b/app/scripts/modules/core/src/plugins/plugin.registry.spec.ts index 75ddc5f0efe..2abe44770b5 100644 --- a/app/scripts/modules/core/src/plugins/plugin.registry.spec.ts +++ b/app/scripts/modules/core/src/plugins/plugin.registry.spec.ts @@ -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; @@ -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(); diff --git a/app/scripts/modules/core/src/plugins/plugin.registry.ts b/app/scripts/modules/core/src/plugins/plugin.registry.ts index c0df0f6e43d..9e4a6c161a6 100644 --- a/app/scripts/modules/core/src/plugins/plugin.registry.ts +++ b/app/scripts/modules/core/src/plugins/plugin.registry.ts @@ -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[]; @@ -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(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; }); diff --git a/plugin-manifest.js b/plugin-manifest.js new file mode 100644 index 00000000000..d83f6aff535 --- /dev/null +++ b/plugin-manifest.js @@ -0,0 +1,2 @@ +const plugins = []; +export { plugins }; diff --git a/plugin-manifest.json b/plugin-manifest.json deleted file mode 100644 index fe51488c706..00000000000 --- a/plugin-manifest.json +++ /dev/null @@ -1 +0,0 @@ -[] diff --git a/webpack.config.js b/webpack.config.js index 961c5e26e37..057722dc255 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -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({