Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@rushstack/eslint-plugin-packlets

microsoft358kMIT0.11.0TypeScript support: included

A lightweight alternative to NPM packages for organizing source files within a single project

eslint, eslint-config, packlets, rules

readme

@rushstack/eslint-plugin-packlets

Packlets provide a lightweight alternative to NPM packages for organizing source files within a single project. The formalism is validated using ESLint rules.

Motivation

When building a large application, it's a good idea to organize source files into modules, so that their dependencies can be managed. For example, suppose an application's source files can be grouped as follows:

  • src/logging/*.ts - the logging system
  • src/data-model/*.ts - the data model
  • src/reports/*.ts - the report engine
  • src/*.ts - other arbitrary files such as startup code and the main application

Using file folders is helpful, but it's not very strict. Files under src/logging can easily import files from /src/reports, creating a confusing circular import. They can also import arbitrary application files. Also, there is no clear distinction between which files are the "public API" for src/logging versus its private implementation details.

All these problems can be solved by reorganizing the project into NPM packages (or Rush projects). Something like this:

  • @my-app/logging - the logging system
  • @my-app/data-model - the data model
  • @my-app/reports - the report engine
  • @my-app/application - other arbitrary files such as startup code and the main application

However, separating code in this way has some downsides. The projects need to build separately, which has some tooling costs (for example, "watch mode" now needs to consider multiple projects). In a large monorepo, the library may attract other consumers, before the API has been fully worked out.

Packlets provide a lightweight alternative that offers many of the same benefits of packages, but without the package.json file. It's a great way to prototype your project organization before later graduating your packlets into proper NPM packages.

5 rules for packlets

With packlets, our folders would be reorganized as follows:

  • src/packlets/logging/*.ts - the logging system
  • src/packlets/data-model/*.ts - the data model
  • src/packlets/reports/*.ts - the report engine
  • src/*.ts - other arbitrary files such as startup code and the main application

The packlets-tutorial sample project illustrates this layout in full detail.

The basic design can be summarized in 5 rules:

  1. A "packlet" is defined to be a folder path ./src/packlets/<packlet-name>/index.ts. The index.ts file will have the exported APIs. The <packlet-name> name must consist of lower case words separated by hyphens, similar to an NPM package name.

    Example file paths:

     src/packlets/controls
     src/packlets/logger
     src/packlets/my-long-name

    NOTE: The packlets cannot be nested deeper in the tree. Like with NPM packages, src/packlets is a flat namespace.

  2. Files outside the packlet folder can only import the packlet root index.ts:

    src/app/App.ts

     // Okay
     import { MainReport } from '../packlets/reports';
    
     // Error: The import statement does not use the packlet's entry point (@rushstack/packlets/mechanics)
     import { MainReport } from '../packlets/reports/index';
    
     // Error: The import statement does not use the packlet's entry point (@rushstack/packlets/mechanics)
     import { MainReport } from '../packlets/reports/MainReport';
  3. Files inside a packlet folder should import their siblings directly, not via their own index.ts (which might create a circular reference):

    src/packlets/logging/Logger.ts

     // Okay
     import { MessageType } from "./MessageType";
    
     // Error: Files under a packlet folder must not import from their own index.ts file (@rushstack/packlets/mechanics)
     import { MessageType } from ".";
    
     // Error: Files under a packlet folder must not import from their own index.ts file (@rushstack/packlets/mechanics)
     import { MessageType } from "./index";
  1. Packlets may reference other packlets, but not in a way that would introduce a circular dependency:

    src/packlets/data-model/DataModel.ts

     // Okay
     import { Logger } from '../../packlets/logging';

    src/packlets/logging/Logger.ts

     // Error: Packlet imports create a circular reference:  (@rushstack/packlets/circular-deps)
     //   "logging" is referenced by src/packlets/data-model/DataModel.ts
     //   "data-model" is referenced by src/packlets/logging/Logger.ts
     import { DataModel } from '../../packlets/data-model';
  2. Other source files are allowed outside the src/packlets folder. They may import a packlet, but packlets must only import from other packlets or NPM packages.

    src/app/App.ts

     // Okay
     import { MainReport } from '../packlets/reports';

    src/packlets/data-model/ExampleModel.ts

     // Error: A local project file cannot be imported. A packlet's dependencies must be
     // NPM packages and/or other packlets. (@rushstack/packlets/mechanics)
     import { App } from '../../app/App';

Getting Started

To enable packlet validation for a simple typescript-eslint setup, reference the @rushstack/eslint-plugin-packlets project like this:

<my-project>/.eslintrc.js

module.exports = {
  root: true,
  parser: '@typescript-eslint/parser',
  plugins: ['@typescript-eslint'],
  extends: [
    'eslint:recommended',
    'plugin:@typescript-eslint/recommended',
    'plugin:@rushstack/eslint-plugin-packlets/recommended' // <--- ADD THIS
  ],
  parserOptions: {
    project: './tsconfig.json',
    sourceType: 'module',
    tsconfigRootDir: __dirname
  }
};

Or, if you are using the @rushstack/eslint-config ruleset, add the "packlets" mixin like this:

<my-project>/.eslintrc.js

// This is a workaround for https://github.com/eslint/eslint/issues/3458
require('@rushstack/eslint-config/patch/modern-module-resolution');

module.exports = {
  extends: [
    "@rushstack/eslint-config/profile/node",
    "@rushstack/eslint-config/mixins/packlets" // <--- ADD THIS
  ],
  parserOptions: { tsconfigRootDir: __dirname }
};

The @rushstack/eslint-plugin-packlets plugin implements three separate rules:

  • @rushstack/packlets/mechanics - validates most of the import path rules outlined above.
  • @rushstack/packlets/circular-deps - detects circular dependencies between packlets. This rule requires an ESLint configuration that enables full type information from the TypeScript compiler.
  • @rushstack/packlets/readme - requires each packlet to have a README.md file. This rule is disabled by default.

Requiring a README.md file

If you'd like to require a README.md file in each packlet folder, enable the optional @rushstack/packlets/readme rule.

The minimumReadmeWords option allows you to specify a minimum number of words of documentation in the README.md file. The default value is 10 words.

Example configuration with the @rushstack/packlets/readme rule enabled:

<my-project>/.eslintrc.js

// This is a workaround for https://github.com/eslint/eslint/issues/3458
require('@rushstack/eslint-config/patch/modern-module-resolution');

module.exports = {
  extends: [
    "@rushstack/eslint-config/profile/node",
    "@rushstack/eslint-config/mixins/packlets"
  ],
  parserOptions: { tsconfigRootDir: __dirname },
  overrides: [
    {
      files: ['*.ts', '*.tsx'],

      rules: {
        '@rushstack/packlets/readme': [ // <--- ADD THIS
          'warn',
          { minimumReadmeWords: 10 }
        ]
      }
    }
  ]
};

@rushstack/eslint-plugin-packlets is part of the Rush Stack family of projects. The idea for packlets was originally proposed by @bartvandenende-wm and @victor-wm.

changelog

Change Log - @rushstack/eslint-plugin-packlets

This log was last generated on Tue, 11 Mar 2025 02:12:33 GMT and should not be manually modified.

0.11.0

Tue, 11 Mar 2025 02:12:33 GMT

Minor changes

  • Bump the @typescript-eslint/* packages to add support for TypeScript 5.8.

0.10.0

Sat, 01 Mar 2025 07:23:16 GMT

Minor changes

  • Bump the @typescript-eslint/* dependencies to ~8.24.0 to support newer versions of TypeScript.

0.9.2

Sat, 27 Jul 2024 00:10:27 GMT

Patches

  • Include CHANGELOG.md in published releases again

0.9.1

Sat, 17 Feb 2024 06:24:34 GMT

Version update only

0.9.0

Tue, 16 Jan 2024 18:30:10 GMT

Minor changes

  • Add support for TypeScript 5.3 with @typescript-eslint 6.19.x

0.8.1

Tue, 26 Sep 2023 09:30:33 GMT

Version update only

0.8.0

Fri, 15 Sep 2023 00:36:58 GMT

Minor changes

  • Update @types/node from 14 to 18

0.7.0

Mon, 22 May 2023 06:34:32 GMT

Minor changes

  • Upgrade the @typescript-eslint/* dependencies to ~5.59.2

0.6.1

Mon, 10 Oct 2022 15:23:44 GMT

Patches

  • Fix a link in the README.

0.6.0

Thu, 29 Sep 2022 07:13:06 GMT

Minor changes

  • Upgraded @typescript-eslint dependencies to 5.30.x to enable support for TypeScript 4.8

0.5.0

Wed, 03 Aug 2022 18:40:35 GMT

Minor changes

  • Upgrade TypeScript dependency to 4.7

0.4.1

Fri, 17 Jun 2022 00:16:18 GMT

Version update only

0.4.0

Sat, 23 Apr 2022 02:13:06 GMT

Minor changes

  • Add support for TypeScript 4.6

0.3.6

Sat, 09 Apr 2022 02:24:26 GMT

Patches

  • Rename the "master" branch to "main".

0.3.5

Tue, 15 Mar 2022 19:15:53 GMT

Patches

  • Fix the path in the package.json "directory" field.

0.3.4

Mon, 06 Dec 2021 16:08:32 GMT

Patches

  • Add support for ESLint v8

0.3.3

Wed, 27 Oct 2021 00:08:15 GMT

Patches

  • Update the package.json repository field to include the directory property.

0.3.2

Thu, 07 Oct 2021 07:13:35 GMT

Patches

  • Update typescript-eslint to add support for TypeScript 4.4.

0.3.1

Thu, 23 Sep 2021 00:10:40 GMT

Patches

  • Upgrade the @types/node dependency to version to version 12.

0.3.0

Mon, 12 Jul 2021 23:08:26 GMT

Minor changes

  • Upgrade @typescript-eslint/* packages to 4.28.0 (GitHub #2389)

0.2.2

Mon, 12 Apr 2021 15:10:28 GMT

Patches

  • Fix an issue where the @rushstack/packlets/circular-deps rule did not work correctly with TypeScript 4.2

0.2.1

Tue, 06 Apr 2021 15:14:22 GMT

Patches

  • Fix unlisted dependency on @typescript-eslint/experimental-utils

0.2.0

Wed, 11 Nov 2020 01:08:58 GMT

Minor changes

  • Add an optional "@rushstack/packlets/readme" rule that requires a README.md in each packlet folder

0.1.2

Wed, 28 Oct 2020 01:18:03 GMT

Patches

  • Fix an exception that occured if a source file was added to the "src/packlets" folder, not belonging to any packlet
  • Fix an issue where linting was sometimes not performed on MacOS, because Node.js "path.relative()" incorrectly assumes that every POSIX file system is case-sensitive
  • Fix an issue where @rushstack/packlets/circular-deps did not detect certain types of circular dependencies

0.1.1

Tue, 06 Oct 2020 00:24:06 GMT

Patches

  • Fix broken link to tutorial project in README.md

0.1.0

Mon, 05 Oct 2020 22:36:57 GMT

Minor changes

  • Initial release