-
Notifications
You must be signed in to change notification settings - Fork 23
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
Add file extensions to TS imports #565
base: main
Are you sure you want to change the base?
Conversation
i believe you and i want to help, but also, there are many loader paths in modern javascript, and so i need to know which one is broken like, it works as expected in node require and node dynamic import it works as expected in rollup and esbuild it works as expected in es6 dynamic load with defer and not under CORS i need to know how you're loading things so that i can see it go south a repro would help a whole lot |
|
@StoneCypher any verdict here yet? As far as I can tell, this approach is aligned with TS/Node best practices in 2023. So if we pass your tests ok...gtg? |
@StoneCypher Are you able to get it to build with tsc, ts-node, or ts-loader? I'm running into the same issue with a standard NextJS Typescript setup. Going to patch it with @mhsdef 's changes for now. |
to build with tsc, just i've never tried with ts-node or ts-loader. i suppose i ought to the typescript manual still explicitly says "don't do this," is why i'm dragging my heels i'm starting to think what i should actually do for es6 is ship bundled and rely on external tree shaking. that obviates the discussion, because rollup knows what to do here |
Forgive if it's on page one lol.... could you point us to that? |
this has been a neckbeard fight between the typescript and node tribes for like five years now and i kind of just don't want to get involved in it, is the honest truth, and i kind of just don't trust that it's over also i tried this and my editor's ts hinting broke, and like. ugh i apologize for the ultra-slow turnaround here. in the last 14 days we've had three record breaking storms for 8 days underwater in a theoretically desert city that is entirely unready for this kind of shit. i'm from back east, where this kind of rain wouldn't be a big deal, but out here it's washing cars away instead, which is kind of wild the original reason that es6 imports pointed to an unbundled version of the lib was twofold. one, back then, it made a difference for tree shaking. now that's actually a tree shaking mistake. two, back then, it made in-browser debugging easier. but since then i started shipping source maps, which chrome can unformat with, so, ... whatever. bundling here just puts the problem to bed mafia enforcer style, so, nite-nite it goes, i think. i'm not going to close this until both @mhsdef and @kaxline confirm that this resolves their loader problem. in the meantime, the fact that i was unaware of this is in itself kind of unacceptable, so i'm going to build out a loader matrix in the test set, which covers various node importations, browser, bun, deno, ts-node, ts-loader, et cetera i hope this is okay, that i'm offering an alternative solution. i actually do generally take PRs gladly, because i want to see that contributor count go up but right now i think i've been burned on the extension nonsense enough times, and i'm change-shy i hope that isn't a downer i pushed i'll try to have a build target loader matrix together at the fundamentals by 5.102 or so, and done by maybe 5.110 or so. no promises |
Oh, the .d.ts is pointing to the wrong file name
…On Mon, Feb 5, 2024, 3:22 PM Hew ***@***.***> wrote:
I'll have to dig in at it more later, but, early feedback, no dice:
Screenshot.2024-02-05.at.6.21.07.PM.png (view on web)
<https://github.com/StoneCypher/jssm/assets/2006764/bb0baf62-212e-4bba-89ce-0d8fbff6844c>
—
Reply to this email directly, view it on GitHub
<#565 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAS5KWDZWQA25NDZBTLPHLYSFSTDAVCNFSM6AAAAABCHSMXA2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMRYGQ4DGMJVHA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
this hot mess appears to be the solution i am getting annoyed with ts right now |
This seems to help: When I edit your
"Funnily", though, all this breaks some typing for me that works fine with my patch. Specifically, the data payload in callbacks. Eg:
It had been passing though fine via the generic in the machine instantiation, but, now it is untyped... |
Also noticed |
I'm pretty sure this is back to the file extension issue.
|
i am, slowly, coming around to the position that changing this may in fact be correct right now i'm kicking around a tool in my head which would validate the external interface of a library from i don't want to put testing that directly in the library because, well, good god, installing or relying on several other languages just for a test set would be a miserable thing however doing this without validation is rapidly becoming untenable |
@StoneCypher just checking back, any verdict? I'm going to have to ship imminently. I can fork and add my own version as dep I spose to buy more time. |
@StoneCypher @mhsdef Wow, really appreciate all the hard work here. Don't wait on me to approve anything if the two of you are able to get it working. Hopefully anyone can understand this is not a mess of your creation! I've been battling for weeks at my day job over this ts-loader business so I feel the frustration as well. Sorry I can't dive in and help here. Not sure it's relevant, but I've had some success using |
I have it in usage with a fork at this point. It's 183e721 (this change) and mhsdef@c3510f4 ( |
I'm currently making a tool to test platforms without being part of the library using it Once I have that tool, I can test merging this safely |
Honestly, I've always wanted having the extensions back. The disparity from the rest of the JS world has always felt gross (albeit I guess I've kind of gotten used to it) What's making me so reluctant is there are umpty million quasi-typescript targets, like deno and bun and rome and so on I'm worried that this is a short solution to the ones we're looking at but a long solution to those, and I'm heel-dragging because it still smells like there might be another option Once I can stamp the whole set simultaneously without polluting the downstreams of users, I can stop staring off into the sunset trying to intuit what the right thing to do is, and just measure the damned thing |
a microsoft staff member just tried to commit something similar the referenced threads have other microsoft staff members doubling and tripling down that this is verboten i am very confused rn |
Hey @StoneCypher, I was just trying to go through some of the issues here and I am wondering where the guidance is to not add extensions and use full paths for javascript imports. The Microsoft TypeScript team very much is opposition to use of |
There are two different issues going on here. One is the use of extensions of internal import paths related to Node16 based module resolution. The changes to the .ts files look good. But there aren't extensions added to the imports in .d.ts files. Extensions should also be updated to respect Node16 resolution. For the .d.ts import paths I think either .js or .d.ts would work. The second issue is Node16 resolution from outside the package. In that situation all of the imports are resolved going through package.json exports specification. The lack of types condition and result meant no type information for any one compiling against jssm, but runtime would be fine. Then once fixed with tweak the types don't resolve because of the internal resolution issue - no extensions. It is informative to run just tsc with declaration output and compare that to what is checked in. |
I've updated the description in StoneCypher/fsl#1295 to clarify that my primary concern is @jason-ha's second issue - using jssm from a Node16 TypeScript library. I have proposed a change in the issue that does not require any runtime changes - only rollup config files, package.json, and adds two declaration rollup files that correspond to the bundled es5 and es6 JS. This sidesteps the internal resolution issue because there's no resolution needed to use the types - everything is in a single file. |
@StoneCypher could chime in here authoritatively, but, I think that's solved via his TS build scripting -- |
yeah, that's one of the big problems here is that if i switch to .js, compat .ts has the wrong extension, and if i don't, then .d.ts points to the wrong file i've thought about performing manual file surgery (like i do for the parser, admittedly) but it's just so gross the current practice of naming .js on the out is typescript, but, i am not convinced of any particular configuration's correctness at this time it's very messy i believe that the current issue is getting node16 resolution to respect the .d.ts i'm going to swear word with that for a while if it turns out that changing the filenames is right i'll still land mhsdef's pr, but, that has been breaking my legacy builds and ends me up in effectively the same situation for just the other half of the output |
it's flattering to see this many people trying to collaborate to help me suck less at my hobby project thank you each |
As of 5.7 beta, Microsoft appears to be changing their stance on this via As this is also the thing I want, if I read this correctly, this is now considered an acceptable approach. If I can get this working, I'll do it from your PR so that you're still credited for doing the foundational work, @mhsdef |
See: https://nodejs.org/docs/latest-v20.x/api/esm.html#mandatory-file-extensions and nodejs/node#46006
(And all the related issue malarkey linked off from there too!)
tl;dr: I was getting this at runtime with
jssm
in Node20.x
+ TypeScript5.3.3
:So I went hunting, debuggin', hacking and found the changes here seem to be the correct fix.
I've confirmed it fixed the import problems for me locally in my application.
But I'd appreciate if you could give this a run through in your tests, run the build stuff as needed if it looks good to you, and cut us a new release.
Great library, keep it up, hope that book is still coming! Cheers!