|
1
|
import path from "path" |
|
2
|
|
|
3
|
/** |
|
4
|
* Determines whether a file should be excluded from the build output. |
|
5
|
* |
|
6
|
* Each entry in "chunksToIgnore" is matched against the path *segments* of |
|
7
|
* "relativeFileName" rather than as a raw substring. Single-segment entries |
|
8
|
* (e.g. "test") match a directory or file named exactly that, while |
|
9
|
* multi-segment entries (e.g. "src/admin") only match when those segments |
|
10
|
* appear consecutively in the path. |
|
11
|
* |
|
12
|
* Matching on segments (instead of "String.includes") prevents user files such |
|
13
|
* as "src/scripts/seed-test-accounts.ts" from being silently dropped just |
|
14
|
* because their name happens to contain an ignored substring like "test". |
|
15
|
*/ |
|
16
|
export function isFileIgnored( |
|
17
|
relativeFileName: string, |
|
18
|
chunksToIgnore: string[] |
|
19
|
): boolean { |
|
20
|
const segments = relativeFileName.split(path.sep) |
|
21
|
|
|
22
|
return chunksToIgnore.some((chunk) => { |
|
23
|
const chunkSegments = chunk.split("/") |
|
24
|
return segments.some((_, index) => |
|
25
|
chunkSegments.every( |
|
26
|
(chunkSegment, offset) => segments[index + offset] === chunkSegment |
|
27
|
) |
|
28
|
) |
|
29
|
}) |
|
30
|
} |