Using extensions
Before an extension can be executed with themoon ext command, it must be configured with .moon/extensions.* (excluding built-in’s).
.moon/extensions.yml
moon ext by name. Arguments unique to the extension must be passed after a -- separator.
Built-in extensions
moon is shipped with a few built-in extensions that are configured and enabled by default. Official moon extensions are built and published in our moonrepo/moon-extensions repository.download
Thedownload extension can be used to download a file from a URL into the current workspace, as defined by the --url argument.
--dest argument. However, do note that the destination must be within the current moon workspace, as only certain directories are whitelisted for WASM.
--url(required) - URL of a file to download.--dest- Destination folder to save the file. Defaults to the current working directory.--name- Override the file name. Defaults to the file name in the URL.
migrate-nx
This extension is currently experimental and will be improved over time.
migrate-nx extension can be used to migrate an Nx powered repository to moon. This process will convert the root nx.json and workspace.json files, and any project.json and package.json files found within the repository. The following changes are made:
- Migrates
targetDefaultsas global tasks to.moon/tasks/node.yml(orbun.yml),namedInputsas file groups,workspaceLayoutas projects, and more. - Migrates all
project.jsonsettings tomoon.ymlequivalent settings. Target to task conversion assumes the following:- Target
executorwill be removed, and we’ll attempt to extract the appropriate npm package command. For example,@nx/webpack:build→webpack build. - Target
optionswill be converted to taskargs. - The
{projectRoot}and{workspaceRoot}interpolations will be replaced with moon tokens.
- Target
--bun- Migrate to Bun based commands instead of Node.js.--cleanup- Remove Nx configs/files after migrating.
- Most settings in
nx.json. - Named input variants: external dependencies, dependent task output files, dependent project inputs, or runtime commands.
- Target
configurationsanddefaultConfiguration. Another task will be created instead that usesextends. - Project
rootandsourceRoot.
migrate-turborepo
Themigrate-turborepo extension can be used to migrate a Turborepo powered repository to moon. This process will convert the root turbo.json file, and any turbo.json files found within the repository. The following changes are made:
- Migrates
pipeline(v1) andtasks(v2) global tasks to.moon/tasks/node.yml(orbun.yml) and project scoped tasks tomoon.*. Task commands will executepackage.jsonscripts through a package manager. - Migrates root
global*settings to.moon/tasks/node.yml(orbun.yml) asimplicitInputs.
--bun- Migrate to Bun based commands instead of Node.js.--cleanup- Remove Turborepo configs/files after migrating.
unpack
Theunpack extension can be used to unpack an archive (zip/tar) from a file path or URL into a destination folder.
--src(required) - Path or URL of a file to unpack.--dest- Destination folder to unpack into. Defaults to the current working directory.--prefix- A prefix path to strip from unpacked files.
Creating an extension
Refer to our official WASM guide for more information on how our WASM plugins work, critical concepts to know, how to create a plugin, and more.Refer to our moonrepo/plugins repository for in-depth examples.
Registering metadata
Before we begin, we must implement theregister_extension function, which simply provides some metadata that we can bubble up to users, or to use for deeper integrations.
Implementing execution
Extensions support a single plugin function,execute_extension, which is called by the moon ext command to execute the extension. This is where all your business logic will reside.
Supporting arguments
Most extensions will require arguments, as it provides a mechanism for users to pass information into the WASM runtime. To parse arguments, we provide theArgs trait/macro from the clap crate.
parse_args function.
Supporting configuration
Users can configure extensions with additional settings in.moon/extensions.*. Do note that settings should be in camelCase for them to be parsed correctly!
.moon/extensions.yml
plugin) into a struct. The Default trait must be implemented to handle situations where settings were not configured, or some are missing.
get_extension_config function.