Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide workarounds for both TS (bad peer-provided types handling) and Glint (mishandling of extensions) issues #292

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
38 changes: 37 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,37 @@ 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");
<% if (npm) { %>
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");
},
},
<% } %>
],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this plugin shouldn't be exploded inline into addon's rollup configs 🤔 should it be a new dependency that just provides this? or is it just something that the Embroider addon-dev is providing as a plugin (like the other ones in this file)?

Copy link
Collaborator Author

@NullVoxPopuli NullVoxPopuli Jun 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addon-dev could provide it, if it weren't using tsc to compile (because the way embroider is configured to use tsc right now doesn't actually support await import() in CJS (it gets converted to a require....)).

I would just call it addon.declarations(/* default output "declarations" folder */ ) or something like that.

Copy link
Collaborator Author

@NullVoxPopuli NullVoxPopuli Jun 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could also just publish a new package that provides these few lines, which is very easy (your first suggestion).

maybe.. declarations() is how it's invoked

(doing this would allow me to author a CJS version of the plugin that does proper await import, for addon-dev to use, if that's what we wanted)

Copy link
Contributor

@ijlee2 ijlee2 Jun 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also like to see the Rollup config remain simple and dependencies to a minimum. If I understood the release notes right, the reference directives won't appear with typescript@5.5?

If so, the blueprint could remain as is (or only be updated to handle importing .gts files), and those who are on typescript@<=5.4 could install fix-bad-declaration-output. Maybe you could first try out the release candidate for 5.5 in v2 addons.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naw glint is still borked out of the box

};