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

Function packageFiles

scripts/pack-util.ts:141–178  ·  view source on GitHub ↗
(path: string)

Source from the content-addressed store, hash-verified

139 * @returns {Promise<string[]>}
140 */
141export async function packageFiles(path: string): Promise<string[]> {
142 const { files = DEFAULT_GLOBS, main, bin } = require(`${path}/package.json`)
143
144 const allFiles: string[] = files.concat(
145 FORCED_GLOBS,
146 main ?? [],
147 Object.values(bin ?? {})
148 )
149 const isGlob = (f) => f.includes('*') || f.startsWith('!')
150 const simpleFiles = allFiles
151 .filter((f) => !isGlob(f) && existsSync(join(path, f)))
152 .map((f) => f.replace(/^\.\//, ''))
153 const globFiles = allFiles.filter(isGlob)
154 const globbedFiles = await glob(
155 `+(${globFiles.filter((f) => !f.startsWith('!')).join('|')})`,
156 {
157 cwd: path,
158 ignore: `+(${globFiles
159 .filter((f) => f.startsWith('!'))
160 .map((f) => f.slice(1))
161 .join('|')})`,
162 }
163 )
164 const packageFiles = [...globbedFiles, ...simpleFiles].sort()
165 const set = new Set()
166 return packageFiles.filter((f) => {
167 if (set.has(f)) return false
168 // We add the full path, but check for parent directories too.
169 // This catches the case where the whole directory is added and then a single file from the directory.
170 // The sorting before ensures that the directory comes before the files inside of the directory.
171 while (f.includes('/')) {
172 f = f.replace(/\/[^/]*$/, '')
173 if (set.has(f)) return false
174 }
175 set.add(f)
176 return true
177 })
178}

Callers 2

copyFunction · 0.85
packWithTarFunction · 0.85

Calls 15

joinFunction · 0.90
isGlobFunction · 0.85
startsWithMethod · 0.80
includesMethod · 0.80
replaceMethod · 0.65
requireFunction · 0.50
globFunction · 0.50
concatMethod · 0.45
valuesMethod · 0.45
mapMethod · 0.45
filterMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected