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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@joseantpul/espree-logging-solution

v1.0.1

Published

Adds logs to javascript code

Readme

Open in Codespaces

Práctica Espree logging

Description of the project, how to use

To install use: npm i @joseantpul/espree-logging-solution

Transpiler for JavaScript, adds console.log at the beggining of functions with information such as name of the function we are entering, line of the function and parameters passed.

To use it we just call bin/log.js passing as argument the file with the code.

Documentation

Table of Contents

Parameters

  • inputFile File File with JS code
  • outputFile File

Returns any outputFile with the code including console.log in functions, if no outputFile was specificated it will print the output

addLogging

Takes code as a string and returns an AST wiht the console.log's added at the start of functions

Parameters

Returns any AST of the code with the console.log's added

addBeforeCode

Adds console.log to the node of the function (passed by reference because its an object)

Parameters

  • node object AST node of a function

Resumen de lo aprendido

En esta práctica lo principal ha sido aprender a usar estraverse para recorrer los nodos de nuestro arbol de análisis sintáctico mediante estraverse.traverse y como gracias a esto podemos modificarlo y por consiguiente modificar el código que se genera.

Además se ha aprendido a publicar un paquete en npm.

Finalmente se ha dado un repaso a las herramientas de desarrollo que nos ayudan con nuestro trabajo como los test, cubrimiento, integración continua...

CLI con Commander.js

program
  .version(version)
  .argument("<filename>", 'file with the original code')
  .option("-o, --output <filename>", "file in which to write the output")
  .action((filename, options) => {
    transpile(filename, options.output);
  });
program.parse(process.argv);

Indicar los valores de los argumentos, soportar funciones flecha y añadir el número de línea

Se ha modificado el código de logging-espree.js para que el log también indique los valores de los argumentos que se pasaron a la función, soporte funciones flecha y añada el número de línea. Ejemplo:

function foo(a, b, c) {
  let x = 'tutu';
  let y = (function (x) { return x*x })(2);
  let z = (e => { return e +1 })(4);
  console.log(x,y,z);
}
function foo(a, b) {
    console.log(`Entering foo(${ a }, ${ b })`);
    var x = 'blah';
    var y = function (z) {
        console.log(`Entering <anonymous function>(${ z })`);
        return z + 3;
    }(2);
}
foo(1, 'wut', 3);

Código:

Para detectar Funciones flecha

if (node.type === 'FunctionDeclaration' ||
    node.type === 'ArrowFunctionExpression' ||
    node.type === 'FunctionExpression') {
    addBeforeCode(node);
}

Para añadir número de línea y parámetros

let parmNames = "";
if (node.params.length) {
    parmNames = "${" + node.params.map(param => param.name).join("}, ${") + "}";
}
const lineN = node.loc.start.line;
const beforeCode = "console.log(" + "`" + "Entering " + name + "(" + parmNames + ")" + " at line " + lineN + "`" + ");";

Tests and Covering

Se realizan los test pertinentes en test.mjs para comprobar que las funcionalidades cumplen su función correctamente, ademaś se hace un crubimiento de los test para comprobar que se testea todo el código.

-------------------|---------|----------|---------|---------|------------------- File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s -------------------|---------|----------|---------|---------|------------------- All files | 96 | 92.3 | 100 | 96 |
logging-espree.js | 96 | 92.3 | 100 | 96 | 17-19
-------------------|---------|----------|---------|---------|-------------------

Publicación como paquete npm

  1. Darse de alta en npm
  2. Autenticarse mediante npm adduser
  3. Comprobamos que estamos loggeados npm whoami
  4. Cambiar el name del package.json y ponerle el scope (nuestro nombre de usuario de npm) delante
  5. Publicar con npm publish --access public

Scripts en package.json

"test": "mocha test/test.mjs", "cov": "c8 npm run test", "docgen": "npx documentation build src/logging-espree.js -f md"

Github Actions

Se realiza integración continua corriendo los test jobs: steps: - run: npm run test