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 🙏

© 2024 – Pkg Stats / Ryan Hefner

gatsby-transformer-leasot

v1.3.0

Published

Parse TODOs, FIXMEs & more, then query them via GraphQL

Downloads

33

Readme

gatsby-transformer-leasot

Uses leasot to parse select source files for TODO:, FIXME: and custom comments. Written in Typescript.

Example

// FIXME(Reference): improve example
// TODO: you can add a reference like this as well /Reference
// TODO: example without reference
const comeBackToImprove = () => console.log('Please improve me')

will be transformed to

{
  "todo": {
    "ref": "Reference",
    "line": 7,
    "value": "improve example",
    "file": {
      "relativePath": "README.md"
    }
  }
}

file will be a File reference, so you can query anything gatsby-source-filesystem provides

Live Example

Install

yarn add -D gatsby-transformer-leasot
# or
npm i -D gatsby-transformer-leasot

REQUIRES: gatsby-source-filesystem
You can use gatsby-theme-leasot for convenience.
Alternatively, since v1.2.0, you can bring your own source plugin and set the internalType accordingly.

Usage

{
  resolve: `gatsby-source-filesystem`,
  options: {
    path: __dirname,
    // has to match `sourceInstanceName` field in gatsby-transformer-leasot
    name: `leasot`,
    ignore: [
      // can be customized, it's just what works for me at the moment
      /\.*.*\/(node_modules|\.cache|public|static|dist|\.yarn)\/./,
      /\.*.\.(log|jpe?g|png|gif|ico|json|map|gz|pdf)/,
    ],
  },
},

// without options
`gatsby-transformer-leasot`,

// with options
{
  resolve: `gatsby-transformer-leasot`,
  options: {
    sourceInstanceName: `leasot`,
    // parse `NOTE:` in addition to `TODO:` & `FIXME:`
    customTags: [`NOTE`],
    mode: 'mdx',
  },
},

For mdx to work you have to wrap the value in MDXRenderer provided by gatsby-plugin-mdx

Query

allLeasot(
  sort: { fields: [todo___modifiedTime], order: DESC }
) {
  group(field: todo___tag) {
    fieldValue
    totalCount
    nodes {
      id
      todo {
        tag
        line
        ref
        value
        modifiedTime(formatString: "YYYY-MM-DD H:mm")
        file {
          relativePath
        }
      }
    }
  }
}

Note: The name allLeasot depends on the provided sourceInstanceName in the configs. So when you change it you have to change the name option of gatsby-source-filesystem accordingly, lets say todo then you query for allTodo or todo if you just want a single one.

All config options

| name | type | default | description | | --------------------------------- | --------------- | --------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | sourceInstanceName | string | "leasot" | Has to match the name prop of gatsby-source-filesystem. | | customTags | array | [] | Other tags to look for (besides todos and fixmes). Tags are case-insensitive and are strict matching, i.e PROD tag will match PROD but not PRODUCTS. More in Leasot's Docs | | mode | string | "text" | Supports one of: text, mdx, html. | | truncateLinks | int|object | {length: 32,style: "smart"} | Provide int to change the length only. style can be one of: smart, middle, end. | | associateParser | object | {} | Associate the filetypes with parsers. This allows adding support for new filetypes. More in Leasot's Docs | | customParsers | object | {} | Extend the parsers by parserName, for example override the defaultParser or add a new parser. Leasot's Docs | | internalType (since v1.2.0) | string | "File" | Has to match node.internal.type |

modifiedTime works only locally as file time will be the same on CI

A table showing the Supported Languages & the comment format spec by Leasot in their readme.

Provides its own Schema

That means if your sourced files don't contain anything for gatsby-transformer-leasot to parse it won't crash as Gatsby will be prepared. Also congratulations for finishing off all notes, fixmes & todos 🥳

Changelog

  • v1.1.0 - add he to entity encode the comments

Credits

License

MIT