An open source design system that's fully customizable and agent ready
TypeScript
fix(docsite): resolve heroicons imports in playground editor (#2535)
Kenton Quatman90ef8e4d78a3
diff --git a/apps/docsite/scripts/generate-playground-types.mjs b/apps/docsite/scripts/generate-playground-types.mjsindex 93393b7564..8aaf7f722d 100644--- a/apps/docsite/scripts/generate-playground-types.mjs+++ b/apps/docsite/scripts/generate-playground-types.mjs@@ -143,10 +143,50 @@ declare module '@stylexjs/stylex' {}`;+// Heroicons ambient module declarations. Template and example code still+// imports icons from '@heroicons/react/{16,20,24}/{outline,solid}'. Bundling+// the package's ~10k individual .d.ts files would bloat the payload, so we+// synthesize one ambient module per variant exposing each icon as a named+// export. Icon names are read from the installed package's per-variant+// index.d.ts so the set stays accurate (e.g. 16/solid ships fewer icons).+function buildHeroiconTypes() {+ const variants = ['16/solid', '20/solid', '24/outline', '24/solid'];+ const heroRoot = join(root, '..', '..', 'node_modules', '@heroicons', 'react');+ const iconType =+ 'React.ComponentType<React.SVGProps<SVGSVGElement> & ' ++ '{title?: string; titleId?: string}>';+ const files = {};++ for (const variant of variants) {+ const indexPath = join(heroRoot, variant, 'index.d.ts');+ if (!existsSync(indexPath)) continue;++ const src = readFileSync(indexPath, 'utf-8');+ const names = [+ ...src.matchAll(/export \{ default as (\w+) \}/g),+ ].map(m => m[1]);+ if (names.length === 0) continue;++ const exports = names.map(n => ` export const ${n}: HeroIcon;`).join('\n');+ files[`${variant}.d.ts`] =+ `declare module '@heroicons/react/${variant}' {\n` ++ ` type HeroIcon = ${iconType};\n` ++ `${exports}\n}`;+ }++ return files;+}++const heroiconTypes = buildHeroiconTypes();+console.log(+ `Generated heroicon types: ${Object.keys(heroiconTypes).length} variants`,+);+const output = {'@xds/core': xdsTypes,react: {'index.d.ts': reactTypes, 'jsx-runtime.d.ts': reactJsxRuntimeTypes},'@stylexjs/stylex': {'index.d.ts': stylexTypes},+ '@heroicons/react': heroiconTypes,};const json = JSON.stringify(output);diff --git a/apps/docsite/src/app/playground/PlaygroundClient.tsx b/apps/docsite/src/app/playground/PlaygroundClient.tsxindex 36bbf56700..14bd851be3 100644--- a/apps/docsite/src/app/playground/PlaygroundClient.tsx+++ b/apps/docsite/src/app/playground/PlaygroundClient.tsx@@ -237,6 +237,21 @@ function configureMonaco(monaco: MonacoInstance) {);}+ // Heroicons ambient declarations, one per size/style variant. Template+ // and example code imports icons by name from+ // '@heroicons/react/{16,20,24}/{outline,solid}', so each declaration+ // exposes the variant's icons as named exports. Without these, every+ // heroicons import lights up with a "Cannot find module" red squiggle+ // once semantic validation turns on below.+ const heroiconFiles = packages['@heroicons/react'] ?? {};+ for (const [fileName, content] of Object.entries(heroiconFiles)) {+ const variant = fileName.replace(/\.d\.ts$/, '');+ ts.addExtraLib(+ content,+ `file:///node_modules/@heroicons/react/${variant}/index.d.ts`,+ );+ }+const xdsFiles = packages['@xds/core'] ?? {};const submoduleReexports: string[] = [];