MCPcopy
hub / github.com/vercel/next.js / isFolderEmpty

Function isFolderEmpty

packages/create-next-app/helpers/is-folder-empty.ts:6–67  ·  view source on GitHub ↗
(root: string, name: string)

Source from the content-addressed store, hash-verified

4import { green, blue } from 'picocolors'
5
6export function isFolderEmpty(root: string, name: string): boolean {
7 const validFilesOrFolders = [
8 '.claude',
9 '.cursor',
10 '.DS_Store',
11 '.git',
12 '.gitattributes',
13 '.gitignore',
14 '.gitlab-ci.yml',
15 '.hg',
16 '.hgcheck',
17 '.hgignore',
18 '.idea',
19 '.npmignore',
20 '.travis.yml',
21 '.vscode',
22 '.zed',
23 'LICENSE',
24 'Thumbs.db',
25 'docs',
26 'mkdocs.yml',
27 'npm-debug.log',
28 'yarn-debug.log',
29 'yarn-error.log',
30 'yarnrc.yml',
31 '.yarn',
32 ]
33
34 const conflicts = readdirSync(root).filter(
35 (fileOrFolder) =>
36 !validFilesOrFolders.includes(fileOrFolder) &&
37 // Support IntelliJ IDEA-based editors
38 !/\.iml$/.test(fileOrFolder)
39 )
40
41 if (conflicts.length > 0) {
42 console.log(
43 `The directory ${green(name)} contains files that could conflict:`
44 )
45 console.log()
46 for (const file of conflicts) {
47 try {
48 const stats = lstatSync(join(root, file))
49 if (stats.isDirectory()) {
50 console.log(` ${blue(file)}/`)
51 } else {
52 console.log(` ${file}`)
53 }
54 } catch {
55 console.log(` ${file}`)
56 }
57 }
58 console.log()
59 console.log(
60 'Either try using a new directory name, or remove the files listed above.'
61 )
62 console.log()
63 return false

Callers 2

runFunction · 0.90
createAppFunction · 0.90

Calls 9

readdirSyncFunction · 0.85
greenFunction · 0.85
blueFunction · 0.85
includesMethod · 0.80
isDirectoryMethod · 0.80
testMethod · 0.65
joinFunction · 0.50
filterMethod · 0.45
logMethod · 0.45

Tested by

no test coverage detected