diff --git a/rslib/proto/python.rs b/rslib/proto/python.rs index bf9d30944..db63d612a 100644 --- a/rslib/proto/python.rs +++ b/rslib/proto/python.rs @@ -1,12 +1,12 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use std::io::BufWriter; +use std::io::Cursor; use std::io::Write; use std::path::Path; use anki_io::create_dir_all; -use anki_io::create_file; +use anki_io::write_file_if_changed; use anki_proto_gen::BackendService; use anki_proto_gen::Method; use anyhow::Result; @@ -18,7 +18,7 @@ use prost_reflect::MessageDescriptor; pub(crate) fn write_python_interface(services: &[BackendService]) -> Result<()> { let output_path = Path::new("../../out/pylib/anki/_backend_generated.py"); create_dir_all(output_path.parent().unwrap())?; - let mut out = BufWriter::new(create_file(output_path)?); + let mut out = Cursor::new(Vec::new()); write_header(&mut out)?; for service in services { @@ -29,6 +29,7 @@ pub(crate) fn write_python_interface(services: &[BackendService]) -> Result<()> render_method(service, method, &mut out); } } + write_file_if_changed(output_path, out.into_inner())?; Ok(()) } diff --git a/rslib/proto/typescript.rs b/rslib/proto/typescript.rs index d241bcd53..52cb0ded8 100644 --- a/rslib/proto/typescript.rs +++ b/rslib/proto/typescript.rs @@ -11,6 +11,7 @@ use anki_proto_gen::BackendService; use anki_proto_gen::Method; use anyhow::Result; use inflections::Inflect; +use itertools::Itertools; pub(crate) fn write_ts_interface(services: &[BackendService]) -> Result<()> { let root = Path::new("../../out/ts/lib"); @@ -59,7 +60,7 @@ import type { PostProtoOptions } from "./post"; fn imports(referenced_packages: HashSet) -> String { let mut out = String::new(); - for package in referenced_packages { + for package in referenced_packages.iter().sorted() { writeln!( &mut out, "import * as {} from \"./anki/{}_pb\";", diff --git a/ts/tools/markpure.ts b/ts/tools/markpure.ts index 735f0ae55..534038cce 100644 --- a/ts/tools/markpure.ts +++ b/ts/tools/markpure.ts @@ -28,10 +28,10 @@ function adjustFiles() { const jsFiles = allFilesInDir(root).filter(f => f.endsWith(".js")); for (const file of jsFiles) { - let contents = fs.readFileSync(file, "utf8"); + const contents = fs.readFileSync(file, "utf8"); // allow tree shaking on proto messages - contents = contents.replace( + let newContents = contents.replace( /= proto3.make/g, "= /* @__PURE__ */ proto3.make", ); @@ -39,9 +39,11 @@ function adjustFiles() { // strip out typeName info, which appears to only be required for // certain JSON functionality (though this only saves a few hundred // bytes) - contents = contents.replace(typeRe, "$1(\"\","); + newContents = contents.replace(typeRe, "$1(\"\","); - fs.writeFileSync(file, contents, "utf8"); + if (contents != newContents) { + fs.writeFileSync(file, newContents, "utf8"); + } } }