-
-
Notifications
You must be signed in to change notification settings - Fork 576
Reenable Specta integration #2432
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,15 @@ | ||
/// Running this test will generate a `types.ts` file at the root of the repo, | ||
/// containing every type annotated with `specta::Type` | ||
// #[cfg(all(test, feature = "specta-export"))] | ||
#[ignore] | ||
|
||
#[test] | ||
fn generate_ts_types() { | ||
// TODO: Un-comment this out when we figure out how to reenable the "typescript` Specta feature flag | ||
|
||
// use crate::messages::prelude::FrontendMessage; | ||
// use specta::ts::{export_named_datatype, BigIntExportBehavior, ExportConfig}; | ||
// use specta::{NamedType, TypeMap}; | ||
// use std::fs::File; | ||
// use std::io::Write; | ||
|
||
// let config = ExportConfig::new().bigint(BigIntExportBehavior::Number); | ||
|
||
// let mut type_map = TypeMap::default(); | ||
|
||
// let datatype = FrontendMessage::definition_named_data_type(&mut type_map); | ||
|
||
// let mut export = String::new(); | ||
|
||
// export += &export_named_datatype(&config, &datatype, &type_map).unwrap(); | ||
|
||
// type_map | ||
// .iter() | ||
// .map(|(_, v)| v) | ||
// .flat_map(|v| export_named_datatype(&config, v, &type_map)) | ||
// .for_each(|e| export += &format!("\n\n{e}")); | ||
use specta::TypeCollection; | ||
use specta_typescript::{BigIntExportBehavior, Typescript}; | ||
|
||
// let mut file = File::create("../types.ts").unwrap(); | ||
use crate::messages::prelude::FrontendMessage; | ||
|
||
// write!(file, "{export}").ok(); | ||
Typescript::default() | ||
.bigint(BigIntExportBehavior::Number) | ||
.export_to("../frontend/src/bindings.ts", TypeCollection::default().register::<FrontendMessage>()) | ||
.unwrap(); | ||
} |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import fs from "node:fs"; | ||
import path from "node:path"; | ||
import graphite, { get_specta_types } from "./pkg/graphite_wasm.js"; | ||
|
||
graphite(fs.readFileSync(path.join(import.meta.dirname, './pkg/graphite_wasm_bg.wasm'))).then(() => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We import the wasm file and then call the By doing this we don't need to build a separate x86/ARM binary specially for exporting the types. Commonly this would be done via |
||
fs.writeFileSync("bindings_from_node.ts", get_specta_types()) | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,18 @@ pub fn init_graphite() { | |
log::set_max_level(log::LevelFilter::Debug); | ||
} | ||
|
||
#[cfg(debug_assertions)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We expose a wasm function that returns a string with all the Specta types. This is only enabled in development so Rust can strip more for production builds. |
||
#[wasm_bindgen] | ||
pub fn get_specta_types() -> Result<String, String> { | ||
use specta::TypeCollection; | ||
use specta_typescript::{BigIntExportBehavior, Typescript}; | ||
|
||
Typescript::default() | ||
.bigint(BigIntExportBehavior::Number) | ||
.export(&TypeCollection::default().register::<FrontendMessage>()) | ||
.map_err(|err| err.to_string()) | ||
} | ||
|
||
/// When a panic occurs, notify the user and log the error to the JS console before the backend dies | ||
pub fn panic_hook(info: &panic::PanicHookInfo) { | ||
let info = info.to_string(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed this but it's probally not needed with the wasm exporting solution (hence why it's still
#[ignore]
ed)