diff --git a/files/__addonLocation__/package.json b/files/__addonLocation__/package.json index 762892f..450cdf7 100644 --- a/files/__addonLocation__/package.json +++ b/files/__addonLocation__/package.json @@ -13,11 +13,8 @@ "declarations", "dist" ], - "scripts": {<% if (typescript) { %> - "build": "concurrently '<%= packageManager %>:build:*'", - "build:js": "rollup --config", - "build:types": "glint --declaration",<% } else { %> - "build": "rollup --config",<% } %> + "scripts": { + "build": "rollup --config", "lint": "concurrently '<%= packageManager %>:lint:*(!fix)' --names 'lint:'", "lint:fix": "concurrently '<%= packageManager %>:lint:*:fix' --names 'fix:'", "lint:hbs": "ember-template-lint . --no-error-on-unmatched-pattern", @@ -84,6 +81,8 @@ "prettier-plugin-ember-template-tag": "^2.0.2", "rollup": "^4.16.4"<% if (!isExistingMonorepo) { %>, "rollup-plugin-copy": "^3.5.0"<% } %><% if (typescript) { %>, + "execa": "9.2.0", + "fix-bad-declaration-output": "1.1.4", "typescript": "^5.4.5"<% } %> }, "publishConfig": { diff --git a/files/__addonLocation__/rollup.config.mjs b/files/__addonLocation__/rollup.config.mjs index 2a49ed1..8a895b0 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 { $ } from "execa"; +import { fixBadDeclarationOutput } from "fix-bad-declaration-output"; +<% } %> const addon = new Addon({ srcDir: 'src', @@ -67,5 +71,37 @@ export default { <% filesToCopyFromRootToAddon.forEach((file) => { %> { src: '<%= pathFromAddonToRoot %>/<%= file %>', dest: '.' }, <% }); %> ], }), -<% } %> ], +<% } %> + +<% if (typescript) { %> + { + name: "Build Declarations", + closeBundle: async () => { + /** + * Generate the types (these include /// + await $({ stdio: 'inherit' })`npm exec glint -- --declaration`; + <% } else { %> + await $({ stdio: 'inherit' })`<%= packageManager %> glint --declaration`; + <% } %> + + /** + * https://github.com/microsoft/TypeScript/issues/56571# + * README: https://github.com/NullVoxPopuli/fix-bad-declaration-output + */ + console.log("Fixing types"); + await fixBadDeclarationOutput("declarations/**/*.d.ts", [ + // https://github.com/microsoft/TypeScript/issues/56571#issuecomment-1830436576 + ["TypeScript#56571", { types: "all" }], + // https://github.com/typed-ember/glint/issues/628 + "Glint#628", + ]); + console.log("⚠️ Dangerously (but neededly) fixed bad declaration output from typescript"); + }, + }, +<% } %> + ], };