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

md-link-checker-teamcity

v0.5.0

Published

A markdown link checker that integrates with teamcity service messages.

Downloads

8

Readme

md-link-checker-teamcity

A markdown link checker. A wrapper around markdown-link-check that:

  1. Finds each markdown file (*.md) in your project
  2. Runs markdown-link-check on it
  3. Outputs teamcity service messages and fails the build if unreachable links are found
  4. Optionally, allows for white listing of links that won't fail the build if they are unreachable

Installation

To add it to your project:

npm i -D md-link-checker-teamcity

To install it globally:

npm i -g md-link-checker-teamcity

Team City Usage

Then add a task to the scripts section of your package.json:

"linkck:teamcity": "node node_modules/md-link-checker-teamcity --reporter=teamcity"

And then you can instruct your Team City build to include a step like npm run linkck:teamcity.

This will search for every markdown file in your project and check the links in each. Any dead links will be reported and will cause the build to fail.

The --reporter switch instructs the command to output errors using teamcity service messages and also is responsible for failing the build if dead links are found. Without this switch the command just prints out user friendly messages to the command line.

White Listing

It may be the case that some links in your documents cannot be reached from your build engine. A common reason for this issue is that authentication is required to access the linked file. To avoid these links from failing your build you can add them to a whitelist. They will still be reported as unreachable, but they will no longer cause the build to fail.

Modify your npm script like this:

"linkck:teamcity": "node node_modules/md-link-checker-teamcity --reporter=teamcity --whitelist=./link-whitelist.json"

Where the file link-whitelist.json is an array of links that are whitelisted:

[
    {
        "link": "http://mydomain.com/cool-file.md",
        "reason": "Authentication required"
    },
    {
        "link": "https://myotherdomain.com/",
        "reason": "Authentication required"
    },
]

Command Line Usage

To get user friendly messages simply leave off the --reporter switch.

md-link-checker-teamcity

Example Output

The following output is generated by running md-link-checker-teamcity on this project.

No Reporter and no White List

$ md-link-checker-teamcity
ERROR: 'https://__nothing_garbage.com' in file 'sample/sample-markdown.md' could not be reached.
ERROR: 'https://__whitelisted_garbage.com' in file 'sample/sample-markdown.md' could not be reached.

No Reporter but with White List

In this example the unreachable links are split into to categories: WARN and ERROR. Unreachable whitelisted links show up as warnings only. When used with teamcity they do not trigger a build failure.

$ md-link-checker-teamcity --whitelist=sample/sample-whitelist.json
WARN: 'https://__whitelisted_garbage.com' in file 'sample/sample-markdown.md' could not be reached but is whitelisted.
ERROR: 'https://__nothing_garbage.com' in file 'sample/sample-markdown.md' could not be reached.

Team City Reporter and White List

In this example we are using the TeamCity reporter so the output consists of teamcity service messages that team city can parse and display in build output.

$ md-link-checker-teamcity --reporter=teamcity --whitelist=sample/sample-whitelist.json
##teamcity[inspectionType id='LINK001' name='no-dead-links' description='Reports links that were not reachable.' category='Document issues' flowId='4772759364' timestamp='2017-11-23T17:27:53.461']
##teamcity[inspectionType id='LINK002' name='no-whitelisted-dead-links' description='Reports links that were on a whitelist. These are links that we know may not be reachable by an automated build tool. This inspection is just meant as a informational message.' category='Document issues' flowId='4772759364' timestamp='2017-11-23T17:27:53.462']
##teamcity[inspection typeId='LINK002' message='Whitelisted dead link: https://__whitelisted_garbage.com' file='sample/sample-markdown.md' SEVERITY='INFO' flowId='4772759364' timestamp='2017-11-23T17:27:54.124']
##teamcity[buildProblem description='Dead links detected.' flowId='4772759364' timestamp='2017-11-23T17:27:54.124']
##teamcity[inspection typeId='LINK001' message='Dead link: https://__nothing_garbage.com' file='sample/sample-markdown.md' SEVERITY='ERROR' flowId='4772759364' timestamp='2017-11-23T17:27:54.124']

The first two messages are used to register inspection types with Team City. The third message reports a Whitelisted dead link which has a severity of INFO. The next message reports a build problem and this is what actually fails the build. This message was generated because of the existence of a non-whitelisted dead link which is reported in the last message with a severity of ERROR.

Using in Pull Requests

This tool was written to be used in builds triggered by pull requests. It's default behavior is to check all files in a directory. If you wish to use it in a build you can use the --changed switch to only check those markdown files that have changed in this pull request (vs. master).