-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
[TS/JS] Entry point per namespace and reworked 1.x compatible single file build #7510
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
35e4541
to
8b914b2
Compare
6a38fce
to
54a8158
Compare
6c21594
to
15f6d38
Compare
I've pushed through with this and moved it out of draft for review. It produces valid single file output that is 1.x compatible for the schemas in tests/ts. However, the flatc ts tests failures remains unresolved. I remain convinced what this PR does is worthwile goal and less hacky/quirky than what it replaces so that we only have two kinds of outputs instead of four (!). What I mean with this is that counting 1.x and 2.x current possible JavaScript/TypeScript output you can get 1.x compat single file builds, my initial attempted "flat" namespace entry points, your (@dbaileychess) initial --ts-flat-files and the "modern" individual modular output introduced with the TS rewrite. With this PR we can go back provide only 1.x compatible single file builds and the individual modular output which is what I see as the big win here. While I do agree with the general idea of the flatc tests and what their purpose is I remain unconvinced the flatc ts tests provide real value because of the contrived schemas and that even the current implementation in master does not produce something that is valid JavaScript or TypeScript from such schemas. @dbaileychess I sincerely hope we can discuss or move forward with this in some way. I've put many many hours of effort into this PR. |
Unfortunately I find it hard to resolve the merge with master now due to #7748. Will make a new attempt when I have some more time. |
I've been able to do the merge now as proper as I can but tests specific to no_import_ext fail like follows:
This is expected to me and I don't quite understand how the tests passed in #7748. @ink-su and @sunwen18 do you have any ideas? |
Nevermind I think I understand it now, it needs to be tested using the "old" node resolution mode of typescript. I've separated the tests. But I see another issue now. When using prefix (-o) it looks like module paths become wrong for no_import_ext but strangely enough not for union_vector... sigh. |
I think I've been able to figure out the corner cases now after merge with master. @jkuszmaul can you take a look at this again in the context of bazel? |
@bjornharrtell |
Unfortunately, we lose typing information because the new esbuild method of generating single files does not generate type information. The method used here is a bit hack-ish because it relies on parsing the console output of flatc to figure out what to do.
@bjornharrtell I'll take a look at the failing tests... There was some special logic around reflection.fbs that I had previously, but I may be able to rip it out entirely. |
@bjornharrtell cherry-pick |
And we're green! Thanks @jkuszmaul! Ping @dbaileychess. |
@bjornharrtell I'm going to to approve this without a thorough review (its 241 files !) so I trust this is the path we want to take. @jkuszmaul I appreciate your contributions to help this along! |
This change seems to have broken apache/arrow builds with closure compiler.
it works fine with 23.1.4 |
@domoritz it would be good to track that as a new issue and if you can please provide more details and/or instructions how to reproduce. It is not obvious to me what has caused it. |
Thank you, yes. I need to dig a bit more into it to identify the real issue. I suspect it's something with the changes in the package.json. To reproduce, I clone arrow, |
Thank you for the follow up. I subscribed to the new issue and will try a fixed version when it comes out. |
…file build (google#7510) * [TS/JS] Entry point per namespace * Fix handling of outputpath and array_test * Attempt to fix generate_code * Fix cwd for ts in generate_code * Attempt to fixup bazel and some docs * Add --ts-flat-files to bazel build to get bundle * Move to DEFAULT_FLATC_TS_ARGS * Attempt to add esbuild * Attempt to use npm instead * Remove futile attempt to add esbuild * Attempt to as bazel esbuild * Shuffle * Upgrade bazel deps * Revert failed attempts to get bazel working * Ignore flatc tests for now * Add esbuild dependency * `package.json` Include esbuild * `WORKSPACE` Add fetching esbuild binary * Update WORKSPACE * Unfreeze Lockfile * Update WORKSPACE * Update BUILD.bazel * Rework to suggest instead of running external bundler * Add esbuild generation to test script * Prelim bundle test * Run test JavaScriptTest from flatbuffers 1.x * Deps upgrade * Clang format fix * Revert bazel changes * Fix newline * Generate with type declarations * Handle "empty" root namespace * Adjust tests for typescript_keywords.ts * Separate test procedure for old node resolution module output * Fix rel path for root level re-exports * Bazel support for esbuild-based flatc Unfortunately, we lose typing information because the new esbuild method of generating single files does not generate type information. The method used here is a bit hack-ish because it relies on parsing the console output of flatc to figure out what to do. * Try to fix bazel build for when node isn't present on host * Auto formatting fixes * Fix missing generated code Co-authored-by: Derek Bailey <[email protected]> Co-authored-by: James Kuszmaul <[email protected]>
…file build (google#7510) * [TS/JS] Entry point per namespace * Fix handling of outputpath and array_test * Attempt to fix generate_code * Fix cwd for ts in generate_code * Attempt to fixup bazel and some docs * Add --ts-flat-files to bazel build to get bundle * Move to DEFAULT_FLATC_TS_ARGS * Attempt to add esbuild * Attempt to use npm instead * Remove futile attempt to add esbuild * Attempt to as bazel esbuild * Shuffle * Upgrade bazel deps * Revert failed attempts to get bazel working * Ignore flatc tests for now * Add esbuild dependency * `package.json` Include esbuild * `WORKSPACE` Add fetching esbuild binary * Update WORKSPACE * Unfreeze Lockfile * Update WORKSPACE * Update BUILD.bazel * Rework to suggest instead of running external bundler * Add esbuild generation to test script * Prelim bundle test * Run test JavaScriptTest from flatbuffers 1.x * Deps upgrade * Clang format fix * Revert bazel changes * Fix newline * Generate with type declarations * Handle "empty" root namespace * Adjust tests for typescript_keywords.ts * Separate test procedure for old node resolution module output * Fix rel path for root level re-exports * Bazel support for esbuild-based flatc Unfortunately, we lose typing information because the new esbuild method of generating single files does not generate type information. The method used here is a bit hack-ish because it relies on parsing the console output of flatc to figure out what to do. * Try to fix bazel build for when node isn't present on host * Auto formatting fixes * Fix missing generated code Co-authored-by: Derek Bailey <[email protected]> Co-authored-by: James Kuszmaul <[email protected]>
Implements reworked entry point generation, so that each namespace gets an entrypoint and re-exports children. The top level entry point can be bundled up into a single file that should be 1.x compatible. This also has the benefit of avoiding name clashes which occured in the IMHO not so well thought out previous attempts (including my own) to export everything in a single module at root level. A new option is added
--ts-entry-points
to enable the entry point generation which also implicitly also enables--gen-all
because it needs all symbols for the entry points.Note that this PR also rolls back the change to the npm package entry point name. It was changed to
js/index.js
some time ago but is now back tojs/flatbuffers.js
which it was before (also in earlier 2.x versions) because IMHO that was an unnesseary breaking change. Specifically this makes it possible to run the old test suite from flatbuffers 1.x which is added back astests/ts/JavaScriptTestv1.cjs
and it works with no other modification than moving fromflatbuffers.Long
to nativeBigInt
support which was was a breaking change we made years ago. One could argue we should have keptflatbuffers.Long
for backwards compatibility but that ship has sailed and probably not worth the effort anyway IMHO.The previous implementation of option
--ts-flat-files
has been replaced by esbuild automation. It simply automates runs of esbuild to produce old style 1.x generation single file bundles that assume flatbuffers is available in global scope.This PR also removes some left over older generated TS/JS files missed in #7508.
References #7448.
TODO
--ts-flat-files
is used