File tree Expand file tree Collapse file tree 2 files changed +12
-17
lines changed
Expand file tree Collapse file tree 2 files changed +12
-17
lines changed Original file line number Diff line number Diff line change @@ -166,16 +166,7 @@ let rcl = {
166166 * @return {object } - the object of the required package/interface.
167167 */
168168 require ( name ) {
169- if ( typeof ( name . package ) === 'string' && typeof ( name . type ) === 'string' && typeof ( name . message ) === 'string' ) {
170- return loader . loadInterface ( name . package , name . type , name . message ) ;
171- }
172-
173- if ( name . indexOf ( '/' ) !== - 1 ) {
174- let [ packageName , type , messageName ] = name . split ( '/' ) ;
175- return loader . loadInterface ( packageName , type , messageName ) ;
176- }
177-
178- return loader . loadInterfaceInPackage ( name ) ;
169+ return loader . loadInterface ( name ) ;
179170 } ,
180171
181172 /**
Original file line number Diff line number Diff line change @@ -46,18 +46,22 @@ let interfaceLoader = {
4646 return this . loadInterface ( packageName , type , messageName ) ;
4747 }
4848
49+ // Suppose the name is a package, and traverse the path to collect the IDL files.
50+ let packagePath = path . join ( generator . generatedRoot , name ) ;
51+
52+ // eslint-disable-next-line
53+ let interfaces = fs . readdirSync ( packagePath ) ;
54+ if ( interfaces . length > 0 ) {
55+ return this . loadInterfaceByPath ( packagePath , interfaces ) ;
56+ }
57+
4958 throw new TypeError ( 'A string argument in expected in "package/type/message" format' ) ;
5059 } ,
5160
52- loadInterfaceInPackage ( packageName ) {
53- let packagePath = path . join ( generator . generatedRoot , packageName ) ;
54- // The files under the package folder are limited, so it will not cost too
55- // much time and result in blocking the main thread.
56- // eslint-disable-next-line
57- let files = fs . readdirSync ( packagePath ) ;
61+ loadInterfaceByPath ( packagePath , interfaces ) {
5862 let interfaceInfos = [ ] ;
5963
60- files . forEach ( ( file ) => {
64+ interfaces . forEach ( ( file ) => {
6165 let results = file . match ( / \w + _ _ ( \w + ) _ _ ( \w + ) .j s $ / ) ;
6266 let type = results [ 1 ] ;
6367 let name = results [ 2 ] ;
You can’t perform that action at this time.
0 commit comments