Skip to content

Commit

Permalink
[BUGFIX] Fix require module (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
offirgolan committed Aug 18, 2016
1 parent dad8463 commit e6bf390
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
9 changes: 2 additions & 7 deletions addon/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@
*/

import Ember from 'ember';
import require from 'require';

export function hasEmberData() {
return require.has('ember-data');
}

export function getEmberData() {
return hasEmberData() ? require('ember-data')['default'] : undefined;
export function requireModule(module) {
return self.requirejs.has(module) ? self.require(module).default : undefined;
}

export function unwrapString(input) {
Expand Down
4 changes: 2 additions & 2 deletions addon/validations/internal-result-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

import Ember from 'ember';
import ValidationError from './error';
import { getEmberData } from '../utils/utils';
import { requireModule } from '../utils/utils';

const DS = getEmberData();
const DS = requireModule('ember-data');

const {
get,
Expand Down
6 changes: 4 additions & 2 deletions addon/validators/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

import Ember from 'ember';
import Base from 'ember-cp-validations/validators/base';
const moment = (self.requirejs.entries.moment || self.requirejs.entries['moment/index']) && self.require('moment').default;
import { requireModule } from 'ember-cp-validations/utils/utils';

if (typeof moment === 'undefined') {
const moment = requireModule('moment');

if (!moment) {
throw new Error('MomentJS is required to use the Date validator. The easiest way to install moment.js is to install ember-moment.\n' +
'Installation instructions and documentation can be found at https://github.com/stefanpenner/ember-moment');
}
Expand Down
4 changes: 2 additions & 2 deletions addon/validators/ds-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

import Ember from 'ember';
import Base from 'ember-cp-validations/validators/base';
import { getEmberData } from 'ember-cp-validations/utils/utils';
import { requireModule } from 'ember-cp-validations/utils/utils';

const DS = getEmberData();
const DS = requireModule('ember-data');

if (!DS) {
throw new Error('Ember-Data is required to use the DS Error validator.');
Expand Down

0 comments on commit e6bf390

Please sign in to comment.