|
1 | 1 | import fs from 'fs'
|
2 | 2 | import globby from 'globby'
|
3 | 3 |
|
4 |
| -// Append "use client" to all path chunks that contain "use" hooks |
5 |
| -// So these packages can be directly used in Next.js directly |
6 |
| -// This allows us to see support file splitting with easy next import |
7 |
| -;(async () => { |
8 |
| - console.log('Added use client directive to the following files:') |
9 |
| - const chunkPaths = await globby('chunk*') |
10 |
| - for (const path of chunkPaths) { |
11 |
| - const data = fs.readFileSync(path, 'utf8') |
12 |
| - if ( |
13 |
| - /useState|useEffect|useRef|useCallback|useContext|useMemo|useTheme|useRouter|useRegisterActions|useMatches|useKBar/.test( |
14 |
| - data |
15 |
| - ) |
16 |
| - ) { |
| 4 | + // Append "use client" to all path chunks that contain "use" hooks |
| 5 | + // So these packages can be directly used in Next.js directly |
| 6 | + // This allows us to see support file splitting with easy next import |
| 7 | + ; (async () => { |
| 8 | + console.log('Added use client directive to the following files:') |
| 9 | + const chunkPaths = await globby('chunk*') |
| 10 | + for (const path of chunkPaths) { |
| 11 | + const data = fs.readFileSync(path, 'utf8') |
| 12 | + if ( |
| 13 | + /useState|useEffect|useRef|useCallback|useContext|useMemo|useTheme|useRouter|useRegisterActions|useMatches|useKBar/.test( |
| 14 | + data |
| 15 | + ) |
| 16 | + ) { |
| 17 | + console.log(path) |
| 18 | + const insert = Buffer.from('"use client"\n') |
| 19 | + fs.writeFileSync(path, insert + data) |
| 20 | + } |
| 21 | + } |
| 22 | + // Handle ui differently as they are not split |
| 23 | + const clientPaths = await globby([ |
| 24 | + 'ui/NewsletterForm.js', |
| 25 | + 'ui/BlogNewsletterForm.js', |
| 26 | + 'ui/Pre.js', |
| 27 | + 'search/KBarButton.js', |
| 28 | + 'search/AlgoliaButton.js', |
| 29 | + ]) |
| 30 | + for (const path of clientPaths) { |
17 | 31 | console.log(path)
|
| 32 | + const data = fs.readFileSync(path) |
18 | 33 | const insert = Buffer.from('"use client"\n')
|
19 | 34 | fs.writeFileSync(path, insert + data)
|
20 | 35 | }
|
21 |
| - } |
22 |
| - // Handle ui differently as they are not split |
23 |
| - const clientPaths = await globby([ |
24 |
| - 'ui/NewsletterForm.js', |
25 |
| - 'ui/BlogNewsletterForm.js', |
26 |
| - 'ui/Pre.js', |
27 |
| - 'search/KBarButton.js', |
28 |
| - 'search/AlgoliaButton.js', |
29 |
| - ]) |
30 |
| - for (const path of clientPaths) { |
31 |
| - console.log(path) |
32 |
| - const data = fs.readFileSync(path) |
33 |
| - const insert = Buffer.from('"use client"\n') |
34 |
| - fs.writeFileSync(path, insert + data) |
35 |
| - } |
36 |
| -})() |
| 36 | + })() |
0 commit comments