-
Notifications
You must be signed in to change notification settings - Fork 9.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deps(snyk): prettify snyk snapshot (#5080)
- Loading branch information
1 parent
72988e1
commit 9b8154b
Showing
6 changed files
with
184 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env node | ||
|
||
/** | ||
* @license Copyright 2018 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
'use strict'; | ||
|
||
/** @fileoverview Read in the snyk snapshot, remove whatever we don't need, write it back */ | ||
|
||
const {readFileSync, writeFileSync} = require('fs'); | ||
const prettyJSONStringify = require('pretty-json-stringify'); | ||
|
||
const filename = process.argv[2]; | ||
if (!filename) throw new Error('No filename provided.'); | ||
|
||
const data = readFileSync(filename, 'utf8'); | ||
const output = cleanAndFormat(data); | ||
JSON.parse(output); // make sure it's parseable | ||
writeFileSync(filename, output, 'utf8'); | ||
|
||
/** @typedef {import('../audits/dobetterweb/no-vulnerable-libraries.js').SnykDB} SnykDB */ | ||
|
||
/** | ||
* @param {string} vulnString | ||
* @return {string} | ||
*/ | ||
function cleanAndFormat(vulnString) { | ||
const snapshot = /** @type {!SnykDB} */ (JSON.parse(vulnString)); | ||
for (const libEntries of Object.values(snapshot.npm)) { | ||
libEntries.forEach((entry, i) => { | ||
const pruned = { | ||
id: entry.id, | ||
severity: entry.severity, | ||
semver: {vulnerable: entry.semver.vulnerable}, | ||
}; | ||
|
||
libEntries[i] = pruned; | ||
}); | ||
} | ||
|
||
// Normal pretty JSON-stringify has too many newlines. This strikes the right signal:noise ratio | ||
return prettyJSONStringify(snapshot, { | ||
tab: ' ', | ||
spaceBeforeColon: '', | ||
spaceAfterColon: '', | ||
spaceAfterComma: '', | ||
spaceInsideObject: '', | ||
shouldExpand: (_, level) => level < 3, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* @license Copyright 2018 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
declare module 'pretty-json-stringify' { | ||
interface Params { | ||
tab?: string; | ||
spaceBeforeColon?: string; | ||
spaceAfterColon?: string; | ||
spaceAfterComma?: string; | ||
spaceInsideObject?: string; | ||
spaceInsideArray?: string; | ||
shouldExpand?(obj: Object, level: number, index: string): Boolean; | ||
} | ||
|
||
function stringify(object: Object, params: Params): string; | ||
export = stringify; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters