Open History to see the last commit
1import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'
2import { join } from 'node:path'
3import { fileURLToPath } from 'node:url'
4
5import { describe, expect, it } from 'vitest'
6
7const reactRoot = fileURLToPath(
8 new URL('../src/frameworks/react', import.meta.url),
9)
10
11interface PackageManifest {
12 dependencies?: Record<string, string>
13 devDependencies?: Record<string, string>
14}
15
16function readJson<T>(path: string) {
17 return JSON.parse(readFileSync(path, 'utf8')) as T
18}
19
20function importsLucide(path: string): boolean {
21 if (!existsSync(path)) return false
22
23 return readdirSync(path).some((entry) => {
24 const entryPath = join(path, entry)
25 if (statSync(entryPath).isDirectory()) return importsLucide(entryPath)
26 if (!/\.[cm]?[jt]sx?$/.test(entry)) return false
27
28 return /from\s+['"]lucide-react['"]/.test(readFileSync(entryPath, 'utf8'))
29 })
30}
31
32function lucideConsumers(group: 'add-ons' | 'examples') {
33 const groupRoot = join(reactRoot, group)
34
35 return readdirSync(groupRoot)
36 .map((name) => join(groupRoot, name))
37 .filter((path) => statSync(path).isDirectory())
38 .filter((path) => importsLucide(join(path, 'assets')))
39}
40
41describe('React template dependency ownership', () => {
42 it('does not install Lucide in the base or Tailwind profile', () => {
43 const base = readJson<PackageManifest>(
44 join(reactRoot, 'project/base/package.json'),
45 )
46 const profiles = readJson<{
47 tailwindcss?: { dependencies?: Record<string, string> }
48 }>(join(reactRoot, 'project/packages.json'))
49
50 expect(base.dependencies?.['lucide-react']).toBeUndefined()
51 expect(profiles.tailwindcss?.dependencies?.['lucide-react']).toBeUndefined()
52 })
53
54 it.each([...lucideConsumers('add-ons'), ...lucideConsumers('examples')])(
55 '%s declares Lucide when its emitted source imports it',
56 (consumerPath) => {
57 const manifest = readJson<PackageManifest>(
58 join(consumerPath, 'package.json'),
59 )
60 const dependencies = {
61 ...manifest.dependencies,
62 ...manifest.devDependencies,
63 }
64
65 expect(dependencies['lucide-react']).toBeDefined()
66 },
67 )
68})