-
Notifications
You must be signed in to change notification settings - Fork 333
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
b10a901
commit fced283
Showing
5 changed files
with
112 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
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
5 changes: 5 additions & 0 deletions
5
packages/govuk-frontend/src/govuk/govuk-frontend-component.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 |
---|---|---|
@@ -1 +1,6 @@ | ||
/** | ||
* @deprecated - The file has been renamed `component.mjs` | ||
* @module | ||
*/ | ||
|
||
export { Component as GOVUKFrontendComponent } from './component.mjs' |
45 changes: 45 additions & 0 deletions
45
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,45 @@ | ||
/** | ||
* 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'] | ||
|
||
/** | ||
* 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