Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix command ignoring existing config in an addon #159

Merged
merged 1 commit into from
Dec 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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