{"_id":"@alu0101353647/espree-logging-solution","_rev":"1-ef454f11bfa41fe27c15dc0219305832","name":"@alu0101353647/espree-logging-solution","dist-tags":{"latest":"3.1.0"},"versions":{"0.3.0":{"name":"@alu0101353647/espree-logging-solution","author":{"name":"Juan Guillermo Zafra Fernández","email":"alu0101353647@ull.edu.es"},"description":"Adds logs to javascript code","type":"module","bin":{"funlog":"bin/log.js"},"scripts":{"test":"mocha test/test.mjs","cov":"nyc --reporter=lcov --reporter=text npm test; npm run fix_docs","fix_docs":"mv coverage docs; mv docs/coverage/lcov-report/* docs; rm -rf docs/coverage"},"dependencies":{"acorn":"^8.8.2","commander":"^10.0.0","escodegen":"^2.0.0","espree":"^9.4.1","estraverse":"^5.2.0","underscore":"^1.12.0","nyc":"^15.1.0"},"version":"0.3.0","devDependencies":{"@types/escodegen":"^0.0.7","@types/estraverse":"^5.1.2","mocha":"^10.2.0"},"gitHead":"052c6dc3c51550e5c7943bb20fc8b42a946ab3ac","_id":"@alu0101353647/espree-logging-solution@0.3.0","_nodeVersion":"19.6.0","_npmVersion":"8.10.0","dist":{"integrity":"sha512-NJ1GuEyzMd6YHrW5fkGtpkNSLjpZap7Bx561yG0kViMwwF3nb6g44HzXQLd7ETnEvzCreCJbrBDus+5Lk45+9Q==","shasum":"aeb1a9f80017704965d4584ad4dc4ce7b80c34ae","tarball":"https://registry.npmjs.org/@alu0101353647/espree-logging-solution/-/espree-logging-solution-0.3.0.tgz","fileCount":34,"unpackedSize":93639,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGZdut/u2bvitGnxyA2E6FSqodf38zD4UxffLTcRyuELAiEA8yTXRiqfcBH9xoUyNDIBuERtxxubWVqENgT2kxOYknw="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJj/5ptACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmo/BRAAiscPrx+F1UYaDGDHT/2EHeCX0moSPCNbtlPyPJD1AeCVFH0+\r\n4DYE5vIZeQAnAGOiPaJkoHSSJ1dpWYQL5zplATe27pa3PtUr5QTkVsFc99dL\r\nqOxH+KOBPPdIBMTWAQWUq4q7gTcyXsvFvfl2PHUTDnfE+T7fb08d6tSAZj3q\r\n0FAbq+KFXz+ta7IFwaSp2H4oldZvlRglrtetjeeskIiE29EufihYigeiZFIb\r\nr7MA62F4VqoivmxsKU7hip5raphe0Nkiol9PiFbT6vRfex/1t8LH7lfY+8Ci\r\nYZF0ymAbHHXnDR+dOCZAwjOgvLJbO7m32YUvCYlbwXZlAxL3hQD4uVdr6vKn\r\nO9HfPXXSFFVcMHVv46BxDzxStUQ6nU7H/a0ijQhpKdADgM/qmgi8+vkiS0Px\r\nSTHSf77lcGA04osGkuv9Y4ZVloq6jFzbz6YxMU4L9/BSoWAFlBsDEJMCH1Je\r\nVIGJgmtzSCkQQYHzFdstMr5BGEwPRwV7j+3J7EhheMNMh0WrBmXAbWQ0l56u\r\niY6xCS83P+5aX4gCKnkgC7FCwB7IGAHXef0KpJPFLWa6lUU4MXiv/OVmyQxx\r\nzLLGEkQTfkYaPe9dJLHst4Lu5PFyGyTErKaWwjSuOjCIO5ru/pF8Tm8JCZ73\r\nVkprh0UgtlF+eL1tLDmBLPtQHztVNJ2rubI=\r\n=DsJa\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"alu0101353647","email":"alu0101353647@ull.edu.es"},"directories":{},"maintainers":[{"name":"alu0101353647","email":"alu0101353647@ull.edu.es"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/espree-logging-solution_0.3.0_1677695596859_0.010860908048363482"},"_hasShrinkwrap":false},"3.1.0":{"name":"@alu0101353647/espree-logging-solution","author":{"name":"Juan Guillermo Zafra Fernández","email":"alu0101353647@ull.edu.es"},"description":"Adds logs to javascript code","type":"module","bin":{"funlog":"bin/log.js"},"scripts":{"test":"mocha test/test.mjs","cov":"nyc --reporter=lcov --reporter=text npm test; npm run fix_docs","fix_docs":"mv coverage docs; mv docs/coverage/lcov-report/* docs; rm -rf docs/coverage"},"dependencies":{"acorn":"^8.8.2","commander":"^10.0.0","escodegen":"^2.0.0","espree":"^9.4.1","estraverse":"^5.2.0","underscore":"^1.12.0","nyc":"^15.1.0"},"version":"3.1.0","devDependencies":{"@types/escodegen":"^0.0.7","@types/estraverse":"^5.1.2","mocha":"^10.2.0"},"gitHead":"4abeafc95175149b5202fa0bca2b3fcec0a315ad","_id":"@alu0101353647/espree-logging-solution@3.1.0","_nodeVersion":"19.6.0","_npmVersion":"8.10.0","dist":{"integrity":"sha512-NSwWAtO1JEQNBis+WWQc4FcvLxgr3Ao3xLKEZvuudIlRq9bd/i0bQtzXLznulwgp8Cwpe1rN0pZAQZHVpvRcXg==","shasum":"5f459139cbe460269242ea8b42040ed4957bf1ee","tarball":"https://registry.npmjs.org/@alu0101353647/espree-logging-solution/-/espree-logging-solution-3.1.0.tgz","fileCount":38,"unpackedSize":439654,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDa9WKSszXu9vVcVV41WYfCsSpmFFtFseQH0vzF8nn9NAIhALZssdvOyYzaPNt0qnGTlIu+3CfeIxGyIbJYbAcBgT+i"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJj/6EBACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqeiA/+LRGjFiNaiZiApHJUtp8CWGuAShd1RtySkL5esxb5J6CSjnS5\r\nko472evjqnu7vKBMoJzWsMN9gw6DE8fEdu/E9cWghAOJR+lGuZmQ1aWKckUn\r\nA2Nk3+4vfcI1gNU3KXhXdWWkSDiftAdL2Uz55wszL9j8Gznu07LlQkV9KtNe\r\n+VnTTZf/AK+HBw3LCMCwsv3KozV0YOIuAweUv3xWyyaLxiby9bARcBZ143xU\r\nn4cByv9P7ZFzCdU7pzp7nuRSq9dDLhIwK/rKekCgbYtGWdaA3nwZKBAChBtq\r\n/7D18MAhzXzMwcw44fBN9Q0DDM0+6dZ3W8WDp2z3MVXYsZzvATOoH+B4NCGc\r\n1FNG421Ek22TX1N8QOnrkRFrooEPCNDNWMqyudHgTHqo/VzvX+sfoCLU8eaR\r\nSk/w3z/tutMrWIxkIzq6Pqv8oPy+htXICvoPMJZVXZG9s/YuNHLIshxEGW9z\r\nY8GPL7rlups8nJw8FYMSCRXb2K1XM+3uAEthDfq2R/BIyI4+thl1k9/k1I/c\r\nBbuy6/Xsxl4XvnXAWUzpysfGKhXCR69wmabW9Tb1YQlGq35bIwrjWVcWZVmK\r\ncwAswjVVbz4ePDh5t6ltRqmjGUMgGCcMQt0JBjT7wE99afyDHQ+hea8UQI7L\r\niqbjZFU7C6BWps21bnT6FS7lfsR8vJUwmBs=\r\n=vuDJ\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"alu0101353647","email":"alu0101353647@ull.edu.es"},"directories":{},"maintainers":[{"name":"alu0101353647","email":"alu0101353647@ull.edu.es"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/espree-logging-solution_3.1.0_1677697281401_0.9878497229986847"},"_hasShrinkwrap":false}},"time":{"created":"2023-03-01T18:33:16.806Z","0.3.0":"2023-03-01T18:33:17.049Z","modified":"2023-03-01T19:01:21.793Z","3.1.0":"2023-03-01T19:01:21.687Z"},"maintainers":[{"name":"alu0101353647","email":"alu0101353647@ull.edu.es"}],"description":"Adds logs to javascript code","author":{"name":"Juan Guillermo Zafra Fernández","email":"alu0101353647@ull.edu.es"},"readme":"\r\n# [Práctica Espree Logging](https://ull-esit-gradoii-pl.github.io/practicas/esprima-logging)\r\n\r\n### Procesadores de lenguajes 2022-2023\r\n\r\n#### Juan Guillermo Zafra Fernández alu0101353647\r\n\r\n## Resumen de lo aprendido\r\n\r\nAs complex as the AST tree looks like, it doesn't have any reason to not be manageable. Accessing its values\r\nis easy as a `node.body`, which is a really handy implementation.\r\n\r\nUsing simple conditionals and variables you can build up a compilator and write down metaprograms, due to the \r\ninformation stated above. \r\n\r\nNPM and all the other stuff not related to the program itself was rather annoying to set up, with a thousand things to move press and log in into. I'm a rather simple man.\r\n\r\n## El ejecutable\r\n\r\nEl ejecutable está en `bin/logging.js`\r\n\r\n```\r\n✗ bin/logging.js -h\r\nUsage: jslogging [options] <filename>\r\n\r\nAdds logs to javascript code\r\n\r\nArguments:\r\n  filename                 file with the original code\r\n\r\nOptions:\r\n  -V, --version            output the version number\r\n  -o, --output <filename>  file in which to write the output (default: \"output.js\")\r\n  -h, --help               display help for command\r\n```\r\n\r\n```\r\ngit:(main) ✗ cat test/test1.js \r\nfunction foo(a, b) {   \r\n    var x = 'blah';   \r\n    var y = (function () {\r\n      return 3;\r\n    })();\r\n  }     \r\nfoo(1, 'wut', 3);\r\n➜  git:(template) ✗ bin/logging.js test/test1.js -o salida.js\r\nFile read succesfully\r\nOutput written succesfully in salida.js\r\n➜  git:(template) ✗ node salida.js\r\nEntering foo(1, wut) at line 1\r\nEntering <anonymous function>() at line 3\r\n```\r\n\r\nBelow a piece of code with my doing:\r\n\r\n```bash\r\n(route)$ ./jslogging -o madeUp.js test/test3.js\r\n(route)$ cat madeUp.js\r\nfunction foo(a, b, c) {\r\n    console.log(`Entering foo(${ a }, ${ b }, ${ c }) at line 1`);\r\n    let x = 'tutu';\r\n    let y = function (x) {\r\n        console.log(`Entering <anonymous function>(${ x }) at line 3`);\r\n        return x * x;\r\n    }(2);\r\n    let z = (e => {\r\n        console.log(`Entering <anonymous function>(${ e }) at line 4`);\r\n        return e + 1;\r\n    })(4);\r\n    console.log(x, y, z);\r\n}\r\nfoo(1, 'wut', 3);\r\n```\r\n\r\n## CLI con [Commander.js](https://www.npmjs.com/package/commander)\r\n\r\nCommander is a useful library to not program by hand all the options and the messages, to the point of also providing a helper in case you misstyped any of the options,\r\nit will ask if that one's the one you were looking for. Very handy!\r\n\r\n## Reto 1: Soportar funciones flecha\r\n\r\nThis was a fairly easy task. Using [the AST explorer](https://astexplorer.net/#/gist/30fd4865621d99718672b1cd53d6c3c9/latest), I clicked twice on the *fat arrow function*, \r\nand I was directed to it's name. From that, just add the tag to the or. Below, the code:\r\n\r\n```javascript\r\nfunction addLogging(code) {\r\n  let ast = espree.parse(code, {ecmaVersion:6, loc:true});\r\n\r\n  estraverse.traverse(ast, {\r\n    enter: function(node, parent) {\r\n      if (node.type === 'FunctionDeclaration' ||\r\n        node.type === 'FunctionExpression' ||\r\n        node.type === 'ArrowFunctionExpression') {\r\n        addBeforeCode(node);\r\n      }\r\n    }\r\n  });\r\n  return escodegen.generate(ast);\r\n}\r\n```\r\n\r\n## Reto 2: Añadir el número de línea\r\n\r\nThis was a bit harder, I had to enable `loc: true` at the code above for it to get the lines as well as more info. Once done that, I could simply get the lines \r\nat an argument at the AST.\r\n\r\n```javascript\r\nfunction addBeforeCode(node) {\r\n  let name = node.id ? node.id.name : '<anonymous function>';\r\n  let line = node.loc.start.line; // Line is saved here\r\n  let params = [];\r\n  for (let i = 0; i < node.params.length; ++i) {\r\n    if (i === 0) {\r\n      params.push(`\\$\\{ ${node.params[i].name} \\}`);\r\n    } else {\r\n      params.push(` \\$\\{ ${node.params[i].name} \\}`);\r\n    }\r\n  }\r\n\r\n  let beforeCode = `console.log(\\`Entering ${name}(${params}) at line ${line}\\`);`; // Here you have the line\r\n  let beforeNodes = espree.parse(beforeCode, {ecmaVersion:6}).body; // Is an Array of ASTs\r\n  node.body.body = beforeNodes.concat(node.body.body);\r\n}\r\n```\r\n\r\n## Reto 3: Añadir los argumentos a el output de las funciones\r\n\r\nThis was perhaps the hardest one, because the output had to include stuff to not be interpolated, and thus \r\nhad to escape characters and factor it as the tests liked.\r\n\r\nThe code for it is above, at the console.log, and the parameters are iterated through a loop, pushed to a for and simply outputted \r\nonce concatenated.\r\n\r\n## Tests\r\n\r\nWell, the tests run and go well: have a screenshot.\r\n\r\n![they work!](screenshot/tests.png)\r\n\r\n## Mocking distinto\r\n\r\nMocking has also changed to fit more stuff:\r\n\r\n```js\r\n  let oldLog = console.log; // mocking console.log\r\n  let result = [];\r\n  let resultantString;\r\n  console.log = function (...s) {\r\n      if (s.length > 1) {\r\n          let sString = s.join(' ');\r\n          s = [sString];\r\n      }\r\n      result.push(s);\r\n      resultantString = result.join('\\n');\r\n  };\r\n  eval(output);\r\n```\r\n\r\n## NPM\r\n\r\nUsing the commands:\r\n```bash\r\n npm login\r\n```\r\nAnd setting all the information up (the notes' codes don't work at all),\r\nwe set up the information in bash.\r\n\r\n```bash\r\n npm publish --access=public\r\n```\r\nWith that we publish it.\r\n\r\n![stuff](screenshot/npm-website.png)\r\n\r\n## Docs\r\n\r\nThe command `npm run cov` will run the coverage and set the folder up for GitHub.\r\n\r\nAt GitHub, the page will be posted [here](https://ull-esit-pl-2223.github.io/espree-logging-juan_guillermo-zafra-alu0101353647/).\r\n\r\n![stuff](screenshot/pages.png)\r\n\r\n## Continuous Integration\r\n\r\nWe simply set the very same `nodejs.yml` as the previous assignment:\r\n\r\n```yml\r\n\r\n# Write your workflow for CI here\r\nname: CI\r\n\r\n# Controls when the workflow will run\r\non:\r\n  # Triggers the workflow on push or pull request events but only for the $default-branch branch\r\n  push:\r\n    branches: [ master ]\r\n  pull_request:\r\n    branches: [ master ]\r\n\r\n  # Allows you to run this workflow manually from the Actions tab\r\n  workflow_dispatch:\r\n\r\n# A workflow run is made up of one or more jobs that can run sequentially or in parallel\r\njobs:\r\n  # This workflow contains a single job called \"build\"\r\n  build:\r\n    # The type of runner that the job will run on\r\n    runs-on: ubuntu-latest\r\n\r\n    # Steps represent a sequence of tasks that will be executed as part of the job\r\n    steps:\r\n      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it\r\n      - uses: actions/checkout@v2\r\n\r\n      # Runs a single command using the runners shell\r\n      - name: Set up node\r\n        uses: actions/setup-node@v2\r\n\r\n      # Runs a set of commands using the runners shell\r\n      - name: Install dependencies\r\n        run: npm i\r\n      \r\n      - name: Run tests\r\n        run: npm run test\r\n```\r\nAnd it looks like this in GitHub:\r\n\r\n![stuff](screenshot/continuous-integration.png)\r\n\r\n","readmeFilename":"README.md"}