lukejagodzinski / meteor-astronomy-validators

https://atmospherejs.com/jagi/astronomy-validators
MIT License
11 stars 13 forks source link

Cannot use package jagi:astronomy-validators inside other package #8

Closed parhelium closed 8 years ago

parhelium commented 9 years ago

Cannot use package jagi:astronomy-validators inside other package

Error:

ReferenceError: Match is not defined

ReferenceError: Match is not defined
W20150625-23:50:47.462(2)? (STDERR)     at Function.checks.validators (packages/jagi:astronomy-validators/lib/module/init_class.js:22:1)
W20150625-23:50:47.462(2)? (STDERR)     at Function.methods.addValidators (packages/jagi:astronomy-validators/lib/module/init_class.js:72:1)
W20150625-23:50:47.462(2)? (STDERR)     at Function.onInitClass (packages/jagi:astronomy-validators/lib/module/init_class.js:121:1)
W20150625-23:50:47.462(2)? (STDERR)     at packages/jagi:astronomy/lib/core/class.js:81:1
W20150625-23:50:47.463(2)? (STDERR)     at packages/jagi:astronomy/lib/core/events.js:55:1
W20150625-23:50:47.463(2)? (STDERR)     at Array.forEach (native)
W20150625-23:50:47.463(2)? (STDERR)     at Function._.each._.forEach (packages/underscore/underscore.js:105:1)
W20150625-23:50:47.463(2)? (STDERR)     at Object._.extend.each (packages/jagi:astronomy/lib/core/events.js:51:1)
W20150625-23:50:47.463(2)? (STDERR)     at new Astro.createClass.Astro.Class (packages/jagi:astronomy/lib/core/class.js:80:1)
W20150625-23:50:47.463(2)? (STDERR)     at packages/collections/lib/requests.js:7:1

Do you have idea why ?

I believe adding package check should solve the problem.

lukejagodzinski commented 9 years ago

Yes there is PR waiting for merge https://github.com/jagi/meteor-astronomy-validators/pull/7. I will merge it this weekend and publish new package version.

parhelium commented 9 years ago

@jagi it looks like #7 is really easy fix. Is there any chance you will merge it today or tomorrow ?

lukejagodzinski commented 9 years ago

Sorry for late response. I've merged it today and I will post new version to Atmosphere tomorrow.

parhelium commented 9 years ago

Thanks! Please let me know, when it will be published.

lukejagodzinski commented 9 years ago

Published! v 0.10.8

adriano-di-giovanni commented 8 years ago

I'm developing a package; astronomy-validators is a dependency. I get the error ReferenceError: Validators is not defined. The error doesn't occur if I use simple-validators. Meteor 1.2.0.2.

lukejagodzinski commented 8 years ago

When using the astronomy-validators package inside another package you have also to imply it to access package level variable.

api.use('jagi:astronomy-validators@1.0.4');
api.imply('jagi:astronomy-validators');

If it works with the simple-validators package without implying then it may mean that there is a bug in Meteor packages system.

adriano-di-giovanni commented 8 years ago

Here is package.js

Package.describe({
  name: 'adigiovanni:one-way-accounts',
  version: '0.0.1',
  summary: 'One Way Accounts',
  git: '',
  documentation: 'README.md',
});

Package.onUse(function (api) {
  api.versionsFrom('1.2.0.2');

  // module deps
  api.use('ecmascript');
  api.use('underscore');
  api.use('mongo');
  api.use('jagi:astronomy');
  api.use('jagi:astronomy-validators');
  api.imply('jagi:astronomy-validators');
  // api.use('jagi:astronomy-simple-validators');

  // file deps
  api.addFiles('lib/collections/Accounts.js');
  api.addFiles('lib/models/Account.js');
  api.addFiles('lib/methods.js');
  api.addFiles('lib/server/publications.js', 'server');
  api.addFiles('lib/OneWayAccounts.js');

  api.export('OneWayAccounts');
});

Package.onTest(function (api) {
  // module deps
  api.use('ecmascript');
  api.use('underscore');
  api.use('mongo');
  api.use('jagi:astronomy');
  api.use('jagi:astronomy-validators');
  // api.use('jagi:astronomy-simple-validators');

  api.use('sanjo:jasmine@0.20.2');
  api.use('velocity:console-reporter');
  api.use('velocity:html-reporter');
  api.use('adigiovanni:one-way-accounts');
  api.imply('adigiovanni:one-way-accounts');

  // file deps
  api.addFiles('lib/server/fixtures.js', 'server');
  api.addFiles('tests/server/setup.js', 'server');
  api.addFiles('tests/server/OneWayAccounts.js', 'server');
  // api.addFiles('tests/client/OneWayAccounts.js', 'client');
});

Here is the code using Astronomy and Validators.

/* eslint new-cap: 0 */

Account = Astro.Class({
  name: 'Account',
  collection: Accounts,
  fields: {
    // issuerId: 'object',
    // holderId: 'object',
    issuerId: {
      type: 'object',
      validator: Validators.required(),
    },
    holderId: {
      type: 'object',
      validator: Validators.required(),
    },
    balance: {
      type: 'number',
      'default': 0,
    },
  },
  indexes: {
    parties: {
      fields: {
        issuerId: 1,
        holderId: 1,
      },
      options: {
        unique: true,
      },
    },
  },
  // simpleValidators: {
  //   issuerId: 'required()',
  //   holderId: 'required()',
  // },
});

I added api.imply but I still get ReferenceError: Validators is not defined

Maybe, there is a bug in Meteor package system because I encountered a similar dependency problem using Mongo. Please, find my question on StackOverflow

adriano-di-giovanni commented 8 years ago

Ok, I changed api.use('jagi:astronomy') to api.use('jagi:astronomy@1.1.4') and it seems to work.

This is from the console

jagi:astronomy*             upgraded from 0.2.0 to 1.1.4
jagi:astronomy-validators*  upgraded from 0.3.0 to 1.0.4
jagi:reactive-map           added, version 2.0.0

So, it seems that Meteor selects the wrong version if not specified.

Does it make sense to you?

lukejagodzinski commented 8 years ago

Yes, you always have to provide precise version number, however if not it should throw error. So it seems like a bug in Meteor.