Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/lukebennett88/luke-ui. ui.lukebennett.dev
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263/** * Docs-host playground runtime allowlist: `@luke-ui/react` subpath exports, * the React specifiers the compiler needs, and the third-party and `#docs` * helpers that documented examples import in the playground. * * `@luke-ui/playground-core/specifiers` turns an `exports` map into * specifiers. Docs owns the package name, its `package.json` path, and the list * order below. */import { readFileSync } from 'node:fs';import { dirname, resolve } from 'node:path';import { fileURLToPath } from 'node:url';import { PLAYGROUND_BASE_SPECIFIERS, packageExportSpecifiers,} from '@luke-ui/playground-core/specifiers';import * as z from 'zod';
/** * Third-party packages that docs examples import directly. Add a package here * whenever an example needs to import it in the playground. The Monaco type * list in `generate-playground-types.ts` is a different set on purpose. */const DOCS_PLAYGROUND_THIRD_PARTY_SPECIFIERS = [ '@hookform/resolvers/zod', '@tanstack/react-form', 'react-error-boundary', 'react-hook-form', 'zod',] as const;
/** Docs-only helpers that documented examples can import in the playground. */const DOCS_PLAYGROUND_DOCS_SPECIFIERS = ['#docs'] as const;
const packageJsonSchema = z.object({ exports: z.record(z.string(), z.string()),});
const reactPackageJsonPath = resolve( dirname(fileURLToPath(import.meta.url)), '../../../../packages/@luke-ui/react/package.json',);
/** Specifiers the docs playground preview can `require` at runtime. */export function docsPlaygroundRuntimeSpecifierList(): Array<string> { const reactExports = packageJsonSchema.parse( JSON.parse(readFileSync(reactPackageJsonPath, 'utf8')), ).exports; return [ ...packageExportSpecifiers('@luke-ui/react', reactExports), ...PLAYGROUND_BASE_SPECIFIERS, ...DOCS_PLAYGROUND_THIRD_PARTY_SPECIFIERS, ...DOCS_PLAYGROUND_DOCS_SPECIFIERS, ];}
let cachedSpecifiers: ReadonlySet<string> | undefined;
export function docsPlaygroundSpecifiers(): ReadonlySet<string> { cachedSpecifiers ??= new Set(docsPlaygroundRuntimeSpecifierList()); return cachedSpecifiers;}