npm / magic-string
magic-string
What changed in magic-string 1, from its official release notes, upgrade guides and advisories. Sources checked 2026-10-17.
4 breaking5 new APIs and options6 performance25 fixes and other
See which of these apply to your code, ranked, in your agent:
npx @unstale/cli initmagic-string 140 changes
Breaking changes 4
Separators between sources are trimmed, changing how bundled sources are joined.
Indices below -length are clamped instead of wrapping repeatedly.
An overlapping move now throws instead of corrupting the chunk list.
The package is now pure ESM; the CJS, UMD, and IIFE builds have been dropped.
New APIs and options 5
Adds an affinity option to move().
Adds toMagicString() to flatten a Bundle into a MagicString.
includeContent in Bundle now supports a function.
Adds a high-resolution source map mode using range mappings.
Introduces MagicStringError with concise, consistent messages.
Performance 6
Looks up removed content without scanning every chunk.
Encodes mappings incrementally to reduce peak memory usage.
Avoids split() when locating lines.
Walks unedited chunks line by line when generating mappings.
hasChanged is optimized.
A fast path was added for non-exclusion indentation.
Fixes and other changes 25
Fixes replacement of matched text when an offset is set.
Preserves inserts when update spans several chunks.
Keeps the outro when splitting a removed chunk.
Skips empty matches inside removed content.
Flushes the shared encoder buffer at the end of every drain.
Carries trimStart and trimEnd into the intro and outro.
Treats moving a range to where it already sits as a no-op.
Carries trimStart and trimEnd into the intro and outro.
Preserves inserts anchored to the edges of a removed range.
Returns an empty slice when the end index resolves to zero.
Content added with append or prepend is now indented.
Bundle#length now counts source appends and prepends.
Now counts string-level appends and prepends.
Expands $ substitutions as String.prototype does.
Only passes the groups object when the pattern has named groups.
Indentation in a bundle is guessed from its most common indentation.
Empty matches are handled in replace.
Empty matches are handled in replaceAll.
Cloning now keeps the ignore-list hint and stored names.
hasChanged now reports a change when an edit spans a chunk boundary.
Bundle#isEmpty now counts separators when determining whether a bundle is empty.
Bundle#length counts separators.
update() validates its range and includes indices in range errors.
Replacements longer than the range they replace are trimmed.
Moving a zero-length range no longer crashes.