-
Notifications
You must be signed in to change notification settings - Fork 51
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
Support shipping Glint types with v2 addons #338
Comments
Disclaimer: this is only based on reading that PR, not actually pulling if down and poking it with the typechecker, so I could be wrong! That said: I think what you're hitting there isn't actually specific to Glint, but a more general issue that v2 TS addons are going to have to contend with for a while. Setting One way to work around this and support both "exports": {
"./addon-main.js": "./addon-main.js",
"./*": {
"types": "./dist/*.d.ts",
"default": "./dist/*.js"
}
},
"typesVersions": {
"*": {
"*": ["dist/*"]
}
} |
Hey Dan, this is very valuable feedback, thank you! I didn't realize that support for the Will try out your suggestions and report back! |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as resolved.
This comment was marked as resolved.
I tried this, but failed miserably, idk what's wrong... I had TS updated, added I then reverted the changes and tried to get to a working state with the most simple setup:
Still I am getting the same errors, when running Then added this commit to test what's happening:
What am I missing? 😟 |
This sounds similar to what you'd see with linked packages or another setup where the addon and host app have distinct copies of the package providing the registry. I'll pull the code from your PR later today and see if anything jumps out at me |
@dfreeman Oh, yes, this was it! Thanks again! I accidentally had slightly different versions of glint deps (0.8.0 vs. 0.8.2) in my lockfile, for the v2 addon vs. the test-app. After deduping, everything works again as expected! 🎉 |
So, after adding proper Closing this, as I would consider it a solved problem now. For reference, this is the passing PR again: simonihmig/ember-stargate#494 Footnotes
|
Awesome, I'm glad you got it working!
My understanding is that part of the point of |
Yes, that's how I am understanding it also... I think what is going on is that the app reexports that the addon build is emitting (through https://github.com/embroider-build/embroider/blob/main/packages/addon-dev/src/rollup-app-reexports.ts) have a export { default } from "ember-stargate/components/portal.js"; Which works usually. I didn't investigate this any deeper, but my guess is that when we have an Does that make sense? At least when I patched the app-reexports locally (just updated the You can still see the webpack error here btw. Maybe we need to make the rollup plugin strip the |
|
Extensions are only required for relative imports though, aren't they? My understanding is that for absolute (package-name-rooted) imports like the app reexports, you have to follow whatever pattern is established by |
That's true as a default but it's under the control of each package's |
Ah, thank you both for the clarification/correction, you’re absolutely right. Previous comment rescinded! |
So, that means we can/should strip the extension from the reexport, right? (which would also make the v2 addon's reexport match what you get from |
This makes `rollup-app-reexports` strip file extensions (`.js`) from reexports, aligning with (the blueprint of) v1 addons, and allowing better interoperability with `package.json#exports` with path mappings including extensions, as discussed in typed-ember/glint#338.
This makes `rollup-app-reexports` strip file extensions (`.js`) from reexports, aligning with (the blueprint of) v1 addons, and allowing better interoperability with `package.json#exports` with path mappings including extensions, as discussed in typed-ember/glint#338.
We have already figured out and documented how an addon (v1) should ship its own Glint-based types. This should also be possible for a v2 addon, in the same manner (from the consumer's perspective). However a first experiment doing that was that successful yet (simonihmig/ember-stargate#494)...
The main problem was how to tell TS where to find the
my-addon/glint
module that an app is supposed to import (for the automatic registry registration of its components). While the v2 format does not require any kind of build step per se, most existing v2 addons have that (a pre-publish build step that is), and the v2 addon blueprint also has that baked in. The compiled artefacts will then usually live in a./dist
folder. Webpack (used by Embroider or ember-auto-import) will know how to resolve the imported modules to this folder on disk by making use of theexports
feature of the addon'spackage.json
. While this is well supported by Webpack and Node, only the upcoming TS 4.7 will add support for it. Which is needed to make the import of the addon types (my-addon/glint
) work correctly. So the app would need to be on TS 4.7 to "just work", for older TS versions a manualpaths
entry intsconfig.json
would be required.However even with 4.7 beta, I was not able to make it work (see linked PR above). My IDE would correctly resolve the imported Glint types, but
glint
itself apparently not, continuing to complain due to the addons's components not being added to the registry. 🤔 This needs further investigation...The text was updated successfully, but these errors were encountered: