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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ package-lock.json
/test/output
/jco.sh
/docs/book
/src/**/*.d.ts
/src/**/*.d.ts.map
9 changes: 9 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"include": ["src/**/*"],
"compilerOptions": {
"allowJs": true,
"declaration": true,
"emitDeclarationOnly": true,
"declarationMap": true
}
}
16 changes: 13 additions & 3 deletions xtask/src/build/jco.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use anyhow::Context;
use anyhow::{Context, Result};
use std::{collections::HashMap, fs, io::Write, path::PathBuf};

use anyhow::Result;
use wit_component::ComponentEncoder;
use xshell::{cmd, Shell};

pub(crate) fn run() -> Result<()> {
transpile(
Expand All @@ -14,6 +13,17 @@ pub(crate) fn run() -> Result<()> {
"wasm-tools".to_string(),
)?;

let sh = Shell::new()?;
//Typescript doesn't support arbitrary module namespace identifier names so
//we need to remove it from wasm-tools.js before compiling
//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

)
.read()?;
cmd!(sh, "npx tsc -p tsconfig.json").read()?;

Ok(())
}

Expand Down