Skip to content

Lerna scopes getting all packages names as scope #3023

@emredoganm

Description

@emredoganm

Hi there,

I am using @commitlint/config-lerna-scopes for helping commitlint to find the scope of Lerna to create conventional commits. Today, I noticed that after I changed the workspace configuration from packages/* to packages/** to support nested packages inside the packages folder, the package gathers all packages dependencies like typescript.

Expected Behavior

It should gives me only my packages inside my monorepo while using a nested packages folder approach like packages/**
The output of the scopes should be like this:

✅ Prettied console output for expected scopes
[
  "release",
  "example-package",
  "ds-theme",
  "storybook-utils",
  "test-utils",
  "ui-utils",
  "ds-web-banner",
  "ds-web-button-group",
  "ds-web-context-menu",
  "ds-web-drawer",
  "ds-web-password-field",
  "ds-web-progress-bar",
  "ds-web-phone-number-field",
  "ds-web-select",
  "ds-web-select-with-additional-field",
  "ds-web-stepper",
  "ds-web-tile",
]

Current Behavior

It gives me all packages even the dependencies of my subfolder packages.
Output is like that:

🚨 Prettied console output for current situation for scope names
[
  "release",
  "example-package",
  "ds-theme",
  "storybook-utils",
  "test-utils",
  "ui-utils",
  "ds-web-banner",
  "ds-web-button-group",
  "ds-web-context-menu",
  "ds-web-drawer",
  "ds-web-password-field",
  "ds-web-progress-bar",
  "ds-web-phone-number-field",
  "ds-web-select",
  "ds-web-select-with-additional-field",
  "ds-web-stepper",
  "ds-web-tile",
  "typescript",
  "resolve-pathname",
  "history",
  "typescript",
  "value-equal",
  "typescript",
  "typescript",
  "typescript",
  "typescript",
  "typescript",
  "typescript",
  "typescript",
  "typescript",
  "typescript",
  "typescript",
  "typescript",
  "typescript",
  "typescript",
  "typescript",
  "typescript",
  "typescript",
  "typescript",
  "typescript",
  "acorn-import-assertions",
  "commander",
  "acorn",
  "loader-runner",
  "serialize-javascript",
  "supports-color",
  "tapable",
  "jest-worker",
  "terser",
  "terser-webpack-plugin",
  "ts-loader",
  "typescript",
  "watchpack",
  "webpack",
  "webpack-cli",
  "webpack-sources",
  "acorn",
  "acorn-import-assertions",
  "commander",
  "jest-worker",
  "loader-runner",
  "serialize-javascript",
  "supports-color",
  "tapable",
  "terser",
  "terser-webpack-plugin",
  "ts-loader",
  "typescript",
  "watchpack",
  "webpack",
  "webpack-cli",
  "webpack-sources",
  "typescript",
  "typescript",
  "acorn",
  "typescript",
  "acorn-import-assertions",
  "jest-worker",
  "loader-runner",
  "serialize-javascript",
  "commander",
  "supports-color",
  "tapable",
  "terser",
  "terser-webpack-plugin",
  "ts-loader",
  "watchpack",
  "webpack",
  "typescript",
  "webpack-cli",
  "webpack-sources",
  "typescript",
  "typescript",
  "typescript",
  "typescript",
  "typescript",
  "typescript",
  "typescript",
  "helper-wasm-section",
  "wasm-edit",
  "wast-printer",
  "wasm-opt",
  "configtest",
  "info",
  "serve",
  "bin",
  "dist",
  "helper-wasm-section",
  "wasm-opt",
  "wasm-edit",
  "wast-printer",
  "configtest",
  "info",
  "serve",
  "dist",
  "bin",
  "helper-wasm-section",
  "wasm-edit",
  "wast-printer",
  "wasm-opt",
  "configtest",
  "info",
  "serve",
  "bin",
  "dist",
  "commander",
  "source-map",
  "commander",
  "source-map",
  "commander",
  "source-map"
]
## Affected packages
  • cli
  • core
  • prompt
  • config-angular

Possible Solution

Steps to Reproduce (for bugs)

  1. Change your workspace configuration from workspaces: ['packages/*'] to workspaces: ['packages/**']
  2. You should see the scopes with the cli command if you give a wrong scope to your commit
🗂️ commitlint.config.js
  const { utils } = require('@commitlint/config-lerna-scopes');
  
  module.exports = {
    extends: [
      '@commitlint/config-conventional',
      '@commitlint/config-lerna-scopes',
    ],
    rules: {
      'scope-enum': async ctx => [
        2,
        'always',
        [...(await utils.getPackages(ctx)), 'release'],
      ],
    },
  };

Context

Your Environment

Executable Version
commitlint --version 16.0.2
git --version 2.35.1
node --version v14.18.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions