-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve loading of Prettier plugins and types (#365)
- Loading branch information
1 parent
88253a9
commit 3d6ffbc
Showing
6 changed files
with
86 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@bfra.me/prettier-plugins": minor | ||
--- | ||
|
||
Export fully-qualified Prettier `Plugin` and improve typings | ||
|
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,6 @@ | ||
--- | ||
"@bfra.me/prettier-config": minor | ||
--- | ||
|
||
Resolve installed Prettier plugins to `Plugin` objects; improve typings | ||
|
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,26 @@ | ||
import type {Plugin} from 'prettier' | ||
|
||
export type InteropDefault<T> = T extends {default: infer U} ? U : T | ||
|
||
function interopDefault<T>(m: T): InteropDefault<T> { | ||
return (m as any).default || m | ||
} | ||
|
||
import {default as pluginPackageJson} from '@bfra.me/prettier-plugins/package-json' | ||
const resolvedPlugins: Record<string, Plugin> = { | ||
'@bfra.me/prettier-plugins/package-json': interopDefault(pluginPackageJson), | ||
} | ||
|
||
export const resolve = <T extends Plugin>( | ||
resolver: (id: string) => string, | ||
plugin: string, | ||
): string | T => { | ||
try { | ||
if (resolvedPlugins[plugin]) { | ||
return resolvedPlugins[plugin] as unknown as T | ||
} | ||
return resolver(plugin) | ||
} finally { | ||
return plugin | ||
} | ||
} |
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