Skip to content

Commit

Permalink
Embroider compat (#299)
Browse files Browse the repository at this point in the history
* Embroider compat

* import directly
  • Loading branch information
snewcomer authored May 21, 2021
1 parent 6a32eff commit 21ae4eb
Show file tree
Hide file tree
Showing 12 changed files with 1,836 additions and 2,734 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:
ember-lts-3.16,
ember-lts-3.20,
ember-lts-3.24,
embroider-safe,
embroider-optimized
]
steps:
- uses: actions/checkout@v2
Expand Down
5 changes: 2 additions & 3 deletions addon/validators/confirmation.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import buildMessage from 'ember-changeset-validations/utils/validation-errors';
import { validate } from 'ember-validators';
import evValidateConfirmation from 'ember-validators/confirmation';
import { assign } from '@ember/polyfills';


export default function validateConfirmation(options = {}) {
return (key, newValue, _oldValue, changes , content = {}) => {
// Combine the changes on top of the content so that we evaluate against both default values
// and valid changes. `changes` only has valid changes that have been made and won't include
// default values
let model = assign({}, content, changes);

let result = validate('confirmation', newValue, options, model, key);
let result = evValidateConfirmation(newValue, options, model, key);
return (result === true) ? true : buildMessage(key, result);
};
}
4 changes: 2 additions & 2 deletions addon/validators/exclusion.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import buildMessage from 'ember-changeset-validations/utils/validation-errors';
import { validate } from 'ember-validators';
import evValidateExclusion from 'ember-validators/exclusion';

export default function validateExclusion(options = {}) {
if (options.list) {
options.in = options.list;
}

return (key, value) => {
let result = validate('exclusion', value, options, null, key);
let result = evValidateExclusion(value, options, null, key);
return (result === true) ? true : buildMessage(key, result);
};
}
4 changes: 2 additions & 2 deletions addon/validators/format.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isEmpty } from '@ember/utils';
import buildMessage from 'ember-changeset-validations/utils/validation-errors';
import { validate } from 'ember-validators';
import evValidateFormat from 'ember-validators/format';

export default function validateFormat(options = {}) {
let hasOptions = !isEmpty(Object.keys(options));
Expand All @@ -10,7 +10,7 @@ export default function validateFormat(options = {}) {
return true;
}

let result = validate('format', value, options, null, key);
let result = evValidateFormat(value, options, null, key);
return (result === true) ? true : buildMessage(key, result);
};
}
4 changes: 2 additions & 2 deletions addon/validators/inclusion.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import buildMessage from 'ember-changeset-validations/utils/validation-errors';
import { validate } from 'ember-validators';
import evValidateInclusion from 'ember-validators/inclusion';

export default function validateInclusion(options = {}) {
if (options.list) {
options.in = options.list;
}

return (key, value) => {
let result = validate('inclusion', value, options, null, key);
let result = evValidateInclusion(value, options, null, key);
return (result === true) ? true : buildMessage(key, result);
};
}
4 changes: 2 additions & 2 deletions addon/validators/length.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import buildMessage from 'ember-changeset-validations/utils/validation-errors';
import withDefaults from 'ember-changeset-validations/utils/with-defaults';
import { validate } from 'ember-validators';
import evValidateLength from 'ember-validators/length';

export default function validateLength(options = {}) {
options = withDefaults(options, { useBetweenMessage: true });

return (key, value) => {
let result = validate('length', value, options, null, key);
let result = evValidateLength(value, options, null, key);
return (result === true) ? true : buildMessage(key, result);
};
}
4 changes: 2 additions & 2 deletions addon/validators/number.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import buildMessage from 'ember-changeset-validations/utils/validation-errors';
import withDefaults from 'ember-changeset-validations/utils/with-defaults';
import { validate } from 'ember-validators';
import evValidateNumber from 'ember-validators/number';

export default function validateNumber(options = {}) {
options = withDefaults(options, { allowString: true, allowNone: false });
Expand All @@ -10,7 +10,7 @@ export default function validateNumber(options = {}) {
}

return (key, value) => {
let result = validate('number', value, options, null, key);
let result = evValidateNumber(value, options, null, key);
return (result === true) ? true : buildMessage(key, result);
};
}
4 changes: 2 additions & 2 deletions addon/validators/presence.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import buildMessage from 'ember-changeset-validations/utils/validation-errors';
import { validate } from 'ember-validators';
import evValidatePresence from 'ember-validators/presence';

export default function validatePresence(options) {
let targets;
Expand All @@ -20,7 +20,7 @@ export default function validatePresence(options) {
return true;
}

let result = validate('presence', value, options, null, key);
let result = evValidatePresence(value, options, null, key);

if (typeof result === 'boolean' || typeof result === 'string') {
return result;
Expand Down
5 changes: 4 additions & 1 deletion config/ember-try.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const getChannelURL = require('ember-source-channel-url');
const { embroiderSafe, embroiderOptimized } = require('@embroider/test-setup');

module.exports = async function() {
return {
Expand Down Expand Up @@ -76,7 +77,9 @@ module.exports = async function() {
'@ember/jquery': '^0.5.1'
}
}
}
},
embroiderSafe(),
embroiderOptimized(),
]
};
};
3 changes: 2 additions & 1 deletion ember-cli-build.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const EmberAddon = require('ember-cli/lib/broccoli/ember-addon');
const { maybeEmbroider } = require('@embroider/test-setup');

module.exports = function(defaults) {
let app = new EmberAddon(defaults, {
Expand All @@ -14,5 +15,5 @@ module.exports = function(defaults) {
behave. You most likely want to be modifying `./index.js` or app's build file
*/

return app.toTree();
return maybeEmbroider(app);
};
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@
"ember-cli-babel": "^7.11.1",
"ember-cli-htmlbars": "^4.0.5",
"ember-get-config": "^0.2.4",
"ember-validators": "^3.0.1"
"ember-validators": "^3.0.1",
"validated-changeset": "~0.14.5"
},
"devDependencies": {
"@ember/optional-features": "^1.0.0",
"@embroider/test-setup": "^0.39.1",
"babel-eslint": "^10.0.3",
"broccoli-asset-rev": "^3.0.0",
"ember-auto-import": "^1.5.3",
Expand Down
Loading

0 comments on commit 21ae4eb

Please sign in to comment.