Skip to content

Commit

Permalink
fix: #1 command add resolves all dependencies to add to scope registry
Browse files Browse the repository at this point in the history
  • Loading branch information
favoyang committed Jan 8, 2020
1 parent dce296e commit 3b603be
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 150 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ The tool is designed to work with [the OpenUPM registry](https://openupm.com), b

## How it works

The cli adds the 3rd-party registry as a scoped registry, and maintain the scopes and dependencies fields when adding/removing packages. If manifest file is modified, unity package manager will detect it and try to resolve the changes.
The command line tool installs the 3rd-party registry as a scoped registry, and maintains the `Packages/manifest.json` file when adding/removing packages. If the manifest file is modified, the *Unity Package Manager* will detect the changes and try to resolve the package dependencies.

Notice that the cli does not directly resolve dependencies or install/uninstall package tarballs, at least not for now.
> Notice: the command line tool does not directly install/uninstall package tarballs, at least for now.
## Installation

Expand Down Expand Up @@ -60,7 +60,9 @@ openupm add <pkg>@git@github.com:...
openupm add <pkg>@https://github.com/...
openupm add <pkg>@file:...
```
Notice: openupm will not verify package name for git, https and file protocol.
The package itself and all dependencies that exist in the registry will be served by the scope registry.

> Notice: openupm will not verify package or resolve dependencies for git, https and file protocol.
### Remove packages
```
Expand Down
30 changes: 24 additions & 6 deletions lib/cmd-add.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const _ = require("lodash");
const log = require("./logger");
const url = require("url");
const {
env,
fetchPackageInfo,
fetchPackageDependencies,
getLatestVersion,
loadManifest,
parseEnv,
Expand Down Expand Up @@ -34,6 +36,8 @@ const _add = async function(pkg) {
let useUpstream = false;
// parse name
let { name, version } = parseName(pkg);
// packages that added to scope registry
const pkgsInScope = [];
const isGitOrLocal =
version &&
(version.startsWith("git") ||
Expand All @@ -59,6 +63,18 @@ const _add = async function(pkg) {
log.info(`${versions.reverse().join(", ")}`);
return { code: 1, dirty };
}
// pkgsInScope
if (!useUpstream) {
const pkgs = await fetchPackageDependencies({
name,
version,
deep: true
});
pkgs
.filter(x => !x.upstream && !x.module)
.map(x => x.name)
.forEach(name => pkgsInScope.push(name));
} else pkgsInScope.push(name);
}
// load manifest
let manifest = loadManifest();
Expand Down Expand Up @@ -100,13 +116,15 @@ const _add = async function(pkg) {
dirty = true;
}
let entry = manifest.scopedRegistries.filter(filterEntry)[0];
// scopes
// apply pkgsInScope
let scopesSet = new Set(entry.scopes || []);
if (!scopesSet.has(name)) {
scopesSet.add(name);
dirty = true;
}
scopesSet.add(env.namespace);
pkgsInScope.push(env.namespace);
pkgsInScope.forEach(name => {
if (!scopesSet.has(name)) {
scopesSet.add(name);
dirty = true;
}
});
entry.scopes = Array.from(scopesSet).sort();
}
// save manifest
Expand Down
Loading

0 comments on commit 3b603be

Please sign in to comment.