@@ -9,6 +9,9 @@ import { HttpServer } from "./http"
9
9
10
10
export type Activate = ( httpServer : HttpServer , args : Args ) => void
11
11
12
+ /**
13
+ * Plugins must implement this interface.
14
+ */
12
15
export interface Plugin {
13
16
activate : Activate
14
17
}
@@ -23,6 +26,9 @@ require("module")._load = function (request: string, parent: object, isMain: boo
23
26
return originalLoad . apply ( this , [ request . replace ( / ^ c o d e - s e r v e r / , path . resolve ( __dirname , "../.." ) ) , parent , isMain ] )
24
27
}
25
28
29
+ /**
30
+ * Load a plugin and run its activation function.
31
+ */
26
32
const loadPlugin = async ( pluginPath : string , httpServer : HttpServer , args : Args ) : Promise < void > => {
27
33
try {
28
34
const plugin : Plugin = require ( pluginPath )
@@ -37,24 +43,34 @@ const loadPlugin = async (pluginPath: string, httpServer: HttpServer, args: Args
37
43
}
38
44
}
39
45
40
- const _loadPlugins = async ( httpServer : HttpServer , args : Args ) : Promise < void > => {
41
- const pluginPath = path . resolve ( __dirname , "../../plugins" )
42
- const files = await util . promisify ( fs . readdir ) ( pluginPath , {
43
- withFileTypes : true ,
44
- } )
45
- await Promise . all ( files . map ( ( file ) => loadPlugin ( path . join ( pluginPath , file . name ) , httpServer , args ) ) )
46
- }
47
-
48
- export const loadPlugins = async ( httpServer : HttpServer , args : Args ) : Promise < void > => {
46
+ /**
47
+ * Load all plugins in the specified directory.
48
+ */
49
+ const _loadPlugins = async ( pluginDir : string , httpServer : HttpServer , args : Args ) : Promise < void > => {
49
50
try {
50
- await _loadPlugins ( httpServer , args )
51
+ const files = await util . promisify ( fs . readdir ) ( pluginDir , {
52
+ withFileTypes : true ,
53
+ } )
54
+ await Promise . all ( files . map ( ( file ) => loadPlugin ( path . join ( pluginDir , file . name ) , httpServer , args ) ) )
51
55
} catch ( error ) {
52
56
if ( error . code !== "ENOENT" ) {
53
57
logger . warn ( error . message )
54
58
}
55
59
}
60
+ }
61
+
62
+ /**
63
+ * Load all plugins from the plugin directory. Defaults to `plugins` inside the
64
+ * code-server directory but can be set with `PLUGIN_DIR`.
65
+
66
+ * Also load any individual plugins found in `PLUGIN_DIRS` (colon-separated).
67
+ * This allows you to test and develop plugins without having to move them into
68
+ * one directory.
69
+ */
70
+ export const loadPlugins = async ( httpServer : HttpServer , args : Args ) : Promise < void > => {
71
+ await _loadPlugins ( path . resolve ( process . env . PLUGIN_DIR || path . join ( __dirname , "../../plugins" ) ) , httpServer , args )
56
72
57
- if ( process . env . PLUGIN_DIR ) {
58
- await loadPlugin ( process . env . PLUGIN_DIR , httpServer , args )
73
+ if ( process . env . PLUGIN_DIRS ) {
74
+ await Promise . all ( process . env . PLUGIN_DIRS . split ( ":" ) . map ( ( dir ) => loadPlugin ( dir , httpServer , args ) ) )
59
75
}
60
76
}
0 commit comments