nodejs plugin assumes a version key in the package.json

Bug #1838474 reported by Rob Cresswell
6
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://github.com/snapcore/snapcraft/blob/master/snapcraft/plugins/nodejs.py#L211

description: updated
Revision history for this message
mase (i-lp-f) wrote :

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 :
https://github.com/npm/cli/blob/latest/lib/npm.js

It appears NPM treats this as an exception:

  try {
    // startup, ok to do this synchronously
    var j = parseJSON(fs.readFileSync(
      path.join(__dirname, '../package.json')) + '')
    npm.name = j.name
    npm.version = j.version
  } catch (ex) {
    try {
      log.info('error reading version', ex)
    } catch (er) {}
    npm.version = ex
  }

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.