unstale

npm / magic-string

magic-string

What changed in magic-string 1, from its official release notes, upgrade guides and advisories. Sources checked 2026-11-30.

5 breaking5 new APIs and options8 performance30 fixes and other

See which of these apply to your code, ranked, in your agent:

npx @unstale/cli init

@unstale/cli on npm

magic-string 148 changes

Breaking changes 5

  • Non-integer and out-of-range indices are now rejected consistently.

    1.4.5release notes

  • Separators between sources are trimmed, changing how bundled sources are joined.

    1.2.3release notes

  • Indices below -length are clamped instead of wrapping repeatedly.

    1.2.3release notes

  • An overlapping move now throws instead of corrupting the chunk list.

    1.2.1release notes

  • The package is now pure ESM; the CJS, UMD, and IIFE builds have been dropped.

    1.0.0release notes

New APIs and options 5

  • Adds an affinity option to move().

    1.4.0release notes

  • Adds toMagicString() to flatten a Bundle into a MagicString.

    1.4.0release notes

  • includeContent in Bundle now supports a function.

    1.3.0release notes

  • Adds a high-resolution source map mode using range mappings.

    1.3.0release notes

  • Introduces MagicStringError with concise, consistent messages.

    1.2.0release notes

Performance 8

  • The slice start chunk is found without scanning the list.

    1.4.5release notes

  • These paths use fewer allocations and avoid quadratic lookups.

    1.4.5release notes

  • Looks up removed content without scanning every chunk.

    1.4.2release notes

  • Encodes mappings incrementally to reduce peak memory usage.

    1.4.0release notes

  • Avoids split() when locating lines.

    1.3.0release notes

  • Walks unedited chunks line by line when generating mappings.

    1.3.0release notes

  • hasChanged is optimized.

    1.2.2release notes

  • A fast path was added for non-exclusion indentation.

    1.0.0release notes

Fixes and other changes 30

  • The method now shifts replacesUntil and replacedFrom correctly.

    1.4.5release notes

  • Indent exclusions are respected on moved edits and CRLF bundle intros.

    1.4.5release notes

  • The stored name is preserved when an overwritten range is split.

    1.4.5release notes

  • Empty matches at a chunk boundary inside removed content are skipped.

    1.4.4release notes

  • snip now respects the offset.

    1.4.4release notes

  • Content is kept when update throws across a split point.

    1.4.4release notes

  • Fixes replacement of matched text when an offset is set.

    1.4.3release notes

  • Preserves inserts when update spans several chunks.

    1.4.3release notes

  • Keeps the outro when splitting a removed chunk.

    1.4.2release notes

  • Skips empty matches inside removed content.

    1.4.2release notes

  • Flushes the shared encoder buffer at the end of every drain.

    1.4.1release notes

  • Carries trimStart and trimEnd into the intro and outro.

    1.3.2release notes

  • Treats moving a range to where it already sits as a no-op.

    1.3.2release notes

  • Preserves inserts anchored to the edges of a removed range.

    1.3.2release notes

  • Returns an empty slice when the end index resolves to zero.

    1.3.2release notes

  • Content added with append or prepend is now indented.

    1.3.0release notes

  • Bundle#length now counts source appends and prepends.

    1.3.0release notes

  • Now counts string-level appends and prepends.

    1.3.0release notes

  • Expands $ substitutions as String.prototype does.

    1.3.0release notes

  • Only passes the groups object when the pattern has named groups.

    1.3.0release notes

  • Indentation in a bundle is guessed from its most common indentation.

    1.2.3release notes

  • Empty matches are handled in replace.

    1.2.3release notes

  • Empty matches are handled in replaceAll.

    1.2.3release notes

  • Cloning now keeps the ignore-list hint and stored names.

    1.2.2release notes

  • hasChanged now reports a change when an edit spans a chunk boundary.

    1.2.2release notes

  • Bundle#isEmpty now counts separators when determining whether a bundle is empty.

    1.2.1release notes

  • Bundle#length counts separators.

    1.1.1release notes

  • update() validates its range and includes indices in range errors.

    1.1.1release notes

  • Replacements longer than the range they replace are trimmed.

    1.1.0release notes

  • Moving a zero-length range no longer crashes.

    1.0.0release notes