Skip to content

Commit

Permalink
Prevent version number update during development
Browse files Browse the repository at this point in the history
  • Loading branch information
querkmachine authored and colinrotherham committed Mar 29, 2023
1 parent 60cda6d commit a0c375b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
23 changes: 13 additions & 10 deletions postcss.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import unopacity from 'postcss-unopacity'
import unrgba from 'postcss-unrgba'

import { pkg } from './config/index.js'
import { isDev } from './tasks/helpers/task-arguments.mjs'

/**
* PostCSS config
Expand Down Expand Up @@ -61,17 +62,19 @@ export default ({ from = '', to = '', env = 'production' }) => {
}

// Add GOV.UK Frontend release version
config.plugins.push({
postcssPlugin: 'govuk-frontend-version',
Declaration: {
// Find CSS declaration for version, update value
// https://github.com/postcss/postcss/blob/main/docs/writing-a-plugin.md
// https://postcss.org/api/#declaration
'--govuk-frontend-version': (decl) => {
decl.value = `"${pkg.version}"`
if (!isDev) {
config.plugins.push({
postcssPlugin: 'govuk-frontend-version',
Declaration: {
// Find CSS declaration for version, update value
// https://github.com/postcss/postcss/blob/main/docs/writing-a-plugin.md
// https://postcss.org/api/#declaration
'--govuk-frontend-version': (decl) => {
decl.value = `"${pkg.version}"`
}
}
}
})
})
}

// Always minify CSS
if (config.syntax !== scss) {
Expand Down
22 changes: 14 additions & 8 deletions tasks/scripts.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { pkg } from '../config/index.js'
import { getListing } from '../lib/file-helper.js'
import { componentPathToModuleName } from '../lib/helper-functions.js'

import { isDev } from './helpers/task-arguments.mjs'
import { assets } from './index.mjs'

/**
Expand Down Expand Up @@ -40,22 +41,27 @@ export async function compileJavaScript ([modulePath, { srcPath, destPath, fileP
const moduleSrcPath = join(srcPath, modulePath)
const moduleDestPath = join(destPath, filePath ? filePath(parse(modulePath)) : modulePath)

// Rollup plugins
const plugins = []

// Rollup output format
const format = moduleDestPath.endsWith('.mjs')
? 'es'
: 'umd'

if (!isDev) {
// Add GOV.UK Frontend release version
// @ts-expect-error "This expression is not callable" due to incorrect types
plugins.push(replace({
include: join(srcPath, 'common/govuk-frontend-version.mjs'),
values: { development: pkg.version }
}))
}

// Create Rollup bundle
const bundle = await rollup({
input: moduleSrcPath,
plugins: [
// Add GOV.UK Frontend release version
// @ts-expect-error "This expression is not callable" due to incorrect types
replace({
include: join(srcPath, 'common/govuk-frontend-version.mjs'),
values: { development: pkg.version }
})
],
plugins,

// Preserve JavaScript ESM import statements
experimentalPreserveModules: format === 'es'
Expand Down

0 comments on commit a0c375b

Please sign in to comment.