Skip to content

Commit

Permalink
audit: respect production flag in audit and install
Browse files Browse the repository at this point in the history
  • Loading branch information
tommilligan committed Nov 27, 2018
1 parent d817134 commit 58f9d6b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/cli/commands/audit.js
Expand Up @@ -130,7 +130,8 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg
workspaceLayout,
});

const vulnerabilities = await audit.performAudit(manifest, install.resolver, install.linker, patterns);
const {production} = config;
const vulnerabilities = await audit.performAudit(manifest, install.resolver, install.linker, patterns, production);
const totalVulnerabilities =
vulnerabilities.info +
vulnerabilities.low +
Expand Down Expand Up @@ -178,7 +179,11 @@ export default class Audit {
}
}

_mapHoistedTreesToAuditTree(manifest: Object, hoistedTrees: HoistedTrees): AuditTree {
_mapHoistedTreesToAuditTree(manifest: Object, hoistedTrees: HoistedTrees, production: boolean): AuditTree {
let requires = Object.assign({}, manifest.dependencies || {});
if (!production) {
requires = Object.assign(requires, manifest.devDependencies || {}, manifest.optionalDependencies || {});
}
const auditTree: AuditTree = {
name: manifest.name || undefined,
version: manifest.version || undefined,
Expand All @@ -187,12 +192,7 @@ export default class Audit {
metadata: {
//TODO: What do we send here? npm sends npm version, node version, etc.
},
requires: Object.assign(
{},
manifest.dependencies || {},
manifest.devDependencies || {},
manifest.optionalDependencies || {},
),
requires,
integrity: undefined,
dependencies: {},
};
Expand Down Expand Up @@ -248,10 +248,11 @@ export default class Audit {
resolver: PackageResolver,
linker: PackageLinker,
patterns: Array<string>,
production: boolean,
): Promise<AuditVulnerabilityCounts> {
this._insertWorkspacePackagesIntoManifest(manifest, resolver);
const hoistedTrees = await hoistedTreeBuilder(resolver, linker, patterns);
const auditTree = this._mapHoistedTreesToAuditTree(manifest, hoistedTrees);
const auditTree = this._mapHoistedTreesToAuditTree(manifest, hoistedTrees, production);
this.auditData = await this._fetchAudit(auditTree);
return this.auditData.metadata.vulnerabilities;
}
Expand Down
1 change: 1 addition & 0 deletions src/cli/commands/install.js
Expand Up @@ -612,6 +612,7 @@ export class Install {
this.resolver,
this.linker,
topLevelPatterns,
!!this.config.production,
);
auditFoundProblems =
auditVulnerabilityCounts.info ||
Expand Down

0 comments on commit 58f9d6b

Please sign in to comment.