-
Notifications
You must be signed in to change notification settings - Fork 508
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 Async/Await in Rollup Plugins by migrating to @wessberg/rollup-plugin-ts
#208
Support Async/Await in Rollup Plugins by migrating to @wessberg/rollup-plugin-ts
#208
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's it.
Sorry, y'all, for the delayed update, but, with one minor caveat, we should now be good to go, here. The remaining 'hitch' relates to the name of the emitted type declaration files. In
However, the plugin wants to emit declaration files on a (potential) chunk/entry-by-chunk/entry basis using actual filenames, bundle-type-suffixes, etc.. As a consequence, no Thus, to retain functional parity with respect to typings, I changed the default |
@medelman17, that's correct, So if Rollup writes an output chunk to |
Nice |
Happened to hit this yesterday and it's annoying to work around. Any idea when this could be merged? |
Not especially related to the PR, but just my 2cents :)
And that's kind of strange, but understanding it. If you output 2 formats - cjs and esm (as in my case, in different directories - Actually, it may help for the PR. Not sure. |
Yes. This is precisely the hitch above. What to do about that?
Since TSDX does both cjs and esm out of the box, by default we generate two identical .d.ts files (neither of which is named index.d.ts 🙄), but for the file names, using this plugin.
In other words: 😬
I suppose I lean towards, ‘letting it happen,’ but I don’t have enough skills/experience to feel confident about that. That said, even writing an extra build step just to clean up the naming issue purely for aesthetics feels hack-y. So, if, as a practical matter, having the extra types included in the package has a negligible impact, I would accept that as a trade off. But I don’t know RT impact.
Get Outlook for iOS<https://aka.ms/o0ukef>
…________________________________
From: Charlike Mike Reagent <[email protected]>
Sent: Monday, September 30, 2019 12:03:51 AM
To: jaredpalmer/tsdx <[email protected]>
Cc: Michael Edelman <[email protected]>; Mention <[email protected]>
Subject: Re: [jaredpalmer/tsdx] Support Async/Await in Rollup Plugins (#208)
Not especially related to the PR, but just my 2cents :)
@wessberg<https://github.com/wessberg>: So if Rollup writes an output chunk to
And that's kind of strange, but understanding it. If you output 2 formats - cjs and esm (as in my case, in different directories - dist/cjs/index.js and dist/esm/index.js), it generates basically the same type files (dist/cjs/index.d.ts and dist/esm/index.d.ts, which is unnecessary. In my case I did workaround it<https://github.com/tunnckoCore/configs/blob/a90e8183a4a7a678ec0e42dec253277c789a7001/packages/rollup-config/create-config.js#L219-L229> to just generate types at dist/types/index.d.ts. But yea, I understand why this is/should happen.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#208?email_source=notifications&email_token=ADQ3VLKZSNOD7MFL5CIDL6TQMF3CPA5CNFSM4IWK7QZ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD74LAZY#issuecomment-536391783>, or mute the thread<https://github.com/notifications/unsubscribe-auth/ADQ3VLKLXHGCGNMY676TR3LQMF3CPANCNFSM4IWK7QZQ>.
|
Oh sure, I'm sleepy, haha. I'll check it later today:
Besides that, feels too much :D |
@tunnckoCore, @medelman17, if you use If this is an important feature requirement for you, I can look into providing a hook to the config that is invoked with the path to a declaration file immediately before it is emitted, which then allows you to rewrite it to something else. That would allow you to always write to the same path and with the same name, no matter the amount of Rollup outputs. Would you be interested in this? @tunnckoCore The generation of declarations could potentialy have some form of shared caching that may enhance performance, given that the input will be identical. But I don't see how we could avoid generating declarations for each Rollup output, given that the output configs in Rollup can be very different. For example, the entry- and chunk names may differ. Let me give an example: In a multi-chunk setup with two outputs: ESM and CJS, where the chunk name patterns differ, Rollup may convert this: import {Foo} from "./foo";
console.log(Foo);
export type Bar = typeof Foo; To this for ESM // index.esm.js
import {Foo} from "./chunk-0027dabcd....js";
console.log(Foo); And this for CJS: // index.cjs.js
const foo = require("./other-pattern-123456...");
console.log(foo.Foo); Now, if we wanted to generate - and bundle - declarations for these two index files, it becomes clear that they are different. The // index.esm.d.ts
import {Foo} from "./chunk-0027dabcd...";
export declare type Bar = typeof Foo; And the import {Foo} from "./other-pattern-123456...";
export declare type Bar = typeof Foo; So under these circumstances, they would be different. For by far the most library builds (though definitely not all of them), then yes, the declarations will be identical and only a single chunk will be emitted. I guess we could look into a heuristic saying something like "If all Rollup options like |
Yea yea, that's exactly what I did.
Don't it's needed at all for this case here - I'll try some things based on this PR. But might be a cool feature for some other cases.
Yea, I see it now more clearly. It's possible, and the trick is quite easy. But TSDX does not support/emit/do anything chunks related anyway. So it's not the case here. Basically the thing is that: for the one output format, use the plugin without providing tsconfig option, which means it will pick it up automatically, which must include (if you want declaration files at all) |
So, basically I'll try to change this to something like opts.format === 'esm'
? ts({
tsconfig: tsconfig => ({
...tsconfig,
target: ScriptTarget.ESNext,
sourceMap: true,
declaration: true,
declarationDir: `${paths.appDist}/types`,
jsx: JsxEmit.React,
}),
transpiler: 'babel',
})
: ts({
tsconfig: tsconfig => ({
...tsconfig,
target: ScriptTarget.ESNext,
sourceMap: true,
declaration: false,
jsx: JsxEmit.React,
}),
transpiler: 'babel',
}), @@medelman17, got it? :)
Btw, @jaredpalmer, isn't it be better to always be |
So actually, @wessberg, this hook you are talking about will be in help here. |
Anyway, forget about all the stuff I said. The whole thing boils down to that we use "safe package name" for output filename, instead of If user doesn't use the
I don't understand why we need the package name, "production", "development" and the format in the filename. Always wondered that. It's hard on eyes. Not to mention that if it's "min" it's obviously for production (whatever that may mean in the different cases), right? To be able to have single |
@wessberg cool! I'll try it. offtopic: anytime I'm visiting this PR I'm wondering why it's called that way, @medelman17? 🤔 🤣 |
@wessberg, Yup, it works great. But still, don't think it's for our case here :) |
After above requested changes:
So, yea. We can go with this PR or #219 which suggest changing the |
Which PR are we going with? |
Your call. @medelman17 needs to make changes here. |
I'd go with this one purely for the benefit of having a full history here, even though @tunnckoCore has taken everything to a new level, really. Nevertheless, it looks like @medelman17 has been busy lately.
@tunnckoCore It's explained in the first paragraph of #200 it addresses. PS. Thank you all! <3 |
I can make the needed changes to mine early tomorrow. That said, and while it would be great to have my contribution forever immortalized on my GH profile, I’m pretty sure I’m the only one who will notice. :-)
So, let’s just go with whatever makes the most sense for the library and not make it emotional. If that’s the other PR, no problem. To the extent we can merge the two together and that would make sense, awesome. But ... whichever way, let’s get ‘er done. :-)
Get Outlook for iOS<https://aka.ms/o0ukef>
…________________________________
From: Michał Ordon <[email protected]>
Sent: Saturday, October 5, 2019 8:36:43 PM
To: jaredpalmer/tsdx <[email protected]>
Cc: Michael Edelman <[email protected]>; Mention <[email protected]>
Subject: Re: [jaredpalmer/tsdx] Support Async/Await in Rollup Plugins (#208)
Which PR are we going with?
I'd go with this one purely for the benefit of having a full history here, even though @tunnckoCore<https://github.com/tunnckoCore> has taken everything to a new level, really. Nevertheless, it looks like @medelman17<https://github.com/medelman17> has been busy lately.
What it has to do with async/await?
@tunnckoCore<https://github.com/tunnckoCore> It's explained in the first paragraph of #200<#200> it addresses.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#208?email_source=notifications&email_token=ADQ3VLP6TRJEDGA45HHCZBLQNEXJXA5CNFSM4IWK7QZ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAN6ZFI#issuecomment-538700949>, or mute the thread<https://github.com/notifications/unsubscribe-auth/ADQ3VLNX6OSUNQMMP3HRDXLQNEXJXANCNFSM4IWK7QZQ>.
|
fix: tweak plugin and build config re types/declarations fix: remove console.log; reimplement babel-plugin chore: resolve PR comments
Alrighty. Feedback/changes from @tunnckoCore have been incorporated. :-) |
Cool. But still, I think that we should somehow drop the dependency |
Going with this as it is not a breaking change. We can debate the output/safe-variable name elsewhere. |
Thank you @medelman17 @tunnckoCore. You are both awesome. |
@wessberg/rollup-plugin-ts
@allcontributors please add @medelman17 for code, ideas |
I've put up a pull request to add @medelman17! 🎉 |
@allcontributors please add @tunnckoCore for reviews, code, ideas |
I've put up a pull request to add @tunnckoCore! 🎉 |
@allcontributors please add @wessberg for questions |
I've put up a pull request to add @wessberg! 🎉 |
Thanks everyone for helping with this!! (even if it eventually got rolled back) To close this out for any readers that are unsure -- can see #294 (comment) and #506 for how I ended up fixing/getting this fixed upstream so that async Rollup plugins can be used. |
This is a WIP re #200. Sadly, I cannot, for the life of me, get the last two tests to pass. A screenshot of the issue is included below. It looks related to our babel/typescript relationship-- which is complex. I'm happy to continue digging in, but figured I would surface in case anyone could point me in the right direction.
FWIW, it looks like the new plugin has a fairly robust integration with babel. I'm not sure re purpose of the custom tsdx babel plugin, but could we accomplish the same with a
.babelrc
orbabel.config.js
file? If so, the new plugin looks capable of managing the babel stage. See Meaw.closes #200