Locate GOV.UK Frontend using require.resolve()#2306
Conversation
a73b9d9 to
3e9f2f7
Compare
e01676d to
592ea50
Compare
87e9690 to
7be56f0
Compare
6f8247b to
c909c86
Compare
|
I've moved the GOV.UK Frontend v5 preview commits to another branch Installing the preview from GitHub via npm install --save "alphagov/govuk-frontend#6d1a4ef0a"Not sure if a few Test output is looking a lot better now with some new changes pushed |
|
Pushed again with the GOV.UK Frontend v5 preview |
237d632 to
6f55f04
Compare
6f55f04 to
65a2e3e
Compare
server.js
Outdated
| // Set up GOV.UK Frontend relative paths | ||
| app.locals.govukFrontend = { | ||
| assetPath: govukFrontend.assetPath, | ||
| scripts: govukFrontend.config?.scripts || [] | ||
| } |
There was a problem hiding this comment.
@nataliecarey I think these lines need a suggestion
As written, Nunjucks views will get govukFrontend set to the internal GOV.UK Frontend version
Is there a router/middleware approach we can use to set:
- Set Nunjucks local
govukFrontendto "internal version" by default - Set Nunjucks local
govukFrontendto "plugin version" in plugin pages only
There was a problem hiding this comment.
Turns out Nunjucks, Sass and the error server had overlapping GOV.UK Frontend versions:
But now they're separated I've added separate locals for each:
// Add GOV.UK Frontend paths to Nunjucks locals
app.locals.govukFrontend = govukFrontend
app.locals.govukFrontendInternal = govukFrontendInternalThis allows prototype pages and management pages to clearly use their own versions:
{%- set assetPath = '/manage-prototype/dependencies/govuk-frontend' + govukFrontendInternal.assetPath -%}Or for govuk-branded.njk it can be overridden or default to the plugin version:
{%- set assetPath = assetPath | default('/plugin-assets/govuk-frontend' + govukFrontend.assetPath) -%}60af033 to
5d73dd9
Compare
3ec7f0f to
88a76ec
Compare
| // GOV.UK Frontend plugin config | ||
| config: fse.readJsonSync(path.join(baseDir, 'govuk-prototype-kit.config.json'), { | ||
| throws: false | ||
| }) |
There was a problem hiding this comment.
@BenSurgisonGDS has suggested a new getScriptsAndAssetsConfig() utility for this
Couldn't find a "sync" way using an existing helper so might be a better option
7291342 to
79bbbe4
Compare
79bbbe4 to
ed36da2
Compare
|
Looks good to me, just needs a changelog entry. |
require.resolve()
Replaces `getInternalGovukFrontendDir()` with `govukFrontendPaths()` 1. Prefers internal package in packageDir, then projectDir 2. Prefers plugin package in projectDir, then packageDir
Nunjucks locals have been added to prepare for a future GOV.UK Frontend v5 plugin update with a different directory structure
ed36da2 to
4a40024
Compare
This PR ensures we locate all previously hard-coded GOV.UK Frontend paths
This is in preparation for path changes between v4 (current) and v5 (upcoming) releases:
GOV.UK Frontend v4
node_modules/govuk-frontendnode_modules/govuk-frontend/govuk/all.jsnode_modules/govuk-frontend/govukGOV.UK Frontend v5
node_modules/govuk-frontendnode_modules/govuk-frontend/dist/govuk/all.bundle.jsnode_modules/govuk-frontend/dist/govukPartially closes #2293 and resolves alphagov/govuk-frontend#3759