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 🙏

© 2026 – Pkg Stats / Ryan Hefner

eslint-enforce-package-type

v1.3.0

Published

ESLint plugin to enforce package.json type field (module or commonjs)

Readme

eslint-enforce-package-type

ESLint plugin to enforce package.json type field to be either "module" or "commonjs".

Installation

First, install the required peer dependencies:

npm install --save-dev eslint@^9.0.0 jsonc-eslint-parser@^2.0.0

Then, install the plugin:

npm install --save-dev eslint-enforce-package-type

Usage

Add the plugin to your ESLint configuration:

// eslint.config.js
import enforcePackageType from 'eslint-enforce-package-type';
import jsoncParser from 'jsonc-eslint-parser';

export default [
  // Use recommended configuration (enforces "module" by default)
  ...enforcePackageType.configs.recommended,

  // Or configure manually
  {
    files: ['package.json'],
    plugins: {
      'enforce-package-type': enforcePackageType
    },
    rules: {
      // Default to 'module'
      'enforce-package-type/enforce-package-type': 'error'
      // Or enforce 'commonjs'
      // 'enforce-package-type/enforce-package-type': ['error', { enforceType: 'commonjs' }]
    },
    languageOptions: {
      parser: jsoncParser
    }
  }
];

Then run ESLint:

# Check for issues
npx eslint .

# Or automatically fix issues
npx eslint . --fix

Rule Details

This rule enforces that the type field in package.json is set to either "module" or "commonjs".

Options

The rule accepts an options object with the following properties:

  • enforceType: The type to enforce ("module" or "commonjs"). Defaults to "module".

Auto-fix

This rule supports the --fix option. When enabled, it will:

  • Add the type field if it's missing
  • Change the type field value to match the enforced type
  • Preserve all other fields and formatting

Examples

Valid

{
  "name": "my-package",
  "type": "module"
}
{
  "name": "my-package",
  "type": "commonjs"
}

Invalid

{
  "name": "my-package"
  // Missing type field
}
{
  "name": "my-package",
  "type": "commonjs" // When enforceType is set to "module"
}

Features

  • ✅ Enforces "type" field in package.json
  • ✅ Supports both "module" and "commonjs" types
  • ✅ Provides auto-fix functionality
  • ✅ Configurable default type
  • ✅ Ignores package.json files in node_modules
  • ✅ Works with ESLint flat config

Development

Prerequisites

  • Node.js >= 18
  • npm >= 9

Setup

# Clone the repository
git clone https://github.com/MONEI/eslint-enforce-package-type.git
cd eslint-enforce-package-type

# Install dependencies
npm install

# Run tests
npm test

# Run tests in watch mode
npm run test:watch

# Lint files
npm run lint

# Lint and fix files
npm run lint:fix

# Format files
npm run format

Git Hooks

This project uses husky and lint-staged to ensure code quality before commits:

  • All staged files are formatted with Prettier
  • JavaScript files are linted with ESLint
  • All tests must pass

These checks run automatically before each commit.

Testing

Tests are written using Vitest and follow ESLint's testing conventions. Run tests with:

npm test

The test suite includes:

  • Rule metadata validation
  • Basic functionality tests
  • Edge cases (malformed JSON, invalid types)
  • Auto-fix functionality tests

Releasing

This project uses release-it for version management and package publishing.

Available commands:

# Dry run (no changes)
npm run release:dry

# Regular release
npm run release

# Alpha release
npm run release:alpha

# Beta release
npm run release:beta

The release process:

  1. Runs tests and linting
  2. Bumps version in package.json
  3. Creates a git tag
  4. Creates a GitHub release
  5. Publishes to npm
  6. Formats files after version bump

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Run tests and linting
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

License

MIT