Skip to content

Utility to find all workspace package paths in a monorepo setup.

License

Notifications You must be signed in to change notification settings

nkzw-tech/find-workspaces

Repository files navigation

@nkzw/find-workspaces

Utility to find all workspace package paths in a monorepo setup. Can be used for the packageDir setting for the import-x/no-extraneous-dependencies ESLint rule.

Installation

npm install @nkzw/find-workspaces

Usage

import findWorkspaces from '@nkzw/find-workspaces';

console.log(findWorkspaces()); // Uses `process.cwd()` by default.

console.log(findWorkspaces('/path/to/your/project'));

Supported workspace managers

findWorkspaces supports pnpm, yarn, and npm workspace definitions. When both pnpm-workspace.yaml and package.json workspaces are present, it unions the patterns from both files.

pnpm

# pnpm-workspace.yaml
packages:
  - 'packages/*'
  - 'apps/*'

yarn / npm

// package.json
{
  "workspaces": ["packages/*", "apps/*"]
}
// package.json
{
  "workspaces": {
    "packages": ["packages/*", "apps/*"]
  }
}

Usage with ESLint

import findWorkspaces from '@nkzw/find-workspaces';

export default [
  {
    rules: {
      'import-x/no-extraneous-dependencies': [
        2,
        { packageDir: findWorkspaces() },
      ],
    },
  },
];

About

Utility to find all workspace package paths in a monorepo setup.

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors 2

  •  
  •