magic-string is a small, fast utility for manipulating source code as strings, making light edits like replacing characters, prepending, appending, moving, and overwriting. It also generates version 3 source maps (optionally including original content), which can help when transforming code while preserving mapping back to the original.
Project status
- Actively maintained: Yes, the upstream repo shows very recent activity (last push on 2026-09-15), with multiple bug fix and feature updates released in the same month.
- Update cadence: Frequent, roughly weekly in late August through mid September 2026 (updates on 2026-08-13, 08-19, 08-20, 08-26, and 09-10 and 09-15).
AI summary generated
Recent updates
v1.4.1
v1.4.1 is a targeted bug fix release. It ensures the internal shared scratch buffer used by MappingsEncoder is flushed so that nested map generation (for example, via Bundle includeContent callbacks) cannot overwrite pending encoder output.
v1.4.0
v1.4.0 adds an affinity option to MagicString.move, and introduces Bundle.toMagicString() to flatten a bundle into a single MagicString instance. It also improves sourcemap generation performance by encoding mappings incrementally, and fixes an issue where replace/replaceAll could resurrect removed content.
Featuresv1.3.2
v1.3.2 contains bug fixes focused on correct handling of edge cases in MagicString operations, including remove/slice/move and trimming across intro/outro boundaries. The release notes describe four specific fixes, and the code changes in src/MagicString.ts align for those main behaviors.
v1.3.1
Release v1.3.1 is described as having no significant changes, and the runtime library diff provided is mostly non-functional. The main changes visible in the diff are development and CI-related updates (test workflow refactor, added coverage tooling dependency) plus new/expanded test coverage.
v1.3.0
v1.3.0 adds a new experimental hi-res sourcemap mode that records range mappings, plus improved Bundle source content inclusion via a function option. It also contains several correctness fixes around mapping generation and string replacement behavior, and improves internal performance around line location and mapping walks.
Featuresv1.2.3
v1.2.3 ships a set of bug fixes focused on string replacement edge cases and bundle formatting. In particular it clamps overly-negative indices, improves handling of zero-length regexp/string matches in replace/replaceAll, trims separators between bundle sources, and changes indentation guessing to favor the most common indentation.
v1.2.2
v1.2.2 focuses on fixing and optimizing MagicString's `hasChanged` logic, particularly for edits that span chunk boundaries. It also improves cloning correctness by preserving ignore-list and stored name metadata. The code diff additionally introduces cloning support for `indentExclusionRanges`, which is not mentioned in the release notes.
v1.2.1
This release is focused on correctness fixes in two areas: Bundle emptiness detection and MagicString move safety. Bundle#isEmpty now accounts for separators more accurately, and MagicString.move now throws instead of corrupting the internal chunk list when earlier moves have broken the chunk ordering assumptions.
v1.2.0
v1.2.0 introduces a new Error type, MagicStringError, and updates MagicString, Bundle, and SourceMap to throw this error instead of Error/TypeError in various validation and runtime paths. The public module exports were updated to include MagicStringError, and the test suite was adjusted to assert on the new error type and message patterns.
Featuresv1.1.1
v1.1.1 is presented as a set of bug fixes focused on correct separator handling in Bundle sourcemaps and Bundle#length, plus improved range validation errors for MagicString.update(). The code diff also shows related error-message tightening for MagicString.remove(), and some internal refactoring around MagicString chunk indexing.
v1.1.0
v1.1.0 focuses on a bug fix in trimming behavior for overwrite operations where the replacement text is longer than the target range, and a performance-oriented internal change. It also updates internal chunk tracking to use Map instead of plain object indexing.
v1.0.0
v1.0.0 migrates magic-string to a pure ESM build and switches its type declarations to be generated from the TypeScript source. The release also includes a bug fix for a crash involving zero-length ranges, plus a performance optimization for indent behavior.
Breakingv0.30.21
Release v0.30.21 appears to be a metadata-only update. The diff shows a version bump in package.json, a repository URL format tweak, and an added changelog header entry, with no library code changes.
v0.30.20
This release (v0.30.20) contains no significant changes per the provided release notes. There are no documented updates affecting APIs, behavior, security, performance, or migration steps.
v0.30.19
Release v0.30.19 was published on 2025-09-08, but the publisher provided no release notes or change log details. As a result, there is no documented information about new features, bug fixes, breaking changes, security, or dependency updates in this release.