-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add deprecated JavaScript files to package build
Because they're not imported by `all.mjs` deprecated JavaScript files were not included in the package (in which they need to remain until the next breaking release). This adds a module to store the list of deprecated JavaScript files and helper functions that are then used: - in the Gulp configuration, to add a new task building each deprecated file individually - in the Rollup configuration, to prevent the bundled output of the deprecated files as all we want is for them to be in the package as a module Co-authored-by: Patrick Cartlidge <patrick.cartlidge@digital.cabinet-office.gov.uk> Co-authored-by: Brett Kyle <brett.kyle@digital.cabinet-office.gov.uk>
- Loading branch information
1 parent
1e21410
commit 59adefb
Showing
3 changed files
with
95 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
packages/govuk-frontend/tasks/config/deprecated-scripts.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Logistics for handling files that get renamed and are no longer part of modules imported by `all.mjs` | ||
* but need to remain in the published package to support deprecations before they get removed | ||
*/ | ||
import { join } from 'node:path' | ||
|
||
/** | ||
* Paths to the deprecated files within `src/govuk` | ||
* (excluding the `src/govuk` part) | ||
*/ | ||
export const deprecatedFilesPaths = [ | ||
'govuk-frontend-component.mjs', | ||
'govuk-frontend-component-copy.mjs' | ||
] | ||
|
||
/** | ||
* Checks if given Rollup input is a deprecated file | ||
* | ||
* This helps us decide whether to create bundled version of that input, | ||
* which we don't want for deprecated files (we just want to include them in the package) | ||
* | ||
* @param {string} rollupInput - The path to the input Rollup is compiling | ||
* @returns {boolean} - Whether the path corresponds to a deprecated file | ||
*/ | ||
export function isDeprecated(rollupInput) { | ||
return deprecatedFilesPaths.some((deprecatedFilePath) => | ||
rollupInput.endsWith(join('govuk', deprecatedFilePath)) | ||
) | ||
} | ||
|
||
/** | ||
* Creates a glob matching the list of paths | ||
* | ||
* @param {string[]} paths - The list of paths to create a glob for | ||
* @returns {string} - A glob matching the deprecated files | ||
*/ | ||
export function createGlobFromPaths(paths) { | ||
// Curly brace syntax in glob only works | ||
// when there's more than one pattern to match | ||
// so we need to distinguish between the two. | ||
if (paths.length > 1) { | ||
const joinedGlobs = paths.join(',') | ||
|
||
return `{${joinedGlobs}}` | ||
} | ||
|
||
return paths[0] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters