grant / ts2gas

A function that transpiles TypeScript to Google Apps Script.
http://npmjs.com/ts2gas
MIT License
88 stars 11 forks source link

require and import #26

Open paxperscientiam opened 5 years ago

paxperscientiam commented 5 years ago

There's a note in the readme indicating that noLib is fixed at false. Does that mean ts2gas does not currently handle imports? Like, I'm trying to import a module, but nothing seems to happen.

Thanks.

balloman commented 2 years ago

For anyone else experiencing this issue, I was actually able to fix it by explicitly setting the clasp version to 2.3.1 AND setting the typescript version to 4.3.5 in the package.json. Additionally, you can only run clasp locally, as I haven't been able to figure out how to modify dependency versions for global packages. Seems a typescript update has broken the implementation somehow, but this fixed it for me

mrts commented 2 years ago

ts2gas handling of import/export of module is in fact extremely limited, deceitful and a bad idea to start with.

Maybe, but it was working well with clasp 2.3.1 and TypeScript 4.3.5 for both me and @balloman. I would argue that as it did already work, it would be a good idea to build a solid solution upon the working bits instead of abandoning it. But I am in no position to rally for this and I'm sure you have a much better understanding of the impediments. By the way, I am really grateful for your work and admire it a lot!

PopGoesTheWza commented 2 years ago

This ‘feature’ is in fact a mirage:

Currently, GAS do not support any module systems. The closed thing one could relate are Script Libraries. Other than that, the namespace approach is the (deprecated) Typescript feature which offer some of the benefits that comes with modules.

now back to ts2gas; this library relies on a per source file transpilation feature. This is fine for most common and basic use, but:

as of this posting, there is no pending feature worth implementing in ts2gas. The only reasonable things one could argue is upgrading the typescript dependency in order to benefit a specific new feature of the typescript language. With the last typescript releases, it’s compiler api has gone through significant changes, which implies to maintain the AST manipulation code.

Overall it is quite a tedious task, which I can’t be truly thrilled about if the only gain is to preserve a “bad feature’ like the “fool everyone into thinking they have modules, yeah”.

indeed, that was sarcasm.

PopGoesTheWza commented 2 years ago

[…] it would be a good idea to build a solid solution upon the working bits instead of abandoning it

Trust me, I have given that subject thorough consideration. Unless for use cases that I am unaware of, ts2gas is only meaningful as an easy-setup/quick-start clasp feature. Whenever you hit the need of integrating external modules or want to use typescript feature like incremental builds and project references, your sole viable solution is to manage your compilation/transpilation/bundling separately, and rely on clasp solely to push your target .js/.gs files.

That being said, if one comes to me with a sample repo to prove me otherwise, I would gladly review it.

mrts commented 2 years ago

Thanks for the thorough explanation!