@nodesecure/tarball
Version:
NodeSecure tarball scanner
45 lines • 1.53 kB
JavaScript
// Import Node.js Dependencies
import path from "node:path";
// Import Third-party Dependencies
import * as conformance from "@nodesecure/conformance";
import { ManifestManager } from "@nodesecure/mama";
// Import Internal Dependencies
import { SourceCodeReport, SourceCodeScanner } from "./SourceCodeScanner.class.js";
import { getTarballComposition } from "../utils/index.js";
export class NpmTarball {
static JS_EXTENSIONS = new Set([".js", ".mjs", ".cjs"]);
manifest;
constructor(mama) {
if (!ManifestManager.isLocated(mama)) {
throw new Error("ManifestManager must have a location");
}
this.manifest = mama;
}
async scanFiles() {
const location = this.manifest.location;
const [composition, spdx] = await Promise.all([
getTarballComposition(location),
conformance.extractLicenses(location)
]);
const code = await new SourceCodeScanner(this.manifest).iterate({
manifest: [...this.manifest.getEntryFiles()]
.flatMap(filterJavaScriptFiles()),
javascript: composition.files
.flatMap(filterJavaScriptFiles())
});
return {
conformance: spdx,
composition,
code
};
}
}
function filterJavaScriptFiles() {
return (file) => {
if (NpmTarball.JS_EXTENSIONS.has(path.extname(file))) {
return file;
}
return [];
};
}
//# sourceMappingURL=NpmTarball.class.js.map