Skip to content

Commit

Permalink
fix(ts): ensure typechecks pass without peer deps installed
Browse files Browse the repository at this point in the history
- @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]>
  • Loading branch information
unicornware committed Feb 22, 2023
1 parent 1ca8a5f commit 81b55ca
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
36 changes: 35 additions & 1 deletion build.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

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

/**
Expand All @@ -13,7 +14,40 @@ import pkg from './package.json' assert { type: 'json' }
*/
const config: Config = defineBuildConfig({
entries: [
{ dts: 'only' },
{
dts: 'only',
plugins: [
{
name: 'ts-ignore-peers',
setup({ onEnd }: PluginBuild): void {
return void onEnd((result: BuildResult<{ write: false }>): void => {
const { outputFiles } = result

/**
* Regular expression used to insert `// @ts-ignore` above
* property declarations.
*
* @const {RegExp} regex
*/
const regex: RegExp = /\n( +)(.+?\??: )(import\('node-fetch'\).+)/

/**
* Property declaration with `// @ts-ignore` prepended.
*
* @const {string} replacement
*/
const replacement: string =
'\n$1// @ts-ignore peer dependency\n$1$2$3'

return void (result.outputFiles = outputFiles.map(output => ({
...output,
text: output.text.replace(regex, replacement)
})))
})
}
}
]
},
{
dts: false,
pattern: ['**/index.ts', 'enums/*', 'internal/*', 'utils/*'],
Expand Down
1 change: 0 additions & 1 deletion src/interfaces/options-get-format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ interface GetFormatOptions {
*
* @default {}
*/
// @ts-ignore peer dependency
req?: import('node-fetch').RequestInit | undefined
}

Expand Down
1 change: 0 additions & 1 deletion src/interfaces/options-get-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ interface GetSourceOptions {
*
* @default {}
*/
// @ts-ignore peer dependency
req?: import('node-fetch').RequestInit | undefined
}

Expand Down

0 comments on commit 81b55ca

Please sign in to comment.