Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove built govuk-frontend from committed files #3498

Merged
merged 13 commits into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 6 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ module.exports = {
'never', {
startLines: 1
}
]
],

// Ignore `govuk-frontend` exports as they require auto-generated files
'import/no-unresolved': ['error', { ignore: ['govuk-frontend'] }],
'n/no-missing-import': ['error', { allowModules: ['govuk-frontend'] }],
'n/no-missing-require': ['error', { allowModules: ['govuk-frontend'] }]
},
settings: {
jsdoc: {
Expand Down
55 changes: 55 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,61 @@ This change was made in [pull request #3599: Enable new link styles by default](

### Breaking changes

You must make the following changes when you migrate to this release, or your service might break.

#### Update package file paths
romaricpascal marked this conversation as resolved.
Show resolved Hide resolved

In preparation for additional build targets, we've moved our package files into a directory called `dist`.

##### Node.js and other bundlers

Replace `govuk-frontend/govuk` with `govuk-frontend/dist/govuk` in any JavaScript `require()` or `import` file paths.

For example using `require()`:

```js
const Button = require('govuk-frontend/dist/govuk/components/button/button')
```

For example using `import`:

```js
import Button from 'govuk-frontend/dist/govuk-esm/components/button/button.mjs'
```

##### If you’re using Sass

Replace `govuk-frontend/govuk` with `govuk-frontend/dist/govuk` in any [Sass](https://sass-lang.com/) `@import` paths.

For example:

```scss
@import "node_modules/govuk-frontend/dist/govuk/all";
```

If you’ve [added `node_modules/govuk-frontend` as a Sass import path](https://frontend.design-system.service.gov.uk/importing-css-assets-and-javascript/#simplify-sass-import-paths), update it with the `/dist` suffix:

```js
loadPaths: [
'node_modules/govuk-frontend/dist'
]
```

##### If you’re using Nunjucks

Replace `govuk-frontend` with `govuk-frontend/dist` in any [`nunjucks.configure()`](https://mozilla.github.io/nunjucks/api.html#configure) search paths:

```js
nunjucks.configure([
'node_modules/govuk-frontend/dist'
])
```

These changes were made in the following pull requests:

- [#3491: Update Review app to import `govuk-frontend` via local package](https://github.com/alphagov/govuk-frontend/pull/3491)
- [#3498: Remove built `dist` and `package` from source](https://github.com/alphagov/govuk-frontend/pull/3498)

#### "Compatibility mode" features are no longer supported

GOV.UK Frontend no longer supports compatibility with [our old frameworks](https://frontend.design-system.service.gov.uk/migrating-from-legacy-products/#migrate-from-our-old-frameworks): GOV.UK Elements, GOV.UK Template and GOV.UK Frontend Toolkit. You can no longer incrementally add GOV.UK Frontend to an existing service using one of these previous frameworks. We have removed the following Sass variables and one mixin which controlled compatibility mode:
Expand Down
4 changes: 2 additions & 2 deletions bin/build-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -e

# Check if there are unexpected changes. Changes to CHANGELOG.md, package.json
# and package-lock.json files are expected as part of the normal release process.
changes="$(git status --porcelain -- ':!CHANGELOG.md' ':!packages/govuk-frontend/dist/package.json' ':!package-lock.json')"
changes="$(git status --porcelain -- ':!CHANGELOG.md' ':!packages/govuk-frontend/package.json' ':!package-lock.json')"
if [[ -n $changes ]]; then
echo "⚠ Unexpected changes in your working directory:"
echo "$changes"
Expand All @@ -30,7 +30,7 @@ npm run test
npm run build:package
npm run build:release

ALL_PACKAGE_VERSION=$(node -p "require('./packages/govuk-frontend/dist/package.json').version")
ALL_PACKAGE_VERSION=$(node -p "require('./packages/govuk-frontend/package.json').version")
TAG="v$ALL_PACKAGE_VERSION"
CURRENT_BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)

Expand Down
4 changes: 2 additions & 2 deletions bin/generate-npm-tag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ set -e
# Get highest tag published on Github
HIGHEST_PUBLISHED_VERSION=$(git tag --list 2>/dev/null | sort -V | tail -n1 2>/dev/null | sed 's/v//g')

# Extract tag version from ./packages/govuk-frontend/dist/package.json
CURRENT_VERSION=$(node -p "require('./packages/govuk-frontend/dist/package.json').version")
# Extract tag version from ./packages/govuk-frontend/package.json
CURRENT_VERSION=$(node -p "require('./packages/govuk-frontend/package.json').version")

function version() { echo "$@" | awk -F. '{ printf("%d%03d%03d\n", $1,$2,$3); }'; }

Expand Down
26 changes: 10 additions & 16 deletions bin/pre-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,19 @@ git checkout -b $BRANCH_NAME
# Build the package as normal
npm run build:package

# Check if the new built package has anything new to commit
if [[ -n $(git status --porcelain) ]]; then
echo "✍️ Commiting changed package"
git add packages/govuk-frontend/dist/
git add --force packages/govuk-frontend/govuk-prototype-kit.config.json

git commit -m "Release GOV.UK Frontend to '$BRANCH_NAME' for testing"
echo "✍️ Force commit package"
git add --force packages/govuk-frontend/dist/
git add --force packages/govuk-frontend/govuk-prototype-kit.config.json
git commit --allow-empty -m "Release GOV.UK Frontend to '$BRANCH_NAME' for testing"

# Create a local branch containing the packages/govuk-frontend/dist directory
echo "✨ Filter the branch to only the packages/govuk-frontend/dist/ directory..."
git filter-branch --force --subdirectory-filter packages/govuk-frontend/dist
# Create a local branch containing the packages/govuk-frontend directory
echo "✨ Filter the branch to only the packages/govuk-frontend/ directory..."
git filter-branch --force --subdirectory-filter packages/govuk-frontend
colinrotherham marked this conversation as resolved.
Show resolved Hide resolved

# Force the push of the branch to the remote Github origin
git push origin $BRANCH_NAME:$BRANCH_NAME --force
# Force the push of the branch to the remote Github origin
git push origin $BRANCH_NAME:$BRANCH_NAME --force

echo "⚠️ Branch pushed to '$BRANCH_NAME', do not edit this by hand."
else
echo "⚠️ No new changes to the package."
fi
echo "⚠️ Branch pushed to '$BRANCH_NAME', do not edit this by hand."

git checkout -

Expand Down
4 changes: 2 additions & 2 deletions bin/publish-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ cd packages/govuk-frontend/dist
echo "🗒 Package published!"
cd ..

# Extract tag version from ./packages/govuk-frontend/dist/package.json
ALL_PACKAGE_VERSION=$(node -p "require('./packages/govuk-frontend/dist/package.json').version")
# Extract tag version from ./packages/govuk-frontend/package.json
ALL_PACKAGE_VERSION=$(node -p "require('./packages/govuk-frontend/package.json').version")
TAG="v$ALL_PACKAGE_VERSION"

if [ $(git tag -l "$TAG") ]; then
Expand Down
2 changes: 1 addition & 1 deletion docs/contributing/tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ npm scripts are defined in `package.json`. These trigger a number of Gulp tasks.
- output files into `./dist`
- copy fonts and images
- compile JavaScript and Sass
- append version number from `packages/govuk-frontend/dist/package.json` to compiled JavaScript and CSS files
- append version number from `packages/govuk-frontend/package.json` to compiled JavaScript and CSS files
- runs `npm run postbuild:release` (which will test the output is correct)

## Gulp tasks
Expand Down
4 changes: 2 additions & 2 deletions docs/contributing/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ cd ../govuk-design-system
git checkout main
git pull
npm ci # note running `npm ci` after `npm link` will destroy the link.
npm link ../govuk-frontend/packages/govuk-frontend/dist/
npm link ../govuk-frontend/packages/govuk-frontend/
```

When you've finished testing, run this command to unlink the package:

```bash
npm unlink ../govuk-frontend/packages/govuk-frontend/dist/
npm unlink ../govuk-frontend/packages/govuk-frontend/
```

## 9. Tell us what you’ve tested and checked
Expand Down
2 changes: 1 addition & 1 deletion docs/contributing/versioning.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ This includes:

### npm package

The other primary way is through what is [published to npm](/packages/govuk-frontend/dist).
The other primary way is through what is [published to npm](/packages/govuk-frontend).

This includes:

Expand Down
14 changes: 8 additions & 6 deletions package-lock.json

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

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "govuk-frontend-repository",
"description": "Used only for the development of GOV.UK Frontend, see `packages/govuk-frontend/dist/package.json` for the published `package.json`",
"description": "Used only for the development of GOV.UK Frontend, see `packages/govuk-frontend/package.json` for the published `package.json`",
"engines": {
"node": "^18.12.0",
"npm": "^8.1.0 || ^9.1.0"
Expand All @@ -19,16 +19,17 @@
"build-release": "./bin/build-release.sh",
"publish-release": "./bin/publish-release.sh",
"pre-release": "./bin/pre-release.sh",
"predev": "npm run build --workspace govuk-frontend",
"dev": "concurrently \"npm run dev --workspace govuk-frontend-review\" \"npm run dev --workspace govuk-frontend\" --kill-others --names \"app,pkg\" --prefix-colors \"red.dim,blue.dim\"",
"build:app": "npm run build --workspace govuk-frontend-review",
"build:package": "npm run build:package --workspace govuk-frontend",
"build:release": "npm run build:release --workspace govuk-frontend",
"build:types": "tsc --build tsconfig.build.json",
"postbuild:package": "jest --color --selectProjects \"Build tasks\" --testMatch \"**/*package.test*\"",
"postbuild:release": "jest --color --selectProjects \"Build tasks\" --testMatch \"**/*release.test*\"",
"heroku-postbuild": "npm run build --workspace govuk-frontend-review",
"heroku-postbuild": "npm run build --workspace govuk-frontend --workspace govuk-frontend-review",
"postheroku-postbuild": "NPM_CONFIG_PRODUCTION=true npm ci --ignore-scripts --omit=optional --workspace govuk-frontend-review",
"pretest": "npm run build --workspace govuk-frontend-review",
"pretest": "npm run build --workspace govuk-frontend --workspace govuk-frontend-review",
"test": "jest --color --ignoreProjects \"Build tasks\" --maxWorkers=50%",
"lint": "npm run lint:editorconfig && npm run lint:prettier && npm run lint:js && npm run lint:scss",
"lint:editorconfig": "npm run lint:editorconfig:cli",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const router = express.Router()
* Add middleware to serve static assets
*/

router.use('/assets', express.static(packageNameToPath('govuk-frontend', 'src/govuk/assets')))
router.use('/assets', express.static(packageNameToPath('govuk-frontend', 'dist/govuk/assets')))
router.use('/javascripts', express.static(join(paths.app, 'dist/javascripts')))
router.use('/stylesheets', express.static(join(paths.app, 'dist/stylesheets')))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import beautify from 'js-beautify'
* @returns {string} Nunjucks code
*/
export function getHTMLCode (componentName, params) {
const templatePath = packageNameToPath('govuk-frontend', `src/govuk/components/${componentName}/template.njk`)
const templatePath = packageNameToPath('govuk-frontend', `dist/govuk/components/${componentName}/template.njk`)

// Render to HTML
const html = this.env.render(templatePath, { params }).trim()
Expand Down
4 changes: 2 additions & 2 deletions packages/govuk-frontend-review/src/common/nunjucks/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export function renderer (app) {
const appViews = [
join(paths.app, 'src/views/layouts'),
join(paths.app, 'src/views'),
packageNameToPath('govuk-frontend', 'src/govuk/components'),
packageNameToPath('govuk-frontend', 'src/govuk')
packageNameToPath('govuk-frontend', 'dist/govuk/components'),
packageNameToPath('govuk-frontend', 'dist/govuk')
]

// Initialise nunjucks environment
Expand Down
5 changes: 2 additions & 3 deletions packages/govuk-frontend-review/tasks/watch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ export const watch = (options) => gulp.parallel(
gulp.watch([
`${slash(paths.root)}/sassdoc.config.yaml`,
`${slash(paths.app)}/src/**/*.scss`,
`${slash(paths.package)}/src/govuk/**/*.scss`,
`!${slash(paths.package)}/src/govuk/vendor/*`
`${slash(paths.package)}/dist/govuk/**/*.scss`
], styles(options))
),

Expand All @@ -53,7 +52,7 @@ export const watch = (options) => gulp.parallel(
gulp.watch([
`${slash(paths.root)}/typedoc.config.js`,
`${slash(paths.app)}/src/javascripts/**/*.mjs`,
`${slash(paths.package)}/src/govuk/**/*.mjs`
`${slash(paths.package)}/dist/govuk-esm/**/*.mjs`
], scripts(options))
)
)
51 changes: 26 additions & 25 deletions packages/govuk-frontend/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,14 @@
const { resolve } = require('path')

module.exports = {
settings: {
node: {
version: '^18.12.0'
}
},
overrides: [
{
files: ['src/**/*.{cjs,js,mjs}'],
excludedFiles: ['**/*.test.{cjs,js,mjs}'],
env: {
browser: true
},
rules: {
'no-var': 'off',

// JSDoc blocks are mandatory
'jsdoc/require-jsdoc': [
'error', {
enableFixer: false,
require: {
ClassDeclaration: true,
ClassExpression: true,
FunctionExpression: true,
MethodDefinition: true
}
}
]
}
},
{
files: ['govuk/**/*.mjs'],
files: ['src/govuk/**/*.mjs'],
excludedFiles: ['**/*.test.mjs'],
parser: '@typescript-eslint/parser',
parserOptions: {
Expand All @@ -43,6 +25,9 @@ module.exports = {
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'plugin:es-x/restrict-to-es5'
],
env: {
browser: true
},
rules: {
// Allow unknown `.prototype` members until ES6 classes
'@typescript-eslint/no-unsafe-member-access': 'off',
Expand All @@ -51,7 +36,23 @@ module.exports = {
'@typescript-eslint/no-this-alias': 'off',

// Rollup transpiles modules to AMD export/define
'es-x/no-modules': 'off'
'es-x/no-modules': 'off',

// Allow `var` until let/const supported
'no-var': 'off',

// JSDoc blocks are mandatory
'jsdoc/require-jsdoc': [
'error', {
enableFixer: false,
require: {
ClassDeclaration: true,
ClassExpression: true,
FunctionExpression: true,
MethodDefinition: true
}
}
]
}
},
{
Expand Down
3 changes: 0 additions & 3 deletions packages/govuk-frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
govuk-prototype-kit.config.json

# Build output (committed)
!/dist
Loading