Skip to content

Commit 81b55ca

Browse files
committed
fix(ts): ensure typechecks pass without peer deps installed
- @ts-* comments are meaningful comments, but typescript does not preserve them πŸ™ƒπŸ™„ - re-implemented 779cddf as build plugin - microsoft/TypeScript#38628 - microsoft/TypeScript#38628 (comment) Signed-off-by: Lexus Drumgold <[email protected]>
1 parent 1ca8a5f commit 81b55ca

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

β€Žbuild.config.tsβ€Ž

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import { defineBuildConfig, type Config } from '@flex-development/mkbuild'
7+
import type { BuildResult, PluginBuild } from 'esbuild'
78
import pkg from './package.json' assert { type: 'json' }
89

910
/**
@@ -13,7 +14,40 @@ import pkg from './package.json' assert { type: 'json' }
1314
*/
1415
const config: Config = defineBuildConfig({
1516
entries: [
16-
{ dts: 'only' },
17+
{
18+
dts: 'only',
19+
plugins: [
20+
{
21+
name: 'ts-ignore-peers',
22+
setup({ onEnd }: PluginBuild): void {
23+
return void onEnd((result: BuildResult<{ write: false }>): void => {
24+
const { outputFiles } = result
25+
26+
/**
27+
* Regular expression used to insert `// @ts-ignore` above
28+
* property declarations.
29+
*
30+
* @const {RegExp} regex
31+
*/
32+
const regex: RegExp = /\n( +)(.+?\??: )(import\('node-fetch'\).+)/
33+
34+
/**
35+
* Property declaration with `// @ts-ignore` prepended.
36+
*
37+
* @const {string} replacement
38+
*/
39+
const replacement: string =
40+
'\n$1// @ts-ignore peer dependency\n$1$2$3'
41+
42+
return void (result.outputFiles = outputFiles.map(output => ({
43+
...output,
44+
text: output.text.replace(regex, replacement)
45+
})))
46+
})
47+
}
48+
}
49+
]
50+
},
1751
{
1852
dts: false,
1953
pattern: ['**/index.ts', 'enums/*', 'internal/*', 'utils/*'],

β€Žsrc/interfaces/options-get-format.tsβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ interface GetFormatOptions {
7474
*
7575
* @default {}
7676
*/
77-
// @ts-ignore peer dependency
7877
req?: import('node-fetch').RequestInit | undefined
7978
}
8079

β€Žsrc/interfaces/options-get-source.tsβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ interface GetSourceOptions {
5252
*
5353
* @default {}
5454
*/
55-
// @ts-ignore peer dependency
5655
req?: import('node-fetch').RequestInit | undefined
5756
}
5857

0 commit comments

Comments
Β (0)