Back to Explore

Rich-Harris/magic-string

GitHub
7 updates · last 90 days4 watchersOpen source

Last release:

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. Recent updates are very close together (v1.2.3 on 2026-08-26, then v1.2.2 on 2026-08-20, v1.2.1 on 2026-08-19, v1.2.0 on 2026-08-13), and the latest upstream push is 2026-08-26.
  • Apparent update cadence looks like roughly weekly during August 2026 (and multiple updates within a two-week window), suggesting active development rather than a slow maintenance cycle.

AI summary generated

AI-generated from public sources. May be inaccurate. Report

Recent updates

  • v1.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.

    Features
  • v1.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.

    Breaking
  • v0.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.