Repository: ember-intl/ember-intl (ts)

Issue:
default ember-intl blueprint throws an error
With the current ember-intl@3.1.0 there's a bug where `requiresTranslation` is not a function.
This causes the build to fail unitl a user provides a `requiresTranslation` function.

The issue is probably caused by [`Object.assign(defaults, provided)`](https://github.com/ember-intl/ember-intl/blob/master/index.js#L167) overwriting the default `requiresTranslation`.

One possible solution would be to check that addonConfig.requiresTranslation is a function and if not, overwrite it with the default function.

(Sorry for introducing that bug :) )

I can open a PR with the possible solution mentioned above.

Alternatively we could comment the `requiresTranslation` option from the blueprint to unset it.

Pull request:
fix(index): ensure that `requiresTranslation` option is a function
fixes #592

Patch:
diff --git a/index.js b/index.js
index 6d2a15da..67495c5d 100644
--- a/index.js
+++ b/index.js
@@ -18,6 +18,17 @@ const utils = require('./lib/utils');
 const buildTree = require('./lib/broccoli/build-translation-tree');
 const TranslationReducer = require('./lib/broccoli/translation-reducer');
 
+const defaultConfig = {
+  locales: null,
+  publicOnly: false,
+  disablePolyfill: false,
+  autoPolyfill: false,
+  inputPath: 'translations',
+  outputPath: 'translations',
+  throwMissingTranslations: false,
+  requiresTranslation: (/* key, locale */) => true
+};
+
 module.exports = {
   name: 'ember-intl',
   opts: null,
@@ -164,19 +175,12 @@ module.exports = {
   },
 
   createOptions(environment) {
-    let addonConfig = Object.assign(
-      {
-        locales: null,
-        publicOnly: false,
-        disablePolyfill: false,
-        autoPolyfill: false,
-        inputPath: 'translations',
-        outputPath: 'translations',
-        throwMissingTranslations: false,
-        requiresTranslation: (/* key, locale */) => true
-      },
-      this.readConfig(environment)
-    );
+    let addonConfig = Object.assign({}, defaultConfig, this.readConfig(environment));
+
+    if (typeof addonConfig.requiresTranslation !== 'function') {
+      this.log('Configured `requiresTranslation` is not a function. Using default implementation.');
+      addonConfig.requiresTranslation = defaultConfig.requiresTranslation;
+    }
 
     if (addonConfig.locales) {
       addonConfig.locales = utils


Test patch:
diff --git a/tests-node/unit/index-test.js b/tests-node/unit/index-test.js
new file mode 100644
index 00000000..b16b5371
--- /dev/null
+++ b/tests-node/unit/index-test.js
@@ -0,0 +1,22 @@
+'use strict';
+
+let mocha = require('mocha');
+let expect = require('chai').expect;
+
+let subject = require('../../index');
+
+describe('index', function() {
+  it('createOptions ensures that requiresTranslation is a function.', function() {
+    const index = Object.assign({}, subject);
+    const logs = [];
+
+    index.log = message => logs.push(message);
+    index.readConfig = () => ({ requiresTranslation: undefined });
+
+    const addonConfig = index.createOptions.call(index);
+
+    expect(addonConfig.requiresTranslation).to.be.a('function');
+
+    expect(logs).to.deep.equal(['Configured `requiresTranslation` is not a function. Using default implementation.']);
+  });
+});