npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@a-la/source-map-generator

v1.0.1

Published

[fork] Generates Source Maps, Works With Google Closure Compiler.

Downloads

41

Readme

@a-la/source-map-generator

npm version

@a-la/source-map-generator is a fork of Mozilla/SourceMap that Generates Source Maps and Works With Google Closure Compiler. It was rewritten in ES6 syntax and externs for GCC were provided for compilation.

yarn add @a-la/source-map-generator

Table Of Contents

API

The package is available by importing its default function:

import sourceMapGenerator from '@a-la/source-map-generator'

class SourceMapGenerator

An instance of the SourceMapGenerator represents a source map which is being built incrementally.

Removed Methods For Now

  • [x] static fromSourceMap
  • [x] applySourceMap

constructor(  conf: Config,): SourceMapGenerator

The constructor method is called to create a new source map.

_sourceMapGenerator.Config: Options for the program.

| Name | Type | Description | Default | | -------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | | file | string | The filename of the generated source. | - | | sourceRoot | string | A root for all relative URLs in this source map. | - | | skipValidation | boolean | When true, disables validation of mappings as they are added. This can improve performance but should be used with discretion, as a last resort. Even then, one should avoid using this flag when running tests, if possible. | false |

import SourceMapGenerator from '@a-la/source-map-generator'
import { readFileSync } from 'fs'

const file = `${readFileSync(__filename)}`

const gen = new SourceMapGenerator({
  file: 'example/index.js',
})
/**
 * Generate the source map for the file, keeping all positions as they are.
 *
 * The first two rules will update inline and block comments to not have any tokens in them.
 * The third rule will break each line into tokens and add mappings.
 */
const linesInSource = file
  .replace(/\/\*(?:[\s\S]+?)\*\//g, (match, pos) => {
    const next = file[pos + match.length]
    if (next == '\n') return '\n'.repeat(match.split('\n').length - 1)

    const lines = match.split('\n')
    const lastLineI = lines.length - 1
    const lastLine = lines[lastLineI]
    const ss = ' '.repeat(lastLine.length)
    const ws = '\n'.repeat(lastLineI)
    return `${ws}${ss}`
  })
  .replace(/\/\/(.+)/gm, (match) => {
    return ' '.repeat(match.length)
  })
  .split('\n')
linesInSource.forEach((l, i) => {
  const line = i + 1
  l
    .replace(/(?:(?:\s+)|(?:[$_\w\d]+)|.)/g, (match, column) => {
      if (column == 0 && /^\s+$/.test(match)) return
      const generated = {
        line,
        column,
      }
      const m = {
        generated,
        source: __filename,
        original: generated,
      }
      gen.addMapping(m)
    })
})
gen.setSourceContent(__filename, file)
const sourceMap = gen.toJSON()
console.log(sourceMap)
{ version: 3,
  sources: [ '/Users/zavr/a-la/source-map-generator/example/index.js' ],
  names: [],
  mappings: 'AAAA,MAAM,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG;AACtC,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE;;AAEhC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;;AAEzC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,kBAAkB,CAAC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fs\'\n\nconst file = `${readFileSync(__filename)}`\n\nconst gen = new SourceMapGenerator({\n  file: \'example/index.js\',\n})\n/**\n * Generate the source map for the file, keeping all positions as they are.\n *\n * The first two rules will update inline and block comments to not have any tokens in them.\n * The third rule will break each line into tokens and add mappings.\n */\nconst linesInSource = file\n  .replace(/\\/\\*(?:[\\s\\S]+?)\\*\\//g, (match, pos) => {\n    const next = file[pos + match.length]\n    if (next == \'\\n\') return \'\\n\'.repeat(match.split(\'\\n\').length - 1)\n\n    const lines = match.split(\'\\n\')\n    const lastLineI = lines.length - 1\n    const lastLine = lines[lastLineI]\n    const ss = \' \'.repeat(lastLine.length)\n    const ws = \'\\n\'.repeat(lastLineI)\n    return `${ws}${ss}`\n  })\n  .replace(/\\/\\/(.+)/gm, (match) => {\n    return \' \'.repeat(match.length)\n  })\n  .split(\'\\n\')\nlinesInSource.forEach((l, i) => {\n  const line = i + 1\n  l\n    .replace(/(?:(?:\\s+)|(?:[$_\\w\\d]+)|.)/g, (match, column) => {\n      if (column == 0 && /^\\s+$/.test(match)) return\n      const generated = {\n        line,\n        column,\n      }\n      const m = {\n        generated,\n        source: __filename,\n        original: generated,\n      }\n      gen.addMapping(m)\n    })\n})\ngen.setSourceContent(__filename, file)\nconst sourceMap = gen.toJSON()\nconsole.log(sourceMap)' ] }

Copyright

Original Authors: Mozilla