moonrepo / moon

A build system and monorepo management tool for the web ecosystem, written in Rust.
https://moonrepo.dev/moon
MIT License
2.9k stars 157 forks source link

[bug] Extending a task named "test" results in an error saying that the test task is unknown #1648

Closed bgatellier closed 1 month ago

bgatellier commented 2 months ago

Describe the bug

Having a task that extends a task named test results in an error saying that the test task is unknown.

Steps to reproduce

  1. Define a task named test
  2. Define a task named coverage and make it extends test
  3. Run the coverage task: moon run :coverage

Expected behavior

The command is executed without error

Screenshots

Here is my complete.moon/tasks.yml configuration (I paste it raw below the screenshot) image

$schema: 'https://moonrepo.dev/schemas/tasks.json'
tasks:
  build:
    command: tsc --project tsconfig.build.json
    deps:
      # remove the lib/ directory
      - target: cleanup
        args: lib
      # build dependent projects
      - ^:build
  cleanup:
    command: rimraf
    options:
      cache: false
      internal: true
  check:
    command: pnpm exec biome check
    options:
      affectedFiles: true
      affectedPassInputs: true
  test:
    command: pnpm vitest run --project=@scodi/$project
    deps:
      # build dependent projects
      - ^:build
    options:
      runFromWorkspaceRoot: true
  coverage:
    extends: test
    args:
      - '--coverage'
      - '--coverage.reportsDirectory=$projectSource/coverage'
    deps:
      # remove the coverage/ directory
      - target: cleanup
        args: coverage
  publish:
    command: pnpm jsr publish

Environment

  System:
    OS: Linux 5.15 Ubuntu 22.04.4 LTS 22.04.4 LTS (Jammy Jellyfish)
    CPU: (12) x64 AMD Ryzen 5 3600X 6-Core Processor
    Memory: 5.82 GB / 7.74 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 18.20.4 - ~/.proto/shims/node
    pnpm: 9.9.0 - ~/.proto/shims/pnpm
  Managers:
    Apt: 2.4.12 - /usr/bin/apt
  Utilities:
    Git: 2.34.1 - /usr/bin/git
    Curl: 7.81.0 - /usr/bin/curl
    OpenSSL: 3.0.2 - /usr/bin/openssl
  IDEs:
    Nano: 6.2 - /usr/bin/nano
    VSCode: 1.93.0 - /root/.vscode-server/bin/4849ca9bdf9666755eb463db297b69e5385090e3/bin/remote-cli/code
    Vim: 8.2 - /usr/bin/vim
  Languages:
    Bash: 5.1.16 - /usr/bin/bash
    Perl: 5.34.0 - /usr/bin/perl
    Python3: 3.10.12 - /usr/bin/python3

Additional context

Tested with moon 1.27.10 and 1.28.1

Changing the extended task name in favor of tests or test2 does not trigger the error.

milesj commented 2 months ago

@bgatellier Is the inheriting project excluding/renaming the test task by chance?

bgatellier commented 2 months ago

@bgatellier Is the inheriting project excluding/renaming the test task by chance?

Not renaming, but after debugging and further investigation with your suggestion, 1 project have the following moon.yml:

workspace:
  inheritedTasks:
    exclude:
      - build
      - test

And adding the coverage task to the exclusion list did the trick.

Sorry for the additional issue and thanks for your help and super quick answer!

milesj commented 2 months ago

Np!

Let me see if I can show a better error message here (assuming there's enough context).

bgatellier commented 1 month ago

Np!

Let me see if I can show a better error message here (assuming there's enough context).

That would be lovely

milesj commented 1 month ago

Added a little message in v1.28.3