Skip to main content

Setup workspace

3 min

Once moon has been initialized, we must setup the workspace, which is denoted by the .moon folder and a relative package.json -- this is known as the workspace root. The workspace is in charge of:

  • Integrating with a version control system.
  • Defining configuration that applies to its entire tree.
  • Housing projects to build a project graph.
  • Managing a toolchain that automatically installs Node.js and other tools.
  • Running tasks and the build system.

Configuring Node.js

The most important tool within moon and its toolchain is Node.js, as it's the backbone of a JavaScript based repository. Let's now define the Node.js version we want to install in the toolchain, enforce for developers, and to utilize when running moon commands, by updating node.version in .moon/workspace.yml.

This setting requires an explicit semantic version and does not support version ranges, so let's set it to the latest version. We suggest always using an Active LTS version.

.moon/workspace.yml
node:
version: '16.15.0'

Let's now run moon --log debug setup to verify that Node.js is downloaded and installed correctly. Pretty cool right?

Configuring a package manager

Even though Node.js is now installed, we need a package manager to install dependencies. During installation, we talked about choosing a package manager, so let's use that choice here by defining node.packageManager.

.moon/workspace.yml
node:
version: '16.15.0'
packageManager: 'yarn'

By default moon will install the latest version of a package manager, but this isn't consistently updated, so we suggest defining an explicit semantic version for the package manager as well, through the node.<packageManager>.version setting.

.moon/workspace.yml
node:
version: '16.15.0'
packageManager: 'yarn'
yarn:
version: '3.2.0'

Once again, let's run moon --log debug setup to verify the package manager is installed, and also take note that Node.js is already installed. Based on the example configuration above, we'll be switching from npm (the default) to yarn.

Configuring a version control system

moon defaults to git for a VCS, so feel free to skip this if you use git.

moon requires a version control system (VCS) to be present for functionality like file diffing, hashing, and revision comparison. The VCS and its default branch can be configured through the vcs setting.

.moon/workspace.yml
vcs:
manager: 'git'
defaultBranch: 'master'

Next steps