Skip to content

Commit fd1621a

Browse files
committed
Make sure ignore strategies receive directories with trailing slash
ignore strategies like git, expect directories to be passed in with a trailing slash in order to properly match. consider a source tree: ├── hello │   └── index.html ├── index.html now we want to exclude everything except all html files (including all subdirectories). this can be done with a gitignore of: * !*/ !*.html in order for the git ignore strategy to properly match this, it needs to know that hello is a directory. this patch just does that by appending a trailing slash for the ignore strategies.
1 parent dc07f52 commit fd1621a

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

packages/@aws-cdk/core/lib/fs/copy.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@ export function copyDirectory(srcDir: string, destDir: string, options: CopyOpti
1515
throw new Error(`${srcDir} is not a directory`);
1616
}
1717

18-
const files = fs.readdirSync(srcDir);
18+
const files = fs.readdirSync(srcDir, { withFileTypes: true });
1919
for (const file of files) {
20-
const sourceFilePath = path.join(srcDir, file);
20+
const sourceFilePath = path.join(srcDir, file.name);
2121

22-
if (ignoreStrategy.ignores(sourceFilePath)) {
22+
const ignorePath = sourceFilePath + (file.name && file.isDirectory() ? path.sep : '');
23+
if (ignoreStrategy.ignores(ignorePath)) {
2324
continue;
2425
}
2526

26-
const destFilePath = path.join(destDir, file);
27+
const destFilePath = path.join(destDir, file.name);
2728

2829
let stat: fs.Stats | undefined = follow === SymlinkFollowMode.ALWAYS
2930
? fs.statSync(sourceFilePath)

packages/@aws-cdk/core/lib/fs/ignore.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ export class GlobIgnoreStrategy extends IgnoreStrategy {
117117
}
118118

119119
let relativePath = path.relative(this.absoluteRootPath, absoluteFilePath);
120+
if (relativePath) {
121+
relativePath += absoluteFilePath.endsWith(path.sep) ? path.sep : '';
122+
}
120123
let excludeOutput = false;
121124

122125
for (const pattern of this.patterns) {
@@ -174,6 +177,9 @@ export class GitIgnoreStrategy extends IgnoreStrategy {
174177
}
175178

176179
let relativePath = path.relative(this.absoluteRootPath, absoluteFilePath);
180+
if (relativePath) {
181+
relativePath += absoluteFilePath.endsWith(path.sep) ? path.sep : '';
182+
}
177183

178184
return this.ignore.ignores(relativePath);
179185
}
@@ -217,6 +223,9 @@ export class DockerIgnoreStrategy extends IgnoreStrategy {
217223
}
218224

219225
let relativePath = path.relative(this.absoluteRootPath, absoluteFilePath);
226+
if (relativePath) {
227+
relativePath += absoluteFilePath.endsWith(path.sep) ? path.sep : '';
228+
}
220229

221230
return this.ignore.ignores(relativePath);
222231
}

0 commit comments

Comments
 (0)