Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
combine-source-map
Advanced tools
Add source maps of multiple files, offset them and then combine them into one source map
The combine-source-map npm package is used to create and modify source maps, which are files that map from the transformed source to the original source, allowing developers to debug their code more easily. This package is particularly useful when dealing with multiple source files that need to be combined into a single file, while still maintaining accurate source maps.
Create a new source map
This feature allows you to create a new source map for a given file. In this example, a new source map is created for 'bundle.js'.
const combine = require('combine-source-map');
const map = combine.create('bundle.js');
console.log(map);
Add a file to the source map
This feature allows you to add a file to the source map. In this example, 'file1.js' is added to the source map with its content and starting line number.
const combine = require('combine-source-map');
const map = combine.create('bundle.js');
map.addFile({ sourceFile: 'file1.js', source: 'console.log("file1");' }, { line: 0 });
console.log(map);
Generate the source map
This feature allows you to generate the source map in base64 format. In this example, after adding 'file1.js' to the source map, the source map is generated and logged in base64 format.
const combine = require('combine-source-map');
const map = combine.create('bundle.js');
map.addFile({ sourceFile: 'file1.js', source: 'console.log("file1");' }, { line: 0 });
const sourceMap = map.base64();
console.log(sourceMap);
The source-map package provides a library for generating and consuming source maps. It offers more granular control over source map generation and manipulation compared to combine-source-map, making it suitable for more complex use cases.
The gulp-sourcemaps package is a plugin for Gulp that simplifies the process of generating and working with source maps in a Gulp build pipeline. It is more integrated with the Gulp ecosystem, making it a better choice for projects that use Gulp for task automation.
Webpack is a module bundler that includes built-in support for source maps. It provides a comprehensive solution for bundling JavaScript applications, including source map generation, making it a more feature-rich but complex alternative to combine-source-map.
Add source maps of multiple files, offset them and then combine them into one source map.
var convert = require('convert-source-map');
var combine = require('combine-source-map');
var fooComment = '//# sourceMappingURL=data:application/json;base64,eyJ2Z [..] pzJylcbiJdfQ==';
var barComment = '//# sourceMappingURL=data:application/json;base64,eyJ2Z [..] VjaycpXG4iXX0=';
var fooFile = {
source: '(function() {\n\n console.log(require(\'./bar.js\'));\n\n}).call(this);\n' + '\n' + fooComment
, sourceFile: 'foo.js'
};
var barFile = {
source: '(function() {\n\n console.log(alert(\'alerts suck\'));\n\n}).call(this);\n' + '\n' + barComment
, sourceFile: 'bar.js'
};
var offset = { line: 2 };
var base64 = combine
.create('bundle.js')
.addFile(fooFile, offset)
.addFile(barFile, { line: offset.line + 8 })
.base64();
var sm = convert.fromBase64(base64).toObject();
console.log(sm);
{ version: 3,
file: 'bundle.js',
sources: [ 'foo.coffee', 'bar.coffee' ],
names: [],
mappings: ';;;AAAA;CAAA;CAAA,CAAA,CAAA,IAAO,GAAK;CAAZ;;;;;ACAA;CAAA;CAAA,CAAA,CAAA,IAAO,GAAK;CAAZ',
sourcesContent:
[ 'console.log(require \'./bar.js\')\n',
'console.log(alert \'alerts suck\')\n' ] }
npm install combine-source-map
/**
* @name create
* @function
* @param file {String} optional name of the generated file
* @param sourceRoot { String} optional sourceRoot of the map to be generated
* @return {Object} Combiner instance to which source maps can be added and later combined
*/
/**
* Adds map to underlying source map.
* If source contains a source map comment that has the source of the original file inlined it will offset these
* mappings and include them.
* If no source map comment is found or it has no source inlined, mappings for the file will be generated and included
*
* @name addMap
* @function
* @param opts {Object} { sourceFile: {String}, source: {String} }
* @param offset {Object} { line: {Number}, column: {Number} }
*/
/**
* @name base64
* @function
* @return {String} base64 encoded combined source map
*/
/**
* @name comment
* @function
* @return {String} base64 encoded sourceMappingUrl comment of the combined source map
*/
/**
* @name removeComments
* @function
* @param src
* @return {String} src with all sourceMappingUrl comments removed
*/
Read and run the more elaborate example in order to get a better idea how things work.
FAQs
Add source maps of multiple files, offset them and then combine them into one source map
The npm package combine-source-map receives a total of 1,227,315 weekly downloads. As such, combine-source-map popularity was classified as popular.
We found that combine-source-map demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.