From 75e52a37742833679711fca2b48fdf8a04fcb521 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Tue, 3 Nov 2020 16:24:06 -0500 Subject: [PATCH] plugin.ts: Fixes for @code-asher --- ci/dev/test.sh | 3 +++ src/node/plugin.ts | 19 +++++++++++++++---- test/plugin.test.ts | 3 +-- test/test-plugin/Makefile | 5 +++++ 4 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 test/test-plugin/Makefile diff --git a/ci/dev/test.sh b/ci/dev/test.sh index 983b2f29..6eaa3878 100755 --- a/ci/dev/test.sh +++ b/ci/dev/test.sh @@ -4,6 +4,9 @@ set -euo pipefail main() { cd "$(dirname "$0")/../.." + cd test/test-plugin + make -s out/index.js + cd $OLDPWD mocha -r ts-node/register ./test/*.test.ts "$@" } diff --git a/src/node/plugin.ts b/src/node/plugin.ts index cdd9c3d9..f0dca275 100644 --- a/src/node/plugin.ts +++ b/src/node/plugin.ts @@ -23,7 +23,10 @@ interface Plugin extends pluginapi.Plugin { } interface Application extends pluginapi.Application { - plugin: Plugin + /* + * Clone of the above without functions. + */ + plugin: Omit } /** @@ -57,7 +60,15 @@ export class PluginAPI { // Add plugin key to each app. apps.push( ...pluginApps.map((app) => { - return { ...app, plugin: p } + return { + ...app, + plugin: { + name: p.name, + version: p.version, + description: p.description, + modulePath: p.modulePath, + }, + } }), ) } @@ -74,8 +85,8 @@ export class PluginAPI { } /** - * loadPlugins loads all plugins based on this.csPluginPath - * and this.csPlugin. + * loadPlugins loads all plugins based on this.csPlugin, + * this.csPluginPath and the built in plugins. */ public async loadPlugins(): Promise { // Built-in plugins. diff --git a/test/plugin.test.ts b/test/plugin.test.ts index 69c4572e..5836dead 100644 --- a/test/plugin.test.ts +++ b/test/plugin.test.ts @@ -12,8 +12,7 @@ describe("plugin", () => { const papi = new PluginAPI(logger, path.resolve(__dirname, "test-plugin") + ":meow") await papi.loadPlugins() - // We remove the function fields from the application's plugins. - const apps = JSON.parse(JSON.stringify(await papi.applications())) + const apps = await papi.applications() assert.deepEqual( [ diff --git a/test/test-plugin/Makefile b/test/test-plugin/Makefile new file mode 100644 index 00000000..fb66dc81 --- /dev/null +++ b/test/test-plugin/Makefile @@ -0,0 +1,5 @@ +out/index.js: src/index.ts + yarn build + +node_modules: package.json yarn.lock + yarn