Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Runtime compatibility check of loopback version #18

Open
bajtos opened this issue Jun 12, 2014 · 1 comment
Open

Runtime compatibility check of loopback version #18

bajtos opened this issue Jun 12, 2014 · 1 comment

Comments

@bajtos
Copy link
Contributor

bajtos commented Jun 12, 2014

Since #14 dropped peer dependency on loopback, there is no mechanism notifying developers when they use incompatible loopback and loopback-testing versions.

We should implement a runtime version check.

@bajtos
Copy link
Contributor Author

bajtos commented Jun 12, 2014

@ritch What if we just wrote a simple version check like this:

  var pkg = require('./package.json');
  var loopbackPkg = require('loopback/package.json');
  var isCompatible = semver.satisfies(loopbackPkg.version, pkg.loopbackVersion);

  if(!isCompatible) {
    throw new Error('incompatible loopback version');
  }

The problem with this check is that loopback must be requireable from loopback-testing, which goes against the current design, where the app/model dependencies are injected by the caller.

Here is what I would like to do instead:

  • modify loopback/lib/application.js to provide access to loopback or loopback.version.

  • modify loopback/lib/models/mode.js to provide access to loobpack or loopback.version.

  • the version checking code will be moved to helpers:

    _beforeEach.withApp = function(app) {
      assertLoopBackVersionIsCompatible(app.loopback.version);
    
      // the original code of `withApp`
    }
    
    // shared by all helpers
    function assertLoopBackVersionIsCompatible(loopbackVersion) {
      var pkg = require('./package.json');
      var isCompatible = semver.satisfies(loopbackVersion, pkg.loopbackVersion);
    
      if(!isCompatible) {
        throw new Error('incompatible loopback version');
      }
    }

Thoughts?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

1 participant