From 00cfd9bdf1f69acb4391dfa8e751d21ed48b8ba9 Mon Sep 17 00:00:00 2001 From: Asher Date: Thu, 21 Jan 2021 13:49:45 -0600 Subject: [PATCH] Add working directory to plugin config --- src/node/plugin.ts | 2 ++ src/node/routes/index.ts | 3 ++- typings/pluginapi.d.ts | 5 +++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/node/plugin.ts b/src/node/plugin.ts index 72f4d0e6..1e9e901c 100644 --- a/src/node/plugin.ts +++ b/src/node/plugin.ts @@ -65,6 +65,7 @@ export class PluginAPI { */ private readonly csPlugin = "", private readonly csPluginPath = `${path.join(util.paths.data, "plugins")}:/usr/share/code-server/plugins`, + private readonly workingDirectory: string | undefined = undefined, ) { this.logger = logger.named("pluginapi") } @@ -249,6 +250,7 @@ export class PluginAPI { p.init({ logger: logger, + workingDirectory: this.workingDirectory, }) logger.debug("loaded") diff --git a/src/node/routes/index.ts b/src/node/routes/index.ts index 0070c695..1c4483ff 100644 --- a/src/node/routes/index.ts +++ b/src/node/routes/index.ts @@ -145,7 +145,8 @@ export const register = async ( app.use("/static", _static.router) app.use("/update", update.router) - const papi = new PluginAPI(logger, process.env.CS_PLUGIN, process.env.CS_PLUGIN_PATH) + const workingDir = args._ && args._.length > 0 ? path.resolve(args._[args._.length - 1]) : undefined + const papi = new PluginAPI(logger, process.env.CS_PLUGIN, process.env.CS_PLUGIN_PATH, workingDir) await papi.loadPlugins() papi.mount(app, wsApp) app.use("/api/applications", apps.router(papi)) diff --git a/typings/pluginapi.d.ts b/typings/pluginapi.d.ts index 65d5f9af..1802f089 100644 --- a/typings/pluginapi.d.ts +++ b/typings/pluginapi.d.ts @@ -212,6 +212,11 @@ export interface PluginConfig { * All plugin logs should be logged via this logger. */ readonly logger: Logger + + /** + * Plugins should default to this directory when applicable. + */ + readonly workingDirectory?: string } /**