Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
gzupanda
code-server
提交
afff86ae
C
code-server
项目概览
gzupanda
/
code-server
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
code-server
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
afff86ae
编写于
11月 03, 2020
作者:
A
Anmol Sethi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
plugin.ts: Adjust to implement pluginapi.d.ts correctly
上级
fed545e6
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
48 addition
and
18 deletion
+48
-18
src/node/plugin.ts
src/node/plugin.ts
+23
-10
test/plugin.test.ts
test/plugin.test.ts
+8
-2
test/test-plugin/package.json
test/test-plugin/package.json
+0
-1
test/test-plugin/src/index.ts
test/test-plugin/src/index.ts
+9
-3
tsconfig.json
tsconfig.json
+2
-1
typings/pluginapi.d.ts
typings/pluginapi.d.ts
+6
-1
未找到文件。
src/node/plugin.ts
浏览文件 @
afff86ae
...
...
@@ -10,11 +10,11 @@ const fsp = fs.promises
interface
Plugin
extends
pluginapi
.
Plugin
{
/**
* These fields are populated from the plugin's package.json.
* These fields are populated from the plugin's package.json
* and now guaranteed to exist.
*/
name
:
string
version
:
string
description
:
string
/**
* path to the node module on the disk.
...
...
@@ -34,7 +34,7 @@ interface Application extends pluginapi.Application {
* Please see that file for details.
*/
export
class
PluginAPI
{
private
readonly
plugins
=
new
Array
<
Plugin
>
()
private
readonly
plugins
=
new
Map
<
string
,
Plugin
>
()
private
readonly
logger
:
Logger
public
constructor
(
...
...
@@ -54,7 +54,7 @@ export class PluginAPI {
*/
public
async
applications
():
Promise
<
Application
[]
>
{
const
apps
=
new
Array
<
Application
>
()
for
(
const
p
of
this
.
plugins
)
{
for
(
const
[
_
,
p
]
of
this
.
plugins
)
{
const
pluginApps
=
await
p
.
applications
()
// Add plugin key to each app.
...
...
@@ -65,8 +65,11 @@ export class PluginAPI {
plugin
:
{
name
:
p
.
name
,
version
:
p
.
version
,
description
:
p
.
description
,
modulePath
:
p
.
modulePath
,
displayName
:
p
.
displayName
,
description
:
p
.
description
,
path
:
p
.
path
,
},
}
}),
...
...
@@ -79,7 +82,7 @@ export class PluginAPI {
* mount mounts all plugin routers onto r.
*/
public
mount
(
r
:
express
.
Router
):
void
{
for
(
const
p
of
this
.
plugins
)
{
for
(
const
[
_
,
p
]
of
this
.
plugins
)
{
r
.
use
(
`/
${
p
.
name
}
`
,
p
.
router
())
}
}
...
...
@@ -129,7 +132,7 @@ export class PluginAPI {
encoding
:
"
utf8
"
,
})
const
packageJSON
:
PackageJSON
=
JSON
.
parse
(
str
)
for
(
const
p
of
this
.
plugins
)
{
for
(
const
[
_
,
p
]
of
this
.
plugins
)
{
if
(
p
.
name
===
packageJSON
.
name
)
{
this
.
logger
.
warn
(
`ignoring duplicate plugin
${
q
(
p
.
name
)}
at
${
q
(
dir
)}
, using previously loaded
${
q
(
p
.
modulePath
)}
`
,
...
...
@@ -138,7 +141,7 @@ export class PluginAPI {
}
}
const
p
=
this
.
_loadPlugin
(
dir
,
packageJSON
)
this
.
plugins
.
push
(
p
)
this
.
plugins
.
set
(
p
.
name
,
p
)
}
catch
(
err
)
{
if
(
err
.
code
!==
"
ENOENT
"
)
{
this
.
logger
.
warn
(
`failed to load plugin:
${
err
.
message
}
`
)
...
...
@@ -147,6 +150,8 @@ export class PluginAPI {
}
private
_loadPlugin
(
dir
:
string
,
packageJSON
:
PackageJSON
):
Plugin
{
dir
=
path
.
resolve
(
dir
)
const
logger
=
this
.
logger
.
named
(
packageJSON
.
name
)
logger
.
debug
(
"
loading plugin
"
,
field
(
"
plugin_dir
"
,
dir
),
field
(
"
package_json
"
,
packageJSON
))
...
...
@@ -165,11 +170,20 @@ export class PluginAPI {
const
p
=
{
name
:
packageJSON
.
name
,
version
:
packageJSON
.
version
,
description
:
packageJSON
.
description
,
modulePath
:
dir
,
...
require
(
dir
),
}
as
Plugin
if
(
!
p
.
displayName
)
{
throw
new
Error
(
"
plugin missing displayName
"
)
}
if
(
!
p
.
description
)
{
throw
new
Error
(
"
plugin missing description
"
)
}
if
(
!
p
.
path
)
{
throw
new
Error
(
"
plugin missing path
"
)
}
p
.
init
({
logger
:
logger
,
})
...
...
@@ -183,7 +197,6 @@ export class PluginAPI {
interface
PackageJSON
{
name
:
string
version
:
string
description
:
string
engines
:
{
"
code-server
"
:
string
}
...
...
test/plugin.test.ts
浏览文件 @
afff86ae
...
...
@@ -17,14 +17,20 @@ describe("plugin", () => {
assert
.
deepEqual
(
[
{
name
:
"
goland
"
,
name
:
"
test app
"
,
version
:
"
4.0.0
"
,
description
:
"
my description
"
,
iconPath
:
"
/icon.svg
"
,
plugin
:
{
name
:
"
test-plugin
"
,
version
:
"
1.0.0
"
,
description
:
"
Fake plugin for testing code-server's plugin API
"
,
modulePath
:
path
.
join
(
__dirname
,
"
test-plugin
"
),
description
:
"
Plugin used in code-server tests.
"
,
displayName
:
"
Test Plugin
"
,
path
:
"
/test-plugin
"
,
},
},
],
...
...
test/test-plugin/package.json
浏览文件 @
afff86ae
...
...
@@ -2,7 +2,6 @@
"private"
:
true
,
"name"
:
"test-plugin"
,
"version"
:
"1.0.0"
,
"description"
:
"Fake plugin for testing code-server's plugin API"
,
"engines"
:
{
"code-server"
:
"^3.6.0"
},
...
...
test/test-plugin/src/index.ts
浏览文件 @
afff86ae
import
*
as
express
from
"
express
"
import
*
as
path
from
"
path
"
import
*
as
fs
path
from
"
path
"
import
*
as
pluginapi
from
"
../../../typings/pluginapi
"
export
const
displayName
=
"
Test Plugin
"
export
const
path
=
"
/test-plugin
"
export
const
description
=
"
Plugin used in code-server tests.
"
export
function
init
(
config
:
pluginapi
.
PluginConfig
)
{
config
.
logger
.
debug
(
"
test-plugin loaded!
"
)
}
...
...
@@ -9,7 +13,7 @@ export function init(config: pluginapi.PluginConfig) {
export
function
router
():
express
.
Router
{
const
r
=
express
.
Router
()
r
.
get
(
"
/goland/icon.svg
"
,
(
req
,
res
)
=>
{
res
.
sendFile
(
path
.
resolve
(
__dirname
,
"
../public/icon.svg
"
))
res
.
sendFile
(
fs
path
.
resolve
(
__dirname
,
"
../public/icon.svg
"
))
})
return
r
}
...
...
@@ -17,9 +21,11 @@ export function router(): express.Router {
export
function
applications
():
pluginapi
.
Application
[]
{
return
[
{
name
:
"
goland
"
,
name
:
"
test app
"
,
version
:
"
4.0.0
"
,
iconPath
:
"
/icon.svg
"
,
description
:
"
my description
"
,
},
]
}
tsconfig.json
浏览文件 @
afff86ae
...
...
@@ -16,7 +16,8 @@
"tsBuildInfoFile"
:
"./.cache/tsbuildinfo"
,
"incremental"
:
true
,
"rootDir"
:
"./src"
,
"typeRoots"
:
[
"./node_modules/@types"
,
"./typings"
]
"typeRoots"
:
[
"./node_modules/@types"
,
"./typings"
],
"downlevelIteration"
:
true
},
"include"
:
[
"./src/**/*.ts"
]
}
typings/pluginapi.d.ts
浏览文件 @
afff86ae
...
...
@@ -70,9 +70,14 @@ export interface Plugin {
version
?:
string
/**
*
These two ar
e used in the overlay.
*
Nam
e used in the overlay.
*/
displayName
:
string
/**
* Used in overlay.
* Should be a full sentence describing the plugin.
*/
description
:
string
/**
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录