Skip to content

Commit a2da270

Browse files
committed
feat: license file gathering
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent 2188ac3 commit a2da270

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/builders/license.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ SPDX-License-Identifier: Apache-2.0
1717
Copyright (c) OWASP Foundation. All Rights Reserved.
1818
*/
1919

20-
2120
import type NATIVE_FS from 'node:fs'
2221
import type NATIVE_PATH from "node:path";
23-
import {Attachment} from '../models/attachment'
24-
import {AttachmentEncoding} from '../enums/attachmentEncoding'
22+
2523
import {getMimeForLicenseFile} from '../_helpers/mime'
24+
import {AttachmentEncoding} from '../enums/attachmentEncoding'
25+
import {Attachment} from '../models/attachment'
2626

2727

2828
interface FsUtils {
@@ -45,6 +45,9 @@ const LICENSE_FILENAME_PATTERN = /^(?:UN)?LICEN[CS]E|.\.LICEN[CS]E$|^NOTICE$/i
4545

4646
type ErrorReporter = (e:Error) => void
4747

48+
/* eslint-disable-next-line @typescript-eslint/no-empty-function -- ack */
49+
function noop ():void {}
50+
4851
export class LicenseEvidenceFetcher {
4952
readonly #fs: FsUtils
5053
readonly #path: PathUtils
@@ -56,11 +59,13 @@ export class LicenseEvidenceFetcher {
5659
* @param options.path - If omitted, the native `node:path` is used.
5760
*/
5861
constructor(options: { fs?: FsUtils, path?: PathUtils } = {}) {
62+
/* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-require-imports -- needed */
5963
this.#fs = options.fs ?? require('node:fs')
6064
this.#path = options.path ?? require('node:path')
65+
/* eslint-enable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-require-imports */
6166
}
6267

63-
public* fetch(prefixPath: string, onError: ErrorReporter = function () {}): Generator<FetchResult> {
68+
* fetch(prefixPath: string, onError: ErrorReporter = noop): Generator<FetchResult> {
6469
const files = this.#fs.readdirSync(prefixPath)
6570
for (const file of files) {
6671
if (!LICENSE_FILENAME_PATTERN.test(file)) {
@@ -88,7 +93,9 @@ export class LicenseEvidenceFetcher {
8893
}
8994
)
9095
}
91-
} catch (e) {
96+
}
97+
/* c8 ignore next 3 */
98+
catch (e) {
9299
onError(new Error(`skipped license file ${filePath}`, {cause: e}))
93100
}
94101
}

0 commit comments

Comments
 (0)