From 81f842162643c86be3b29a2cc204aa4a168b72bf Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Thu, 18 May 2023 12:21:25 +0100 Subject: [PATCH 1/9] Fix check for missing `fileContents` in files tasks --- shared/tasks/files.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared/tasks/files.mjs b/shared/tasks/files.mjs index c0a2b7a2d4..131057a996 100644 --- a/shared/tasks/files.mjs +++ b/shared/tasks/files.mjs @@ -45,8 +45,8 @@ export async function version (assetPath, options) { export async function write (assetPath, { destPath, filePath, fileContents }) { const assetDestPath = join(destPath, filePath ? filePath(parse(assetPath)) : assetPath) - if (!fileContents) { - throw new Error("Option 'fileContents' required") + if (!destPath || !fileContents) { + throw new Error("Options 'destPath' and 'fileContents' required") } await mkdir(dirname(assetDestPath), { recursive: true }) From 1518cdbf98a7e87057758a2bde1e81da497bb4cc Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Thu, 18 May 2023 12:19:17 +0100 Subject: [PATCH 2/9] Remove unused `ignore` option from files tasks --- shared/tasks/assets.mjs | 1 - shared/tasks/files.mjs | 12 ++++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/shared/tasks/assets.mjs b/shared/tasks/assets.mjs index aebd381e11..f0380a2c9b 100644 --- a/shared/tasks/assets.mjs +++ b/shared/tasks/assets.mjs @@ -84,7 +84,6 @@ export async function write (filePath, result) { * @typedef {object} AssetFileOptions * @property {(file: import('path').ParsedPath) => string} [filePath] - File path formatter * @property {(contents?: string) => Promise} [fileContents] - File contents formatter - * @property {string[]} [ignore] - File path patterns to ignore */ /** diff --git a/shared/tasks/files.mjs b/shared/tasks/files.mjs index 131057a996..6eaa2ff6a9 100644 --- a/shared/tasks/files.mjs +++ b/shared/tasks/files.mjs @@ -13,10 +13,9 @@ import slash from 'slash' * @param {string} pattern - Pattern to remove * @param {AssetEntry[1]} options - Asset options */ -export async function clean (pattern, { destPath, ignore }) { +export async function clean (pattern, { destPath }) { await deleteAsync(slash(join(destPath, pattern)), { - cwd: paths.root, - ignore + cwd: paths.root }) } @@ -60,11 +59,8 @@ export async function write (assetPath, { destPath, filePath, fileContents }) { * @param {string} pattern - Minimatch pattern * @param {AssetEntry[1]} options - Asset options */ -export async function copy (pattern, { srcPath, destPath, ignore = [] }) { - const srcPatterns = [slash(join(srcPath, pattern))] - .concat(ignore.map((pattern) => `!${pattern}`)) - - await cpy(srcPatterns, destPath, { cwd: srcPath }) +export async function copy (pattern, { srcPath, destPath }) { + await cpy([slash(join(srcPath, pattern))], destPath, { cwd: srcPath }) } /** From 4b9044aeef07e8535c208296a069e91b1d167377 Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Fri, 19 May 2023 12:00:43 +0100 Subject: [PATCH 3/9] Remove unnecessary `*.json` file renames Config files are already JSON formatted so we can configure the filename in the shared task --- packages/govuk-frontend/tasks/scripts.mjs | 6 +----- shared/tasks/configs.mjs | 5 +++++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/govuk-frontend/tasks/scripts.mjs b/packages/govuk-frontend/tasks/scripts.mjs index 932c32bfb4..e0592dc33a 100644 --- a/packages/govuk-frontend/tasks/scripts.mjs +++ b/packages/govuk-frontend/tasks/scripts.mjs @@ -39,11 +39,7 @@ export const compile = (options) => gulp.series( task.name("compile:js 'govuk-prototype-kit'", () => configs.compile('govuk-prototype-kit.config.mjs', { srcPath: join(options.srcPath, 'govuk-prototype-kit'), - destPath: resolve(options.destPath, '../'), // Top level (not dist) for compatibility - - filePath (file) { - return join(file.dir, `${file.name}.json`) - } + destPath: resolve(options.destPath, '../') // Top level (not dist) for compatibility }) ) ) diff --git a/shared/tasks/configs.mjs b/shared/tasks/configs.mjs index 4e72d3abc5..19c87758ad 100644 --- a/shared/tasks/configs.mjs +++ b/shared/tasks/configs.mjs @@ -17,6 +17,11 @@ export async function compile (modulePath, options) { return files.write(modulePath, { ...options, + // Rename with `*.json` extension + filePath ({ dir, name }) { + return join(dir, `${name}.json`) + }, + // Format config as JSON async fileContents () { return JSON.stringify(await configFn(), undefined, 2) From aebb4a5b50e729590331782371c053d073f4f71e Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Fri, 19 May 2023 11:52:38 +0100 Subject: [PATCH 4/9] Remove unnecessary `*.scss` file renames MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The source files are already Sass so don’t need renaming --- packages/govuk-frontend/tasks/styles.mjs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/packages/govuk-frontend/tasks/styles.mjs b/packages/govuk-frontend/tasks/styles.mjs index 1484c3026d..daac72c967 100644 --- a/packages/govuk-frontend/tasks/styles.mjs +++ b/packages/govuk-frontend/tasks/styles.mjs @@ -15,11 +15,7 @@ export const compile = (options) => gulp.series( task.name('compile:scss', () => styles.compile('**/*.scss', { srcPath: join(options.srcPath, 'govuk'), - destPath: join(options.destPath, 'govuk'), - - filePath (file) { - return join(file.dir, `${file.name}.scss`) - } + destPath: join(options.destPath, 'govuk') }) ), @@ -29,11 +25,7 @@ export const compile = (options) => gulp.series( task.name("compile:scss 'govuk-prototype-kit'", () => styles.compile('init.scss', { srcPath: join(options.srcPath, 'govuk-prototype-kit'), - destPath: join(options.destPath, 'govuk-prototype-kit'), - - filePath (file) { - return join(file.dir, `${file.name}.scss`) - } + destPath: join(options.destPath, 'govuk-prototype-kit') }) ) ) From b464d624bdac5c416d048bc2895d2d1dd8964eaa Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Fri, 19 May 2023 12:14:17 +0100 Subject: [PATCH 5/9] Ensure shared task `options` are mandatory unless specified --- shared/tasks/assets.mjs | 8 ++++---- shared/tasks/components.mjs | 6 ++---- shared/tasks/configs.mjs | 2 +- shared/tasks/files.mjs | 8 ++++---- shared/tasks/index.mjs | 2 +- shared/tasks/scripts.mjs | 3 +-- shared/tasks/styles.mjs | 2 +- 7 files changed, 14 insertions(+), 17 deletions(-) diff --git a/shared/tasks/assets.mjs b/shared/tasks/assets.mjs index f0380a2c9b..9183d7b019 100644 --- a/shared/tasks/assets.mjs +++ b/shared/tasks/assets.mjs @@ -72,10 +72,10 @@ export async function write (filePath, result) { * Asset path options * * @typedef {object} AssetPathOptions - * @property {string} [basePath] - Base directory, for example `/path/to/package` - * @property {string} [srcPath] - Input directory, for example `/path/to/package/src` - * @property {string} [destPath] - Output directory, for example `/path/to/package/dist` - * @property {string} [workspace] - Workspace directory (relative), for example `package/dist` + * @property {string} basePath - Base directory, for example `/path/to/package` + * @property {string} srcPath - Input directory, for example `/path/to/package/src` + * @property {string} destPath - Output directory, for example `/path/to/package/dist` + * @property {string} workspace - Workspace directory (relative), for example `package/dist` */ /** diff --git a/shared/tasks/components.mjs b/shared/tasks/components.mjs index 253ccdee15..0c0b000e42 100644 --- a/shared/tasks/components.mjs +++ b/shared/tasks/components.mjs @@ -11,7 +11,7 @@ import { files } from './index.mjs' * Generate fixtures.json from component data * * @param {AssetEntry[0]} pattern - Path to ${componentName}.yaml - * @param {AssetEntry[1]} options - Asset options + * @param {Pick} options - Asset options */ export async function generateFixtures (pattern, { srcPath, destPath }) { const componentDataPaths = await getListing(srcPath, pattern) @@ -22,7 +22,6 @@ export async function generateFixtures (pattern, { srcPath, destPath }) { // Write to destination await files.write(componentDataPath, { - srcPath, destPath, // Rename to fixtures.json @@ -44,7 +43,7 @@ export async function generateFixtures (pattern, { srcPath, destPath }) { * Generate macro-options.json from component data * * @param {AssetEntry[0]} pattern - Path to ${componentName}.yaml - * @param {AssetEntry[1]} options - Asset options + * @param {Pick} options - Asset options */ export async function generateMacroOptions (pattern, { srcPath, destPath }) { const componentDataPaths = await getListing(srcPath, pattern) @@ -55,7 +54,6 @@ export async function generateMacroOptions (pattern, { srcPath, destPath }) { // Write to destination await files.write(componentDataPath, { - srcPath, destPath, // Rename to 'macro-options.json' diff --git a/shared/tasks/configs.mjs b/shared/tasks/configs.mjs index 19c87758ad..3ad3cfdb25 100644 --- a/shared/tasks/configs.mjs +++ b/shared/tasks/configs.mjs @@ -7,7 +7,7 @@ import { files } from './index.mjs' * Write config to JSON * * @param {AssetEntry[0]} modulePath - File path to config - * @param {AssetEntry[1]} options - Asset options + * @param {Pick} options - Asset options * @returns {Promise} */ export async function compile (modulePath, options) { diff --git a/shared/tasks/files.mjs b/shared/tasks/files.mjs index 6eaa2ff6a9..c7f4f750bf 100644 --- a/shared/tasks/files.mjs +++ b/shared/tasks/files.mjs @@ -11,7 +11,7 @@ import slash from 'slash' * Delete path globs for a given destination * * @param {string} pattern - Pattern to remove - * @param {AssetEntry[1]} options - Asset options + * @param {Pick} options - Asset options */ export async function clean (pattern, { destPath }) { await deleteAsync(slash(join(destPath, pattern)), { @@ -23,7 +23,7 @@ export async function clean (pattern, { destPath }) { * Write `packages/govuk-frontend/package.json` version to file * * @param {AssetEntry[0]} assetPath - File path to asset - * @param {AssetEntry[1]} options - Asset options + * @param {Pick} options - Asset options */ export async function version (assetPath, options) { await write(assetPath, { @@ -39,7 +39,7 @@ export async function version (assetPath, options) { * Write file task * * @param {AssetEntry[0]} assetPath - File path to asset - * @param {AssetEntry[1]} options - Asset options + * @param {Pick} options - Asset options */ export async function write (assetPath, { destPath, filePath, fileContents }) { const assetDestPath = join(destPath, filePath ? filePath(parse(assetPath)) : assetPath) @@ -57,7 +57,7 @@ export async function write (assetPath, { destPath, filePath, fileContents }) { * Copies files to destination * * @param {string} pattern - Minimatch pattern - * @param {AssetEntry[1]} options - Asset options + * @param {Pick} options - Asset options */ export async function copy (pattern, { srcPath, destPath }) { await cpy([slash(join(srcPath, pattern))], destPath, { cwd: srcPath }) diff --git a/shared/tasks/index.mjs b/shared/tasks/index.mjs index 9a1f4df168..8247a92c64 100644 --- a/shared/tasks/index.mjs +++ b/shared/tasks/index.mjs @@ -14,6 +14,6 @@ export * as task from './task.mjs' /** * Types for tasks * - * @typedef {Required} TaskOptions + * @typedef {import('./assets.mjs').AssetPathOptions} TaskOptions * @typedef {(options: TaskOptions) => import('gulp').TaskFunction} TaskFunction */ diff --git a/shared/tasks/scripts.mjs b/shared/tasks/scripts.mjs index 400ccab224..3f09babfd0 100644 --- a/shared/tasks/scripts.mjs +++ b/shared/tasks/scripts.mjs @@ -15,8 +15,7 @@ import { isDev } from './helpers/task-arguments.mjs' * Compile JavaScript task * * @param {string} pattern - Minimatch pattern - * @param {AssetEntry[1]} [options] - Asset options - * @returns {Promise} + * @param {AssetEntry[1]} options - Asset options */ export async function compile (pattern, options) { const modulePaths = await getListing(options.srcPath, pattern) diff --git a/shared/tasks/styles.mjs b/shared/tasks/styles.mjs index 89c21c5aad..8e32f19ae3 100644 --- a/shared/tasks/styles.mjs +++ b/shared/tasks/styles.mjs @@ -17,7 +17,7 @@ import { assets } from './index.mjs' * Compile Sass to CSS task * * @param {string} pattern - Minimatch pattern - * @param {AssetEntry[1]} [options] - Asset options + * @param {AssetEntry[1]} options - Asset options */ export async function compile (pattern, options) { const modulePaths = await getListing(options.srcPath, pattern) From aed596e315ae4fa9e891ba2fc3efaa1bf975ef51 Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Fri, 19 May 2023 12:25:39 +0100 Subject: [PATCH 6/9] Ensure shared task `options` are fully populated MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We’re not running `tsc` in strict mode so can easily break tasks by not specifying the required properties --- packages/govuk-frontend-review/tasks/scripts.mjs | 2 ++ packages/govuk-frontend-review/tasks/styles.mjs | 2 ++ packages/govuk-frontend/tasks/build/package.mjs | 4 +--- packages/govuk-frontend/tasks/build/release.mjs | 14 ++++++-------- packages/govuk-frontend/tasks/scripts.mjs | 4 ++++ packages/govuk-frontend/tasks/styles.mjs | 4 ++++ 6 files changed, 19 insertions(+), 11 deletions(-) diff --git a/packages/govuk-frontend-review/tasks/scripts.mjs b/packages/govuk-frontend-review/tasks/scripts.mjs index c602b36bfc..5acb176d6f 100644 --- a/packages/govuk-frontend-review/tasks/scripts.mjs +++ b/packages/govuk-frontend-review/tasks/scripts.mjs @@ -12,6 +12,8 @@ import gulp from 'gulp' export const compile = (options) => gulp.series( task.name('compile:js', () => scripts.compile('all.mjs', { + ...options, + srcPath: join(options.srcPath, 'javascripts'), destPath: join(options.destPath, 'javascripts'), diff --git a/packages/govuk-frontend-review/tasks/styles.mjs b/packages/govuk-frontend-review/tasks/styles.mjs index f7b0a0a171..2d97798d0b 100644 --- a/packages/govuk-frontend-review/tasks/styles.mjs +++ b/packages/govuk-frontend-review/tasks/styles.mjs @@ -12,6 +12,8 @@ import gulp from 'gulp' export const compile = (options) => gulp.series( task.name('compile:scss', () => styles.compile('**/[!_]*.scss', { + ...options, + srcPath: join(options.srcPath, 'stylesheets'), destPath: join(options.destPath, 'stylesheets'), diff --git a/packages/govuk-frontend/tasks/build/package.mjs b/packages/govuk-frontend/tasks/build/package.mjs index a970b74390..76fd7ec32d 100644 --- a/packages/govuk-frontend/tasks/build/package.mjs +++ b/packages/govuk-frontend/tasks/build/package.mjs @@ -13,9 +13,7 @@ import { fixtures, scripts, styles, templates } from '../index.mjs' */ export default (options) => gulp.series( task.name('clean', () => - files.clean('*', { - destPath: options.destPath - }) + files.clean('*', options) ), fixtures(options), diff --git a/packages/govuk-frontend/tasks/build/release.mjs b/packages/govuk-frontend/tasks/build/release.mjs index f09cbdf51b..ed6b34a3b1 100644 --- a/packages/govuk-frontend/tasks/build/release.mjs +++ b/packages/govuk-frontend/tasks/build/release.mjs @@ -12,9 +12,7 @@ import gulp from 'gulp' */ export default (options) => gulp.series( task.name('clean', () => - files.clean('*', { - destPath: options.destPath - }) + files.clean('*', options) ), // Copy GOV.UK Frontend static assets @@ -28,8 +26,9 @@ export default (options) => gulp.series( // Compile GOV.UK Frontend JavaScript task.name('compile:js', () => scripts.compile('all.mjs', { + ...options, + srcPath: join(options.srcPath, 'govuk'), - destPath: options.destPath, filePath (file) { return join(file.dir, `${file.name.replace(/^all/, pkg.name)}-${pkg.version}.min.js`) @@ -40,8 +39,9 @@ export default (options) => gulp.series( // Compile GOV.UK Frontend Sass task.name('compile:scss', () => styles.compile('**/[!_]*.scss', { + ...options, + srcPath: join(options.srcPath, 'govuk'), - destPath: options.destPath, filePath (file) { return join(file.dir, `${file.name.replace(/^all/, pkg.name)}-${pkg.version}.min.css`) @@ -51,8 +51,6 @@ export default (options) => gulp.series( // Update GOV.UK Frontend version task.name("file:version 'VERSION.txt'", () => - files.version('VERSION.txt', { - destPath: options.destPath - }) + files.version('VERSION.txt', options) ) ) diff --git a/packages/govuk-frontend/tasks/scripts.mjs b/packages/govuk-frontend/tasks/scripts.mjs index e0592dc33a..6eb88aec39 100644 --- a/packages/govuk-frontend/tasks/scripts.mjs +++ b/packages/govuk-frontend/tasks/scripts.mjs @@ -14,6 +14,8 @@ export const compile = (options) => gulp.series( */ task.name('compile:mjs', () => scripts.compile('!(*.test).mjs', { + ...options, + srcPath: join(options.srcPath, 'govuk'), destPath: join(options.destPath, 'govuk-esm') }) @@ -24,6 +26,8 @@ export const compile = (options) => gulp.series( */ task.name('compile:js', () => scripts.compile('**/!(*.test).mjs', { + ...options, + srcPath: join(options.srcPath, 'govuk'), destPath: join(options.destPath, 'govuk'), diff --git a/packages/govuk-frontend/tasks/styles.mjs b/packages/govuk-frontend/tasks/styles.mjs index daac72c967..f662868a35 100644 --- a/packages/govuk-frontend/tasks/styles.mjs +++ b/packages/govuk-frontend/tasks/styles.mjs @@ -14,6 +14,8 @@ export const compile = (options) => gulp.series( */ task.name('compile:scss', () => styles.compile('**/*.scss', { + ...options, + srcPath: join(options.srcPath, 'govuk'), destPath: join(options.destPath, 'govuk') }) @@ -24,6 +26,8 @@ export const compile = (options) => gulp.series( */ task.name("compile:scss 'govuk-prototype-kit'", () => styles.compile('init.scss', { + ...options, + srcPath: join(options.srcPath, 'govuk-prototype-kit'), destPath: join(options.destPath, 'govuk-prototype-kit') }) From 591311d3650fd7f1003b071d58fe0c2cb6bb6a14 Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Thu, 18 May 2023 12:37:41 +0100 Subject: [PATCH 7/9] Remove duplicate `@types/node` package --- package-lock.json | 1 - package.json | 1 - 2 files changed, 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index cf68695b9e..3de4d2d45f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,6 @@ "devDependencies": { "@babel/core": "^7.21.8", "@babel/preset-env": "^7.21.5", - "@types/node": "^20.1.5", "@typescript-eslint/eslint-plugin": "^5.59.5", "@typescript-eslint/parser": "^5.59.5", "concurrently": "^8.0.1", diff --git a/package.json b/package.json index 0f264da8e0..39fc660a97 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,6 @@ "devDependencies": { "@babel/core": "^7.21.8", "@babel/preset-env": "^7.21.5", - "@types/node": "^20.1.5", "@typescript-eslint/eslint-plugin": "^5.59.5", "@typescript-eslint/parser": "^5.59.5", "concurrently": "^8.0.1", From 48f2b10d9ac30ff2e6d1bd5c5e721474a04d5eeb Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Fri, 19 May 2023 11:58:10 +0100 Subject: [PATCH 8/9] Ensure all task file options have comments --- packages/govuk-frontend-review/tasks/scripts.mjs | 5 +++-- packages/govuk-frontend-review/tasks/styles.mjs | 5 +++-- packages/govuk-frontend/tasks/build/release.mjs | 10 ++++++---- packages/govuk-frontend/tasks/scripts.mjs | 5 +++-- shared/tasks/assets.mjs | 2 ++ shared/tasks/components.mjs | 4 ++-- shared/tasks/configs.mjs | 2 +- shared/tasks/files.mjs | 1 + 8 files changed, 21 insertions(+), 13 deletions(-) diff --git a/packages/govuk-frontend-review/tasks/scripts.mjs b/packages/govuk-frontend-review/tasks/scripts.mjs index 5acb176d6f..5617d0b4af 100644 --- a/packages/govuk-frontend-review/tasks/scripts.mjs +++ b/packages/govuk-frontend-review/tasks/scripts.mjs @@ -17,8 +17,9 @@ export const compile = (options) => gulp.series( srcPath: join(options.srcPath, 'javascripts'), destPath: join(options.destPath, 'javascripts'), - filePath (file) { - return join(file.dir, `${file.name}.min.js`) + // Rename with `*.min.js` extension + filePath ({ dir, name }) { + return join(dir, `${name}.min.js`) } }) ), diff --git a/packages/govuk-frontend-review/tasks/styles.mjs b/packages/govuk-frontend-review/tasks/styles.mjs index 2d97798d0b..c023d8b460 100644 --- a/packages/govuk-frontend-review/tasks/styles.mjs +++ b/packages/govuk-frontend-review/tasks/styles.mjs @@ -17,8 +17,9 @@ export const compile = (options) => gulp.series( srcPath: join(options.srcPath, 'stylesheets'), destPath: join(options.destPath, 'stylesheets'), - filePath (file) { - return join(file.dir, `${file.name}.min.css`) + // Rename with `*.min.css` extension + filePath ({ dir, name }) { + return join(dir, `${name}.min.css`) } }) ), diff --git a/packages/govuk-frontend/tasks/build/release.mjs b/packages/govuk-frontend/tasks/build/release.mjs index ed6b34a3b1..20815f5ebd 100644 --- a/packages/govuk-frontend/tasks/build/release.mjs +++ b/packages/govuk-frontend/tasks/build/release.mjs @@ -30,8 +30,9 @@ export default (options) => gulp.series( srcPath: join(options.srcPath, 'govuk'), - filePath (file) { - return join(file.dir, `${file.name.replace(/^all/, pkg.name)}-${pkg.version}.min.js`) + // Rename using package name (versioned) and `*.min.js` extension + filePath ({ dir, name }) { + return join(dir, `${name.replace(/^all/, pkg.name)}-${pkg.version}.min.js`) } }) ), @@ -43,8 +44,9 @@ export default (options) => gulp.series( srcPath: join(options.srcPath, 'govuk'), - filePath (file) { - return join(file.dir, `${file.name.replace(/^all/, pkg.name)}-${pkg.version}.min.css`) + // Rename using package name (versioned) and `*.min.css` extension + filePath ({ dir, name }) { + return join(dir, `${name.replace(/^all/, pkg.name)}-${pkg.version}.min.css`) } }) ), diff --git a/packages/govuk-frontend/tasks/scripts.mjs b/packages/govuk-frontend/tasks/scripts.mjs index 6eb88aec39..d0ef0d8ccc 100644 --- a/packages/govuk-frontend/tasks/scripts.mjs +++ b/packages/govuk-frontend/tasks/scripts.mjs @@ -31,8 +31,9 @@ export const compile = (options) => gulp.series( srcPath: join(options.srcPath, 'govuk'), destPath: join(options.destPath, 'govuk'), - filePath (file) { - return join(file.dir, `${file.name}.js`) + // Rename with `*.js` extension + filePath ({ dir, name }) { + return join(dir, `${name}.js`) } }) ), diff --git a/shared/tasks/assets.mjs b/shared/tasks/assets.mjs index 9183d7b019..99a36463d4 100644 --- a/shared/tasks/assets.mjs +++ b/shared/tasks/assets.mjs @@ -26,6 +26,7 @@ export async function write (filePath, result) { writeTasks.push(files.write(base, { destPath: dir, + // Add source code async fileContents () { return code } @@ -47,6 +48,7 @@ export async function write (filePath, result) { writeTasks.push(files.write(`${base}.map`, { destPath: dir, + // Add source map as JSON async fileContents () { return JSON.stringify(map) } diff --git a/shared/tasks/components.mjs b/shared/tasks/components.mjs index 0c0b000e42..85e821ab3c 100644 --- a/shared/tasks/components.mjs +++ b/shared/tasks/components.mjs @@ -29,7 +29,7 @@ export async function generateFixtures (pattern, { srcPath, destPath }) { return join(dir, 'fixtures.json') }, - // Replace contents with JSON + // Add fixtures as JSON (formatted) async fileContents () { return JSON.stringify(fixture, null, 4) } @@ -61,7 +61,7 @@ export async function generateMacroOptions (pattern, { srcPath, destPath }) { return join(dir, 'macro-options.json') }, - // Replace contents with JSON + // Add macro options as JSON (formatted) async fileContents () { return JSON.stringify(macroOption, null, 4) } diff --git a/shared/tasks/configs.mjs b/shared/tasks/configs.mjs index 3ad3cfdb25..ae5302e610 100644 --- a/shared/tasks/configs.mjs +++ b/shared/tasks/configs.mjs @@ -22,7 +22,7 @@ export async function compile (modulePath, options) { return join(dir, `${name}.json`) }, - // Format config as JSON + // Add config as JSON (formatted) async fileContents () { return JSON.stringify(await configFn(), undefined, 2) } diff --git a/shared/tasks/files.mjs b/shared/tasks/files.mjs index c7f4f750bf..1e373cf1e6 100644 --- a/shared/tasks/files.mjs +++ b/shared/tasks/files.mjs @@ -29,6 +29,7 @@ export async function version (assetPath, options) { await write(assetPath, { ...options, + // Add package version async fileContents () { return pkg.version } From ab15994587de14d6ff9541a3789a98eca5f90ddb Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Fri, 19 May 2023 12:14:26 +0100 Subject: [PATCH 9/9] Configure paths so `tsc` can locate GOV.UK Frontend source MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Our main export in package.json is `"dist/govuk/all.js"` so we need to remap this to our source code for internal use only, otherwise code autocomplete doesn’t work in the review app This can be removed if we export type declarations in the package instead --- packages/govuk-frontend-review/tsconfig.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/govuk-frontend-review/tsconfig.json b/packages/govuk-frontend-review/tsconfig.json index 8e33a85306..668c26bff2 100644 --- a/packages/govuk-frontend-review/tsconfig.json +++ b/packages/govuk-frontend-review/tsconfig.json @@ -8,5 +8,10 @@ "../../shared/lib", "../../shared/tasks" ], - "exclude": ["./dist/**", "../govuk-frontend/dist/**"] + "exclude": ["./dist/**", "../govuk-frontend/dist/**"], + "compilerOptions": { + "paths": { + "govuk-frontend": ["../govuk-frontend/src/govuk/all.mjs"] + } + } }