File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed
Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import updateNotifier from 'update-notifier';
99import posthtml from 'posthtml' ;
1010import outResolve from './out-resolve' ;
1111import cfgResolve from './cfg-resolve' ;
12+ import pluginResolve from './plugin-resolve' ;
1213
1314const package_ = require ( '../package.json' ) ;
1415updateNotifier ( { pkg : package_ } ) . notify ( ) ;
@@ -93,7 +94,7 @@ const read = file => new Promise(resolve => {
9394const interopRequire = object => object && object . __esModule ? object . default : object ;
9495
9596const getPlugins = config => Object . keys ( config . plugins || { } )
96- . map ( plugin => interopRequire ( require ( plugin ) ) ( config . plugins [ plugin ] ) ) ;
97+ . map ( plugin => interopRequire ( require ( pluginResolve ( plugin , config . root ) ) ) ( config . plugins [ plugin ] ) ) ;
9798
9899const config = cfgResolve ( cli ) ;
99100
Original file line number Diff line number Diff line change 1+ import path from 'path' ;
2+
3+ const pluginExist = ( pluginPath ) => {
4+ try {
5+ require ( pluginPath ) ;
6+ return true ;
7+ } catch { }
8+
9+ return false ;
10+ }
11+
12+ export default ( pluginName , root = './' ) => {
13+ if ( pluginExist ( pluginName ) ) {
14+ return pluginName ;
15+ }
16+
17+ const pluginResolvePath = path . resolve ( path . join ( root , pluginName ) ) ;
18+ if ( pluginExist ( pluginResolvePath ) ) {
19+ return pluginResolvePath ;
20+ }
21+
22+ return pluginName ;
23+ }
You can’t perform that action at this time.
0 commit comments