mirror of https://git.tuxpa.in/a/code-server.git
plugin: More review fixes
Next commit will address Will's comments about the typings being weird.
This commit is contained in:
parent
706bc23f04
commit
8a8159c683
|
@ -86,7 +86,7 @@ export class PluginAPI {
|
||||||
*/
|
*/
|
||||||
public mount(r: express.Router): void {
|
public mount(r: express.Router): void {
|
||||||
for (const [, p] of this.plugins) {
|
for (const [, p] of this.plugins) {
|
||||||
r.use(`/${p.name}`, p.router())
|
r.use(`/${p.routerPath}`, p.router())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,7 +154,7 @@ export class PluginAPI {
|
||||||
this.plugins.set(p.name, p)
|
this.plugins.set(p.name, p)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.code !== "ENOENT") {
|
if (err.code !== "ENOENT") {
|
||||||
this.logger.warn(`failed to load plugin: ${err.message}`)
|
this.logger.warn(`failed to load plugin: ${err.stack}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -170,17 +170,24 @@ export class PluginAPI {
|
||||||
const logger = this.logger.named(packageJSON.name)
|
const logger = this.logger.named(packageJSON.name)
|
||||||
logger.debug("loading plugin", field("plugin_dir", dir), field("package_json", packageJSON))
|
logger.debug("loading plugin", field("plugin_dir", dir), field("package_json", packageJSON))
|
||||||
|
|
||||||
|
if (!packageJSON.name) {
|
||||||
|
throw new Error("plugin package.json missing name")
|
||||||
|
}
|
||||||
|
if (!packageJSON.version) {
|
||||||
|
throw new Error("plugin package.json missing version")
|
||||||
|
}
|
||||||
|
if (!packageJSON.engines || !packageJSON.engines["code-server"]) {
|
||||||
|
throw new Error(`plugin package.json missing code-server range like:
|
||||||
|
"engines": {
|
||||||
|
"code-server": "^3.6.0"
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
}
|
||||||
if (!semver.satisfies(version, packageJSON.engines["code-server"])) {
|
if (!semver.satisfies(version, packageJSON.engines["code-server"])) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`plugin range ${q(packageJSON.engines["code-server"])} incompatible` + ` with code-server version ${version}`,
|
`plugin range ${q(packageJSON.engines["code-server"])} incompatible` + ` with code-server version ${version}`,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (!packageJSON.name) {
|
|
||||||
throw new Error("plugin missing name")
|
|
||||||
}
|
|
||||||
if (!packageJSON.version) {
|
|
||||||
throw new Error("plugin missing version")
|
|
||||||
}
|
|
||||||
|
|
||||||
const p = {
|
const p = {
|
||||||
name: packageJSON.name,
|
name: packageJSON.name,
|
||||||
|
@ -198,6 +205,9 @@ export class PluginAPI {
|
||||||
if (!p.routerPath) {
|
if (!p.routerPath) {
|
||||||
throw new Error("plugin missing router path")
|
throw new Error("plugin missing router path")
|
||||||
}
|
}
|
||||||
|
if (!p.routerPath.startsWith("/") || p.routerPath.length < 2) {
|
||||||
|
throw new Error(`plugin router path ${q(p.routerPath)}: invalid`)
|
||||||
|
}
|
||||||
if (!p.homepageURL) {
|
if (!p.homepageURL) {
|
||||||
throw new Error("plugin missing homepage")
|
throw new Error("plugin missing homepage")
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,8 @@ import * as express from "express"
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Programmability
|
/**
|
||||||
|
* Programmability
|
||||||
*
|
*
|
||||||
* There is also a /api/applications endpoint to allow programmatic access to all
|
* There is also a /api/applications endpoint to allow programmatic access to all
|
||||||
* available applications. It could be used to create a custom application dashboard
|
* available applications. It could be used to create a custom application dashboard
|
||||||
|
|
Loading…
Reference in New Issue