@nodesecure/scanner
Version:
A package API to run a static analysis of your module's dependencies.
136 lines • 5.73 kB
JavaScript
// Import Third-party Dependencies
import { Mutex } from "@openally/mutex";
import { extractAndResolve, scanDirOrArchive, NpmTarballWorkerPool } from "@nodesecure/tarball";
import { DefaultCollectableSet } from "@nodesecure/js-x-ray";
import { ManifestManager } from "@nodesecure/mama";
// Import Internal Dependencies
import { StatsCollector } from "./StatsCollector.class.js";
import { TempDirectory } from "./TempDirectory.class.js";
import { Logger, ScannerLoggerEvents } from "./logger.class.js";
export class TarballScanner {
constructor(options) {
const { tempDir, statsCollector, pacoteProvider, collectables, maxConcurrency, logger, workers } = options;
this.
this.
this.
this.
this.
this.
this.
this.
? new NpmTarballWorkerPool({
workerCount: typeof workers === "number" ? workers : undefined
})
: null;
}
async scan(context) {
if (this.
await this.
}
else {
await this.
}
this.
}
async
const { name, version, ref, registry, location } = context;
const spec = `${name}@${version}`;
const hasLocation = typeof location !== "undefined";
const mama = await this.
const result = await this.
name: `tarball.scanDirOrArchive ${spec}`,
phase: "tarball-scan",
fn: () => this.
location: mama.location,
astAnalyserOptions: {
optionalWarnings: hasLocation
},
collectableTypes: this.
}),
onSuccess: (result, stat) => {
stat.tarball = {
path: result.path,
filesCount: result.composition.files.length
};
}
});
this.
this.
}
async
const { name, version, ref, registry, location = process.cwd(), isRootNode } = context;
const spec = `${name}@${version}`;
const hasLocation = typeof context.location !== "undefined";
using _ = await this.
const mama = await (isRootNode ?
ManifestManager.fromPackageJSON(location) :
extractAndResolve(this.
spec,
registry,
pacoteProvider: this.
}));
await this.
name: `tarball.scanDirOrArchive ${spec}`,
phase: "tarball-scan",
fn: () => scanDirOrArchive(mama, ref, {
astAnalyserOptions: {
optionalWarnings: hasLocation,
collectables: this.
}
}),
onSuccess: (_, stat) => {
stat.tarball = {
path: ref.path,
filesCount: ref.composition.files.length
};
delete ref.path;
}
});
}
async
using _ = await this.
return extractAndResolve(this.
spec,
registry,
pacoteProvider: this.
});
}
const { description, engines, repository, scripts, author, integrity } = result;
Object.assign(ref, { description, engines, repository, scripts, author, integrity });
ref.warnings.push(...result.warnings);
ref.licenses = result.licenses;
ref.uniqueLicenseIds = result.uniqueLicenseIds;
ref.type = result.type;
ref.size = result.size;
ref.composition.extensions.push(...result.composition.extensions);
ref.composition.files.push(...result.composition.files);
ref.composition.minified = result.composition.minified;
ref.composition.unused.push(...result.composition.unused);
ref.composition.missing.push(...result.composition.missing);
ref.composition.required_files = result.composition.required_files;
ref.composition.required_nodejs = result.composition.required_nodejs;
ref.composition.required_thirdparty = result.composition.required_thirdparty;
ref.composition.required_subpath = result.composition.required_subpath;
const flags = result.flags.filter((flag) => flag !== "hasWarnings" || !ref.flags.includes("hasWarnings"));
ref.flags.push(...flags);
}
for (const data of serialized) {
const sharedSet = this.
sharedSet && DefaultCollectableSet.mergeData(sharedSet, data);
}
}
async [Symbol.asyncDispose]() {
await this.
}
}
//# sourceMappingURL=TarballScanner.class.js.map