moon migrate from-package-json <project> sub-command to migrate a project's
moon.yml format. When ran, the following changes are made:
moon.ymltasks. Scripts and tasks are not 1:1, so we'll convert as close as possible while retaining functionality.
package.jsonby removing all converted scripts. If all scripts were converted, the entire block is removed.
dependsOn). Will map a package's name to their moon project name.
$ moon --log debug migrate from-package-json app
moon does its best to infer the
local option, given the small amount
of information available to use. When this option is incorrectly set, it'll result in CI
environments hanging for tasks that are long-running or never-ending (development servers, etc), or
won't run builds that should be. Be sure to audit each task after migration!
<project>- Name of a project, as defined in
When running a script within another script, the full invocation of
npm run ...,
pnpm run ..., or
yarn run ...must be used. Shorthand variants are not supported, for example,
pnpm format. We cannot guarantee that moon will parse these correctly otherwise.package.json
"lint": "eslint .",
- "lint:fix": "yarn lint --fix",
+ "lint:fix": "yarn run lint --fix",
Scripts that run multiple commands with the AND operator (
&&) will create an individual transient task for each command, with all tasks linked in-order using task
deps. These commands will not run in parallel. For example, given the following script:package.json
"check": "yarn run lint && yarn run test && yarn run typecheck"
Would create 3 tasks that create the dependency chain:
check-dep1 (lint) -> check-dep2 (test) -> check (typecheck), instead of the expected parallel execution of
lint | test | typecheck -> check. If you would prefer these commands to run in parallel, then you'll need to craft your tasks manually.
Scripts that change directory (
cd ...), use pipes (
|), redirects (
>), or the OR operator (
||) are not supported and will be skipped. Tasks and scripts are not 1:1 in functionality, as tasks represent that state of a single command execution. However, you can wrap this functionality in a custom script that executes it on the task's behalf.
Life cycle scripts are not converted to tasks and will remain in
package.jsonsince they're required by npm (and other package managers). However, their commands will be updated to execute moon commands when applicable.package.json
- "preversion": "yarn run lint && yarn run test",
+ "preversion": "moon run project:lint && moon run project:test",
This does not apply to
"Post" life cycles for user defined scripts do not work, as moon tasks have no concept of "run this after the task completes", so we suggest against using these entirely. However, we still convert the script and include the base script as a task dependency.
For example, a
posttestscript would be converted into a
posttesttask, with the
testtask included in
deps. For this to actually run correctly, you'll need to use
moon run <project>:posttestAND NOT
moon run <project>:test.