Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions crates/trusted-server-core/src/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,8 @@ fn parse_single_module_filename(filename: &str) -> Option<&'static str> {
.and_then(|s| s.strip_suffix(".min.js").or_else(|| s.strip_suffix(".js")))?;

trusted_server_js::all_module_ids()
.into_iter()
.iter()
.copied()
.find(|&id| id == stem)
}

Expand Down Expand Up @@ -2075,7 +2076,7 @@ fn template_fingerprint(settings: &Settings) -> String {

let mut hasher = sha2::Sha256::new();
hasher.update(
trusted_server_js::concatenated_hash(&trusted_server_js::all_module_ids()).as_bytes(),
trusted_server_js::concatenated_hash(trusted_server_js::all_module_ids()).as_bytes(),
);
// `serde_json::Value` uses a sorted object map without `preserve_order`, making
// independently deserialized HashMaps canonical before they are serialized again.
Expand Down
6 changes: 6 additions & 0 deletions crates/trusted-server-js/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ fn main() {
.expect("should write generated module entry");
}
codegen.push_str("];\n");
writeln!(
codegen,
"pub(crate) const ALL_MODULE_IDS: [&str; {0}] = {{\n let mut ids = [\"\"; {0}];\n let mut index = 0;\n while index < {0} {{\n ids[index] = TSJS_MODULES[index].id;\n index += 1;\n }}\n ids\n}};",
modules.len()
)
.expect("should write generated module IDs");
codegen.push_str("\npub(crate) struct TsjsModuleMeta {\n");
codegen.push_str(" pub bundle: &'static str,\n");
codegen.push_str(" pub id: &'static str,\n");
Expand Down
14 changes: 12 additions & 2 deletions crates/trusted-server-js/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ pub fn module_bundle(id: &str) -> Option<&'static str> {
/// Return all available module IDs, in discovery order (core first).
#[must_use]
#[inline]
pub fn all_module_ids() -> Vec<&'static str> {
TSJS_MODULES.iter().map(|module| module.id).collect()
pub const fn all_module_ids() -> &'static [&'static str] {
&ALL_MODULE_IDS
Comment thread
dhruv8sh marked this conversation as resolved.
}

/// Concatenate core + the requested integration modules into a single JS string.
Expand Down Expand Up @@ -138,6 +138,16 @@ mod tests {
encode(Sha256::digest(bytes))
}

#[test]
fn all_module_ids_matches_generated_module_list() {
let from_modules: Vec<&str> = TSJS_MODULES.iter().map(|module| module.id).collect();
assert_eq!(
all_module_ids(),
from_modules.as_slice(),
"the generated ID list should match the generated module table"
);
}

#[test]
fn generated_single_module_hashes_match_bundle_contents() {
for id in all_module_ids() {
Expand Down
Loading