Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
vinyl-sourcemaps-apply
Advanced tools
Apply a source map to a vinyl file, merging it with preexisting source maps
The vinyl-sourcemaps-apply npm package is used to apply source maps to vinyl files, which are used in the Gulp build system. This package helps in maintaining the mapping between the original source code and the transformed code, which is useful for debugging purposes.
Apply Source Maps
This feature allows you to apply a source map to a vinyl file. The code sample demonstrates creating a vinyl file object, creating a source map consumer, and then applying the source map to the vinyl file using the vinyl-sourcemaps-apply package.
const applySourceMap = require('vinyl-sourcemaps-apply');
const vinylFile = require('vinyl');
const sourceMap = require('source-map');
// Create a vinyl file object
const file = new vinylFile({
cwd: '/',
base: '/test/',
path: '/test/file.js',
contents: Buffer.from('test content'),
sourceMap: {
version: 3,
file: 'file.js',
sources: ['file.coffee'],
names: [],
mappings: 'AAAA'
}
});
// Create a source map consumer
const map = new sourceMap.SourceMapConsumer(file.sourceMap);
// Apply the source map to the vinyl file
applySourceMap(file, map);
The gulp-sourcemaps package is used to generate and write source maps in the Gulp build system. It provides more comprehensive functionality for handling source maps, including initializing, writing, and loading source maps. Compared to vinyl-sourcemaps-apply, gulp-sourcemaps offers a more integrated solution for source map management within Gulp tasks.
The source-map package is a library for generating and consuming source maps. It provides low-level APIs for creating and manipulating source maps. While vinyl-sourcemaps-apply focuses on applying source maps to vinyl files, source-map offers a broader range of functionalities for working with source maps directly.
Apply a source map to a vinyl file, merging it with preexisting source maps.
var applySourceMap = require('vinyl-sourcemaps-apply');
applySourceMap(vinylFile, sourceMap);
var through = require('through2');
var applySourceMap = require('vinyl-sourcemaps-apply');
var myTransform = require('myTransform');
module.exports = function(options) {
function transform(file, encoding, callback) {
// generate source maps if plugin source-map present
if (file.sourceMap) {
options.makeSourceMaps = true;
}
// do normal plugin logic
var result = myTransform(file.contents, options);
file.contents = new Buffer(result.code);
// apply source map to the chain
if (file.sourceMap) {
applySourceMap(file, result.map);
}
this.push(file);
callback();
}
return through.obj(transform);
};
FAQs
Apply a source map to a vinyl file, merging it with preexisting source maps
We found that vinyl-sourcemaps-apply demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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 malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.