-
Notifications
You must be signed in to change notification settings - Fork 11
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 NodeNext module resolution #15
Conversation
@cc-bbohlender could you please remove this line from it doesn't do anything because you commit |
@cc-bbohlender I'm sorry for the delay is it will work with yoga's https://github.com/facebook/yoga/blob/main/javascript/src_js/wrapAsm.d.ts#L24-L26 |
@jeetiss No worries. Thanks for your time :) I have access to the enums since they are exported here: Line 3 in e9141ef
However, it would be best if yoga's types included the .js file extension. I can make a PR there too, if you think it's reasonable, they will accept it. There is additionally a problem with the unsetMeasureFun <-- missing a c |
Nice catch, this should be a PR definitely :) |
Okay, thanks, will do. Do you happen to know why yoga exports the constants on the yoga object? Because the yoga-wasm-web types express that the constants are exported Line 3 in eac8026
But the actual implementation does not export them Line 3 in eac8026 Resulting in no compile error from typescript but a runtime error for: import { UNIT_AUTO } from "yoga-wasm-web"
I would at least export the constants here: Line 3 in eac8026 but I then also, I see no reason to put them on the yoga object |
This is a nice catch too. this is happening because we initialize wasm differently how original yoga does. i think that we should reuse the original yoga as much as possible so we can migrate when it will be released (i hope it will be some time) I'm going to export constants too as in the original yoga package https://github.com/facebook/yoga/blob/main/javascript/src_js/entrypoint/_entryAsync.js#L14 |
Seems like this is not so easy to do because |
Yeah, I see. I guess, we have to wait until yoga changes the js code to es6 modules. However, I would then at least remove the export to prohibit confusion from here: Line 3 in eac8026
I will now continue to make the PR on yoga to use the file extensions and include the typo fix. Depending on how fast that PR goes through, the current PR here, is also valuable for me without the enums from yoga. |
Summary: I wanna repeat the constants export in `yoga-wasm-web`, to achieve ```js import { ALIGN_CENTER } from "yoga-layout"; ``` And I failed. it is impossible because `rollup` and other tools can't transform commonjs `module.exports = { WHATEVER: 1 }` into ECMAScript modules. however, they can work with separate exports like `exports.WHATEVER = 1` and this PR transforms yoga constants into this convertible format This doesn't change anything for the yoga package, but it makes it possible to reexport constants without any modification and hacks, like this ```js export * from "./javascript/src_js/generated/YGEnums.js"; ``` [discussion in yoga-layout-wasm](shuding/yoga-wasm-web#15) Pull Request resolved: #1229 Reviewed By: NickGerleman Differential Revision: D43437177 Pulled By: rshest fbshipit-source-id: bfe1404d1b48779f404e6510f2aafadd7fd4e774
@cc-bbohlender thanks for your contribution! 🎉 I have some ideas on how we can modify |
@jeetiss After reading the comment from the yoga PR, I see a problem. They are not using the "type" field in their package.json, which defaults to "commonjs". The yoga-wasm-web package uses "type": "module". I guess this is to enable "yoga-wasm-web/asm" import instead of "yoga-wasm-web/dist/asm". However, since yoga-wasm-web uses the files from the yoga repo, their interpretation differs since the "type" field in both use cases differs. The hard way would be to write declaration files that can be interpreted as "module" and "commonjs" or to try and transition the yoga repo to also use "module". However, the simplest solution I see is to change this package to "commonjs" and flatten the dist folder in the distribution so that "yoga-wasm-web/asm" can still be imported. Since "commonjs" packages can be used in NodeNext, this would also make this PR obsolete. |
I don't understand why we should support "commonjs" here, because this fork is in
I prefer to keep this package as "module" |
From the yoga repo, there is no reason to change the file extensions in the .d.ts files, since everything works fine even with NodeNext since their package type is "commonjs". Since this package has type "module", the .d.ts files must include the file extensions to support NodeNext. |
The placement of the *.d.ts files currently prevents support for projects that use the NodeNext module resolution since the .d.ts are expected to be placed with their definitions. Additionally, the .js file ending is expected. The changes in this PR should enable both the current node moduleResolution and the NodeNext moduleResolution.