1
1
const log = require ( "@ui5/logger" ) . getLogger ( "resources:adapters:AbstractAdapter" ) ;
2
2
const minimatch = require ( "minimatch" ) ;
3
3
const AbstractReaderWriter = require ( "../AbstractReaderWriter" ) ;
4
+ const Resource = require ( "../Resource" ) ;
4
5
5
6
/**
6
7
* Abstract Resource Adapter
@@ -49,6 +50,25 @@ class AbstractAdapter extends AbstractReaderWriter {
49
50
return [ ] ;
50
51
}
51
52
patterns = Array . prototype . concat . apply ( [ ] , patterns ) ;
53
+ if ( ! options . nodir ) {
54
+ for ( let i = patterns . length - 1 ; i >= 0 ; i -- ) {
55
+ const idx = this . _virBaseDir . indexOf ( patterns [ i ] ) ;
56
+ if ( patterns [ i ] && idx !== - 1 && idx < this . _virBaseDir . length ) {
57
+ const subPath = patterns [ i ] ;
58
+ return Promise . resolve ( [
59
+ new Resource ( {
60
+ project : this . project ,
61
+ statInfo : { // TODO: make closer to fs stat info
62
+ isDirectory : function ( ) {
63
+ return true ;
64
+ }
65
+ } ,
66
+ path : subPath
67
+ } )
68
+ ] ) ;
69
+ }
70
+ }
71
+ }
52
72
return this . _runGlob ( patterns , options , trace ) ;
53
73
} ) ;
54
74
}
@@ -62,6 +82,7 @@ class AbstractAdapter extends AbstractReaderWriter {
62
82
*/
63
83
_normalizePattern ( virPattern ) {
64
84
return Promise . resolve ( ) . then ( ( ) => {
85
+ const that = this ;
65
86
const mm = new minimatch . Minimatch ( virPattern ) ;
66
87
67
88
const basePathParts = this . _virBaseDir . split ( "/" ) ;
@@ -71,41 +92,50 @@ class AbstractAdapter extends AbstractReaderWriter {
71
92
for ( i = 0 ; i < basePathParts . length ; i ++ ) {
72
93
const globPart = subset [ i ] ;
73
94
if ( globPart === undefined ) {
74
- log . verbose ( "Ran out of glob parts to match. This should not happen." ) ;
75
- return - 42 ;
95
+ log . verbose ( "Ran out of glob parts to match (this should not happen):" ) ;
96
+ if ( that . _project ) { // project is optional
97
+ log . verbose ( `Project: ${ that . _project . metadata . name } ` ) ;
98
+ }
99
+ log . verbose ( `Virtual base path: ${ that . _virBaseDir } ` ) ;
100
+ log . verbose ( `Pattern to match: ${ virPattern } ` ) ;
101
+ log . verbose ( `Current subset (tried index ${ i } ):` ) ;
102
+ log . verbose ( subset ) ;
103
+ return { idx : i , virtualMatch : true } ;
76
104
}
77
105
const basePathPart = basePathParts [ i ] ;
78
106
if ( typeof globPart === "string" ) {
79
107
if ( globPart !== basePathPart ) {
80
- return - 42 ;
108
+ return null ;
81
109
} else {
82
110
continue ;
83
111
}
84
112
} else if ( globPart === minimatch . GLOBSTAR ) {
85
113
return i ;
86
114
} else { // Regex
87
115
if ( ! globPart . test ( basePathPart ) ) {
88
- return - 42 ;
116
+ return null ;
89
117
} else {
90
118
continue ;
91
119
}
92
120
}
93
121
}
94
122
if ( subset . length === basePathParts . length ) {
95
- return - 1 ;
123
+ return { rootMatch : true } ;
96
124
}
97
- return i ;
125
+ return { idx : i } ;
98
126
}
99
127
100
128
const resultGlobs = [ ] ;
101
129
for ( let i = 0 ; i < mm . set . length ; i ++ ) {
102
- const matchIdx = matchSubset ( mm . set [ i ] ) ;
103
- let resultPattern ;
104
- if ( matchIdx !== - 42 ) {
105
- if ( matchIdx === - 1 ) { // matched one up
130
+ const match = matchSubset ( mm . set [ i ] ) ;
131
+ if ( match ) {
132
+ let resultPattern ;
133
+ if ( match . virtualMatch ) {
134
+ resultPattern = basePathParts . slice ( 0 , match . idx ) . join ( "/" ) ;
135
+ } else if ( match . rootMatch ) { // matched one up
106
136
resultPattern = "" ; // root "/"
107
137
} else { // matched at some part of the glob
108
- resultPattern = mm . globParts [ i ] . slice ( matchIdx ) . join ( "/" ) ;
138
+ resultPattern = mm . globParts [ i ] . slice ( match . idx ) . join ( "/" ) ;
109
139
if ( resultPattern . startsWith ( "/" ) ) {
110
140
resultPattern = resultPattern . substr ( 1 ) ;
111
141
}
0 commit comments