Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ var parse = require('spdx-expression-parse')
var satisfies = require('semver').satisfies
var spdxAllowed = require('spdx-whitelisted')

function licensee (configuration, path, callback) {
async function licensee (configurationOriginal, path, callback) {
// We do not want to modify original object when looping this method
// 'structuredClone' is not defined in test
var configuration = JSON.parse(JSON.stringify(configurationOriginal))

if (!validConfiguration(configuration)) {
return callback(new Error('Invalid configuration'))
}
Expand All @@ -34,7 +38,7 @@ function licensee (configuration, path, callback) {
callback(new Error('No licenses or packages allowed.'))
} else {
var arborist = new Arborist({ path })
arborist.loadActual({ forceActual: true })
return arborist.loadActual({ forceActual: true })
.then(function (tree) {
var dependencies = Array.from(tree.inventory.values())
.filter(function (dependency) {
Expand All @@ -43,7 +47,7 @@ function licensee (configuration, path, callback) {
if (configuration.filterPackages) {
dependencies = configuration.filterPackages(dependencies)
}
callback(null, findIssues(configuration, dependencies))
return callback(null, findIssues(configuration, dependencies))
})
.catch(function (error) {
return callback(error)
Expand Down Expand Up @@ -108,9 +112,14 @@ function findIssues (configuration, dependencies) {
}
})

results.sort(function (a, b) {
return a.name.localeCompare(b.name)
})
// Non existing symlinks will not have metadata
const noName = results.filter(x => !x.name)

if (!noName) {
results.sort(function (a, b) {
return a.name.localeCompare(b.name)
})
}

return results
}
Expand Down Expand Up @@ -174,6 +183,11 @@ function resultForPackage (configuration, tree) {
typeof ignore.author === 'string' &&
personMatches(result.author, ignore.author)
) return true
if (
ignore.path &&
typeof ignore.path === 'string' &&
result.path.includes(ignore.path)
) return true
return false
})
if (ignored) {
Expand Down Expand Up @@ -224,6 +238,9 @@ function resultForPackage (configuration, tree) {
}

function startsWith (string, prefix) {
if (!string) {
return false
}
return string.toLowerCase().indexOf(prefix.toLowerCase()) === 0
}

Expand Down
9 changes: 9 additions & 0 deletions tests/nonexistent-symlinked-subdependency/.licensee.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"licenses": {
"spdx": [
"Apache-2.0"
]
},
"packages": {},
"ignore": [{ "path": "nonexistent/symlinked/node_modules/subdependency" }]
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions tests/nonexistent-symlinked-subdependency/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "nonexistent-symlinked-subdependency",
"dependencies": {
"@nonexistent/symlinked": "*"
},
"private": true
}
15 changes: 15 additions & 0 deletions tests/nonexistent-symlinked-subdependency/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var tap = require('tap')

var results = require('../run')(['--ndjson'], __dirname)

tap.equal(results.status, 0)

var output = results.stdout.trim().split('\n').map(line => JSON.parse(line))

tap.assert(
output.some(result => result.name === 'nonexistent/symlinked' && result.approved === true)
)

tap.assert(
output.some(result => result.version === '' && result.approved === true)
)