Add HashFiles to the toolkit (#830)

* add hash files to the toolkit
This commit is contained in:
Thomas Boop
2021-06-07 14:26:00 -04:00
committed by GitHub
parent c9af6bb1b3
commit c5e1af5dc3
4 changed files with 200 additions and 0 deletions

View File

@@ -1,5 +1,7 @@
import {Globber, DefaultGlobber} from './internal-globber'
import {GlobOptions} from './internal-glob-options'
import {HashFileOptions} from './internal-hash-file-options'
import {hashFiles as _hashFiles} from './internal-hash-files'
export {Globber, GlobOptions}
@@ -15,3 +17,21 @@ export async function create(
): Promise<Globber> {
return await DefaultGlobber.create(patterns, options)
}
/**
* Computes the sha256 hash of a glob
*
* @param patterns Patterns separated by newlines
* @param options Glob options
*/
export async function hashFiles(
patterns: string,
options?: HashFileOptions
): Promise<string> {
let followSymbolicLinks = true
if (options && typeof options.followSymbolicLinks === 'boolean') {
followSymbolicLinks = options.followSymbolicLinks
}
const globber = await create(patterns, {followSymbolicLinks})
return _hashFiles(globber)
}