Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions scripts/generate-phosphor-icon-registry.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,38 @@ writeFileSync(
path.join(process.cwd(), 'src/components/ds/phosphor-icons.generated.ts'),
output,
)

// The barrel re-exports every icon under both `Name` (deprecated) and
// `NameIcon`. Redeclaring the module with only the suffixed members makes the
// deprecated spelling a type error instead of a strikethrough, so the rename
// done in #1094 cannot quietly regress.
//
// This replaces the barrel's types wholesale, so the handful of non-icon
// exports have to be carried over as well or anything importing them breaks.
// Subpaths must match the package's own exports map (`./lib`, `./ssr`, `./*`).
// Pointing at the underlying `dist/` files instead resolves to nothing, and
// with skipLibCheck on that failure is silent: every re-exported symbol
// degrades to `any` rather than raising an error here.
const suffixedExports = iconNames
.map(
(iconName) =>
` export { ${getLocalName(iconName)} } from '@phosphor-icons/react/${iconName}'`,
)
.join('\n')

const declaration = `// Generated by scripts/generate-phosphor-icon-registry.mjs.
// Restricts the @phosphor-icons/react barrel to its supported \`Icon\`-suffixed
// exports; importing a bare name (e.g. \`Star\`) is a compile error.
declare module '@phosphor-icons/react' {
export type { Icon, IconProps, IconWeight } from '@phosphor-icons/react/lib'
export { IconContext, IconBase } from '@phosphor-icons/react/lib'
export * as SSR from '@phosphor-icons/react/ssr'

${suffixedExports}
}
`

writeFileSync(
path.join(process.cwd(), 'src/types/phosphor-icons.generated.d.ts'),
declaration,
)
Loading
Loading