From d98a34e744b74733066f6db8e0b1e6698ee89c9c Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Thu, 6 Apr 2023 14:45:27 +0100 Subject: [PATCH] Move config, lib, tasks into shared directory --- .../workflows/actions/install-node/action.yml | 1 + app/tsconfig.json | 8 +- docs/contributing/application-architecture.md | 26 +++--- docs/contributing/tasks.md | 2 +- lib/{ => helpers}/tsconfig.json | 0 package-lock.json | 89 +++++++++++++++++-- package.json | 4 +- package.json.unit.test.js | 2 +- {config => shared/config}/index.js | 0 {config => shared/config}/jest/.eslintrc.js | 0 .../config}/jest/browser/close.mjs | 0 .../config}/jest/browser/download.mjs | 0 .../config}/jest/browser/download.test.mjs | 0 .../config}/jest/browser/open.mjs | 0 .../config}/jest/environment/jsdom.mjs | 0 .../config}/jest/environment/puppeteer.mjs | 0 {config => shared/config}/jest/matchers.js | 0 .../config}/jest/server/start.mjs | 2 +- .../config}/jest/server/stop.mjs | 0 {config => shared/config}/package.json | 0 {config => shared/config}/paths.js | 4 +- {config => shared/config}/ports.js | 0 {config => shared/config}/tsconfig.json | 2 +- {lib => shared/lib}/.eslintrc.js | 0 {lib => shared/lib}/helpers/files.js | 0 .../lib}/helpers/files.unit.test.js | 0 {lib => shared/lib}/helpers/index.js | 0 {lib => shared/lib}/helpers/names.js | 0 .../lib}/helpers/names.unit.test.mjs | 0 {lib => shared/lib}/helpers/puppeteer.js | 0 {lib => shared/lib}/helpers/tests.js | 0 {lib => shared/lib}/index.js | 0 {lib => shared/lib}/package.json | 0 shared/lib/tsconfig.json | 7 ++ {tasks => shared/tasks}/assets.mjs | 0 {tasks => shared/tasks}/browser.mjs | 0 {tasks => shared/tasks}/build/dist.mjs | 0 {tasks => shared/tasks}/build/dist.test.mjs | 0 {tasks => shared/tasks}/build/index.mjs | 0 {tasks => shared/tasks}/build/package.mjs | 0 .../tasks}/build/package.test.mjs | 0 {tasks => shared/tasks}/components.mjs | 0 {tasks => shared/tasks}/configs.mjs | 0 {tasks => shared/tasks}/files.mjs | 0 .../tasks}/helpers/task-arguments.mjs | 0 .../helpers/task-arguments.unit.test.mjs | 0 {tasks => shared/tasks}/index.mjs | 0 {tasks => shared/tasks}/npm.mjs | 0 {tasks => shared/tasks}/package.json | 0 {tasks => shared/tasks}/scripts.mjs | 0 {tasks => shared/tasks}/styles.mjs | 0 {tasks => shared/tasks}/task.mjs | 0 {tasks => shared/tasks}/tsconfig.json | 2 +- src/tsconfig.json | 2 +- tsconfig.json | 8 +- 55 files changed, 125 insertions(+), 34 deletions(-) rename lib/{ => helpers}/tsconfig.json (100%) rename {config => shared/config}/index.js (100%) rename {config => shared/config}/jest/.eslintrc.js (100%) rename {config => shared/config}/jest/browser/close.mjs (100%) rename {config => shared/config}/jest/browser/download.mjs (100%) rename {config => shared/config}/jest/browser/download.test.mjs (100%) rename {config => shared/config}/jest/browser/open.mjs (100%) rename {config => shared/config}/jest/environment/jsdom.mjs (100%) rename {config => shared/config}/jest/environment/puppeteer.mjs (100%) rename {config => shared/config}/jest/matchers.js (100%) rename {config => shared/config}/jest/server/start.mjs (70%) rename {config => shared/config}/jest/server/stop.mjs (100%) rename {config => shared/config}/package.json (100%) rename {config => shared/config}/paths.js (78%) rename {config => shared/config}/ports.js (100%) rename {config => shared/config}/tsconfig.json (50%) rename {lib => shared/lib}/.eslintrc.js (100%) rename {lib => shared/lib}/helpers/files.js (100%) rename {lib => shared/lib}/helpers/files.unit.test.js (100%) rename {lib => shared/lib}/helpers/index.js (100%) rename {lib => shared/lib}/helpers/names.js (100%) rename {lib => shared/lib}/helpers/names.unit.test.mjs (100%) rename {lib => shared/lib}/helpers/puppeteer.js (100%) rename {lib => shared/lib}/helpers/tests.js (100%) rename {lib => shared/lib}/index.js (100%) rename {lib => shared/lib}/package.json (100%) create mode 100644 shared/lib/tsconfig.json rename {tasks => shared/tasks}/assets.mjs (100%) rename {tasks => shared/tasks}/browser.mjs (100%) rename {tasks => shared/tasks}/build/dist.mjs (100%) rename {tasks => shared/tasks}/build/dist.test.mjs (100%) rename {tasks => shared/tasks}/build/index.mjs (100%) rename {tasks => shared/tasks}/build/package.mjs (100%) rename {tasks => shared/tasks}/build/package.test.mjs (100%) rename {tasks => shared/tasks}/components.mjs (100%) rename {tasks => shared/tasks}/configs.mjs (100%) rename {tasks => shared/tasks}/files.mjs (100%) rename {tasks => shared/tasks}/helpers/task-arguments.mjs (100%) rename {tasks => shared/tasks}/helpers/task-arguments.unit.test.mjs (100%) rename {tasks => shared/tasks}/index.mjs (100%) rename {tasks => shared/tasks}/npm.mjs (100%) rename {tasks => shared/tasks}/package.json (100%) rename {tasks => shared/tasks}/scripts.mjs (100%) rename {tasks => shared/tasks}/styles.mjs (100%) rename {tasks => shared/tasks}/task.mjs (100%) rename {tasks => shared/tasks}/tsconfig.json (60%) diff --git a/.github/workflows/actions/install-node/action.yml b/.github/workflows/actions/install-node/action.yml index 38189f80c7d..eeaacdd7fe0 100644 --- a/.github/workflows/actions/install-node/action.yml +++ b/.github/workflows/actions/install-node/action.yml @@ -16,6 +16,7 @@ runs: app/node_modules docs/examples/*/node_modules package/node_modules + shared/*/node_modules - name: Setup Node.js uses: ./.github/workflows/actions/setup-node diff --git a/app/tsconfig.json b/app/tsconfig.json index 03195d2d812..30e443a2a0f 100644 --- a/app/tsconfig.json +++ b/app/tsconfig.json @@ -1,5 +1,11 @@ { "extends": "../tsconfig.base.json", - "include": ["**/*.js", "**/*.mjs", "../config", "../lib", "../tasks"], + "include": [ + "**/*.js", + "**/*.mjs", + "../shared/config", + "../shared/lib", + "../shared/tasks" + ], "exclude": ["./dist/**"] } diff --git a/docs/contributing/application-architecture.md b/docs/contributing/application-architecture.md index 2e5d78b84bc..bfa2de09f0f 100644 --- a/docs/contributing/application-architecture.md +++ b/docs/contributing/application-architecture.md @@ -8,10 +8,6 @@ Binary/executable files (i.e. bash scripts) mainly used in the [publishing process](/docs/releasing/publishing.md). -- `config/` - - Configuration files for the review app and [Jest](https://github.com/facebook/jest). - - `dist/` **contains auto-generated files** Standalone builds of govuk-frontend. Provides a way to consume govuk-frontend without using npm. @@ -20,19 +16,25 @@ Documentation files. -- `lib/` - - Application modules and helpers. - - `package/` **contains auto-generated files** package published on npm. Consume all of govuk-frontend through a single package. -- `src/` +- `shared/` - Source files. See README.md in the src directory for details. + - `config/` + + Configuration files for the review app and [Jest](https://github.com/facebook/jest). -- `tasks/` + - `lib/` - Application modules and helpers. See [tasks](tasks.md) for more information about the tasks. + Application modules and helpers. + + - `tasks/` + + See [tasks](tasks.md) for more information about the tasks. + +- `src/` + + Source files. See README.md in the src directory for details. diff --git a/docs/contributing/tasks.md b/docs/contributing/tasks.md index 8a2aa2e7799..8a990aabbd4 100644 --- a/docs/contributing/tasks.md +++ b/docs/contributing/tasks.md @@ -53,7 +53,7 @@ npm scripts are defined in `package.json`. These trigger a number of Gulp tasks. ## Gulp tasks -Project Gulp tasks are defined in [`gulpfile.mjs`](../../gulpfile.mjs) and the [`tasks/`](../../tasks) folder. +Project Gulp tasks are defined in [`gulpfile.mjs`](../../gulpfile.mjs) and the [`tasks/`](../../shared/tasks) folder. **`gulp --tasks`** diff --git a/lib/tsconfig.json b/lib/helpers/tsconfig.json similarity index 100% rename from lib/tsconfig.json rename to lib/helpers/tsconfig.json diff --git a/package-lock.json b/package-lock.json index 2dcfcf34b27..62c694b65f7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,11 +9,9 @@ "license": "MIT", "workspaces": [ "app", - "config", "docs/examples/*", - "lib", "package", - "tasks" + "shared/*" ], "dependencies": { "@babel/core": "^7.21.4", @@ -157,6 +155,7 @@ }, "config": { "name": "govuk-frontend-config", + "extraneous": true, "license": "MIT", "dependencies": { "govuk-frontend": "*", @@ -430,6 +429,7 @@ } }, "lib": { + "extraneous": true, "license": "MIT", "dependencies": { "cheerio": "^1.0.0-rc.12", @@ -11852,11 +11852,11 @@ "link": true }, "node_modules/govuk-frontend-config": { - "resolved": "config", + "resolved": "shared/config", "link": true }, "node_modules/govuk-frontend-lib": { - "resolved": "lib", + "resolved": "shared/lib", "link": true }, "node_modules/govuk-frontend-review": { @@ -11864,7 +11864,7 @@ "link": true }, "node_modules/govuk-frontend-tasks": { - "resolved": "tasks", + "resolved": "shared/tasks", "link": true }, "node_modules/govuk-frontend-webpack-boilerplate": { @@ -25713,8 +25713,85 @@ "node": ">= 4.2.0" } }, + "shared/config": { + "license": "MIT", + "dependencies": { + "govuk-frontend": "*", + "jest-axe": "^7.0.1", + "jest-dev-server": "^8.0.5", + "jest-environment-jsdom": "^29.5.0", + "jest-environment-node-single-context": "^29.0.0", + "jest-environment-puppeteer": "^8.0.6", + "puppeteer": "^19.8.2" + }, + "engines": { + "node": "^18.12.0", + "npm": "^8.1.0 || ^9.1.0" + } + }, + "shared/lib": { + "license": "MIT", + "dependencies": { + "cheerio": "^1.0.0-rc.12", + "front-matter": "^4.0.2", + "glob": "^10.0.0", + "jest-axe": "^7.0.1", + "js-yaml": "^4.1.0", + "minimatch": "^8.0.3", + "nunjucks": "^3.2.3", + "outdent": "^0.8.0" + }, + "devDependencies": { + "puppeteer": "^19.8.2", + "sass-embedded": "^1.60.0" + }, + "engines": { + "node": "^18.12.0", + "npm": "^8.1.0 || ^9.1.0" + }, + "optionalDependencies": { + "govuk-frontend-config": "*" + } + }, + "shared/tasks": { + "license": "MIT", + "dependencies": { + "@npmcli/run-script": "^6.0.0", + "@percy/puppeteer": "^2.0.2", + "@percy/sdk-utils": "^1.21.0", + "chalk": "^5.2.0", + "cpy": "^9.0.1", + "del": "^7.0.0", + "gulp": "^4.0.2", + "gulp-cli": "^2.3.0", + "js-yaml": "^4.1.0", + "nunjucks": "^3.2.3", + "plugin-error": "^2.0.1", + "postcss": "^8.4.21", + "postcss-load-config": "^4.0.1", + "puppeteer": "^19.8.2", + "rollup": "0.59.4", + "rollup-plugin-replace": "^2.2.0", + "sass-embedded": "^1.60.0", + "slash": "^5.0.0", + "terser": "^5.16.8", + "yargs-parser": "^21.1.1" + }, + "devDependencies": { + "@percy/cli": "^1.21.0" + }, + "engines": { + "node": "^18.12.0", + "npm": "^8.1.0 || ^9.1.0" + }, + "optionalDependencies": { + "govuk-frontend-config": "*", + "govuk-frontend-lib": "*" + } + }, "tasks": { "name": "govuk-frontend-tasks", + "extraneous": true, "license": "MIT", "dependencies": { "@npmcli/run-script": "^6.0.0", diff --git a/package.json b/package.json index e50c1bcfccf..4b32259aba5 100644 --- a/package.json +++ b/package.json @@ -9,11 +9,9 @@ "license": "MIT", "workspaces": [ "app", - "config", "docs/examples/*", - "lib", "package", - "tasks" + "shared/*" ], "scripts": { "postinstall": "npm ls --depth=0", diff --git a/package.json.unit.test.js b/package.json.unit.test.js index e710ffa3067..9d1c2ffcb24 100644 --- a/package.json.unit.test.js +++ b/package.json.unit.test.js @@ -1,5 +1,5 @@ const packageLockJson = require('./package-lock.json') -const packageJson = require('./tasks/package.json') +const packageJson = require('./shared/tasks/package.json') describe('because rollup 0.60 drops support for Internet Explorer 8', () => { describe('rollup', () => { diff --git a/config/index.js b/shared/config/index.js similarity index 100% rename from config/index.js rename to shared/config/index.js diff --git a/config/jest/.eslintrc.js b/shared/config/jest/.eslintrc.js similarity index 100% rename from config/jest/.eslintrc.js rename to shared/config/jest/.eslintrc.js diff --git a/config/jest/browser/close.mjs b/shared/config/jest/browser/close.mjs similarity index 100% rename from config/jest/browser/close.mjs rename to shared/config/jest/browser/close.mjs diff --git a/config/jest/browser/download.mjs b/shared/config/jest/browser/download.mjs similarity index 100% rename from config/jest/browser/download.mjs rename to shared/config/jest/browser/download.mjs diff --git a/config/jest/browser/download.test.mjs b/shared/config/jest/browser/download.test.mjs similarity index 100% rename from config/jest/browser/download.test.mjs rename to shared/config/jest/browser/download.test.mjs diff --git a/config/jest/browser/open.mjs b/shared/config/jest/browser/open.mjs similarity index 100% rename from config/jest/browser/open.mjs rename to shared/config/jest/browser/open.mjs diff --git a/config/jest/environment/jsdom.mjs b/shared/config/jest/environment/jsdom.mjs similarity index 100% rename from config/jest/environment/jsdom.mjs rename to shared/config/jest/environment/jsdom.mjs diff --git a/config/jest/environment/puppeteer.mjs b/shared/config/jest/environment/puppeteer.mjs similarity index 100% rename from config/jest/environment/puppeteer.mjs rename to shared/config/jest/environment/puppeteer.mjs diff --git a/config/jest/matchers.js b/shared/config/jest/matchers.js similarity index 100% rename from config/jest/matchers.js rename to shared/config/jest/matchers.js diff --git a/config/jest/server/start.mjs b/shared/config/jest/server/start.mjs similarity index 70% rename from config/jest/server/start.mjs rename to shared/config/jest/server/start.mjs index d0bd411772b..580f3546fab 100644 --- a/config/jest/server/start.mjs +++ b/shared/config/jest/server/start.mjs @@ -1,6 +1,6 @@ import { setup } from 'jest-dev-server' -import config from '../../../jest-dev-server.config.js' +import config from '../../../../jest-dev-server.config.js' // Start web server(s) export default async () => { diff --git a/config/jest/server/stop.mjs b/shared/config/jest/server/stop.mjs similarity index 100% rename from config/jest/server/stop.mjs rename to shared/config/jest/server/stop.mjs diff --git a/config/package.json b/shared/config/package.json similarity index 100% rename from config/package.json rename to shared/config/package.json diff --git a/config/paths.js b/shared/config/paths.js similarity index 78% rename from config/paths.js rename to shared/config/paths.js index 8c808b5c7a6..1e0c7a66d2f 100644 --- a/config/paths.js +++ b/shared/config/paths.js @@ -1,7 +1,7 @@ -const { dirname, join } = require('path') +const { join, resolve } = require('path') // Repository root directory -const rootPath = dirname(__dirname) +const rootPath = resolve(__dirname, '../../') /** * Config paths diff --git a/config/ports.js b/shared/config/ports.js similarity index 100% rename from config/ports.js rename to shared/config/ports.js diff --git a/config/tsconfig.json b/shared/config/tsconfig.json similarity index 50% rename from config/tsconfig.json rename to shared/config/tsconfig.json index 5248e5b80ff..fe8b62ccb99 100644 --- a/config/tsconfig.json +++ b/shared/config/tsconfig.json @@ -1,4 +1,4 @@ { - "extends": "../tsconfig.base.json", + "extends": "../../tsconfig.base.json", "include": ["**/*.js", "**/*.mjs"] } diff --git a/lib/.eslintrc.js b/shared/lib/.eslintrc.js similarity index 100% rename from lib/.eslintrc.js rename to shared/lib/.eslintrc.js diff --git a/lib/helpers/files.js b/shared/lib/helpers/files.js similarity index 100% rename from lib/helpers/files.js rename to shared/lib/helpers/files.js diff --git a/lib/helpers/files.unit.test.js b/shared/lib/helpers/files.unit.test.js similarity index 100% rename from lib/helpers/files.unit.test.js rename to shared/lib/helpers/files.unit.test.js diff --git a/lib/helpers/index.js b/shared/lib/helpers/index.js similarity index 100% rename from lib/helpers/index.js rename to shared/lib/helpers/index.js diff --git a/lib/helpers/names.js b/shared/lib/helpers/names.js similarity index 100% rename from lib/helpers/names.js rename to shared/lib/helpers/names.js diff --git a/lib/helpers/names.unit.test.mjs b/shared/lib/helpers/names.unit.test.mjs similarity index 100% rename from lib/helpers/names.unit.test.mjs rename to shared/lib/helpers/names.unit.test.mjs diff --git a/lib/helpers/puppeteer.js b/shared/lib/helpers/puppeteer.js similarity index 100% rename from lib/helpers/puppeteer.js rename to shared/lib/helpers/puppeteer.js diff --git a/lib/helpers/tests.js b/shared/lib/helpers/tests.js similarity index 100% rename from lib/helpers/tests.js rename to shared/lib/helpers/tests.js diff --git a/lib/index.js b/shared/lib/index.js similarity index 100% rename from lib/index.js rename to shared/lib/index.js diff --git a/lib/package.json b/shared/lib/package.json similarity index 100% rename from lib/package.json rename to shared/lib/package.json diff --git a/shared/lib/tsconfig.json b/shared/lib/tsconfig.json new file mode 100644 index 00000000000..5e941c80727 --- /dev/null +++ b/shared/lib/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../tsconfig.base.json", + "include": ["**/*.js", "**/*.mjs", "../config"], + "compilerOptions": { + "lib": ["ESNext", "DOM"] + } +} diff --git a/tasks/assets.mjs b/shared/tasks/assets.mjs similarity index 100% rename from tasks/assets.mjs rename to shared/tasks/assets.mjs diff --git a/tasks/browser.mjs b/shared/tasks/browser.mjs similarity index 100% rename from tasks/browser.mjs rename to shared/tasks/browser.mjs diff --git a/tasks/build/dist.mjs b/shared/tasks/build/dist.mjs similarity index 100% rename from tasks/build/dist.mjs rename to shared/tasks/build/dist.mjs diff --git a/tasks/build/dist.test.mjs b/shared/tasks/build/dist.test.mjs similarity index 100% rename from tasks/build/dist.test.mjs rename to shared/tasks/build/dist.test.mjs diff --git a/tasks/build/index.mjs b/shared/tasks/build/index.mjs similarity index 100% rename from tasks/build/index.mjs rename to shared/tasks/build/index.mjs diff --git a/tasks/build/package.mjs b/shared/tasks/build/package.mjs similarity index 100% rename from tasks/build/package.mjs rename to shared/tasks/build/package.mjs diff --git a/tasks/build/package.test.mjs b/shared/tasks/build/package.test.mjs similarity index 100% rename from tasks/build/package.test.mjs rename to shared/tasks/build/package.test.mjs diff --git a/tasks/components.mjs b/shared/tasks/components.mjs similarity index 100% rename from tasks/components.mjs rename to shared/tasks/components.mjs diff --git a/tasks/configs.mjs b/shared/tasks/configs.mjs similarity index 100% rename from tasks/configs.mjs rename to shared/tasks/configs.mjs diff --git a/tasks/files.mjs b/shared/tasks/files.mjs similarity index 100% rename from tasks/files.mjs rename to shared/tasks/files.mjs diff --git a/tasks/helpers/task-arguments.mjs b/shared/tasks/helpers/task-arguments.mjs similarity index 100% rename from tasks/helpers/task-arguments.mjs rename to shared/tasks/helpers/task-arguments.mjs diff --git a/tasks/helpers/task-arguments.unit.test.mjs b/shared/tasks/helpers/task-arguments.unit.test.mjs similarity index 100% rename from tasks/helpers/task-arguments.unit.test.mjs rename to shared/tasks/helpers/task-arguments.unit.test.mjs diff --git a/tasks/index.mjs b/shared/tasks/index.mjs similarity index 100% rename from tasks/index.mjs rename to shared/tasks/index.mjs diff --git a/tasks/npm.mjs b/shared/tasks/npm.mjs similarity index 100% rename from tasks/npm.mjs rename to shared/tasks/npm.mjs diff --git a/tasks/package.json b/shared/tasks/package.json similarity index 100% rename from tasks/package.json rename to shared/tasks/package.json diff --git a/tasks/scripts.mjs b/shared/tasks/scripts.mjs similarity index 100% rename from tasks/scripts.mjs rename to shared/tasks/scripts.mjs diff --git a/tasks/styles.mjs b/shared/tasks/styles.mjs similarity index 100% rename from tasks/styles.mjs rename to shared/tasks/styles.mjs diff --git a/tasks/task.mjs b/shared/tasks/task.mjs similarity index 100% rename from tasks/task.mjs rename to shared/tasks/task.mjs diff --git a/tasks/tsconfig.json b/shared/tasks/tsconfig.json similarity index 60% rename from tasks/tsconfig.json rename to shared/tasks/tsconfig.json index 14e1460e532..4073f258b8d 100644 --- a/tasks/tsconfig.json +++ b/shared/tasks/tsconfig.json @@ -1,4 +1,4 @@ { - "extends": "../tsconfig.base.json", + "extends": "../../tsconfig.base.json", "include": ["**/*.js", "**/*.mjs", "../config", "../lib"] } diff --git a/src/tsconfig.json b/src/tsconfig.json index 16a9ea8e51c..a5964985879 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -1,6 +1,6 @@ { "extends": "../tsconfig.base.json", - "include": ["**/*.js", "**/*.mjs", "../config", "../lib"], + "include": ["**/*.js", "**/*.mjs", "../shared/config", "../shared/lib"], "compilerOptions": { "lib": ["ESNext", "DOM"], "target": "ES2015", diff --git a/tsconfig.json b/tsconfig.json index 08c5337c0c8..17678e9b470 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,16 +6,16 @@ "path": "./app" }, { - "path": "./config" + "path": "./shared/config" }, { - "path": "./lib" + "path": "./shared/lib" }, { - "path": "./src" + "path": "./shared/tasks" }, { - "path": "./tasks" + "path": "./src" } ] }