GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — tanstack.com/scripts/generate-phosphor-icon-registry.mjs at main · stackgraph/tanstack.com Expand file tree/ Copy pathgenerate-phosphor-icon-registry.mjsMore file actions 80 lines (71 loc) · 2.84 KB / Copy pathgenerate-phosphor-icon-registry.mjsFile metadata and controls80 lines (71 loc) · 2.84 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 import { readdirSync, writeFileSync } from 'node:fs' import path from 'node:path' import { fileURLToPath } from 'node:url' const packageRoot = path.dirname( fileURLToPath(import.meta.resolve('@phosphor-icons/react/package.json')), ) const iconNames = readdirSync(path.join(packageRoot, 'dist/csr')) .filter((fileName) => fileName.endsWith('.es.js')) .map((fileName) => fileName.slice(0, -'.es.js'.length)) .sort((a, b) => a.localeCompare(b)) // Every icon module exports both `Name` (deprecated) and `NameIcon`. The // suffixed export is the supported one and never collides with a JS global. const getLocalName = (iconName) => `${iconName}Icon` const imports = iconNames .map( (iconName) => `import { ${getLocalName(iconName)} } from '@phosphor-icons/react/${iconName}'`, ) .join('\n') const entries = iconNames .map( (iconName) => ` { name: '${iconName}', Cmp: ${getLocalName(iconName)} },`, ) .join('\n') const output = `// Generated by scripts/generate-phosphor-icon-registry.mjs. // Importing individual icon modules keeps this registry out of the shared // @phosphor-icons/react barrel used by the rest of the site. import type { Icon } from '@phosphor-icons/react' ${imports} export const phosphorIconRegistry: ReadonlyArray<{ name: string Cmp: Icon }> = [ ${entries} ] ` 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, ) |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |