diff --git a/crates/trusted-server-core/src/publisher.rs b/crates/trusted-server-core/src/publisher.rs index 0e0a1ad92..83854d17c 100644 --- a/crates/trusted-server-core/src/publisher.rs +++ b/crates/trusted-server-core/src/publisher.rs @@ -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) } @@ -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. diff --git a/crates/trusted-server-js/build.rs b/crates/trusted-server-js/build.rs index ba6cd88f2..8fbd34c9e 100644 --- a/crates/trusted-server-js/build.rs +++ b/crates/trusted-server-js/build.rs @@ -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"); diff --git a/crates/trusted-server-js/src/bundle.rs b/crates/trusted-server-js/src/bundle.rs index be5aa35cc..267f74495 100644 --- a/crates/trusted-server-js/src/bundle.rs +++ b/crates/trusted-server-js/src/bundle.rs @@ -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 } /// Concatenate core + the requested integration modules into a single JS string. @@ -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() {