diff --git a/packages/glob/RELEASES.md b/packages/glob/RELEASES.md index 84aa06be..142cae8d 100644 --- a/packages/glob/RELEASES.md +++ b/packages/glob/RELEASES.md @@ -1,5 +1,8 @@ # @actions/glob Releases +### 0.5.0 +- 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) + ### 0.4.0 - Pass in the current workspace as a parameter to HashFiles [#1318](https://github.com/actions/toolkit/pull/1318) diff --git a/packages/glob/__tests__/internal-globber.test.ts b/packages/glob/__tests__/internal-globber.test.ts index 4ae670fe..4b9d22ad 100644 --- a/packages/glob/__tests__/internal-globber.test.ts +++ b/packages/glob/__tests__/internal-globber.test.ts @@ -708,7 +708,7 @@ describe('globber', () => { expect(itemPaths).toEqual([]) }) - it('returns hidden files', async () => { + it('returns hidden files by default', async () => { // Create the following layout: // // /.emptyFolder @@ -734,6 +734,26 @@ describe('globber', () => { ]) }) + it('ignores hidden files when excludeHiddenFiles is set', async () => { + // Create the following layout: + // + // /.emptyFolder + // /.file + // /.folder + // /.folder/file + const root = path.join(getTestTemp(), 'ignores-hidden-files') + await createHiddenDirectory(path.join(root, '.emptyFolder')) + await createHiddenDirectory(path.join(root, '.folder')) + await createHiddenFile(path.join(root, '.file'), 'test .file content') + await fs.writeFile( + path.join(root, '.folder', 'file'), + 'test .folder/file content' + ) + + const itemPaths = await glob(root, {excludeHiddenFiles: true}) + expect(itemPaths).toEqual([root]) + }) + it('returns normalized paths', async () => { // Create the following layout: // /hello/world.txt diff --git a/packages/glob/package-lock.json b/packages/glob/package-lock.json index 7b954259..17817543 100644 --- a/packages/glob/package-lock.json +++ b/packages/glob/package-lock.json @@ -1,6 +1,6 @@ { "name": "@actions/glob", - "version": "0.4.0", + "version": "0.5.0", "lockfileVersion": 3, "requires": true, "description": "Actions glob lib", diff --git a/packages/glob/package.json b/packages/glob/package.json index 62e6bd29..637f9c6a 100644 --- a/packages/glob/package.json +++ b/packages/glob/package.json @@ -1,6 +1,6 @@ { "name": "@actions/glob", - "version": "0.4.0", + "version": "0.5.0", "preview": true, "description": "Actions glob lib", "keywords": [ diff --git a/packages/glob/src/internal-glob-options-helper.ts b/packages/glob/src/internal-glob-options-helper.ts index c798b165..f1dd5fe9 100644 --- a/packages/glob/src/internal-glob-options-helper.ts +++ b/packages/glob/src/internal-glob-options-helper.ts @@ -9,7 +9,8 @@ export function getOptions(copy?: GlobOptions): GlobOptions { followSymbolicLinks: true, implicitDescendants: true, matchDirectories: true, - omitBrokenSymbolicLinks: true + omitBrokenSymbolicLinks: true, + excludeHiddenFiles: false } if (copy) { @@ -32,6 +33,11 @@ export function getOptions(copy?: GlobOptions): GlobOptions { result.omitBrokenSymbolicLinks = copy.omitBrokenSymbolicLinks core.debug(`omitBrokenSymbolicLinks '${result.omitBrokenSymbolicLinks}'`) } + + if (typeof copy.excludeHiddenFiles === 'boolean') { + result.excludeHiddenFiles = copy.excludeHiddenFiles + core.debug(`excludeHiddenFiles '${result.excludeHiddenFiles}'`) + } } return result diff --git a/packages/glob/src/internal-glob-options.ts b/packages/glob/src/internal-glob-options.ts index ac1e93f1..8b721550 100644 --- a/packages/glob/src/internal-glob-options.ts +++ b/packages/glob/src/internal-glob-options.ts @@ -36,4 +36,13 @@ export interface GlobOptions { * @default true */ omitBrokenSymbolicLinks?: boolean + + /** + * Indicates whether to exclude hidden files (files and directories starting with a `.`). + * This does not apply to Windows files and directories with the hidden attribute unless + * they are also prefixed with a `.`. + * + * @default false + */ + excludeHiddenFiles?: boolean } diff --git a/packages/glob/src/internal-globber.ts b/packages/glob/src/internal-globber.ts index 3978d625..7f56b9b5 100644 --- a/packages/glob/src/internal-globber.ts +++ b/packages/glob/src/internal-globber.ts @@ -128,6 +128,11 @@ export class DefaultGlobber implements Globber { continue } + // Hidden file or directory? + if (options.excludeHiddenFiles && path.basename(item.path).match(/^\./)) { + continue + } + // Directory if (stats.isDirectory()) { // Matched