Skip to content

Commit 8a8159c

Browse files
committed
plugin: More review fixes
Next commit will address Will's comments about the typings being weird.
1 parent 706bc23 commit 8a8159c

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

src/node/plugin.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export class PluginAPI {
8686
*/
8787
public mount(r: express.Router): void {
8888
for (const [, p] of this.plugins) {
89-
r.use(`/${p.name}`, p.router())
89+
r.use(`/${p.routerPath}`, p.router())
9090
}
9191
}
9292

@@ -154,7 +154,7 @@ export class PluginAPI {
154154
this.plugins.set(p.name, p)
155155
} catch (err) {
156156
if (err.code !== "ENOENT") {
157-
this.logger.warn(`failed to load plugin: ${err.message}`)
157+
this.logger.warn(`failed to load plugin: ${err.stack}`)
158158
}
159159
}
160160
}
@@ -170,17 +170,24 @@ export class PluginAPI {
170170
const logger = this.logger.named(packageJSON.name)
171171
logger.debug("loading plugin", field("plugin_dir", dir), field("package_json", packageJSON))
172172

173+
if (!packageJSON.name) {
174+
throw new Error("plugin package.json missing name")
175+
}
176+
if (!packageJSON.version) {
177+
throw new Error("plugin package.json missing version")
178+
}
179+
if (!packageJSON.engines || !packageJSON.engines["code-server"]) {
180+
throw new Error(`plugin package.json missing code-server range like:
181+
"engines": {
182+
"code-server": "^3.6.0"
183+
}
184+
`)
185+
}
173186
if (!semver.satisfies(version, packageJSON.engines["code-server"])) {
174187
throw new Error(
175188
`plugin range ${q(packageJSON.engines["code-server"])} incompatible` + ` with code-server version ${version}`,
176189
)
177190
}
178-
if (!packageJSON.name) {
179-
throw new Error("plugin missing name")
180-
}
181-
if (!packageJSON.version) {
182-
throw new Error("plugin missing version")
183-
}
184191

185192
const p = {
186193
name: packageJSON.name,
@@ -198,6 +205,9 @@ export class PluginAPI {
198205
if (!p.routerPath) {
199206
throw new Error("plugin missing router path")
200207
}
208+
if (!p.routerPath.startsWith("/") || p.routerPath.length < 2) {
209+
throw new Error(`plugin router path ${q(p.routerPath)}: invalid`)
210+
}
201211
if (!p.homepageURL) {
202212
throw new Error("plugin missing homepage")
203213
}

typings/pluginapi.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ import * as express from "express"
4545
*
4646
*/
4747

48-
/* Programmability
48+
/**
49+
* Programmability
4950
*
5051
* There is also a /api/applications endpoint to allow programmatic access to all
5152
* available applications. It could be used to create a custom application dashboard

0 commit comments

Comments
 (0)