How to Configure File Updates
This guide shows you how to configure Nagare to update version strings in multiple files during releases. Use this approach when you need to keep version information synchronized across different file types.
Before you begin
Section titled “Before you begin”Ensure you have:
- Nagare initialized in your project (
deno task nagare init) - A
nagare.config.tsfile in your project root - Basic understanding of regular expressions (for custom patterns)
Built-in file handlers
Section titled “Built-in file handlers”Nagare includes intelligent file handlers that automatically detect and update common file types without custom configuration.
Supported file types
Section titled “Supported file types”- JSON Files:
deno.json,package.json,jsr.json - TypeScript/JavaScript:
version.ts,constants.ts, and similar files - Markdown:
README.mdand other.mdfiles (updates version badges and references) - YAML:
.yamland.ymlconfiguration files - Language-specific:
Cargo.toml(Rust),pyproject.toml(Python)
Simple configuration
Section titled “Simple configuration”// ✅ Recommended: Use built-in handlersexport default { updateFiles: [ { path: "./deno.json" }, { path: "./package.json" }, { path: "./README.md" }, { path: "./jsr.json" }, { path: "./Cargo.toml" }, ],} as NagareConfig;Custom file patterns
Section titled “Custom file patterns”For files not covered by built-in handlers, you can define custom patterns.
Basic custom pattern
Section titled “Basic custom pattern”export default { updateFiles: [ { path: "./config/app.yaml", patterns: { // ✅ SAFE: Line-anchored pattern version: /^version:\s*"([^"]+)"/m, }, }, ],} as NagareConfig;Multiple patterns in one file
Section titled “Multiple patterns in one file”export default { updateFiles: [ { path: "./src/constants.ts", patterns: { version: /^export const VERSION = "([^"]+)"/m, buildNumber: /^export const BUILD_NUMBER = (\d+)/m, }, }, ],} as NagareConfig;Custom update function
Section titled “Custom update function”For complex update logic, use a custom function:
export default { updateFiles: [ { path: "./src/metadata.ts", updateFn: (content, data) => { // Update version content = content.replace( /VERSION:\s*"[^"]+"/, `VERSION: "${data.version}"`, );
// Update build date content = content.replace( /BUILD_DATE:\s*"[^"]+"/, `BUILD_DATE: "${data.buildDate}"`, );
return content; }, }, ],} as NagareConfig;Advanced patterns
Section titled “Advanced patterns”JSON path updates
Section titled “JSON path updates”For nested JSON properties:
export default { updateFiles: [ { path: "./package.json", patterns: { // Update nested property version: /^(\s*"version":\s*)"[^"]+"/m, // Update in dependencies dependency: /^(\s*"@myorg\/mypackage":\s*)"[^"]+"/m, }, }, ],} as NagareConfig;YAML configurations
Section titled “YAML configurations”export default { updateFiles: [ { path: "./docker-compose.yml", patterns: { // Update image tag imageTag: /^(\s*image:\s*myapp:)[\w.-]+$/m, }, }, ],} as NagareConfig;Multi-line patterns
Section titled “Multi-line patterns”For patterns spanning multiple lines:
export default { updateFiles: [ { path: "./Dockerfile", patterns: { // Update LABEL version version: /^(LABEL version=)"[^"]+"/m, }, }, ],} as NagareConfig;Pattern validation
Section titled “Pattern validation”Nagare validates file update patterns to prevent common issues:
Safe patterns (recommended)
Section titled “Safe patterns (recommended)”// ✅ SAFE: Line-anchored with specific context/^(\s*"version":\s*)"[^"]+"/m
// ✅ SAFE: Matches only at line start/^version:\s*"([^"]+)"/m
// ✅ SAFE: Specific field name/^export const VERSION = "([^"]+)"/mPatterns to avoid
Section titled “Patterns to avoid”// ❌ DANGEROUS: Could match nested fields/"version":\s*"[^"]+"/
// ❌ DANGEROUS: Too broad, could match comments/version.*"[^"]+"/
// ❌ DANGEROUS: No anchoring/VERSION = "[^"]+"/Testing your configuration
Section titled “Testing your configuration”Preview changes
Section titled “Preview changes”Test your file update patterns without making changes:
# Preview all file updatesdeno task nagare:dry
# Check specific filesdeno task nagare --dry-run --verboseValidate patterns
Section titled “Validate patterns”# Test pattern matchingdeno run -A scripts/check-patterns.tsTroubleshooting
Section titled “Troubleshooting”Pattern not matching
Section titled “Pattern not matching”Problem: “No matches found for pattern”
Solution:
- Check that the pattern uses line anchors (
^and$) - Verify the file contains the expected content
- Test the regex with a tool like regex101.com
Multiple matches
Section titled “Multiple matches”Problem: “Pattern matches multiple locations”
Solution:
- Make the pattern more specific
- Use line anchors to match only intended lines
- Consider using
updateFnfor complex logic
File corruption
Section titled “File corruption”Problem: “File content corrupted after update”
Solution:
- Use built-in handlers when possible
- Test patterns with
--dry-runfirst - Ensure patterns have proper capture groups
Best practices
Section titled “Best practices”- Use built-in handlers when possible for reliability
- Test patterns thoroughly with
--dry-runbefore releases - Be specific - narrow patterns prevent unintended matches
- Use line anchors (
^and$) for safety - Document custom patterns for team understanding