Skip to content

Commit 54cbd53

Browse files
committed
plugin.ts: Make application endpoint paths absolute
1 parent 87c3105 commit 54cbd53

File tree

5 files changed

+20
-13
lines changed

5 files changed

+20
-13
lines changed

src/node/plugin.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ export class PluginAPI {
6060
// Add plugin key to each app.
6161
apps.push(
6262
...pluginApps.map((app) => {
63+
app = {...app, path: path.join(p.routerPath, app.path || "")}
64+
app = {...app, iconPath: path.join(app.path || "", app.iconPath)}
6365
return {
6466
...app,
6567
plugin: {
@@ -69,7 +71,7 @@ export class PluginAPI {
6971

7072
displayName: p.displayName,
7173
description: p.description,
72-
path: p.path,
74+
routerPath: p.routerPath,
7375
},
7476
}
7577
}),
@@ -192,8 +194,8 @@ export class PluginAPI {
192194
if (!p.description) {
193195
throw new Error("plugin missing description")
194196
}
195-
if (!p.path) {
196-
throw new Error("plugin missing path")
197+
if (!p.routerPath) {
198+
throw new Error("plugin missing router path")
197199
}
198200

199201
p.init({

test/plugin.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ describe("plugin", () => {
2121
version: "4.0.0",
2222

2323
description: "This app does XYZ.",
24-
iconPath: "/icon.svg",
24+
iconPath: "/test-plugin/test-app/icon.svg",
25+
path: "/test-plugin/test-app",
2526

2627
plugin: {
2728
name: "test-plugin",
@@ -30,7 +31,7 @@ describe("plugin", () => {
3031

3132
displayName: "Test Plugin",
3233
description: "Plugin used in code-server tests.",
33-
path: "/test-plugin",
34+
routerPath: "/test-plugin",
3435
},
3536
},
3637
],

test/test-plugin/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
out/index.js: src/index.ts
2-
yarn build
2+
# Typescript always emits, even on errors.
3+
yarn build || rm out/index.js
34

45
node_modules: package.json yarn.lock
56
yarn

test/test-plugin/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as fspath from "path"
33
import * as pluginapi from "../../../typings/pluginapi"
44

55
export const displayName = "Test Plugin"
6-
export const path = "/test-plugin"
6+
export const routerPath = "/test-plugin"
77
export const description = "Plugin used in code-server tests."
88

99
export function init(config: pluginapi.PluginConfig) {
@@ -24,6 +24,7 @@ export function applications(): pluginapi.Application[] {
2424
name: "Test App",
2525
version: "4.0.0",
2626
iconPath: "/icon.svg",
27+
path: "/test-app",
2728

2829
description: "This app does XYZ.",
2930
},

typings/pluginapi.d.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ import * as express from "express"
4545
*
4646
* There is also a /api/applications endpoint to allow programmatic access to all
4747
* available applications. It could be used to create a custom application dashboard
48-
* for example.
48+
* for example. An important difference with the API is that all application paths
49+
* will be absolute (i.e have the plugin path prepended) so that they may be used
50+
* directly.
4951
*/
5052

5153
/**
@@ -60,30 +62,30 @@ export interface Plugin {
6062
*
6163
* Fetched from package.json.
6264
*/
63-
name?: string
65+
readonly name?: string
6466

6567
/**
6668
* The version for the plugin in the overlay.
6769
*
6870
* Fetched from package.json.
6971
*/
70-
version?: string
72+
readonly version?: string
7173

7274
/**
7375
* Name used in the overlay.
7476
*/
75-
displayName: string
77+
readonly displayName: string
7678

7779
/**
7880
* Used in overlay.
7981
* Should be a full sentence describing the plugin.
8082
*/
81-
description: string
83+
readonly description: string
8284

8385
/**
8486
* The path at which the plugin router is to be registered.
8587
*/
86-
path: string
88+
readonly routerPath: string
8789

8890
/**
8991
* init is called so that the plugin may initialize itself with the config.

0 commit comments

Comments
 (0)