MCPcopy Create free account
hub / github.com/Effect-TS/effect / parseDockerignore

Function parseDockerignore

packages/effect/src/IgnoreFile.ts:921–971  ·  view source on GitHub ↗
(source: string)

Source from the content-addressed store, hash-verified

919 * `ignorefile.ReadAll` followed by `patternmatcher.New`.
920 */
921const parseDockerignore = (source: string): Array<DockerPattern> | DockerError => {
922 const patterns: Array<DockerPattern> = []
923 const lines = source.split("\n")
924 for (let index = 0; index < lines.length; index++) {
925 let line = lines[index]
926 if (line.endsWith("\r")) {
927 line = line.slice(0, -1)
928 }
929 if (index === 0 && line.startsWith("")) {
930 line = line.slice(1)
931 }
932 if (line.startsWith("#")) {
933 continue
934 }
935 const trimmed = goTrim(line)
936 if (trimmed === "") {
937 continue
938 }
939 let exclusion = trimmed.startsWith("!")
940 let pattern = exclusion ? goTrim(trimmed.slice(1)) : trimmed
941 if (pattern !== "") {
942 pattern = clean(pattern)
943 if (pattern.length > 1 && pattern.startsWith("/")) {
944 pattern = pattern.slice(1)
945 }
946 }
947 if (exclusion) {
948 pattern = `!${pattern}`
949 }
950 // `New` trims and cleans the result again before reading a leading `!`,
951 // so `!/` is a bare `!`, `/ x` is `x` and `/!x` is an exception
952 pattern = goTrim(pattern)
953 if (pattern === "") {
954 continue
955 }
956 pattern = clean(pattern)
957 exclusion = pattern.startsWith("!")
958 if (exclusion) {
959 if (pattern.length === 1) {
960 return { line: index + 1, pattern: trimmed, message: `illegal exclusion pattern: "!"` }
961 }
962 pattern = pattern.slice(1)
963 }
964 const match = compileDocker(pattern)
965 if (typeof match === "string") {
966 return { line: index + 1, pattern: trimmed, message: match }
967 }
968 patterns.push({ exclusion, matcher: dockerMatcher(pattern, match) })
969 }
970 return patterns
971}
972
973const wildcardChars = /[*[\]?^\\]/
974

Callers 1

dockerignoreFunction · 0.85

Calls 7

goTrimFunction · 0.85
compileDockerFunction · 0.85
dockerMatcherFunction · 0.85
sliceMethod · 0.80
cleanFunction · 0.70
pushMethod · 0.65
splitMethod · 0.45

Tested by

no test coverage detected