From 38b5e5be1983866d0e740c28388bcc397b26d94e Mon Sep 17 00:00:00 2001 From: simonihmig Date: Sat, 14 Dec 2019 09:09:36 +0100 Subject: [PATCH] Fix command ignoring existing config in an addon Fixes #74 --- commands/index.js | 6 +++--- tests/commands-test.js | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/commands/index.js b/commands/index.js index e425c29..d2bde02 100644 --- a/commands/index.js +++ b/commands/index.js @@ -30,16 +30,16 @@ const SHARED = { }, _ensureConfigFile() { + let configPath = getConfigPath(this.project); + try { - return this.project.resolveSync('./config/optional-features.json'); + return this.project.resolveSync(configPath); } catch(err) { if (err.code !== 'MODULE_NOT_FOUND') { throw err; } } - let configPath = getConfigPath(this.project); - mkdirp.sync(path.join(this.project.root, path.dirname(configPath))); fs.writeFileSync(configPath, '{}', { encoding: 'UTF-8' }); diff --git a/tests/commands-test.js b/tests/commands-test.js index 13b1249..9bad7ff 100644 --- a/tests/commands-test.js +++ b/tests/commands-test.js @@ -199,6 +199,45 @@ QUnit.module('commands', hooks => { ` }, 'it should have rewritten the config file with the appropiate flags'); })); + + QUnit.test('it rewrites the config file with a custom config path', co.wrap(function *(assert) { + project.write({ + 'package.json': strip` + { + "name": "dummy", + "description": "", + "version": "0.0.0", + "devDependencies": { + "@ember/optional-features": "*", + "ember-cli": "*", + "ember-source": "*" + }, + "ember-addon": { + "configPath": "foo/bar" + } + } + ` + }); + + project.write({ + 'optional-features.json': strip(` + { + "template-only-glimmer-components": true + } + `) + }, 'foo/bar'); + + yield run(testCase.command, 'application-template-wrapper', { input: 'no\n' }); + + assert.deepEqual(project.read('foo/bar'), { + 'optional-features.json': strip` + { + "application-template-wrapper": ${testCase.expected}, + "template-only-glimmer-components": true + } + ` + }, 'it should have rewritten the config file with the appropiate flags'); + })); }); });