Skip to content

Commit

Permalink
feat: add support for excluding a nested directory files using a dire…
Browse files Browse the repository at this point in the history
…ctory pattern ends with a slash (#1062)

Co-authored-by: tj-actions[bot] <[email protected]>
Co-authored-by: GitHub Action <[email protected]>
  • Loading branch information
3 people authored Jan 18, 2024
1 parent d9b22df commit d9dadb0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
21 changes: 10 additions & 11 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,7 @@ export async function run(): Promise<void> {

const gitignorePath = path.join(workingDirectory, '.gitignore')

let filePatterns = files
.split(filesSeparator)
.filter(p => p !== '')
.join('\n')
let filePatterns = files.split(filesSeparator).filter(Boolean).join('\n')

core.debug(`file patterns: ${filePatterns}`)

Expand All @@ -97,11 +94,14 @@ export async function run(): Promise<void> {
if (excludedFiles !== '') {
const excludedFilePatterns = excludedFiles
.split(excludedFilesSeparator)
.filter(p => p !== '')
.filter(Boolean)
.map(p => {
if (!p.startsWith('!')) {
p = `!${p}`
}
if (p.endsWith(path.sep)) {
p = `${p}${path.sep}**`
}
return p
})
.join('\n')
Expand Down
11 changes: 6 additions & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,15 @@ async function* lineOfFileGenerator({
input: fileStream,
crlfDelay: Infinity
})
for await (const line of rl) {
for await (let line of rl) {
if (!line.startsWith('#') && line !== '') {
if (excludedFiles) {
if (line.startsWith('!')) {
yield line
} else {
yield `!${line}`
line = line.startsWith('!') ? line : `!${line}`
if (line.endsWith(path.sep)) {
line = `${line}${path.sep}**`
}

yield line
} else {
yield line
}
Expand Down

0 comments on commit d9dadb0

Please sign in to comment.