traceur-source-maps

    1.0.6 • Public • Published

    traceur-source-maps

    NPM version Build status Coveralls status Support us

    When using Traceur as a command-line utility to transpile Node.js source code, it provides --source-maps option to create source map files. But when using at runtime by requiring traceur module to live-transpile files, Traceur lacks the ability to reports correct stack trace.

    Here comes this module to solve that problem: it provides source map for Node.js files when using Traceur on the fly.

    Installation

    This module can be installed easily with npm:

    $ npm install traceur-source-maps

    Usage

    Below is a small example to describe how to use this module.

    bootstrap.js:

    var traceur = require('traceur');
     
    require('traceur-source-maps').install(traceur);
     
    traceur.require.makeDefault(function (filePath) {
      return !~filePath.indexOf('node_modules');
    });
    // There is no need to pass `{ sourceMaps: true }` as options,
    // source mapping is always enabled after install
     
    require('./main');

    main.js:

    import { hey } from './greet';
     
    hey();

    greet.js:

    export function hey() {
      hi();
    }
     
    export function hi() {
      throw new Error('Call me maybe!');
    }

    Run bootstrap.js using Node.js, notice the stack trace reports correct line number where the error occurred (line 6 of greet.js).

    $ node bootstrap.js
     
    /some/dir/greet.js:6
      throw new Error('Call me maybe!');
     
            ^
    Error: Call me maybe!
        at hi (/some/dir/greet.js:6:9)
        at hey (/some/dir/greet.js:2:3)
        at Object.<anonymous> (/some/dir/main.js:3:1)
        at Module._compile (module.js:456:26)
        at Object.Module._extensions..js (/some/dir/node_modules/traceur-source-maps/node_modules/traceur/src/node/require.js:65:21)
        at Module.load (module.js:356:32)
        at Function.Module._load (module.js:312:12)
        at Module.require (module.js:364:17)
        at require (module.js:380:17)
        at Object.<anonymous> (/some/dir/bootstrap.js:12:1)

    Compatibility

    • This module conflicts with all source code which uses source-map-support module (or maybe some modules with similar features) to provide source mapping.

    • This module has been tested to run properly with Traceur version 0.0.72 (latest version at the time of writing). It could be broken in the future if Traceur introduces non backward-compatible changes. In that circumstance, feel free to create new issue or create a pull request.

    Contributing

    Before create a pull request, make sure that you:

    To execute all tests, simply run:

    $ npm test
    

    Contributors

    License

    This module is released under MIT license.

    Install

    npm i traceur-source-maps

    DownloadsWeekly Downloads

    214

    Version

    1.0.6

    License

    MIT

    Last publish

    Collaborators

    • meo