Socket
Socket
Sign inDemoInstall

merge-source-map

Package Overview
Dependencies
1
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    merge-source-map

Merge old source map and new source map in multi-transform flow


Version published
Weekly downloads
3.3M
increased by4.6%
Maintainers
1
Install size
796 kB
Created
Weekly downloads
 

Package description

What is merge-source-map?

The merge-source-map npm package is a utility that allows developers to merge multiple source maps. This is particularly useful in development environments where JavaScript files are transformed through processes like minification or transpilation, and maintaining accurate source maps is crucial for debugging.

What are merge-source-map's main functionalities?

Merge Source Maps

This feature allows the merging of two source maps into one. It is useful when you have transformations applied in stages and need to track the original source accurately across these transformations.

const mergeSourceMap = require('merge-source-map');
const originalMap = { version: 3, sources: ['foo.js'], names: [], mappings: 'AAAA' };
const additionalMap = { version: 3, sources: ['foo.js'], names: [], mappings: 'CAAC' };
const mergedMap = mergeSourceMap(originalMap, additionalMap);
console.log(mergedMap);

Other packages similar to merge-source-map

Readme

Source

merge-source-map

npm-version downloads travis-ci Coverage Status

Merge old source map and new source map in multi-transform flow

API

var merge = require('merge-source-map')

merge(oldMap, newMap)

Merge old source map and new source map and return merged. If old or new source map value is falsy, return another one as it is.

oldMap : object|undefined
old source map object
newmap : object|undefined
new source map object

Example

var esprima    = require('esprima'),
    estraverse = require('estraverse'),
    escodegen  = require('escodegen'),
    convert    = require('convert-source-map'),
    merge      = require('merge-source-map')

const CODE = 'a = 1',
      FILEPATH = 'a.js'

// create AST of original code
var ast = esprima.parse(CODE, {sourceType: 'module', loc: true})

// transform AST of original code
estraverse.replace(ast, {
  enter: function(node, parent) { /* change AST */ },
  leave: function(node, parent) { /* change AST */ }
})

// generate code and source map from transformed AST
var gen = escodegen.generate(ast, {
  sourceMap: FILEPATH,
  sourceMapWithCode: true,
  sourceContent: CODE
})

// merge old source map and new source map
var oldMap = convert.fromSource(CODE) && convert.fromSource(CODE).toObject(),
    newMap = JSON.parse(gen.map.toString()),
    mergedMap = merge(oldMap, newMap),
    mapComment = convert.fromObject(mergedMap).toComment()

// attach merge source map to transformed code
var transformed = gen.code + '\n' + mapComment

console.log(transformed);

Test

% npm install
% npm test

License

MIT (c) keik

Keywords

FAQs

Last updated on 25 Dec 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc