- What is sycho/sourcemap used for in a Laravel application?
- It is a small PHP library for reading Source Map v3 JSON and translating positions in compiled or minified JavaScript and CSS back to the original file, line, and column. In a Laravel codebase the realistic uses are decoding frontend stack traces inside an error-reporting path, validating emitted maps in a CI or artisan build command, and internal developer tooling. It is infrastructure glue, not a customer-facing capability, so keep it behind an internal service rather than calling it from controllers.
- How do I install sycho/sourcemap with Composer?
- Install it with composer require sycho/sourcemap; it is a standard PSR-4 autoloaded library with no framework dependencies. You then instantiate its classes directly in your own code. There is no published Laravel integration layer, so plan on writing the wiring yourself.
- Which PHP and Laravel versions does sycho/sourcemap support?
- The package does not publish a visible CI matrix or explicit PHP version guarantee, so read the require constraint in its composer.json before adopting it. Check it against your matrix, for example Laravel 10 on PHP 8.1+ and Laravel 11 on PHP 8.2+. Pin the version and run a smoke test on your own map fixtures rather than assuming compatibility.
- Is there a service provider or facade for Laravel package discovery?
- No. sycho/sourcemap is framework-agnostic and ships without a service provider, facade, config file, or auto-discovery. Register it manually in one of your own service providers and bind it as a singleton behind an internal contract such as SourceMapResolver. That wrapper keeps a future swap or fork to a single file.
- Does sycho/sourcemap parse source maps, generate them, or both?
- The package describes both directions: mapping generated positions to original sources and generating mappings for compiled assets. The public API is not documented in detail, so confirm in the vendored source whether generation, composition across chained transforms, and indexed maps are actually implemented before you rely on them. Budget a short spike to read the code first.
- How do I map a minified line and column back to the original source file?
- Load the .map JSON for the asset, hand it to the parser, then pass the generated line and column reported by the stack trace. It returns the original source path, line, and column for that position. Since the API surface is not fully documented, isolate the call in one adapter class so an upstream change stays contained.
- What is the memory behaviour on large 5-20 MB source maps?
- This is unverified and a real risk, because parsers of this kind typically decode the whole document into PHP arrays. A multi-megabyte map with embedded sourcesContent can be expensive to hold in memory. Enforce a size cap in configuration and do the work in a queued job or CLI command, never in a synchronous user request.
- Is it safe to parse source maps that come from an untrusted source?
- Do not. There is no documented input validation and parsing is effectively unbounded, so treat maps as internal build artefacts only. Restrict parsing to maps your own pipeline emits, reject oversized payloads before decoding, and never expose the parser to user-supplied JSON.
- Does it implement the full Source Map v3 specification, including indexed sections and sourcesContent?
- Coverage is not documented, so verify Base64 VLQ decoding, mappings segment semantics, the names array, sourcesContent, and indexed maps with sections entries against real production maps. The dangerous failure mode is silent mis-mapping: plausible but wrong file, line, and column output that looks like it works. Build a fixture set of known-good maps and assert exact resolved positions in your test suite.
- Is sycho/sourcemap actively maintained, and what are the alternatives?
- Maturity signals are weak: a single maintainer, negligible adoption, and no visible release cadence or test suite, which is a real bus-factor concern for anything long-lived. The alternatives are build tooling that already emits maps (Vite, esbuild, webpack, Rollup) plus platforms like Sentry and browser devtools that consume them, or writing VLQ parsing in-house. In-house parsing is only a few days of subtle work, so treat adoption as a small, reversible pilot behind a feature flag rather than a committed dependency.