1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//! wasm-slim library
//!
//! This library provides the core functionality for WASM bundle size optimization.
//! It can be used programmatically in addition to the CLI interface.
//!
//! # Basic Example
//!
//! Creating and validating configuration:
//!
//! ```
//! use wasm_slim::config::file::{ConfigFile, ProfileSettings};
//!
//! // Create configuration with custom profile settings
//! let config = ConfigFile {
//! template: "balanced".to_string(),
//! profile: Some(ProfileSettings {
//! opt_level: Some("z".to_string()),
//! lto: Some("thin".to_string()),
//! strip: Some(true),
//! codegen_units: Some(1),
//! panic: Some("abort".to_string()),
//! }),
//! wasm_opt: None,
//! size_budget: None,
//! };
//!
//! assert_eq!(config.template, "balanced");
//! ```
//!
//! # Advanced Example: Size Budget Validation
//!
//! Using size budgets to enforce WASM bundle size limits:
//!
//! ```
//! use wasm_slim::config::file::SizeBudget;
//!
//! // Create a size budget with target and thresholds
//! let budget = SizeBudget {
//! target_size_kb: Some(300),
//! warn_threshold_kb: Some(400),
//! max_size_kb: Some(500),
//! };
//!
//! // Validate budget constraints
//! let validation = budget.validate();
//! assert!(validation.is_ok());
//!
//! // Invalid budget (target > max) should fail
//! let bad_budget = SizeBudget {
//! target_size_kb: Some(600),
//! warn_threshold_kb: Some(400),
//! max_size_kb: Some(500),
//! };
//! assert!(bad_budget.validate().is_err());
//! ```
//!
//! # Advanced Example: Multi-stage Workflow
//!
//! Creating backups before modification:
//!
//! ```
//! use wasm_slim::optimizer::BackupManager;
//! use wasm_slim::config::file::ConfigFile;
//! use std::path::Path;
//! use tempfile::TempDir;
//! use std::fs;
//!
//! // Setup temporary workspace
//! let workspace = TempDir::new().unwrap();
//! let cargo_toml = workspace.path().join("Cargo.toml");
//! fs::write(&cargo_toml, "[package]\nname = \"test\"\n").unwrap();
//!
//! // Create backup before modification
//! let backup_mgr = BackupManager::new(workspace.path());
//! let backup_path = backup_mgr.create_backup(&cargo_toml).unwrap();
//! assert!(backup_path.exists());
//!
//! // Backup contains original content
//! let backup_content = fs::read_to_string(&backup_path).unwrap();
//! assert!(backup_content.contains("test"));
//!
//! // Now safe to modify the original file
//! let config = ConfigFile::default();
//! fs::write(&cargo_toml, "[package]\nname = \"optimized\"\n").unwrap();
//! ```
/// Analysis tools for WASM bundles
/// Performance tracking utilities
/// CI/CD integration tooling
/// Command handlers for CLI operations
/// Configuration file and template management
/// Enhanced error types with contextual suggestions
/// Shared formatting utilities
/// Git metadata utilities
/// Infrastructure traits for filesystem and command execution
/// Cargo.toml optimization and backup management
/// Build pipeline orchestration
/// Rust toolchain detection and management
/// Tool detection and version checking