()
| 4 | |
| 5 | class ConditionalImportFixer extends BaseFixer { |
| 6 | async run() { |
| 7 | const files = []; |
| 8 | const scss = fs.readFileSync(this.filePath, 'utf8'); |
| 9 | const result = await this.processCss(scss, this.transformConditionalImport()); |
| 10 | files.push({ filePath: this.filePath, data: result.css }); |
| 11 | const imports = this.mapFilesToRootFile(result.messages, this.filePath); |
| 12 | const toUpdateNestedImports = []; |
| 13 | for await (const fileImport of imports) { |
| 14 | const importFile = this.findImportedFile(fileImport.file, fileImport.rootFile); |
| 15 | const importFileScss = fs.readFileSync(importFile, { encoding: 'utf8' }); |
| 16 | const nestedImportFiles = await this.getNesterImportFiles(importFileScss, importFile); |
| 17 | if (nestedImportFiles) { |
| 18 | imports.push(...nestedImportFiles); |
| 19 | // at this moment I don't know if this is an actual mixin |
| 20 | toUpdateNestedImports.push(...nestedImportFiles); |
| 21 | } else { |
| 22 | const mixinFile = await this.processCss( |
| 23 | importFileScss, |
| 24 | this.transformRootToMixin(fileImport.file), |
| 25 | ); |
| 26 | files.push({ |
| 27 | filePath: importFile, |
| 28 | data: mixinFile.css, |
| 29 | }); |
| 30 | } |
| 31 | } |
| 32 | if (this.shouldUpdateMixinNameInRootFile(toUpdateNestedImports)) { |
| 33 | const mixins = this.mapMixinNameToImportFileName(result.mixins); |
| 34 | // the target file is not updated right away, so the fresh content is in files object |
| 35 | this.updateRootFileMixinName(files, toUpdateNestedImports, mixins); |
| 36 | } |
| 37 | return files; |
| 38 | } |
| 39 | |
| 40 | shouldUpdateMixinNameInRootFile(toUpdateNestedImports) { |
| 41 | return toUpdateNestedImports.length > 0; |
nothing calls this directly
no test coverage detected