nodejs plugin assumes a version key in the package.json
Bug #1838474 reported by
Rob Cresswell
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Snapcraft |
New
|
Undecided
|
Unassigned |
Bug Description
The nodejs plugin currently assumes a version key is present in the package.json[1]; crashing out with a KeyError if it isn't, and doesn't enable any other way of providing a package version, nor does it appear to inherit or otherwise use the 'version' key in the snapcraft.yaml.
What's the best way to fix this? I've really lost my patience trying to wrestle with the tooling and broken links in the documentation, so I'd like to raise a PR to address this ASAP so I can move on.
1. https:/
description: | updated |
To post a comment you must log in.
According to the documentation on https:/ /docs.npmjs. com/files/ package. json
"If you plan to publish your package, the most important things in your package.json are the name and version fields as they will be required. The name and version together form an identifier that is assumed to be completely unique. Changes to the package should come along with changes to the version. If you don’t plan to publish your package, the name and version fields are optional."
Looking at the NPM source code : /github. com/npm/ cli/blob/ latest/ lib/npm. js
https:/
It appears NPM treats this as an exception:
try { fs.readFileSync ( join(__ dirname, '../package.json')) + '') info('error reading version', ex)
// startup, ok to do this synchronously
var j = parseJSON(
path.
npm.name = j.name
npm.version = j.version
} catch (ex) {
try {
log.
} catch (er) {}
npm.version = ex
}