-
Notifications
You must be signed in to change notification settings - Fork 24
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
Operating on non-externs? #44
Comments
Whoops - I misread the isExtern() filter, the code reads as the opposite of what I understood it (though the effect is the same), because that isExtern check is unrelated to closure's notion of externs. Instead, this is sort of "is this type a first-party type, given to the generator as an extern, and not from a dependency mapping file". I can clearly see that when you give the generator non-externs, it parses them, but the point of the bug still stands: java files don't seem to be emitted for them, so writing java code against those types doesn't make sense (short of my current approach: run tsc/tsickle to turn .ts into .d.ts+.js, run tsickle again to turn .d.ts to externs, manually edit the confusing bits, and then run jsinterop-generator). |
Yes, isExtern method there should be renamed, it is not really related Closure extern. Starting from Closure then using tsickle back and forth to generate js externs to generate Java wrapper will not work. Because your Java code will try to treat Closure code as externs files and J2CL will not generate proper goog.require for them. Going to your original question and follow up questions: |
Okay - disregarding typescript, I do have npm+node+bazel wiring that seems to work to take .ts code, generate .d.ts files from them, use tsickle to emit externs (and never feed them to closure), and use jsinterop-generator on those externs to emit generated
In GWT2, this shouldn't matter, correct? This mostly applies to j2cl wanting to see a proper |
Yes, it never matters for GWT2 because for GWT2 all javascript is external. For J2CL, some JavaScript is external some is not. External is code is that that is not fed into Closure compiler and they require externs. In short, if you don't supply your npm+node+bazel stuff to closure, use externs + jsinteropgenerator to access them from J2CL it should work. (But if your npm+node+bazel stuff is behind the scenes using closure or other obfuscation mechanism, then you will be potentially creating new set problems (e.g. name collisions)). |
Got it, thank you. Are there any avenues by which I could help contribute to this effort, either the work that was already started, or a new approach based on the work that was previously attempted? While the specific use case I described appears to work for my specific needs, there are a lot of people interested in finding a way to consume other TS libraries into GWT2 or J2CL. |
I'm experimenting with taking Closure-annotated JS (both hand-written and generated from TypeScript via tsickle). I was surprised to discover that when the generator runs, it only emits jsinterop types that represent the provided externs - "actual" JS gets no java generated for it.
As an example, take a j2cl-based project with closure-compatible JS libraries that need to be used/consumed from Java. Feeding non-
@extern
js results in no output (and a chmod error in format_jarsrc), probably becausejsinterop.generator.closure.ClosureJsInteropGenerator#generateJarFile
removes non-extern files - removing that check results in the tool trying to also generate java for dependencies (like elemental2-core+promise, which effectively every library must depend on).--
Going a bit further: It appears from poking around in the repo that I might just be thinking about this wrong or using the tool wrong, and that this isn't a real limitation. For example,
DependencyFileWriter
specifically calls out TypeScript rather than closure externs?Are typescript .d.ts files intended to be supported, specifically those generated via tsickle? The sample I tried nearly works, at least with this one addition to
jsinterop.generator.closure.ClosureJsInteropGenerator#createCompilerOptions
:but even then the library I'm working with hits errors, whether operating tsc-generated .d.ts files, or ones emitted by tsickle (and for the record, I've been unable to get tsickle yet to emit actual externs, it only wants to provide either
.mjs
files with an empty externs.js, or.js
+.d.ts
. Perhaps it works better if you avoid bazel, but my goal was to stay within the ecosystem).--
Are these use cases intended to be supported, or am I just doing it wrong?
The text was updated successfully, but these errors were encountered: