( outRoot: string )
| 3 | import { listUnencodedSassVariables, SassVariable } from './validate-file' |
| 4 | |
| 5 | export async function verifyInjectedSassVariables( |
| 6 | outRoot: string |
| 7 | ): Promise<void> { |
| 8 | if (process.env.NODE_ENV !== 'production') { |
| 9 | return |
| 10 | } |
| 11 | |
| 12 | console.log(`Checking all SASS variables have been encoded correctly…`) |
| 13 | |
| 14 | const root = path.dirname(outRoot) |
| 15 | |
| 16 | const allStyleSheets = path.join(outRoot, '*.css') |
| 17 | const stylesheets = glob.sync(allStyleSheets) |
| 18 | |
| 19 | const unencodedVariables = new Array<SassVariable>() |
| 20 | |
| 21 | for (const stylesheet of stylesheets) { |
| 22 | const relativePath = path.relative(root, stylesheet) |
| 23 | console.log(` Checking stylesheet: ${relativePath}…`) |
| 24 | const result = await listUnencodedSassVariables(stylesheet) |
| 25 | unencodedVariables.push(...result) |
| 26 | } |
| 27 | |
| 28 | if (unencodedVariables.length > 0) { |
| 29 | console.log( |
| 30 | `SASS variables were found in the generated stylesheets. This means some styles will not render as expected at runtime.` |
| 31 | ) |
| 32 | |
| 33 | for (const stylesheet of stylesheets) { |
| 34 | const matches = unencodedVariables.filter(v => v.fileName === stylesheet) |
| 35 | |
| 36 | if (matches.length > 0) { |
| 37 | console.log(`In file: ${stylesheet}`) |
| 38 | |
| 39 | matches.forEach(v => |
| 40 | console.log(` - Line ${v.lineNumber}: '${v.text}'`) |
| 41 | ) |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | console.log( |
| 46 | `Look for the source of these styles under app/styles/ and ensure they are wrapped in a '#{}'.` |
| 47 | ) |
| 48 | |
| 49 | throw new Error() |
| 50 | } |
| 51 | } |
no test coverage detected