@parcel/source-map
A purpose build source-maps library for combining and manipulating source-maps.
Last updated 5 years ago by devongovett .
MIT · Original npm · Tarball · package.json
$ npm install @parcel/source-map 
SYNC missed versions from official npm registry.

Parcel's source-map library

A source map library purpose-build for the Parcel bundler with a focus on fast combining and manipulating of source-maps.

To learn more about how sourcemaps are formatted and how they work, you can have a look at the SourceMap Specification.

How to use this library?

If you want to use this library in your project or are looking to write a Parcel plugin with sourcemap support this should explain how you could get started.

For more information we have added doctypes to each function of the SourceMap class so you can have an in depth look at what everything does.

Creating a SourceMap instance

You can create a sourcemap from another sourcemap or by creating it one mapping at a time.

Creating from existing sourcemap

To create a sourcemap from an existing sourcemap you have to ensure it is a JS Object first by asking for the object version from whichever transpiler you're running or by parsing the serialised map using JSON.parse or any other JSON parser.

After this you can call the function addVLQMap(map, lineOffset, columnOffset) this function takes in the parameters map, lineOffset and columnOffset. The map argument corresponds to the sourcemap object. The line and column offset are optional parameters used for offsetting the generated line and column. (this can be used when post-processing or wrapping the code linked to the sourcemap, in Parcel this is used when combining maps).

Example:

import SourceMap from '@parcel/source-map';

const RAW_SOURCEMAP = {
  version: 3,
  file: "helloworld.js",
  sources: ["helloworld.coffee"],
  names: [],
  mappings: "AAAA;AAAA,EAAA,OAAO,CAAC,GAAR,CAAY,aAAZ,CAAA,CAAA;AAAA",
};

let sourcemap = new SourceMap();
sourcemap.addVLQMap(RAW_SOURCEMAP);

// This function removes the underlying references in the native code
sourcemap.delete();

Creating a sourcemap one mapping at a time

If you want to use this library to create a sourcemap from scratch you can, for this you can call the addIndexedMapping(mapping, lineOffset, columnOffset) function.

Example:

import SourceMap from '@parcel/source-map';

let sourcemap = new SourceMap();

// Add a single mapping
sourcemap.addIndexedMapping({
  generated: {
    // line index starts at 1
    line: 1,
    // column index starts at 0
    column: 4
  },
  original: {
    // line index starts at 1
    line: 1,
    // column index starts at 0
    column: 4
  },
  source: 'index.js',
  // Name is optional
  name: 'A'
});

// This function removes the underlying references in the native code
sourcemap.delete();

Caching

For caching sourcemaps we have a toBuffer() function which returns a buffer that can be saved on disk for later use and combining sourcemaps very quickly.

You can add a cached map to a SourceMap instance using the addBuffer(buffer, lineOffset) function, where you can also offset the generated line and column.

Inspiration and purpose

Why did we write this library

Parcel is a performance conscious bundler, and therefore we like to optimise Parcel's performance as much as possible.

Our original source-map implementation used mozilla's source-map and a bunch of javascript and had issues with memory usage and serialization times (we were keeping all mappings in memory using JS objects and write/read it using JSON for caching).

This implementation has been written from scratch in Rust minimizing the memory usage, by utilizing indexes for sources and names and optimizing serialization times by using Buffers instead of JSON for caching.

Previous works and inspiration

Without these libraries this library wouldn't be as good as it is today. We've inspired and optimized our code using ideas and patterns used inside these libraries as well as used it to figure out how sourcemaps should be handled properly.

Contributing to this library

All contributions to this library are welcome as is with any part of Parcel's vast collection of libraries and tools.

Prerequisites

To be able to build and work on this project you need to have the following tools installed:

Building the project

For development purposes you might want to build or rebuild the project, for this you need to build the N-API module and JS Code.

To do this run the following commands: (for more information about this you can have a look in ./package.json and ./Makefile)

yarn transpile && yarn build:node

Tagging a release

Before you're able to tag a release ensure to have cargo-release installed cargo install cargo-release, we use it to tag the cargo files with a release tag.

yarn tag-release <version>

Current Tags

  • 2.1.1                                ...           latest (2 years ago)
  • 2.0.0-alpha.3.1                                ...           next (5 years ago)
  • 2.0.0-nightly.167                                ...           nightly (5 years ago)
  • 2.0.0-alpha.1.1                                ...           v2 (5 years ago)

90 Versions

  • 2.1.1                                ...           2 years ago
  • 2.1.0                                ...           2 years ago
  • 2.0.5                                ...           3 years ago
  • 2.0.4                                ...           3 years ago
  • 2.0.3                                ...           3 years ago
  • 2.0.2                                ...           3 years ago
  • 2.0.1                                ...           3 years ago
  • 2.0.0                                ...           3 years ago
  • 2.0.0-rc.7                                ...           3 years ago
  • 2.0.0-rc.6                                ...           3 years ago
  • 2.0.0-rc.5                                ...           3 years ago
  • 2.0.0-rc.4                                ...           4 years ago
  • 2.0.0-rc.3                                ...           4 years ago
  • 2.0.0-rc.2                                ...           4 years ago
  • 2.0.0-rc.1.0                                ...           4 years ago
  • 2.0.0-alpha.4.23                                ...           4 years ago
  • 2.0.0-alpha.4.22                                ...           4 years ago
  • 2.0.0-alpha.4.21                                ...           4 years ago
  • 2.0.0-alpha.4.20                                ...           4 years ago
  • 2.0.0-alpha.4.19                                ...           4 years ago
  • 2.0.0-alpha.4.18                                ...           4 years ago
  • 2.0.0-alpha.4.17                                ...           4 years ago
  • 2.0.0-alpha.4.16                                ...           4 years ago
  • 2.0.0-alpha.4.15                                ...           4 years ago
  • 2.0.0-alpha.4.14                                ...           4 years ago
  • 2.0.0-alpha.4.13                                ...           5 years ago
  • 2.0.0-alpha.4.12                                ...           5 years ago
  • 2.0.0-alpha.4.11                                ...           5 years ago
  • 2.0.0-alpha.4.10                                ...           5 years ago
  • 2.0.0-alpha.4.9                                ...           5 years ago
  • 2.0.0-alpha.4.8                                ...           5 years ago
  • 2.0.0-alpha.4.7                                ...           5 years ago
  • 2.0.0-alpha.4.6                                ...           5 years ago
  • 2.0.0-alpha.4.5                                ...           5 years ago
  • 2.0.0-alpha.4.4                                ...           5 years ago
  • 2.0.0-nightly.167                                ...           5 years ago
  • 2.0.0-alpha.4.3                                ...           5 years ago
  • 2.0.0-alpha.4.2                                ...           5 years ago
  • 2.0.0-alpha.4.1                                ...           5 years ago
  • 2.0.0-nightly.166                                ...           5 years ago
  • 2.0.0-alpha.4                                ...           5 years ago
  • 2.0.0-nightly.165                                ...           5 years ago
  • 2.0.0-nightly.159                                ...           5 years ago
  • 2.0.0-nightly.156                                ...           5 years ago
  • 2.0.0-nightly.155                                ...           5 years ago
  • 2.0.0-nightly.151                                ...           5 years ago
  • 2.0.0-nightly.150                                ...           5 years ago
  • 2.0.0-nightly.149                                ...           5 years ago
  • 2.0.0-nightly.148                                ...           5 years ago
  • 2.0.0-nightly.146                                ...           5 years ago
  • 2.0.0-nightly.144                                ...           5 years ago
  • 2.0.0-nightly.143                                ...           5 years ago
  • 2.0.0-nightly.142                                ...           5 years ago
  • 2.0.0-nightly.140                                ...           5 years ago
  • 2.0.0-nightly.137                                ...           5 years ago
  • 2.0.0-nightly.135                                ...           5 years ago
  • 2.0.0-nightly.133                                ...           5 years ago
  • 2.0.0-nightly.132                                ...           5 years ago
  • 2.0.0-nightly.130                                ...           5 years ago
  • 2.0.0-nightly.127                                ...           5 years ago
  • 2.0.0-nightly.122                                ...           5 years ago
  • 2.0.0-nightly.121                                ...           5 years ago
  • 2.0.0-nightly.120                                ...           5 years ago
  • 2.0.0-nightly.119                                ...           5 years ago
  • 2.0.0-nightly.118                                ...           5 years ago
  • 2.0.0-nightly.117                                ...           5 years ago
  • 2.0.0-nightly.116                                ...           5 years ago
  • 2.0.0-nightly.115                                ...           5 years ago
  • 2.0.0-nightly.112                                ...           5 years ago
  • 2.0.0-nightly.107                                ...           5 years ago
  • 2.0.0-nightly.102                                ...           5 years ago
  • 2.0.0-nightly.101                                ...           5 years ago
  • 2.0.0-nightly.97                                ...           5 years ago
  • 2.0.0-nightly.92                                ...           5 years ago
  • 2.0.0-nightly.88                                ...           5 years ago
  • 2.0.0-nightly.87                                ...           5 years ago
  • 2.0.0-nightly.85                                ...           5 years ago
  • 2.0.0-nightly.79                                ...           5 years ago
  • 2.0.0-nightly.72                                ...           5 years ago
  • 2.0.0-nightly.69                                ...           5 years ago
  • 2.0.0-nightly.68                                ...           5 years ago
  • 2.0.0-nightly.67                                ...           5 years ago
  • 2.0.0-nightly.66                                ...           5 years ago
  • 2.0.0-nightly.65                                ...           5 years ago
  • 2.0.0-alpha.3.1                                ...           5 years ago
  • 2.0.0-alpha.3                                ...           5 years ago
  • 2.0.0-alpha.2.1                                ...           5 years ago
  • 2.0.0-alpha.2                                ...           5 years ago
  • 2.0.0-alpha.1.1                                ...           5 years ago
  • 2.0.0-alpha.1                                ...           5 years ago

© 2010 - cnpmjs.org x YWFE | Home | YWFE