@@ -29,7 +29,7 @@ const blocked_statements = [
29
29
] ;
30
30
31
31
const sourceFolders = [ './src' , './e2e' ] ;
32
- const scopePackages = glob ( 'src/lib/*' ) ;
32
+ const libRoot = 'src/lib' ;
33
33
const blockedRegex = new RegExp ( blocked_statements . join ( '|' ) , 'g' ) ;
34
34
const importRegex = / f r o m \s + ' ( .* ) ' ; / g;
35
35
@@ -58,7 +58,9 @@ findTestFiles()
58
58
lineCount ++ ;
59
59
60
60
let matches = line . match ( blockedRegex ) ;
61
- let scopeImport = isRelativeScopeImport ( fileName , line ) ;
61
+ let scopeImport = path . relative ( libRoot , fileName ) . startsWith ( '..' )
62
+ ? isRelativeScopeImport ( fileName , line )
63
+ : false ;
62
64
63
65
if ( matches || scopeImport ) {
64
66
@@ -155,6 +157,10 @@ function findChangedFiles() {
155
157
* @param line Line to be checked.
156
158
*/
157
159
function isRelativeScopeImport ( fileName , line ) {
160
+ if ( fileName . startsWith ( libRoot ) ) {
161
+ return false ;
162
+ }
163
+
158
164
let importMatch = importRegex . exec ( line ) ;
159
165
160
166
// We have to reset the last index of the import regex, otherwise we
@@ -184,8 +190,7 @@ function isRelativeScopeImport(fileName, line) {
184
190
if ( fileScope . path !== importScope . path ) {
185
191
186
192
// Creates a valid import statement, which uses the correct scope package.
187
- let importFilePath = path . relative ( importScope . path , importPath ) ;
188
- let validImportPath = `@angular/material/${ importScope . name } /${ importFilePath } ` ;
193
+ let validImportPath = `@angular/material` ;
189
194
190
195
return {
191
196
fileScope : fileScope . name ,
@@ -200,9 +205,7 @@ function isRelativeScopeImport(fileName, line) {
200
205
filePath = path . normalize ( filePath ) ;
201
206
202
207
// Iterate through all scope paths and try to find them inside of the file path.
203
- var scopePath = scopePackages
204
- . filter ( scope => filePath . indexOf ( path . normalize ( scope ) ) !== - 1 )
205
- . pop ( ) ;
208
+ var scopePath = filePath . indexOf ( path . normalize ( libRoot ) ) == - 1 ? libRoot : filePath ;
206
209
207
210
// Return an object containing the name of the scope and the associated path.
208
211
return {
0 commit comments