Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

karma-sourcemap-loader-srcroot

demerzel319MIT0.3.9

Karma plugin that locates and loads existing javascript source map files.

karma-plugin, karma-preprocessor, source-maps, javascript

readme

karma-sourcemap-loader-srcroot

Preprocessor that locates and loads existing source maps.

Why

This is a fork to provide the 'transform' option and make it available via npm.

When you use karma not in isolation but as part of a build process (e.g. using grunt or gulp) it is often the case that the compilation/transpilation is done on a previous step of the process and not handled by karma preprocessors. In these cases source maps don't get loaded by karma and you lose the advantages of having them.

How it works

This plug-in supports both inline and external source maps.

Inline source maps are located by searching "sourceMappingURL=" inside the javascript file, both plain text and base64-encoded maps are supported.

External source maps are located by appending ".map" to the javascript file name. So if for example you have Hello.js, the preprocessor will try to load source map from Hello.js.map.

Installation

Just add karma-sourcemap-loader-srcroot as a devDependency in your package.json.

{
  "devDependencies": {
    "karma-sourcemap-loader-srcroot": "~0.3"
  }
}

Or issue the following command:

npm install karma-sourcemap-loader-srcroot --save-dev

Configuration

The code below shows a sample configuration of the preprocessor.

// karma.conf.js
module.exports = function(config) {
  config.set({
    preprocessors: {
      '**/*.js': ['sourcemap']
    },
    sourcemap: {
      transform: function(mapData) {
        mapData.sourceRoot = '/';
      }
    }
  });
};

Configuration Parameters

  • transform - function - allows transforming the map data prior to loading.

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

[0.4.0] - 2022-02-05

Added

  • Allow remapping or otherwise changing source paths in source maps
  • Allow changing sourceRoot in source maps
  • Allow adapting the source map files alone, if served separately by the Karma web server
  • Add option onlyWithURL to disable the source map loading for files without sourceMappingURL
  • Add option strict for a strict error handling of invalid and/or missing source maps

Fixed

  • Fix handling of raw (URI-encoded) source maps - trim the leading , before parsing the content
  • Warn about a missing external source map, is the source mapping URL is invalid
  • Handle malformed source map content as a warning or failure