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

@lint-ts-index/cli

v0.1.1

Published

Check whether TS files are exported in index.ts

Downloads

2

Readme

@lint-ts-index/cli

GitHub tag (latest SemVer) License GitHub issues

Purpose of this tool is to check that every files or subdirectories are exported in their corresponding index.ts files.

$ lint-ts-index
foo.ts is not exported in index.ts
If you believe it's an error, please add an exclusion in .indexignore

Have you ever forget to export the content of a new source file into the index.ts file of it's parent directory? Not anymore!

:warning: This project is still experimental and subject to important changes. Use it at your own risk

Installation

Please note that lint-ts-index also exists as an eslint plugin. If you already use the linter in your project, it might be a better choice to use it.

Also, since you might prefer a to use a specific version of the compiler, the typescript package is not installed automatically as a dependency of @lint-ts-index/cli. Which means that you must also install it by yourself alongside the tool.

Global

npm install --global @lint-ts-index/cli

Append typescript at the end of the line if it's not already installed globally.

Project

Install the tool and add it to your package.json as a devDependency with:

npm install --save-dev @lint-ts-index/cli

Append typescript at the end of the line if it's not already installed in your project.

Then it's preferable to add this NPM script in your package.json file so that you can call the linter with npm run lint:ts-index:

{
  "scripts": {
    "lint:ts-index": "lint-ts-index",
    // You can also call the command from your existing lint script.
    "lint": "lint-ts-index && prettier"
    // ...
  }
  // ...
}

Usage

Usage: lint-ts-index [options] [directory]

Check that every files or subdirectories are exported in their corresponding index.ts files.

Arguments:
  directory            The directory to search recursively for index.ts files

Options:
  -c, --config <file>  Use this configuration overriding .lint-ts-index.*
                       config options if present
  -f, --fix            (Experimental) Automatically export the missing sources
                       in their index.ts
  --version            Output version information and exit
  -h, --help           Display help for command

NPX (requires no installation)

npx @lint-ts-index/cli

Examples

Simple example

Given the following directory:

examples/simple/fail
├── bar.ts
├── foo.ts
└── index.ts

And index.ts content:

export * from './bar';

Calling lint-ts-index would exit with a non-zero exit code and output the following:

$ lint-ts-index
foo.ts is not exported in index.ts
If you believe it's an error, please add an exclusion in .indexignore

To fix this error, you can either add the missing export * from './foo'; line in index.ts or add a .indexignore file to ignore the file from the list of modules which must be exported.

Let's say that, in our case, we don't want to export the file. Then, content of the .indexignore, would have the following content:

foo.ts

Once the corrections are applied, the linter should output nothing and have a successful exit code.

Advanced example

Given the following directory:

examples/advanced/fail
├── bar.ts
├── command-line
│   ├── helper.ts
│   ├── index.ts
│   └── plugin-api
│       ├── context.ts
│       ├── factory.ts
│       └── index.ts
├── foo.ts
├── index.ts
├── private
│   └── secret.ts
└── public
    ├── index.ts
    ├── private-file.ts
    └── public-file.ts

Specific requirements:

  • By default, content of advanced should be exported in index.ts.
  • foo.ts contains only private functions which we don't want to expose in the public API.
  • command-line is the code for a command-line tool.
    • command-line/index.ts contains the main entry point and should not be loaded as a library.
    • command-line/helper.ts is some internal utility functions used by command-line/index.ts.
    • command-line/plugin-api will be exposed publicly in a specific plugin API.
  • private has some secret functions in it which we don't want to expose in the public API.
  • public contains most of the public interfaces which must be exposed in the public API. We want to check that every file in it gets exported in public/index.ts
    • public/private-file.ts is a file which we don't want to expose in the public API although it is placed in the public directory.

As-is, the lint-ts-index output would look like this:

$ lint-ts-index
foo.ts is not exported in index.ts
command-line is not exported in index.ts
private is not exported in index.ts
command-line/helper.ts is not exported in command-line/index.ts
command-line/plugin-api is not exported in command-line/index.ts
public/private-file.ts is not exported in public/index.ts
If you believe it's an error, please add an exclusion in .indexignore

Because we need to respect the rules above, the solution here is not to export the reported files and directories. We have to write a .indexignore file with these lines:

foo.ts
private
command-line
command-line/index.ts
public/private-file.ts

Then, the linter should pass and still detect new additions in the directories whose content should be exported by default.

Configuration

See Configuration File Formats.

See also

License

This project is licensed under the MIT license which you can find a copy in the LICENSE file.