Skip to content

Commit

Permalink
Provide TS workarounds for both TS and Glint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Jun 13, 2024
1 parent cb4d7ee commit 5bcc201
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
9 changes: 4 additions & 5 deletions files/__addonLocation__/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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": {
Expand Down
34 changes: 33 additions & 1 deletion files/__addonLocation__/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -67,5 +71,33 @@ export default {
<% filesToCopyFromRootToAddon.forEach((file) => { %> { src: '<%= pathFromAddonToRoot %>/<%= file %>', dest: '.' },
<% }); %> ],
}),
<% } %> ],
<% } %>

<% if (typescript) { %>
{
name: "Build Declarations",
closeBundle: async () => {
/**
* Generate the types (these include /// <reference types="ember-source/types"
* but our consumers may not be using those, or have a new enough ember-source that provides them.
*/
console.log("Building types");
await $({ stdio: 'inherit' })`./node_modules/.bin/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");
},
},
<% } %>
],
};

0 comments on commit 5bcc201

Please sign in to comment.