Skip to content

Commit e57cd1a

Browse files
author
Robert Jackson
committed
Ensure we support both bin field formats for resolving ember-template-recast
npm@6 automatically migrates `"bin": "lib/foo.js"` into `"bin": { "package-name": "lib/foo.js" }`. When we were running under `yarn` or `npm@7` we don't have this problem, but CI currently tests against npm@6.
1 parent 2ba29af commit e57cd1a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/bin-support.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,15 @@ async function runTemplateTransform(transformPath, args) {
6868
let binOptions = ['-t', transformPath, ...paths];
6969
let templateRecastDir = path.dirname(require.resolve('ember-template-recast/package.json'));
7070
let templateRecastPkg = require('ember-template-recast/package');
71-
let templateRecastBinPath = path.join(templateRecastDir, templateRecastPkg.bin);
7271

73-
return execa(templateRecastBinPath, binOptions, {
72+
// npm@6 changes `bin: 'lib/bin.js'` into `bin: { 'ember-template-recast':
73+
// 'lib/bin.js' }` automatically this ensures that we read either format
74+
let templateRecastBinPath =
75+
typeof templateRecastPkg.bin === 'string'
76+
? templateRecastPkg.bin
77+
: templateRecastPkg.bin['ember-template-recast'];
78+
79+
return execa(path.join(templateRecastDir, templateRecastBinPath), binOptions, {
7480
stdio: 'inherit',
7581
env: {
7682
CODEMOD_CLI_ARGS: JSON.stringify(options),

0 commit comments

Comments
 (0)