webpack-license-plugin
Version:
Extracts OSS license information of the npm packages in your webpack output
25 lines (20 loc) • 660 B
text/typescript
import type IFileSystem from './types/IFileSystem'
import { join } from 'node:path'
/**
* Reads notice text from notice file.
*
* If no notice file is found returns null.
*/
export default class NoticeTextReader {
constructor(private fileSystem: IFileSystem) {}
public async readNoticeText(moduleDir: string): Promise<string | null> {
const noticeFilename = this.fileSystem
.listPaths(moduleDir)
.find(filename => /^notice/i.test(filename))
if (!noticeFilename) {
return null
}
const noticeFilePath = join(moduleDir, noticeFilename)
return this.fileSystem.readFile(noticeFilePath).replace(/\r\n/g, '\n')
}
}