Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created April 30, 2021 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaacs/ba515d0c5cd4eaab7de99d3bd4566f94 to your computer and use it in GitHub Desktop.
Save isaacs/ba515d0c5cd4eaab7de99d3bd4566f94 to your computer and use it in GitHub Desktop.
diff --git a/lib/audit-report.js b/lib/audit-report.js
index 77cd6511..e585d827 100644
--- a/lib/audit-report.js
+++ b/lib/audit-report.js
@@ -101,6 +101,7 @@ class AuditReport extends Map {
async run () {
this.report = await this[_getReport]()
+ this.log.silly('audit report', this.report)
if (this.report)
await this[_init]()
return this
@@ -289,6 +290,7 @@ class AuditReport extends Map {
try {
// first try the super fast bulk advisory listing
const body = prepareBulkData(this.tree, this[_omit])
+ this.log.silly('audit', 'bulk request', body)
// no sense asking if we don't have anything to audit,
// we know it'll be empty
@@ -304,7 +306,8 @@ class AuditReport extends Map {
})
return await res.json()
- } catch (_) {
+ } catch (er) {
+ this.log.silly('audit', 'bulk request failed', String(er.body))
// that failed, try the quick audit endpoint
const body = prepareData(this.tree, this.options)
const res = await fetch('/-/npm/v1/security/audits/quick', {
diff --git a/lib/node.js b/lib/node.js
index a54f76af..cdda25ef 100644
--- a/lib/node.js
+++ b/lib/node.js
@@ -111,10 +111,21 @@ class Node {
const pkg = sourceReference ? sourceReference.package
: normalize(options.pkg || {})
- this.name = name ||
- nameFromFolder(path || pkg.name || realpath) ||
- pkg.name ||
- null
+ if (name)
+ this.name = name
+ else {
+ const { name: pkgname } = pkg
+ const nff = nameFromFolder(path)
+ const nm = !nff ? false
+ : nff.includes('/') ? basename(dirname(dirname(path)))
+ : basename(dirname(path))
+ if (nm === 'node_modules')
+ this.name = nff
+ else if (pkg.name)
+ this.name = pkg.name
+ else
+ this.name = null
+ }
// should be equal if not a link
this.path = path ? resolve(path) : null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment