Skip to content

Commit

Permalink
Merge pull request #4996 from alphagov/remove-custom-sass-logger
Browse files Browse the repository at this point in the history
Replace custom Sass logger w/ silenceDeprecations
  • Loading branch information
36degrees committed May 22, 2024
2 parents 5531c99 + b46960e commit 63ecf74
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 78 deletions.
13 changes: 0 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion shared/tasks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"@govuk-frontend/lib": "*",
"@npmcli/run-script": "^7.0.4",
"@percy/puppeteer": "^2.0.2",
"chalk": "^5.3.0",
"gulp": "^4.0.2",
"gulp-cli": "^3.0.0",
"nunjucks": "^3.2.4",
Expand Down
65 changes: 1 addition & 64 deletions shared/tasks/styles.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { join, parse } from 'path'
import { paths } from '@govuk-frontend/config'
import { getListing } from '@govuk-frontend/lib/files'
import { packageTypeToPath } from '@govuk-frontend/lib/names'
import chalk from 'chalk'
import PluginError from 'plugin-error'
import postcss from 'postcss'
// eslint-disable-next-line import/default
Expand Down Expand Up @@ -82,6 +81,7 @@ export async function compileStylesheet([

// Turn off dependency warnings
quietDeps: true,
silenceDeprecations: ['slash-div'],

// Enable source maps
sourceMap: true,
Expand All @@ -100,14 +100,6 @@ export async function compileStylesheet([
join(paths.root, 'node_modules')
],

// Sass custom logger
logger: logger({
suppressed: [
'Using / for division is deprecated and will be removed in Dart Sass 2.0.0.',
'Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.'
]
}),

verbose: true
}))

Expand All @@ -134,61 +126,6 @@ export async function compileStylesheet([
await assets.write(moduleDestPath, result)
}

/**
* Sass custom logger
*
* @param {{ suppressed: string[] }} config - Logger config
* @returns {import('sass-embedded').Logger} Sass logger
*/
export const logger = (config) => ({
warn(message, options) {
let log = `${message}\n`

// Silence Sass suppressed warnings
if (config.suppressed.some((warning) => log.includes(warning))) {
return
}

// Check for code snippet
if (options.span) {
const { context, start, text } = options.span

// Line number with column width
const number = start.line + 1
const column = ' '.repeat(`${number}`.length)

// Source code warning arrows
const arrows = '^'
.repeat(text.length)
.padStart(context.indexOf(text) + text.length)

// Source code snippet showing warning in red
log += '\n\n'
log += `${chalk.blue(`${column} ╷`)}\n`
log += `${chalk.blue(`${number} │`)} ${context.replace(
text,
chalk.red(text)
)}`
log += `${chalk.blue(`${column} │`)} ${chalk.red(arrows)}\n`
log += `${chalk.blue(`${column} ╵`)}\n`
}

// Check for stack trace
options.stack
?.trim()
.split('\n')
.forEach((line) => {
log += ` ${line}\n`
})

const title = chalk.bold.yellow(
options.deprecation ? 'Deprecation Warning' : 'Warning'
)

console.warn(`${title}: ${log}`)
}
})

/**
* @typedef {import('./assets.mjs').AssetEntry} AssetEntry
* @typedef {import('./assets.mjs').AssetOutput} AssetOutput
Expand Down

0 comments on commit 63ecf74

Please sign in to comment.