diff --git a/packages/lucide-react-native/package.json b/packages/lucide-react-native/package.json index cb506edeb..2e3c1cfd3 100644 --- a/packages/lucide-react-native/package.json +++ b/packages/lucide-react-native/package.json @@ -55,11 +55,12 @@ "dist" ], "scripts": { - "build": "pnpm clean && pnpm copy:license && pnpm build:icons && pnpm build:bundles", + "build": "pnpm clean && pnpm copy:license && pnpm build:icons && pnpm build:bundles && pnpm check:icon-subpaths", "copy:license": "cp ../../LICENSE ./LICENSE", "clean": "rm -rf dist && rm -rf stats && rm -rf ./src/icons/*.ts", "build:icons": "build-icons --output=./src --templateSrc=./scripts/exportTemplate.mts --renderUniqueKey --iconFileExtension=.ts --exportFileName=index.ts --withAliases --separateAliasesFile --separateAliasesFileIgnore=fingerprint --aliasesFileExtension=.ts", "build:bundles": "rollup -c ./rollup.config.mjs", + "check:icon-subpaths": "node ./scripts/checkIconSubpaths.mts", "test": "pnpm build:icons && vitest run", "test:watch": "vitest watch", "typecheck": "pnpm build:icons && tsc" diff --git a/packages/lucide-react-native/rollup.config.mjs b/packages/lucide-react-native/rollup.config.mjs index d4833bc07..2d81d1c14 100644 --- a/packages/lucide-react-native/rollup.config.mjs +++ b/packages/lucide-react-native/rollup.config.mjs @@ -11,7 +11,14 @@ const dtsOptions = { const packageName = 'LucideReact'; const outputFileName = 'lucide-react-native'; const outputDir = 'dist'; -const inputs = ['src/lucide-react-native.ts', 'src/icons/index.ts']; +const iconAndAliasEntries = await getIconEntryNamesAndAliases(); +// Alias modules (e.g. `icons/trash-2`) aren't imported by the index, so list them as entries +// to emit the runtime files the `./icons/*` export map points at. +const inputs = [ + 'src/lucide-react-native.ts', + 'src/icons/index.ts', + ...Object.values(iconAndAliasEntries), +]; const bundles = [ { format: 'cjs', @@ -28,7 +35,6 @@ const bundles = [ }, ]; -const iconAndAliasEntries = await getIconEntryNamesAndAliases(); const typesModuleMatcher = /[/\\]src[/\\]types\.(d\.)?ts$/; const configs = bundles.map(({ inputs, outputDir, format, preserveModules, extension = 'js' }) => ({ diff --git a/packages/lucide-react-native/scripts/checkIconSubpaths.mts b/packages/lucide-react-native/scripts/checkIconSubpaths.mts new file mode 100644 index 000000000..16d55e255 --- /dev/null +++ b/packages/lucide-react-native/scripts/checkIconSubpaths.mts @@ -0,0 +1,16 @@ +// Fails the build when an `icons/*` subpath has type declarations but no runtime file. +import { existsSync, readdirSync } from 'node:fs'; + +const declarations = readdirSync('dist/types/icons').filter((file) => file.endsWith('.d.ts')); + +const missing = declarations.flatMap((file) => { + const name = file.replace(/\.d\.ts$/, ''); + return [`dist/esm/icons/${name}.mjs`, `dist/cjs/icons/${name}.js`].filter( + (runtimeFile) => !existsSync(runtimeFile), + ); +}); + +if (missing.length > 0) { + console.error(`Missing runtime files for icon subpaths:\n${missing.join('\n')}`); + process.exit(1); +}