Skip to content

Commit

Permalink
Address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
simonihmig committed Jun 25, 2020
1 parent 0d3607e commit 3c734ca
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
2 changes: 2 additions & 0 deletions commands/local/generate/codemod.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,5 +180,7 @@ module.exports.handler = function handler(options) {
return jsHandler(options);
case 'hbs':
return hbsHandler(options);
default:
throw new Error(`Unknown type: "${options.type}"`);
}
};
10 changes: 4 additions & 6 deletions src/bin-support.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,11 @@ async function runTemplateTransform(
expandDirectories: { extensions: extensions.split(',') },
});
let transformPath = path.join(binRoot, '..', 'transforms', transformName, 'index.js');

let templateRecastPkg = require('ember-template-recast/package');
let templateRecastPath = path.dirname(require.resolve('ember-template-recast/package'));
let binPath = path.join(templateRecastPath, templateRecastPkg.bin);

let binOptions = ['-t', transformPath, ...foundPaths];

return execa(binPath, binOptions, {
return execa('ember-template-recast', binOptions, {
stdio: 'inherit',
preferLocal: true,
env: {
CODEMOD_CLI_ARGS: JSON.stringify(options),
},
Expand All @@ -84,6 +80,8 @@ async function runTransform(binRoot, transformName, args, extensions, type = 'js
return runJsTransform(binRoot, transformName, args, extensions);
case 'template':
return runTemplateTransform(binRoot, transformName, args, extensions);
default:
throw new Error(`Unknown type passed to runTransform: "${type}"`);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/test-support.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ function runTransformTest(options) {
return jscodeshiftTest(options);
case 'template':
return templateTest(options);
default:
throw new Error(`Unknown type passed to runTransformTest: "${options.type}"`);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/test-support/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ const globby = require('globby');
const { transformDetails } = require('./utils');
const { transform, parse } = require('ember-template-recast');

function runTemplateTest(plugin, { path, source }, expectedOutput) {
function runTemplateTest(plugin, { path: pluginPath, source }, expectedOutput) {
const code = plugin(
{
path,
path: pluginPath,
source,
},
{
Expand All @@ -23,7 +23,7 @@ function runTemplateTest(plugin, { path, source }, expectedOutput) {
}
);

expect((code || '').trim()).toEqual(expectedOutput.trim());
expect(code || '').toEqual(expectedOutput);
}

module.exports = function templateTest(options) {
Expand Down Expand Up @@ -57,7 +57,7 @@ module.exports = function templateTest(options) {
it('is idempotent', function() {
runTemplateTest(
plugin,
{ path: testInputPath, source: fs.readFileSync(inputPath, 'utf8') },
{ path: testInputPath, source: fs.readFileSync(outputPath, 'utf8') },
fs.readFileSync(outputPath, 'utf8')
);
});
Expand Down

0 comments on commit 3c734ca

Please sign in to comment.