Skip to content
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

Updating build process to create .d.ts declaration files #256

Merged
merged 7 commits into from
Nov 20, 2023

Conversation

landonxjames
Copy link
Contributor

@landonxjames landonxjames commented Nov 13, 2023

Updating build process to create .d.ts declaration files so jco is usable as a library in a typescript project.

The changes to enable this:

  • Add a minimal tsconfig.json to generate ts types from the JSDoc comments. See the ts docs for more info about the configuration.
  • Update the package.json build script to run tsc
  • Update .gitignore to ignore the new .d.ts and .d.ts.map files which are generated in the src/ directory.
  • Add new option to --no-namespaced-exports to jco to prevent generating exports like test as "test:flavorful/test" which are not currently compatible with typescript. See Support “Arbitrary module namespace identifier names” microsoft/TypeScript#40594

Resolves #168.
Resolves #253

//See: https://github.com/microsoft/TypeScript/issues/40594
cmd!(
sh,
"sed -i'' -e 's/tools as \"local:wasm-tools\\/tools\"//g' ./obj/wasm-tools.js"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than doing this via replacement (since if jco has this issue itself then other libraries built with jco will too), perhaps we should instead make it a transpile option to omit these names?

Perhaps something like --ts-compat or --no-namespaced-exports. Would you be interested in working on a patch along those lines here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep happy to take a look at that (and fix this windows build issue). Will probably take me a few more days or through the weekend, but any pointers to that section of the code (and potentially how cli options flow from the js to the rust bits) would be appreciated

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, the exports are output by the "esm bindgen" render routine in https://github.com/bytecodealliance/jco/blob/main/crates/js-component-bindgen/src/esm_bindgen.rs#L184.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright updates are made and the --no-namespaced-exports option has been added

Also adding a test for the `--no-namespaced-exports` option
And other changes to make the build work on Windows
@guybedford guybedford added this pull request to the merge queue Nov 20, 2023
@guybedford
Copy link
Collaborator

Great work, thanks for adding this.

Merged via the queue into bytecodealliance:main with commit 839d8f3 Nov 20, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide Typescript type declarations for jco API Generated export seems invalid
2 participants