src/utils/npm-audit.js
function removeIgnoredVulnerabilities(response, options) {
    try {
        const ignoredVulnerabilities = getIgnoredVulnerabilities(options);
        if (ignoredVulnerabilities && ignoredVulnerabilities.length === 0) {
            return response;
        }
        const filteredResponse = JSON.parse(JSON.stringify(response, null, 2));

        /* prettier-ignore */
        filteredResponse.actions = filteredResponse.actions
            ? filteredResponse.actions
                .map((action) => {
                    action.resolves = action.resolves.filter(
                        (resolve) =>
                            ignoredVulnerabilities.indexOf(`${resolve.id}`) < 0
                    );
                    return action;
                })
                .filter((action) => action.resolves.length > 0)
            : [];

        ignoredVulnerabilities.forEach(
            (ignoredVulnerability) =>
                delete filteredResponse.advisories[ignoredVulnerability]
        );

        const vulnerabilitiesMetadata = {
            info: 0,
            low: 0,
            moderate: 0,
            high: 0,
            critical: 0,
        };

        const severities = {};
        const advisories = filteredResponse.advisories;
        for (const key in advisories) {
            if (advisories.hasOwnProperty(key)) {
                const advisory = advisories[key];
                severities[`${advisory.id}`] = advisory.severity;
            }
        }

        filteredResponse.actions.forEach((action) => {
            action.resolves.forEach((resolve) => {
                vulnerabilitiesMetadata[severities[`${resolve.id}`]] += 1;
            });
        });

        filteredResponse.metadata.vulnerabilities = vulnerabilitiesMetadata;

        return filteredResponse;
    } catch (error) {
        if (response) {
            response.internalErrors = response.internalErrors || [];
            response.internalErrors.push(error);
            return response;
        }
        return response;
    }
}
function removeIgnoredVulnerabilities(response, options) {
    try {
        const ignoredVulnerabilities = getIgnoredVulnerabilities(options);
        if (ignoredVulnerabilities && ignoredVulnerabilities.length === 0) {
            return response;
        }
        const filteredResponse = JSON.parse(JSON.stringify(response, null, 2));

        /* prettier-ignore */
        filteredResponse.actions = filteredResponse.actions
            ? filteredResponse.actions
                .map((action) => {
                    action.resolves = action.resolves.filter(
                        (resolve) =>
                            ignoredVulnerabilities.indexOf(`${resolve.id}`) < 0
                    );
                    return action;
                })
                .filter((action) => action.resolves.length > 0)
            : [];

        ignoredVulnerabilities.forEach(
            (ignoredVulnerability) =>
                delete filteredResponse.advisories[ignoredVulnerability]
        );

        const vulnerabilitiesMetadata = {
            info: 0,
            low: 0,
            moderate: 0,
            high: 0,
            critical: 0,
        };

        const severities = {};
        const advisories = filteredResponse.advisories;
        for (const key in advisories) {
            if (advisories.hasOwnProperty(key)) {
                const advisory = advisories[key];
                severities[`${advisory.id}`] = advisory.severity;
            }
        }

        filteredResponse.actions.forEach((action) => {
            action.resolves.forEach((resolve) => {
                vulnerabilitiesMetadata[severities[`${resolve.id}`]] += 1;
            });
        });

        filteredResponse.metadata.vulnerabilities = vulnerabilitiesMetadata;

        return filteredResponse;
    } catch (error) {
        if (response) {
            response.internalErrors = response.internalErrors || [];
            response.internalErrors.push(error);
            return response;
        }
        return response;
    }
}
function removeIgnoredVulnerabilities ( response , options ) { try { const ignoredVulnerabilities = getIgnoredVulnerabilities ( options ) ; if ( ignoredVulnerabilities && ignoredVulnerabilities . length === 0 ) { return response ; } const filteredResponse = JSON . parse ( JSON . stringify ( response , null , 2 ) ) ; /* prettier-ignore */ filteredResponse . actions = filteredResponse . actions ? filteredResponse . actions . map ( ( action ) => { action . resolves = action . resolves . filter ( ( resolve ) => ignoredVulnerabilities . indexOf ( ` ${ resolve . id } ` ) < 0 ) ; return action ; } ) . filter ( ( action ) => action . resolves . length > 0 ) : [ ] ; ignoredVulnerabilities . forEach ( ( ignoredVulnerability ) => delete filteredResponse . advisories [ ignoredVulnerability ] ) ; const vulnerabilitiesMetadata = { info : 0 , low : 0 , moderate : 0 , high : 0 , critical : 0 , } ; const severities = { } ; const advisories = filteredResponse . advisories ; for ( const key in advisories ) { if ( advisories . hasOwnProperty ( key ) ) { const advisory = advisories [ key ] ; severities [ ` ${ advisory . id } ` ] = advisory . severity ; } } filteredResponse . actions . forEach ( ( action ) => { action . resolves . forEach ( ( resolve ) => { vulnerabilitiesMetadata [ severities [ ` ${ resolve . id } ` ] ] += 1 ; } ) ; } ) ; filteredResponse . metadata . vulnerabilities = vulnerabilitiesMetadata ; return filteredResponse ; } catch ( error ) { if ( response ) { response . internalErrors = response . internalErrors || [ ] ; response . internalErrors . push ( error ) ; return response ; } return response ; } }
Remove, from npm audit command response, the vulnerabilities defined in .auditignore file
@param {*} response - result of the npm audit command (eventually modified by previous middlewares execution)
@param {DefaultOptions} options - options
Remove from npm audit command response the vulnerabilities defined in . auditignore file