File tree Expand file tree Collapse file tree 4 files changed +58
-1
lines changed Expand file tree Collapse file tree 4 files changed +58
-1
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ export class PluginHost extends AbstractComponent<Application> {
20
20
*/
21
21
load ( ) : boolean {
22
22
const logger = this . application . logger ;
23
- const plugins = this . plugins . length ? this . plugins : this . discoverNpmPlugins ( ) ;
23
+ const plugins = this . plugins . length ? this . resolvePluginPaths ( this . plugins ) : this . discoverNpmPlugins ( ) ;
24
24
25
25
if ( plugins . some ( plugin => plugin . toLowerCase ( ) === 'none' ) ) {
26
26
return true ;
@@ -133,4 +133,29 @@ export class PluginHost extends AbstractComponent<Application> {
133
133
return false ;
134
134
}
135
135
}
136
+
137
+ /**
138
+ * Resolves plugin paths to absolute paths from the current working directory
139
+ * (`process.cwd()`).
140
+ *
141
+ * ```txt
142
+ * ./plugin -> resolve
143
+ * ../plugin -> resolve
144
+ * plugin -> don't resolve (module resolution)
145
+ * /plugin -> don't resolve (already absolute path)
146
+ * c:\plugin -> don't resolve (already absolute path)
147
+ * ```
148
+ *
149
+ * @param plugins
150
+ */
151
+ private resolvePluginPaths ( plugins : string [ ] ) {
152
+ const cwd = process . cwd ( ) ;
153
+ return plugins . map ( plugin => {
154
+ // treat plugins that start with `.` as relative, requiring resolution
155
+ if ( plugin . startsWith ( '.' ) ) {
156
+ return Path . resolve ( cwd , plugin ) ;
157
+ }
158
+ return plugin ;
159
+ } ) ;
160
+ }
136
161
}
Original file line number Diff line number Diff line change 1
1
import { Application } from '..' ;
2
2
import Assert = require( 'assert' ) ;
3
3
import * as mockery from 'mockery' ;
4
+ import * as path from 'path' ;
4
5
5
6
describe ( 'PluginHost' , function ( ) {
6
7
before ( function ( ) {
@@ -27,4 +28,27 @@ describe('PluginHost', function () {
27
28
'typedoc-plugin-2'
28
29
] ) ;
29
30
} ) ;
31
+
32
+ it ( 'loads a plugin with relative path' , function ( ) {
33
+ const app = new Application ( ) ;
34
+ app . bootstrap ( {
35
+ plugin : [ './dist/test/plugins/relative' ]
36
+ } ) ;
37
+
38
+ Assert . deepEqual ( app . plugins . plugins , [
39
+ './dist/test/plugins/relative'
40
+ ] ) ;
41
+ } ) ;
42
+
43
+ it ( 'loads a plugin with absolute path' , function ( ) {
44
+ const app = new Application ( ) ;
45
+ const absolutePath = path . resolve ( __dirname , './plugins/absolute' ) ;
46
+ app . bootstrap ( {
47
+ plugin : [ absolutePath ]
48
+ } ) ;
49
+
50
+ Assert . deepEqual ( app . plugins . plugins , [
51
+ absolutePath
52
+ ] ) ;
53
+ } ) ;
30
54
} ) ;
Original file line number Diff line number Diff line change
1
+ import { Application } from '../..' ;
2
+
3
+ module . exports = ( pluginHost : Application ) => {
4
+ } ;
Original file line number Diff line number Diff line change
1
+ import { Application } from '../..' ;
2
+
3
+ module . exports = ( pluginHost : Application ) => {
4
+ } ;
You can’t perform that action at this time.
0 commit comments