Security News
npm Updates Search Experience with New Objective Sorting Options
npm has a revamped search experience with new, more transparent sorting options—Relevance, Downloads, Dependents, and Publish Date.
@parcel/source-map
Advanced tools
@parcel/source-map is a library for working with source maps, which are files that map from the transformed source code back to the original source code. This is useful for debugging and understanding the transformations applied to the code.
Creating a Source Map
This feature allows you to create a new source map and add mappings to it using VLQ (Variable Length Quantity) encoding.
const { SourceMap } = require('@parcel/source-map');
const map = new SourceMap();
map.addVLQMap({
version: 3,
file: 'out.js',
sources: ['foo.js', 'bar.js'],
names: ['src', 'maps', 'are', 'fun'],
mappings: 'AA,AB;;ABCDE;' // VLQ encoded mappings
});
console.log(map.toBuffer());
Adding a Mapping
This feature allows you to add individual mappings to the source map, specifying the generated and original positions, the source file, and an optional name.
const { SourceMap } = require('@parcel/source-map');
const map = new SourceMap();
map.addMapping({
generated: { line: 1, column: 5 },
original: { line: 2, column: 10 },
source: 'source.js',
name: 'myFunction'
});
console.log(map.toBuffer());
Loading an Existing Source Map
This feature allows you to load an existing source map into the SourceMap object, enabling further manipulation or inspection.
const { SourceMap } = require('@parcel/source-map');
const existingMap = {
version: 3,
file: 'out.js',
sources: ['foo.js', 'bar.js'],
names: ['src', 'maps', 'are', 'fun'],
mappings: 'AA,AB;;ABCDE;'
};
const map = new SourceMap();
map.addVLQMap(existingMap);
console.log(map.toBuffer());
Generating Source Map Buffer
This feature allows you to generate a buffer representation of the source map, which can be written to a file or used in other ways.
const { SourceMap } = require('@parcel/source-map');
const map = new SourceMap();
map.addMapping({
generated: { line: 1, column: 5 },
original: { line: 2, column: 10 },
source: 'source.js',
name: 'myFunction'
});
const buffer = map.toBuffer();
console.log(buffer);
The 'source-map' package is a library for generating and consuming source maps. It provides similar functionalities to @parcel/source-map, such as creating source maps, adding mappings, and loading existing maps. However, 'source-map' is more widely used and has a larger community.
The 'source-map-support' package provides source map support for stack traces in Node.js. While it does not offer the same level of manipulation capabilities as @parcel/source-map, it is useful for debugging purposes by providing better error stack traces.
The 'convert-source-map' package allows you to convert source maps from/to different formats and embed/extract them from code. It complements @parcel/source-map by providing additional utilities for working with source maps in various formats.
FAQs
A source map library purpose-build for the Parcel bundler with a focus on fast combining and manipulating of source-maps.
We found that @parcel/source-map 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.
Security News
npm has a revamped search experience with new, more transparent sorting options—Relevance, Downloads, Dependents, and Publish Date.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.