-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds the list command. It behaves like calling npm ls without an argument and lists all installed dependencies. See #351
- Loading branch information
1 parent
2403878
commit dbfac8c
Showing
5 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
# `openupm ls` | ||
|
||
The `ls` command prints the name and version of each installed package for a project. | ||
|
||
This command has the `list` alias. On this doc page we will always use the primary command name `ls`. | ||
|
||
## Options | ||
|
||
### Project directory | ||
|
||
By default openupm expects that you run the add command inside your Unity projects root directory. Based on this it determines relative paths to your package manifest etc. | ||
|
||
If you need to run openupm from somewhere else you can change the working directory using the `--chdir`/`-c` option. This option accepts an **absolute** path to a Unity projects root directory. | ||
|
||
```sh | ||
openupm add com.my.package -c /home/user/dev/MyProject | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Command } from "@commander-js/extra-typings"; | ||
import { Logger } from "npmlog"; | ||
import { loadProjectManifestUsing } from "../app/get-dependencies"; | ||
import { partialApply } from "../domain/fp-utils"; | ||
import type { DebugLog } from "../domain/logging"; | ||
import { makePackageSpec } from "../domain/package-spec"; | ||
import { recordEntries } from "../domain/record-utils"; | ||
import type { ReadTextFile } from "../io/fs"; | ||
import { withErrorLogger } from "./error-logging"; | ||
import { workDirOpt } from "./opt-wd"; | ||
|
||
/** | ||
* Makes the `openupm ls` cli command with the given dependencies. | ||
* @param readTextFile IO function for reading a text file. | ||
* @param debugLog IO function for debug-logs. | ||
* @param log Logger for cli output. | ||
* @returns The command. | ||
*/ | ||
export function makeLsCmd( | ||
readTextFile: ReadTextFile, | ||
debugLog: DebugLog, | ||
log: Logger | ||
) { | ||
const getDependencies = partialApply( | ||
loadProjectManifestUsing, | ||
readTextFile, | ||
debugLog | ||
); | ||
|
||
return new Command("ls") | ||
.aliases(["list"]) | ||
.summary("list all currently installed packages") | ||
.description( | ||
`Print the names and versions of all installed packages. | ||
openupm ls` | ||
) | ||
.addOption(workDirOpt) | ||
.action( | ||
withErrorLogger(log, async function (options) { | ||
const projectDirectory = options.chdir; | ||
const manifest = await getDependencies(projectDirectory); | ||
|
||
const dependencies = recordEntries(manifest.dependencies ?? {}); | ||
|
||
dependencies.forEach(([name, version]) => { | ||
log.notice("", makePackageSpec(name, version)); | ||
}); | ||
}) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { ResultCodes } from "../../src/cli/result-codes"; | ||
import { buildProjectManifest } from "../common/data-project-manifest"; | ||
import { runOpenupm } from "./run"; | ||
import { prepareHomeDirectory } from "./setup/directories"; | ||
import { prepareUnityProject } from "./setup/project"; | ||
|
||
describe("list installed packages", () => { | ||
test("should list installed packages", async () => { | ||
const homeDirectory = await prepareHomeDirectory(); | ||
const projectDirectory = await prepareUnityProject(homeDirectory, { | ||
manifest: buildProjectManifest((manifest) => | ||
manifest | ||
.addDependency("dev.comradevanti.opt-unity", "2.0.0", true, true) | ||
.addDependency("com.unity.ugui", "1.0.0", true, false) | ||
), | ||
}); | ||
|
||
const result = await runOpenupm(projectDirectory, ["ls"]); | ||
|
||
expect(result.code).toEqual(ResultCodes.Ok); | ||
expect(result.stdErr).toEqual( | ||
expect.arrayContaining([ | ||
expect.stringContaining("dev.comradevanti.opt-unity@2.0.0"), | ||
expect.stringContaining("com.unity.ugui@1.0.0"), | ||
]) | ||
); | ||
}); | ||
}); |