-
Notifications
You must be signed in to change notification settings - Fork 325
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
Ensure shared task options
are mandatory unless specified
#3647
Conversation
c57fd2f
to
089f45f
Compare
089f45f
to
b2bef58
Compare
Tidying up looks good, cheers! Can you explain the benefits of having I'm expecting that with the types not being optional anymore, we'd catch situations like the one you mentioned in the first post. Would TypeScript warn OK on your first example (for lack of the necessary options)? import { scripts } from 'govuk-frontend-tasks'
// Compile GOV.UK Frontend JavaScript
scripts.compile('!(*.test).mjs', {
destPath: '/custom/build/path'
}) If that's the case, I'd like to understand why we need a custom function for the merging. If it's only for freezing objects, I'm not sure it's that risky to let the objects be extended (especially as we'll be merging in the paths anyways so have a separate object per task call), but open to be convinced otherwise 😊 |
Would you rather I used spread? Happy to change it
Could have alternatively used We'd get the type checking behaviour either way which was the aim: Argument of type '{ srcPath: string; destPath: string; hello: string; }' is not assignable to parameter of type 'Partial<AssetOptions>' |
As we get type checking in any case, I'd reather we have less code and just use spread to start, cheers 😊 |
b2bef58
to
1e8a152
Compare
1e8a152
to
61901b7
Compare
Swapped to using object spread, ready for review again |
@@ -45,7 +45,6 @@ | |||
"devDependencies": { | |||
"@babel/core": "^7.21.8", | |||
"@babel/preset-env": "^7.21.5", | |||
"@types/node": "^20.1.5", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'd accidentally put this in twice
srcPath: join(options.srcPath, 'govuk'), | ||
destPath: options.destPath, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need to repeat ourselves. The destination is already in options
srcPath: join(options.srcPath, 'govuk'), | ||
destPath: options.destPath, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need to repeat ourselves. The destination is already in options
@@ -84,7 +86,6 @@ export async function write (filePath, result) { | |||
* @typedef {object} AssetFileOptions | |||
* @property {(file: import('path').ParsedPath) => string} [filePath] - File path formatter | |||
* @property {(contents?: string) => Promise<string>} [fileContents] - File contents formatter | |||
* @property {string[]} [ignore] - File path patterns to ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We had to carefully ignore the published package.json and README.md in the past
We haven't used this option since merging:
@@ -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<AssetEntry[1], "srcPath" | "destPath">} options - Asset options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This task already provides its own filePath
and fileContents
Here we're narrowing down the types to warn when passing in options that aren't picked
@@ -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<AssetEntry[1], "srcPath" | "destPath">} options - Asset options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This task already provides its own filePath
and fileContents
Here we're narrowing down the types to warn when passing in options that aren't picked
@@ -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<AssetEntry[1], "srcPath" | "destPath">} options - Asset options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This task already provides its own filePath
and fileContents
Here we're narrowing down the types to warn when passing in options that aren't picked
@@ -11,25 +11,25 @@ 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<AssetEntry[1], "destPath">} options - Asset options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The clean task only needs a destPath
so we're being quite strict here
Other properties can be passed in when not TypeScript "strict": true
but they'll be ignored
Config files are already JSON formatted so we can configure the filename in the shared task
The source files are already Sass so don’t need renaming
We’re not running `tsc` in strict mode so can easily break tasks by not specifying the required properties
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
61901b7
to
ab15994
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cheers for updating to using spread 🙌🏻 ⛵
This PR ensures all build task options are mandatory and type checked
I've also included some related changes:
govuk-frontend
JSDoc types again*.scss
to*.scss
)This work was split out whilst adding postcss.config.mjs and rollup.config.mjs files to each workspace
Before
This will crash as no
destPath
has been providedAfter
This works by extending the build options using
...options