yarn-plugin: import appropriate type to verify beforeWorkspacePacking signature

I realised that by default the `Plugin` type from
`@yarnpkg/core` sets the type of the `hooks`
property to `any`. This meant that there wasn't
any restriction on the hooks that could be passed,
and introduced the risk that a typo in the
`beforeWorkspacePacking` name could lead to the
hook being skipped.

This commit pulls in the appropriate type for
Hooks to verify the name and signature of the hook.

Signed-off-by: MT Lewis <mtlewis@users.noreply.github.com>
This commit is contained in:
MT Lewis
2024-11-22 15:28:23 +00:00
parent 124a108c36
commit 27600c2cd3
4 changed files with 6 additions and 2 deletions
+1
View File
@@ -34,6 +34,7 @@
"@backstage/release-manifests": "workspace:^",
"@yarnpkg/core": "^4.0.3",
"@yarnpkg/fslib": "^3.0.2",
"@yarnpkg/plugin-pack": "^4.0.0",
"lodash": "^4.17.21",
"semver": "^7.6.0"
},
+2 -1
View File
@@ -3,9 +3,10 @@
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
import { Hooks } from '@yarnpkg/plugin-pack';
import { Plugin as Plugin_2 } from '@yarnpkg/core';
// @public (undocumented)
const plugin: Plugin_2;
const plugin: Plugin_2<Hooks>;
export default plugin;
```
+2 -1
View File
@@ -22,6 +22,7 @@
*/
import { Plugin, semverUtils, YarnVersion } from '@yarnpkg/core';
import { Hooks } from '@yarnpkg/plugin-pack';
import { beforeWorkspacePacking } from './handlers/beforeWorkspacePacking';
import { BackstageResolver } from './resolver/BackstageResolver';
@@ -43,7 +44,7 @@ if (!semverUtils.satisfiesWithPrereleases(YarnVersion, '^4.1.1')) {
/**
* @public
*/
const plugin: Plugin = {
const plugin: Plugin<Hooks> = {
hooks: {
beforeWorkspacePacking,
},
+1
View File
@@ -45427,6 +45427,7 @@ __metadata:
"@yarnpkg/builder": ^4.0.0
"@yarnpkg/core": ^4.0.3
"@yarnpkg/fslib": ^3.0.2
"@yarnpkg/plugin-pack": ^4.0.0
lodash: ^4.17.21
nodemon: ^3.0.1
semver: ^7.6.0