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

ts-npm-lint

v0.1.0

Published

Utility to create typescript based npm modules. Can also strip reference paths for .d.ts files and check TSD configs.

Downloads

354

Readme

ts-npm-lint

Utility to create typescript based npm modules. Can also strip reference paths for .d.ts files and check TSD configs.

Building strongly typed npm modules using typescript is quite tricky. Especially if your package depends on other packages and you want to offer typings to consumers of your module. This tool checks your package.json, tsconfig.json and tsd.json files to verify your setup.

The goal of this tool that your npm package consumers can ultimately just do the following:

npm install your-cool-page --save

And in some .ts file:

import coolPackage from "your-cool-package".

Installation

npm install -g ts-npm-lint

Usage

Run ts-npm-lint in the root of your package to get information about your current setup.

Run ts-npm-lint --fix-typings to strip triple slash references from your typing files so that they can be used by directly by other packages. Probably this should be part of your build process, after running the typescript compiler. In that case just run npm install ts-npm-lint --save-dev and add something like "build": "tsc && ts-npm-lint --fix-typings" to the scripts section of your package.json.

Example output

To get an idea of the things ts-npm-lint checks, here the output of the tool on different packages:

[ts-npm-lint] package.json doesn't declare a 'typings' entry file. Please include an entry file (without extension), e.g: "typings": "lib/index"

[ts-npm-lint] typescript is not registered as build dependency, please install it using 'npm install typescript --save-dev'

[ts-npm-lint] No 'tsconfig.json' was found. Please use it to define the default build parameters. See: https://github.com/Microsoft/TypeScript/wiki/tsconfig.json

[ts-npm-lint] Some dependencies of this package don't ship with own typings. You can install the 'tsd' tool to manage these. Use 'npm install -g tsd'. For more info see: http://definitelytyped.org/tsd/

[ts-npm-lint] No *.d.ts files where found in the compilers output directory (.). Please run the typescript compiler first and make sure the 'declaration' option is enabled.
[ts-npm-lint] Some dependencies of this package don't ship with their own typings. You can install the 'tsd' tool to manage these. Use 'npm install -g tsd'. For more info see: http://definitelytyped.org/tsd/. Packages without typings:
  lodash, node-uuid, restler, node
[ts-npm-lint] It is recommended to set the compiler output directory using the "outDir" option, so that the typescript sources can be put into .npmignore, and the output files and declaration files in .gitignore. e.g: '"outDir": "lib/"'

[ts-npm-lint] Please mention in the documentation of your package that the following typings might need to be installed using 'tsd install <package> --save':
  when, rest, node, lodash, xml2js, jsonpath, assertion-error, chai, mocha, promises-a-plus, chai-as-promised, nock

[ts-npm-lint] Found '/// <reference path' d.ts file includes in the following .d.ts files:

  ./test/smoke-test.d.ts: /// <reference path="../typings/tsd.d.ts" />

[ts-npm-lint] Please remove those references to make your typings usable for package consumers. Keeping triple slash references might collide with typings used in consuming packages. Remove triple slash references by running 'ts-npm-lint --fix-typings' as part of your build process.

One might find some of the hints opiniated. If it raises any questions, please feel free to file an isue for an explanation!

FAQ

Please start asking!

Q: Does it work on windows? A: Didn't test, but it should.

Future ideas

  • Query tsd to see whether typings are available
  • Instead of prosing a solution, apply a solution
  • Add option to only fix typings in a specified dir
  • Check typescript version (1.6+ required)