Skip to content

fork it to @cspotcode/source-map-support #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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):
Expand All @@ -26,33 +29,33 @@ 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

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.

It is also very useful with Mocha:

```
$ mocha --require source-map-support/register tests/
$ mocha --require @cspotcode/source-map-support/register tests/
```

#### Browser support
Expand Down Expand Up @@ -81,15 +84,15 @@ 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
});
```

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 {
Expand All @@ -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'
});
```
Expand All @@ -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
});
```
Expand All @@ -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.
Expand Down Expand Up @@ -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'); }
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down