Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Coerce version before parsing major #1369

Merged
merged 5 commits into from
Apr 24, 2019

Conversation

timkelty
Copy link
Contributor

@timkelty timkelty commented Apr 18, 2019

With #1366, errors will occur package.json does not contain a fully qualified range (e.g '3', '^3').

TypeError: Invalid Version: 3

TypeError: Invalid Version: ^3

Doing semver.coerce first seems to fix this.

Fixes #1367.
Fixes #1370.

@timkelty timkelty changed the title Coerce version before parsing major. Coerce version before parsing major Apr 18, 2019
@timkelty timkelty self-assigned this Apr 18, 2019
@amorriscode
Copy link

amorriscode commented Apr 23, 2019

@timkelty correct me if I'm wrong but I think it needs to be adjusted here and here as well.

@timkelty
Copy link
Contributor Author

@amorriscode ah indeed! I'll try and update the PR shortly.

@timkelty
Copy link
Contributor Author

timkelty commented Apr 23, 2019

@amorriscode updated library and node.

@eliperelman if you think adding a Neutrino.getDependencyVersion makes sense instead, I can add it and a test.

  getDependencyVersion(dependency, packageJson = this.options.packageJson) {
    const { dependencies = {}, devDependencies = {} } = packageJson || {};

    return (
      (dependency in dependencies || dependency in devDependencies) &&
      semver.coerce(dependencies[dependency] || devDependencies[dependency])
    );
  }

@eliperelman
Copy link
Member

@timkelty I think that solution looks good, although I'm not sure why we would want the packageJson argument. Go for it!

@timkelty
Copy link
Contributor Author

although I'm not sure why we would want the packageJson

@eliperelman yeah no real application for that, other than maybe for tests at some point. I can leave it out until/if we need it.

@timkelty
Copy link
Contributor Author

Ok - Neutrino.getDependencyVersion is now implemented, used by relevant middleware, and has a test.

Copy link
Member

@eliperelman eliperelman left a comment

Choose a reason for hiding this comment

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

🎉

@eliperelman eliperelman merged commit 46793f2 into neutrinojs:master Apr 24, 2019
@edmorley edmorley added the bug label Apr 26, 2019
@edmorley edmorley added this to the Neutrino 9 milestone Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
4 participants