DEV Community

suin
suin

Posted on

How Moonrepo Recognizes Project Languages

In this article, we will explain how the monorepo management tool Moon recognizes the languages of projects.

What is Moon?

Moon is a monorepo management tool. A monorepo is a method of managing multiple projects or packages within a single repository. Moon helps manage these projects efficiently and integrates tasks such as building, testing, and deploying. It manages dependencies between projects and improves development efficiency while maintaining consistency across the repository.

For more details: Moon Official Site

Managing Language Information

Moon maintains language information for each project and selects tasks to execute based on the language. The language information of a project can be set by describing it in the language field of the moon.yml file.

Example for a TypeScript project:

language: typescript
Enter fullscreen mode Exit fullscreen mode

With this setting, tasks defined in the .moon/tasks/typescript.yml file will be executed for that project. This feature is known as task inheritance. For more details, see here.

When No Language is Specified

If no language is specified in moon.yml, Moon will analyze the project's files and automatically identify the language. Thanks to Moon's intelligent design, it determines the programming language based on specific files.

How Language Detection Works

Moon determines the project's programming language based on specific files found in the project's root directory. The following is how Moon detects each language.

1. Checking for Go Files

If any of the following files are found, the project's language is determined to be Go:

  • go.mod
  • go.sum
  • g.lock
  • .gvmrc
  • .go-version

2. Checking for PHP Files

If any of the following files are found, the project's language is determined to be PHP:

  • composer.json
  • composer.lock
  • .phpenv-version
  • .phpbrewrc

3. Checking for Python Files

If any of the following files are found, the project's language is determined to be Python:

  • requirements.txt
  • constraints.txt
  • pyproject.toml
  • .pylock.toml
  • .python-version
  • Pipfile
  • Pipfile.lock
  • poetry.toml
  • poetry.lock

4. Checking for Ruby Files

If any of the following files are found, the project's language is determined to be Ruby:

  • Gemfile
  • Gemfile.lock
  • .bundle
  • .ruby-version

5. Checking for Rust Files

If any of the following files are found, the project's language is determined to be Rust:

  • Cargo.toml
  • Cargo.lock
  • .cargo
  • rust-toolchain.toml
  • rust-toolchain

6. Checking for TypeScript Files

If any of the following files are found, the project's language is determined to be TypeScript:

  • tsconfig.json
  • tsconfig.tsbuildinfo

Additionally, Deno files are also checked:

  • deno.json
  • deno.jsonc
  • deno.lock
  • .dvmrc

7. Checking for JavaScript Files

If any of the following files are found, the project's language is determined to be JavaScript:

  • package.json
  • .nvmrc
  • .node-version
  • package-lock.json
  • .npmrc
  • .pnpmfile.cjs
  • pnpm-lock.yaml
  • pnpm-workspace.yaml
  • yarn.lock
  • .yarn
  • .yarnrc
  • .yarnrc.yml

Additionally, Bun files are also checked:

  • bunfig.toml
  • bun.lockb
  • .bunrc

8. If No Files Are Found

If none of the specific files are found, the project's language is determined to be unknown.

This specification allows Moon to determine the programming language based on the file structure within the project. For more details, see here.

Explicitly Specifying the Language

If you do not want Moon to estimate the project's language, it is recommended to explicitly specify the language field in the moon.yml file. However, be sure to specify a value other than unknown because specifying unknown will trigger the detection feature described above.

I hope this article helps deepen your understanding of how Moon recognizes project languages.

Top comments (0)