-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mismatches in @types packages significantly reduce any type safety gained by using TypeScript. Create a regularly updating issue that tracks all `major.minor` versions for packages with a matching `@types/*`.
- Loading branch information
Showing
2 changed files
with
84 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import pkg from '../../dotcom-rendering/package.json' assert { type: 'json' }; | ||
import { octokit } from './github.ts'; | ||
|
||
const prefix = '@types/'; | ||
|
||
/** | ||
* We only look at major.minor versions as per DefinitelyTyped docs: | ||
* https://github.com/DefinitelyTyped/DefinitelyTyped#how-do-definitely-typed-package-versions-relate-to-versions-of-the-corresponding-library | ||
*/ | ||
const majorMinorVersions = Object.entries(pkg.dependencies).map( | ||
([dependency, version]) => | ||
[dependency, version.match(/(\d+\.\d+)/)?.at(0)] as const, | ||
); | ||
|
||
const dependencies = majorMinorVersions | ||
.filter(([dependency]) => dependency.startsWith(prefix)) | ||
.map(([dependency, version]) => ({ | ||
main: majorMinorVersions.find( | ||
([dep]) => dep === dependency.replace(prefix, ''), | ||
), | ||
type: [dependency, version] as const, | ||
})); | ||
|
||
const body = `## Audit of \`@types/\` packages | ||
### No main package found | ||
${dependencies | ||
.filter(({ main }) => main === undefined) | ||
.map( | ||
({ type: [dependency, version] }) => | ||
`- [ ] \`${dependency}\` – ${version}`, | ||
) | ||
.join('\n')} | ||
### Mismatched versions | ||
${dependencies | ||
.filter(({ main, type }) => main !== undefined && main[1] !== type[1]) | ||
.map( | ||
({ main, type }) => | ||
`- [ ] \`${main?.[0]}\` – ${main?.[1]} (types ${type[1]})`, | ||
) | ||
.join('\n')} | ||
### Matched dependencies | ||
${dependencies | ||
.filter(({ main, type }) => main !== undefined && main[1] === type[1]) | ||
.map(({ main }) => `- [X] \`${main?.[0]}\` – ${main?.[1]}`) | ||
.join('\n')} | ||
`; | ||
|
||
if (!octokit) { | ||
console.log(body); | ||
Deno.exit(); | ||
} | ||
|
||
/** https://github.com/guardian/dotcom-rendering/issues/6965 */ | ||
const issue_number = 6965; | ||
|
||
try { | ||
const { | ||
data: { html_url }, | ||
} = await octokit.rest.issues.update({ | ||
owner: 'guardian', | ||
repo: 'dotcom-rendering', | ||
issue_number, | ||
body, | ||
}); | ||
|
||
console.info(`Updated list of issues for dotcom-rendering#${issue_number}`); | ||
console.info(html_url); | ||
} catch (error) { | ||
console.warn(`Failed to update issue #${issue_number}`); | ||
console.error(error); | ||
|
||
console.log(body); | ||
} | ||
|
||
Deno.exit(); |