Skip to content

Latest commit

 

History

History
66 lines (38 loc) · 2.06 KB

File metadata and controls

66 lines (38 loc) · 2.06 KB

source-map-links

Modern source map link discovery and resolution helpers for JavaScript and TypeScript.

source-map-resolve is deprecated. This package keeps the useful migration concepts: find a sourceMappingURL, parse external or inline source maps, resolve source file URLs, and optionally load source contents. The API is promise-first with sync helpers for build tools.

Install

npm install source-map-links

Usage

import { resolveSourceMap, resolveSources } from "source-map-links";

const result = await resolveSourceMap(code, "/js/app.js", readText);

if (result) {
  const sources = await resolveSources(result.map, result.sourcesRelativeTo, readText);
  console.log(sources.sourcesResolved);
}

Inline data URLs are supported:

import { findSourceMappingURL, parseMapToJSON } from "source-map-links";

const link = findSourceMappingURL(code);
const map = parseMapToJSON(json);

API

findSourceMappingURL(code)

Returns the last sourceMappingURL comment value in JavaScript or CSS code.

parseMapToJSON(text, data?)

Strips the source map XSSI prefix and parses JSON. If parsing fails, the thrown error has sourceMapData.

resolveSourceMap(code, codeUrl, read)

Finds and loads the referenced source map. Returns null when no link exists.

resolveSources(map, mapUrl, read?, options?)

Resolves source URLs and loads source contents where possible.

resolve(code, codeUrl, read, options?)

Convenience helper that resolves the source map and sources.

Sync variants

resolveSourceMapSync, resolveSourcesSync, and resolveSync are available for synchronous build pipelines.

Migration Position

source-map-links is an independent alternative or migration helper for projects moving away from source-map-resolve. It is not affiliated with the original package maintainers or project.

For release context, see the local migration guide, examples, compatibility notes, source metadata, and adoption plan.