Package detail

estrace

coderaiser1.6kMIT5.1.2

trace functions of EcmaScript modules

trace, functions, putout

readme

ESTrace License NPM version Build Status Coverage Status

Trace functions in Node.js EcmaScript Modules. For CommonJS use njsTrace.

Install

npm i estrace

Run

Loaders used to get things done, run with --loader flag:

NODE_OPTIONS="'--loader estrace --no-warnings'" node lint.js

Perf

When you want to see report of the most hot function calls count use:

NODE_OPTIONS="'--loader estrace/perf --no-warnings'" node example/perf.js

Example

Let's suppose you want to trace lint.js:

const checkFile = (a) => a;
lint();

function lint(runners) {
    const files = getFiles(runners);
    const checkedFiles = checkFiles(files);

    return checkedFiles;
}

function getFiles(runners) {
    const files = [];

    for (const run of runners) {
        files.push(...run());
    }

    return files;
}

function lintFiles(files) {
    const linted = [];

    for (const file of files) {
        linted.push(checkFile(file));
    }

    return linted;
}

You will see something like this

coderaiser@cloudcmd:~/estrace$ node --loader estrace example/lint.js
..💣 lint([]) 16.05mb file:///Users/coderaiser/estrace/example/lint.js:5
....💣 getFiles([]) 16.05mb file:///Users/coderaiser/estrace/example/lint.js:12
....💥 getFiles 16.06mb file:///Users/coderaiser/estrace/example/lint.js:12
....💣 lintFiles([]) 16.06mb file:///Users/coderaiser/estrace/example/lint.js:22
....💥 lintFiles 16.06mb file:///Users/coderaiser/estrace/example/lint.js:22
..💥 lint 16.06mb file:///Users/coderaiser/estrace/example/lint.js:5

How ESTrace works?

Let's suppost you have a function: const fn = (a) => a. EStrace will replace it with:

const fn = (a) => {
    try {
        var __estrace_context = __estrace.enter('<anonymous:2>', 'file://hello.js:2', arguments);
        return a;
    } finally {
        __estrace.exit('<anonymous:2>', 'file://hello.js:2', __estrace_context);
    }
};

And you cat get more information about the way your code works.

Ignore function

When you need to ignore a function, just add __estrace.ignore() before function:

export /* __estrace.ignore() */
function enter() {}

And ESTrace won't touch it.

Using as plugin

First of all ESTrace is plugin for 🐊Putout and it can be used independely:

import putout from 'putout';
import {estracePlugin} from 'estrace/plugin';

const source = `
    const fn = (a) => a;
`;

const {code} = putout(source, {
    plugins: [estracePlugin],
});

console.log(code);

Passing file url

If you need to pass url, you can with help of rules :

const {code} = putout(source, {
    rules: {
        'estrace/trace': ['on', {
            url: 'file://hello.js',
        }],
    },
    plugins: [estracePlugin],
});

Exclude functions

When you need to exclude some kinds of functions, you can use universal cross-plugin way:

const {code} = putout(source, {
    rules: {
        'estrace/trace': ['on', {
            url: 'file://hello.js',
            exclude: [
                'ArrowFunctionExpression',
            ],
        }],
    },
    plugins: [estracePlugin],
});

Overriding plugin name

If for some reason you need to override the name of a plugin, you can use default import and name it in a way you like.

import putout from 'putout';
import funnyTracer from 'estrace/plugin';

const source = `
    const fn = (a) => a;
`;

const {code} = putout(source, {
    rules: {
        'funnyTracer/trace': ['on', {
            url: 'file://hello.js',
        }],
    },
    plugins: [
        ['funnyTracer', funnyTracer],
    ],
});

console.log(code);

Supported function types:

FunctionDeclaration (named):

function hello() {
    return 'world';
}

FunctionExpression (anonymous):

hello(function(word) {
    return `hello ${word}`;
});

ArrowFunctionExpression (arrow):

hello((word) => {
    return `hello ${word}`;
});

ClassMethod (method):

class Hello {
    hello(word) {
        return `hello ${word}`;
    }
}

License

MIT

changelog

2025.01.29, v5.1.2

feature:

  • 55b3b57 estrace: eslint-plugin-putout v24.0.0
  • 304131e estrace: putout v38.0.0

2024.12.21, v5.1.1

feature:

  • 116827f estrace: putout v37.5.0
  • d372239 estrace: eslint-plugin-putout v23.3.0

2024.07.19, v5.1.0

feature:

  • fd2b4f5 estrace: eslint v9.7.0
  • 51b4ad1 estrace: c8 v10.1.2
  • 0473a10 estrace: putout v36.0.2
  • 5b723fb estrace: supertape v10.0.0

2024.01.19, v5.0.1

feature:

  • a187e32 estrace: eslint-plugin-putout v22.3.0
  • b2a81cb estrace: c8 v9.1.0
  • 62608ea estrace: putout v35.0.0
  • 85e47b1 estrace: @putout/test v8.0.0
  • 202cb87 estrace: supertape v9.0.0

2023.12.10, v5.0.0

feature:

  • 3d42692 estrace: eslint-plugin-putout v22.0.0
  • 189b5fb estrace: madrun v10.0.0
  • 30cd545 estrace: putout v34.0.0
  • a0ff35a estrace: drop support of node < 18

2023.09.15, v4.2.3

feature:

  • d6a7dfc package: putout v32.0.4

2023.08.07, v4.2.2

feature:

  • 468d944 package: eslint-plugin-putout v19.0.3
  • fb37827 package: putout v31.0.3

2023.08.04, v4.2.1

feature:

  • b5ac54d package: eslint-plugin-putout v19.0.0
  • 18e70fb package: putout v31.0.0
  • 9c465a6 package: nodemon v3.0.1
  • cc3e325 package: @putout/test v7.0.1

2023.07.06, v4.2.0

feature:

  • c9b4ba3 package: putout v30.0.3
  • 07d0fb1 package: eslint-plugin-putout v18.0.0
  • 966b39f package: eslint-plugin-n v16.0.1
  • 08c276d package: c8 v8.0.0
  • bf443fc package: @putout/test v6.6.0

2023.03.06, v4.1.2

feature:

  • package: putout v29.0.0

2022.10.20, v4.1.1

feature:

  • package: supertape v8.1.0
  • package: putout v28.0.0

2022.08.16, v4.1.0

feature:

  • estrace: add perf

2022.07.20, v4.0.2

feature:

  • package: eslint-plugin-n v15.2.4
  • package: eslint-plugin-putout v16.0.0
  • package: putout v27.0.1

2022.05.09, v4.0.1

feature:

  • package: putout v26.0.0
  • package: eslint-plugin-putout v15.1.1

2022.03.07, v4.0.0

feature:

  • package: madrun v9.0.0
  • package: eslint-plugin-putout v14.4.0
  • package: @putout/test v5.1.0
  • package: supertape v7.2.0
  • package: putout v25.2.0
  • estrace: drop support of node < 16

2022.01.13, v3.3.1

feature:

  • (package) eslint-plugin-putout v13.0.1
  • (package) putout v24.0.2

2021.12.21, v3.3.0

feature:

  • (package) eslint-plugin-putout v12.8.0
  • (package) @putout/test v4.1.0
  • (package) putout v23.0.0

2021.11.10, v3.2.2

feature:

  • (package) putout v22.0.0

2021.10.31, v3.2.1

feature:

  • (package) putout v21.0.0
  • (package) eslint-plugin-putout v11.0.0

2021.10.22, v3.2.0

feature:

  • (estrace) add toLoad

2021.10.21, v3.1.0

feature:

  • (package) eslint v8.0.1
  • (estrace) add support of node v16.12

2021.09.14, v3.0.2

feature:

  • (package) eslint-plugin-putout v10.0.1
  • (package) putout v20.0.1

2021.09.10, v3.0.1

fix:

  • (estrace) rm useless result, since it not captured

2021.09.10, v3.0.0

feature:

  • (estrace) add support of __estrace_context (#5)
  • (estrace) add ability to show memory used

2021.09.06, v2.3.0

feature:

  • (estrace) add ability to import plugin as tuple (#4)
  • (estrace) add ability to import tuple
  • (package) supertape v6.0.5

2021.08.23, v2.2.1

feature:

  • (package) putout v19.0.0

2021.08.23, v2.2.0

feature:

  • (estrace) rm useless async
  • (package) eslint v8.0.0-beta.0
  • (package) eslint-plugin-putout v9.2.1

2021.07.23, v2.1.0

feature:

  • (estrace) plugin: simplify using as dynamic import

2021.07.23, v2.0.0

feature:

  • (estrace) changed plugin api: estrace -> estrace/trace

2021.07.23, v1.8.0

feature:

  • (estrace) add support of multiline template literals (#3)

2021.07.08, v1.7.1

fix:

  • (estrace) plugin-trace: rm useless buildReturn

2021.07.08, v1.7.0

feature:

  • (estrace) add try-finally (#2)

2021.06.29, v1.6.1

fix:

  • (estrace) no comments (coderaiser/putout#61)

2021.06.28, v1.6.0

feature:

  • (estrace) add support of StringLiteral used as key in ClassMethod (coderaiser/putout#61)

2021.06.23, v1.5.1

fix:

  • (estrace) put arguments in one line

feature:

  • (estrace) line number: add support of functions declared in ExportDeclaration

2021.06.19, v1.5.0

feature:

  • (estrace) line number: add support of functions declared in ExportDeclaration

2021.06.18, v1.4.3

fix:

  • (estrace) enter: arguments -> last parameter

2021.06.18, v1.4.2

fix:

  • (estrace) exit when no ReturnStatement: __estrace_result last parameter
  • (estrace) log: spaces

2021.06.18, v1.4.1

fix:

  • (estrace) log: spaces

2021.06.18, v1.4.0

feature:

  • (estrace) add ability to use as plugin

2021.06.17, v1.3.1

fix:

  • (estrace) no argument in ReturnStatement

feature:

  • (estrace) add __estrace.ignore()

2021.06.17, v1.3.0

feature:

  • (estrace) add line numbers

2021.06.17, v1.2.0

feature:

  • (estree) enter/exit -> 💣/💥
  • (package) eslint-plugin-putout v8.0.1
  • (estrace) rm try-catch, simplify, add support of ReturnStatement (ValYouW/njsTrace#12)

2021.06.17, v1.1.0

feature:

  • (estrace) rm try-catch, simplify

2021.06.16, v1.0.0

feature:

  • (estrace) add file paths