diff --git a/files/__addonLocation__/package.json b/files/__addonLocation__/package.json index a81736c0..771c7f4c 100644 --- a/files/__addonLocation__/package.json +++ b/files/__addonLocation__/package.json @@ -82,6 +82,8 @@ "prettier-plugin-ember-template-tag": "^1.1.0", "rollup": "^4.9.1"<% if (!isExistingMonorepo) { %>, "rollup-plugin-copy": "^3.5.0"<% } %><% if (typescript) { %>, + "execa": '^8.0.1", + "fix-bad-declaration-output": "^1.1.2", "typescript": "^5.3.3"<% } %> }, "publishConfig": { diff --git a/files/__addonLocation__/rollup.config.mjs b/files/__addonLocation__/rollup.config.mjs index 2a49ed1a..f8b94582 100644 --- a/files/__addonLocation__/rollup.config.mjs +++ b/files/__addonLocation__/rollup.config.mjs @@ -1,6 +1,10 @@ import { babel } from '@rollup/plugin-babel'; <% if (!isExistingMonorepo) { %>import copy from 'rollup-plugin-copy'; <% } %>import { Addon } from '@embroider/addon-dev/rollup'; +<% if (typescript) { %> +import { execaCommand } from 'execa'; +import { fixBadDeclarationOutput } from 'fix-bad-declaration-output'; +<% } %> const addon = new Addon({ srcDir: 'src', @@ -67,5 +71,30 @@ export default { <% filesToCopyFromRootToAddon.forEach((file) => { %> { src: '<%= pathFromAddonToRoot %>/<%= file %>', dest: '.' }, <% }); %> ], }), -<% } %> ], +<% } %> + + { + name: 'generate-types', + closeBundle: async () => { + /** + * We generate the types here as an inline rollup plugin + * so that we can have the correct timing for fixing the types + * after they are generated. + * + * This also provides better CLI output, as Glint and Rollup don't fight + * each other to clear the terminal. + */ + console.log('Building types'); + await execaCommand(`pnpm glint --declaration`, { stdio: 'inherit' }); + + console.log('Fixing types'); + await fixBadDeclarationOutput('declarations/**/*.d.ts', [ + // https://github.com/microsoft/TypeScript/issues/56571 + 'TypeScript#56571', + // https://github.com/typed-ember/glint/issues/628 + 'Glint#628', + ]); + }, + }, + ], };