Skip to content

Commit

Permalink
Merge pull request #10450 from bertdeblock/remove-typescript-warning
Browse files Browse the repository at this point in the history
[ENHANCEMENT] Remove warning when encountering a `.js` file when generating a TS blueprint
  • Loading branch information
kategengler committed Mar 16, 2024
2 parents b6e0e87 + 6b53f50 commit 0f7d0cc
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 24 deletions.
19 changes: 0 additions & 19 deletions lib/models/blueprint.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,21 +481,6 @@ let Blueprint = CoreObject.extend({

// If the blueprint isn't a TS file to begin with, there's nothing to convert.
if (!isTypeScriptFile(fileInfo.outputPath)) {
// If the user wants TypeScript output but there is no TypeScript blueprint available, we want
// to warn them that they're not going to get what they're expecting while still at least giving
// them the JS output. We check for this *after* checking `shouldTranformTypeScript` because
// it's possible for people to set `{typescript: true}` in their `.ember-cli` file, which would
// then erroneously trigger this message every time they generate a JS blueprint even though
// they didn't pass the flag.
if (options.typescript === true && isJavaScriptFile(fileInfo.outputPath)) {
this.ui.writeLine(
chalk.yellow(
"You passed the '--typescript' flag but there is no TypeScript blueprint available. " +
'A JavaScript blueprint will be generated instead.'
)
);
}

return false;
}

Expand Down Expand Up @@ -1767,10 +1752,6 @@ function isTypeScriptFile(filePath) {
return path.extname(filePath) === '.ts' || path.extname(filePath) === '.gts';
}

function isJavaScriptFile(filePath) {
return path.extname(filePath) === '.js' || path.extname(filePath) === '.gjs';
}

/**
* Takes a substring of a string based on byte offsets.
* @private
Expand Down
7 changes: 2 additions & 5 deletions tests/acceptance/typescript-generate-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,11 @@ describe('Acceptance: ember generate with typescript blueprints', function () {
}`
);

const result = await ember(['generate', 'foo', 'bar', '--typescript']);
const output = result.outputStream.map((v) => v.toString());
await ember(['generate', 'foo', 'bar', '--typescript']);

const generated = file('app/foos/bar.js');

expect(generated).to.contain('export default function bar(a, b) {');
expect(output.join('\n')).to.contain(
"You passed the '--typescript' flag but there is no TypeScript blueprint available."
);
});

it('does not generate typescript when the `--no-typescript` flag, even if a typescript blueprint exists', async function () {
Expand Down

0 comments on commit 0f7d0cc

Please sign in to comment.