diff --git a/README.md b/README.md index 40228b7..94c1907 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # Source Map Support -[![Build Status](https://travis-ci.org/evanw/node-source-map-support.svg?branch=master)](https://travis-ci.org/evanw/node-source-map-support) + +[![NPM version](https://img.shields.io/npm/v/@cspotcode/source-map-support.svg?style=flat)](https://npmjs.org/package/@cspotcode/source-map-support) +[![NPM downloads](https://img.shields.io/npm/dm/@cspotcode/source-map-support.svg?style=flat)](https://npmjs.org/package/@cspotcode/source-map-support) +[![Build status](https://img.shields.io/github/workflow/status/cspotcode/node-source-map-support/Continuous%20Integration)](https://github.com/cspotcode/node-source-map-support/actions?query=workflow%3A%22Continuous+Integration%22) This module provides source map support for stack traces in node via the [V8 stack trace API](https://github.com/v8/v8/wiki/Stack-Trace-API). It uses the [source-map](https://github.com/mozilla/source-map) module to replace the paths and line numbers of source-mapped files with their original paths and line numbers. The output mimics node's stack trace format with the goal of making every compile-to-JS language more of a first-class citizen. Source maps are completely general (not specific to any one language) so you can use source maps with multiple compile-to-JS languages in the same node process. @@ -8,7 +11,7 @@ This module provides source map support for stack traces in node via the [V8 sta #### Node support ``` -$ npm install source-map-support +$ npm install @cspotcode/source-map-support ``` Source maps can be generated using libraries such as [source-map-index-generator](https://github.com/twolfson/source-map-index-generator). Once you have a valid source map, place a source mapping comment somewhere in the file (usually done automatically or with an option by your transpiler): @@ -26,7 +29,7 @@ From here you have two options. ##### CLI Usage ```bash -node -r source-map-support/register compiled.js +node -r @cspotcode/source-map-support/register compiled.js ``` ##### Programmatic Usage @@ -34,17 +37,17 @@ node -r source-map-support/register compiled.js Put the following line at the top of the compiled file. ```js -require('source-map-support').install(); +require('@cspotcode/source-map-support').install(); ``` It is also possible to install the source map support directly by requiring the `register` module which can be handy with ES6: ```js -import 'source-map-support/register' +import '@cspotcode/source-map-support/register' // Instead of: -import sourceMapSupport from 'source-map-support' +import sourceMapSupport from '@cspotcode/source-map-support' sourceMapSupport.install() ``` Note: if you're using babel-register, it includes source-map-support already. @@ -52,7 +55,7 @@ Note: if you're using babel-register, it includes source-map-support already. It is also very useful with Mocha: ``` -$ mocha --require source-map-support/register tests/ +$ mocha --require @cspotcode/source-map-support/register tests/ ``` #### Browser support @@ -81,7 +84,7 @@ This library also works if you use AMD (Asynchronous Module Definition), which i This module installs two things: a change to the `stack` property on `Error` objects and a handler for uncaught exceptions that mimics node's default exception handler (the handler can be seen in the demos below). You may want to disable the handler if you have your own uncaught exception handler. This can be done by passing an argument to the installer: ```js -require('source-map-support').install({ +require('@cspotcode/source-map-support').install({ handleUncaughtExceptions: false }); ``` @@ -89,7 +92,7 @@ require('source-map-support').install({ This module loads source maps from the filesystem by default. You can provide alternate loading behavior through a callback as shown below. For example, [Meteor](https://github.com/meteor) keeps all source maps cached in memory to avoid disk access. ```js -require('source-map-support').install({ +require('@cspotcode/source-map-support').install({ retrieveSourceMap: function(source) { if (source === 'compiled.js') { return { @@ -106,7 +109,7 @@ The module will by default assume a browser environment if XMLHttpRequest and wi In some rare cases, e.g. when running a browser emulation and where both variables are also set, you can explictly specify the environment to be either 'browser' or 'node'. ```js -require('source-map-support').install({ +require('@cspotcode/source-map-support').install({ environment: 'node' }); ``` @@ -115,7 +118,7 @@ To support files with inline source maps, the `hookRequire` options can be speci ```js -require('source-map-support').install({ +require('@cspotcode/source-map-support').install({ hookRequire: true }); ``` @@ -135,7 +138,7 @@ throw new Error('test'); // This is the original code compiled.js: ```js -require('source-map-support').install(); +require('@cspotcode/source-map-support').install(); throw new Error('test'); // This is the compiled code // The next line defines the sourceMapping. @@ -179,7 +182,7 @@ demo.ts: ```typescript declare function require(name: string); -require('source-map-support').install(); +require('@cspotcode/source-map-support').install(); class Foo { constructor() { this.bar(); } bar() { throw new Error('this is a demo'); } @@ -210,7 +213,7 @@ Error: this is a demo at node.js:901:3 ``` -There is also the option to use `-r source-map-support/register` with typescript, without the need add the `require('source-map-support').install()` in the code base: +There is also the option to use `-r source-map-support/register` with typescript, without the need add the `require('@cspotcode/source-map-support').install()` in the code base: ``` $ npm install source-map-support typescript @@ -238,7 +241,7 @@ Error: this is a demo demo.coffee: ```coffee -require('source-map-support').install() +require('@cspotcode/source-map-support').install() foo = -> bar = -> throw new Error 'this is a demo' bar() @@ -248,7 +251,7 @@ foo() Compile and run the file using the CoffeeScript compiler from the terminal: ```sh -$ npm install source-map-support coffeescript +$ npm install @cspotcode/source-map-support coffeescript $ node_modules/.bin/coffee --map --compile demo.coffee $ node demo.js diff --git a/package.json b/package.json index 96dedd5..02500ae 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "source-map-support", + "name": "@cspotcode/source-map-support", "description": "Fixes stack traces for files with source maps", "version": "0.5.19", "main": "./source-map-support.js",