Skip to content

Commit

Permalink
Fix command ignoring existing config in an addon (#159)
Browse files Browse the repository at this point in the history
Fix command ignoring existing config in an addon
  • Loading branch information
rwjblue authored Dec 16, 2019
2 parents 8e05d2b + 38b5e5b commit 5867438
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
6 changes: 3 additions & 3 deletions commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
Expand Down
39 changes: 39 additions & 0 deletions tests/commands-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}));
});
});

Expand Down

0 comments on commit 5867438

Please sign in to comment.