Skip to content

Commit 9dba17c

Browse files
committed
Address PR feedback
1 parent 7995cbf commit 9dba17c

4 files changed

Lines changed: 12 additions & 10 deletions

File tree

commands/local/generate/codemod.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,5 +180,7 @@ module.exports.handler = function handler(options) {
180180
return jsHandler(options);
181181
case 'hbs':
182182
return hbsHandler(options);
183+
default:
184+
throw new Error(`Unknown type: "${options.type}"`);
183185
}
184186
};

src/bin-support.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,11 @@ async function runTemplateTransform(
5757
expandDirectories: { extensions: extensions.split(',') },
5858
});
5959
let transformPath = path.join(binRoot, '..', 'transforms', transformName, 'index.js');
60-
61-
let templateRecastPkg = require('ember-template-recast/package');
62-
let templateRecastPath = path.dirname(require.resolve('ember-template-recast/package'));
63-
let binPath = path.join(templateRecastPath, templateRecastPkg.bin);
64-
6560
let binOptions = ['-t', transformPath, ...foundPaths];
6661

67-
return execa(binPath, binOptions, {
62+
return execa('ember-template-recast', binOptions, {
6863
stdio: 'inherit',
64+
preferLocal: true,
6965
env: {
7066
CODEMOD_CLI_ARGS: JSON.stringify(options),
7167
},
@@ -84,6 +80,8 @@ async function runTransform(binRoot, transformName, args, extensions, type = 'js
8480
return runJsTransform(binRoot, transformName, args, extensions);
8581
case 'template':
8682
return runTemplateTransform(binRoot, transformName, args, extensions);
83+
default:
84+
throw new Error(`Unknown type passed to runTransform: "${type}"`);
8785
}
8886
}
8987

src/test-support.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ function runTransformTest(options) {
99
return jscodeshiftTest(options);
1010
case 'template':
1111
return templateTest(options);
12+
default:
13+
throw new Error(`Unknown type passed to runTransformTest: "${options.type}"`);
1214
}
1315
}
1416

src/test-support/template.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ const globby = require('globby');
88
const { transformDetails } = require('./utils');
99
const { transform, parse } = require('ember-template-recast');
1010

11-
function runTemplateTest(plugin, { path, source }, expectedOutput) {
11+
function runTemplateTest(plugin, { path: pluginPath, source }, expectedOutput) {
1212
const code = plugin(
1313
{
14-
path,
14+
path: pluginPath,
1515
source,
1616
},
1717
{
@@ -23,7 +23,7 @@ function runTemplateTest(plugin, { path, source }, expectedOutput) {
2323
}
2424
);
2525

26-
expect((code || '').trim()).toEqual(expectedOutput.trim());
26+
expect(code || '').toEqual(expectedOutput);
2727
}
2828

2929
module.exports = function templateTest(options) {
@@ -57,7 +57,7 @@ module.exports = function templateTest(options) {
5757
it('is idempotent', function() {
5858
runTemplateTest(
5959
plugin,
60-
{ path: testInputPath, source: fs.readFileSync(inputPath, 'utf8') },
60+
{ path: testInputPath, source: fs.readFileSync(outputPath, 'utf8') },
6161
fs.readFileSync(outputPath, 'utf8')
6262
);
6363
});

0 commit comments

Comments
 (0)