MCPcopy Create free account
hub / github.com/npm/cli / gatherAllows

Function gatherAllows

scripts/bundle-and-gitignore-deps.js:128–170  ·  view source on GitHub ↗
(pathParts, usedParts)

Source from the content-addressed store, hash-verified

126 }
127
128 const gatherAllows = (pathParts, usedParts) => {
129 const ignores = []
130 const segments = new AllowSegments(pathParts, usedParts)
131
132 if (segments.next) {
133 // 1) Process scope segment of the path, if it has one
134 if (segments.next.startsWith('@')) {
135 // For scoped deps we need to allow the entire scope dir
136 // due to how gitignore works. Without this the gitignore will
137 // never look to allow our bundled dep since the scope dir was ignored.
138 // It ends up looking like this for `@colors/colors`:
139 //
140 // # Allow @colors dir
141 // !/@colors/
142 // # Ignore everything inside. This is safe because there is
143 // # nothing inside a scope except other packages
144 // !/colors/*
145 //
146 // Then later we will allow the specific dep inside that scope.
147 // This way if a scope includes bundled AND unbundled deps,
148 // we only allow the bundled ones.
149 ignores.push(...segments.allow())
150 }
151
152 // 2) Now we process the name segment of the path
153 // and allow the dir and everything inside of it (like source code, etc)
154 ignores.push(...segments.allowContents({ isDirectory: false }))
155
156 // 3) If we still have remaining segments and the next segment
157 // is a nested node_modules directory...
158 if (segments.next && segments.use() === 'node_modules') {
159 ignores.push(
160 // Allow node_modules and ignore everything inside of it
161 // Set false here since we already "used" the node_modules path segment
162 ...segments.allow({ use: false }),
163 // Repeat the process with the remaining path segments to include whatever is left
164 ...gatherAllows(segments.remaining, segments.used)
165 )
166 }
167 }
168
169 return ignores
170 }
171
172 const allowPaths = new Set()
173 for (const file of files) {

Callers 1

getAllowedPathsFunction · 0.85

Calls 4

allowMethod · 0.95
allowContentsMethod · 0.95
useMethod · 0.95
pushMethod · 0.80

Tested by

no test coverage detected