MCPcopy
hub / github.com/desktop/desktop / verifyInjectedSassVariables

Function verifyInjectedSassVariables

script/validate-sass/validate-all.ts:5–51  ·  view source on GitHub ↗
(
  outRoot: string
)

Source from the content-addressed store, hash-verified

3import { listUnencodedSassVariables, SassVariable } from './validate-file'
4
5export 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}

Callers 1

build.tsFile · 0.90

Calls 4

filterMethod · 0.65
logMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected