Skip to content

Commit 50f2977

Browse files
authored
Add glob option to ignore hidden files (actions#1791)
* Add glob option to ignore hidden files * Use the basename of the file/directory to check for `.` * Ensure the `excludeHiddenFiles` is properly copied * Allow the root directory to be matched * Fix description of `excludeHiddenFiles` * Document Windows hidden attribute limitation * Bump version * `lint` * Document 0.5.0 release * Lint again
1 parent 48a6537 commit 50f2977

7 files changed

+47
-4
lines changed

packages/glob/RELEASES.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# @actions/glob Releases
22

3+
### 0.5.0
4+
- Added `excludeHiddenFiles` option, which is disabled by default to preserve existing behavior [#1791: Add glob option to ignore hidden files](https://github.com/actions/toolkit/pull/1791)
5+
36
### 0.4.0
47
- Pass in the current workspace as a parameter to HashFiles [#1318](https://github.com/actions/toolkit/pull/1318)
58

packages/glob/__tests__/internal-globber.test.ts

+21-1
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ describe('globber', () => {
708708
expect(itemPaths).toEqual([])
709709
})
710710

711-
it('returns hidden files', async () => {
711+
it('returns hidden files by default', async () => {
712712
// Create the following layout:
713713
// <root>
714714
// <root>/.emptyFolder
@@ -734,6 +734,26 @@ describe('globber', () => {
734734
])
735735
})
736736

737+
it('ignores hidden files when excludeHiddenFiles is set', async () => {
738+
// Create the following layout:
739+
// <root>
740+
// <root>/.emptyFolder
741+
// <root>/.file
742+
// <root>/.folder
743+
// <root>/.folder/file
744+
const root = path.join(getTestTemp(), 'ignores-hidden-files')
745+
await createHiddenDirectory(path.join(root, '.emptyFolder'))
746+
await createHiddenDirectory(path.join(root, '.folder'))
747+
await createHiddenFile(path.join(root, '.file'), 'test .file content')
748+
await fs.writeFile(
749+
path.join(root, '.folder', 'file'),
750+
'test .folder/file content'
751+
)
752+
753+
const itemPaths = await glob(root, {excludeHiddenFiles: true})
754+
expect(itemPaths).toEqual([root])
755+
})
756+
737757
it('returns normalized paths', async () => {
738758
// Create the following layout:
739759
// <root>/hello/world.txt

packages/glob/package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/glob/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@actions/glob",
3-
"version": "0.4.0",
3+
"version": "0.5.0",
44
"preview": true,
55
"description": "Actions glob lib",
66
"keywords": [

packages/glob/src/internal-glob-options-helper.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ export function getOptions(copy?: GlobOptions): GlobOptions {
99
followSymbolicLinks: true,
1010
implicitDescendants: true,
1111
matchDirectories: true,
12-
omitBrokenSymbolicLinks: true
12+
omitBrokenSymbolicLinks: true,
13+
excludeHiddenFiles: false
1314
}
1415

1516
if (copy) {
@@ -32,6 +33,11 @@ export function getOptions(copy?: GlobOptions): GlobOptions {
3233
result.omitBrokenSymbolicLinks = copy.omitBrokenSymbolicLinks
3334
core.debug(`omitBrokenSymbolicLinks '${result.omitBrokenSymbolicLinks}'`)
3435
}
36+
37+
if (typeof copy.excludeHiddenFiles === 'boolean') {
38+
result.excludeHiddenFiles = copy.excludeHiddenFiles
39+
core.debug(`excludeHiddenFiles '${result.excludeHiddenFiles}'`)
40+
}
3541
}
3642

3743
return result

packages/glob/src/internal-glob-options.ts

+9
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,13 @@ export interface GlobOptions {
3636
* @default true
3737
*/
3838
omitBrokenSymbolicLinks?: boolean
39+
40+
/**
41+
* Indicates whether to exclude hidden files (files and directories starting with a `.`).
42+
* This does not apply to Windows files and directories with the hidden attribute unless
43+
* they are also prefixed with a `.`.
44+
*
45+
* @default false
46+
*/
47+
excludeHiddenFiles?: boolean
3948
}

packages/glob/src/internal-globber.ts

+5
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ export class DefaultGlobber implements Globber {
128128
continue
129129
}
130130

131+
// Hidden file or directory?
132+
if (options.excludeHiddenFiles && path.basename(item.path).match(/^\./)) {
133+
continue
134+
}
135+
131136
// Directory
132137
if (stats.isDirectory()) {
133138
// Matched

0 commit comments

Comments
 (0)