| 1067 | } |
| 1068 | |
| 1069 | export const testGlob = <E>(layer: Layer.Layer<Fs.FileSystem, E>) => { |
| 1070 | const runPromise = runWith(layer) |
| 1071 | |
| 1072 | const globFixture = Effect.gen(function*() { |
| 1073 | const fs = yield* Fs.FileSystem |
| 1074 | const root = yield* fs.makeTempDirectoryScoped() |
| 1075 | for (const directory of ["src/sub", "a", "b", ".hidden", "node_modules/pkg"]) { |
| 1076 | yield* fs.makeDirectory(`${root}/${directory}`, { recursive: true }) |
| 1077 | } |
| 1078 | for ( |
| 1079 | const file of [ |
| 1080 | "README.md", |
| 1081 | ".env", |
| 1082 | "src/index.ts", |
| 1083 | "src/sub/deep.ts", |
| 1084 | "src/sub/deep.js", |
| 1085 | "a/x.ts", |
| 1086 | "b/y.ts", |
| 1087 | ".hidden/secret.ts", |
| 1088 | "node_modules/pkg/index.ts" |
| 1089 | ] |
| 1090 | ) { |
| 1091 | yield* fs.writeFileString(`${root}/${file}`, "") |
| 1092 | } |
| 1093 | return root |
| 1094 | }) |
| 1095 | |
| 1096 | it.each<{ |
| 1097 | readonly pattern: string |
| 1098 | readonly exclude?: ReadonlyArray<string> |
| 1099 | readonly dot?: boolean |
| 1100 | readonly filter?: readonly ["gitignore" | "dockerignore", string] |
| 1101 | readonly expected: ReadonlyArray<string> |
| 1102 | }>([ |
| 1103 | { |
| 1104 | pattern: "**/*.ts", |
| 1105 | expected: ["a/x.ts", "b/y.ts", "node_modules/pkg/index.ts", "src/index.ts", "src/sub/deep.ts"] |
| 1106 | }, |
| 1107 | { pattern: ".*", expected: [".env", ".hidden"] }, |
| 1108 | { pattern: "src/**", expected: ["src", "src/index.ts", "src/sub", "src/sub/deep.js", "src/sub/deep.ts"] }, |
| 1109 | { pattern: "*/", expected: ["a", "b", "node_modules", "src"] }, |
| 1110 | { pattern: "{a,b}/*.ts", expected: ["a/x.ts", "b/y.ts"] }, |
| 1111 | { pattern: "src/index.ts", expected: ["src/index.ts"] }, |
| 1112 | { pattern: "readme.*", expected: [] }, |
| 1113 | { pattern: "**/.", expected: [] }, |
| 1114 | { pattern: "src/index.ts/.", expected: [] }, |
| 1115 | { pattern: "src/.", expected: ["src"] }, |
| 1116 | { |
| 1117 | pattern: "**/*.ts", |
| 1118 | exclude: ["node_modules"], |
| 1119 | dot: true, |
| 1120 | expected: [".hidden/secret.ts", "a/x.ts", "b/y.ts", "src/index.ts", "src/sub/deep.ts"] |
| 1121 | }, |
| 1122 | { pattern: "*", exclude: ["**/src/", "**/README.md/"], expected: ["README.md", "a", "b", "node_modules"] }, |
| 1123 | // the root is never a result; use `exists` to check it |
| 1124 | { pattern: ".", expected: [] }, |
| 1125 | // `filter` expectations: BuildKit's walk (tonistiigi/fsutil@ca65610) and `git check-ignore --no-index` |
| 1126 | { |