Skip to content

Commit

Permalink
Ensure Sass $govuk-* URL context variables are always set
Browse files Browse the repository at this point in the history
This gives internal pages their own `$govuk-assets-path` Sass variable to internal GOV.UK Frontend to align with Nunjucks

Whilst plugin Sass can continue to use `/plugin-assets`
  • Loading branch information
colinrotherham committed Sep 14, 2023
1 parent b94af0b commit f00177e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
2 changes: 0 additions & 2 deletions lib/assets/sass/manage-prototype.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
$govuk-assets-path: '/manage-prototype/dependencies/govuk-frontend/govuk/assets/';

// Import GOV.UK Frontend within the kit dependency
@import ".tmp/sass/kit-frontend-dependency";

Expand Down
47 changes: 34 additions & 13 deletions lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,18 @@ function sassInclude (filePath) {

function sassKitFrontendDependency () {
const timer = startPerformanceTimer()

const internalGovUkFrontendDir = getInternalGovukFrontendDir()
const internalGovUkFrontendConfig = fse.readJsonSync(path.join(internalGovUkFrontendDir, 'govuk-prototype-kit.config.json'))
const fileContents = internalGovUkFrontendConfig.sass

const govukFrontendSass = internalGovUkFrontendConfig.sass
.map(sassPath => path.join(internalGovUkFrontendDir, sassPath))
.map(sassInclude)
.join('\n')

const fileContents = sassVariables('/manage-prototype/dependencies') +
govukFrontendSass
.map(sassInclude)
.join('\n')

ensureTempDirExists(tmpSassDir)
fse.writeFileSync(path.join(tmpSassDir, '_kit-frontend-dependency.scss'), fileContents)
endPerformanceTimer('sassKitFrontendDependency', timer)
Expand All @@ -116,37 +122,52 @@ function sassLegacyPatterns () {
.join('\n')
} else {
fileContents = `
/* Legacy patterns not included as govuk-frontend plugin not installed */
/* Legacy patterns not included as govuk-frontend plugin not installed */
`
}
fse.writeFileSync(path.join(tmpSassDir, '_legacy-patterns.scss'), fileContents)
endPerformanceTimer('sassLegacyPatterns', timer)
}

function sassPlugins () {
const timer = startPerformanceTimer()
function sassVariables (contextPath = '', isLegacyGovukFrontend = false) {
let fileContents = ''

// Keep $govuk-extensions-url-context for backwards compatibility
// TODO: remove in v14
fileContents += '$govuk-extensions-url-context: "/plugin-assets";\n'
fileContents += '$govuk-plugins-url-context: "/plugin-assets";\n'
fileContents += `$govuk-extensions-url-context: "${contextPath}";\n`
fileContents += `$govuk-plugins-url-context: "${contextPath}";\n`
fileContents += '$govuk-prototype-kit-major-version: 13;\n'
if (plugins.legacyGovukFrontendFixesNeeded()) {

// Patch missing 'init.scss' before GOV.UK Frontend v4.4.0
// in plugin versions, but will default to false for internal
if (isLegacyGovukFrontend) {
fileContents += '$govuk-global-styles: true !default;\n'
fileContents += '$govuk-new-link-styles: true !default;\n'
}
fileContents += plugins.getFileSystemPaths('sass')
.map(sassInclude)
.join('\n')

return fileContents
}

function sassPlugins () {
const timer = startPerformanceTimer()

const fileContents = sassVariables('/plugin-assets', plugins.legacyGovukFrontendFixesNeeded()) +
plugins.getFileSystemPaths('sass')
.map(sassInclude)
.join('\n')

ensureTempDirExists(tmpSassDir)
fse.writeFileSync(path.join(tmpSassDir, '_plugins.scss'), fileContents)
endPerformanceTimer('sassPlugins', timer)
}

function sassErrorPage () {
const timer = startPerformanceTimer()

const fileContents = sassVariables('/manage-prototype/dependencies') +
sassInclude(path.join(libSassDir, 'includes', '_error-page.scss'))

ensureTempDirExists(tmpSassDir)
const fileContents = sassInclude(path.join(libSassDir, 'includes', '_error-page.scss'))
fse.writeFileSync(path.join(tmpSassDir, 'error-page.scss'), fileContents)
endPerformanceTimer('sassErrorPage', timer)
}
Expand Down

0 comments on commit f00177e

Please sign in to comment.