Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/packagedcode/npm.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def build_package(package_data):
version = package_data.get('version')
homepage = package_data.get('homepage', '')

if not name or not version:
if not name:
# a package.json without name and version is not a usable npm package
# FIXME: raise error?
return
Expand Down
8 changes: 8 additions & 0 deletions tests/packagedcode/data/npm/with_name/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{ "name" : "bson"
, "description" : "A bson parser for node.js and the browser"
, "main": "../"
, "directories" : { "lib" : "../lib/bson" }
, "engines" : { "node" : ">=0.6.0" }
, "licenses" : [ { "type" : "Apache License, Version 2.0"
, "url" : "http://www.apache.org/licenses/LICENSE-2.0" } ]
}
40 changes: 40 additions & 0 deletions tests/packagedcode/data/npm/with_name/package.json.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[
{
"type": "npm",
"namespace": null,
"name": "bson",
"version": null,
"qualifiers": {},
"subpath": null,
"primary_language": "JavaScript",
"description": "A bson parser for node.js and the browser",
"release_date": null,
"parties": [],
"keywords": [],
"homepage_url": null,
"download_url": "https://registry.npmjs.org/bson/-/bson-None.tgz",
"size": null,
"sha1": null,
"md5": null,
"sha256": null,
"sha512": null,
"bug_tracking_url": null,
"code_view_url": null,
"vcs_url": null,
"copyright": null,
"license_expression": "apache-2.0",
"declared_license": [{
"type": "Apache License, Version 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0"
}],
"notice_text": null,
"root_path": null,
"dependencies": [],
"contains_source_code": null,
"source_packages": [],
"purl": "pkg:npm/bson",
"repository_homepage_url": "https://www.npmjs.com/package/bson",
"repository_download_url": "https://registry.npmjs.org/bson/-/bson-None.tgz",
"api_data_url": "https://registry.npmjs.org/bson"
}
]
28 changes: 28 additions & 0 deletions tests/packagedcode/data/npm/without_name/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"version": "0.2.0",
"description": "A sample Node.js",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"express": "^4.13.3"
},
"engines": {
"node": "4.0.0"
},
"repository": {
"type": "git",
"url": "https://github.com/heroku/node-js-sample"
},
"keywords": [
"node",
"heroku",
"express"
],
"author": "Mark Pundsack",
"contributors": [
"Zeke Sikelianos <zeke@sikelianos.com> (http://zeke.sikelianos.com)"
],
"license": "MIT"
}
13 changes: 13 additions & 0 deletions tests/packagedcode/test_npm.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,19 @@ def test_parse_npm_shrinkwrap(self):
packages = npm.parse(test_file)
self.check_packages(packages, expected_loc, regen=False)

def test_parse_with_name(self):
test_file = self.get_test_loc('npm/with_name/package.json')
expected_loc = self.get_test_loc('npm/with_name/package.json.expected')
packages = npm.parse(test_file)
self.check_packages(packages, expected_loc, regen=False)

def test_parse_without_name(self):
test_file = self.get_test_loc('npm/without_name/package.json')
try:
npm.parse(test_file)
except AttributeError as e:
assert "'NoneType' object has no attribute 'to_dict'" in str(e)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess there be a better exception raises, like a new one such as a NpmWithoutNameError ?
But we can merge this as is for now. An update later is welcomed!


def test_parse_yarn_lock(self):
test_file = self.get_test_loc('npm/yarn-lock/yarn.lock')
expected_loc = self.get_test_loc(
Expand Down