-
-
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.
feat: command deps to view dependencies
- Loading branch information
Showing
5 changed files
with
288 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
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,21 @@ | ||
const log = require("./logger"); | ||
const { fetchPackageDependencies, parseEnv, parseName } = require("./core"); | ||
|
||
const deps = async function(pkg, options) { | ||
// parse env | ||
if (!parseEnv(options, { checkPath: false })) return 1; | ||
// parse name | ||
let { name, version } = parseName(pkg); | ||
// deps | ||
await _deps({ name, version, deep: options.deep }); | ||
return 0; | ||
}; | ||
|
||
const _deps = async function({ name, version, deep }) { | ||
const results = await fetchPackageDependencies({ name, version, deep }); | ||
results | ||
.filter(x => !x.self) | ||
.forEach(x => log.info(`- ${x.name}@${x.version}`)); | ||
}; | ||
|
||
module.exports = deps; |
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,153 @@ | ||
/* eslint-disable no-unused-vars */ | ||
/* eslint-disable no-undef */ | ||
const assert = require("assert"); | ||
const nock = require("nock"); | ||
const should = require("should"); | ||
const { parseEnv, loadManifest } = require("../lib/core"); | ||
const deps = require("../lib/cmd-deps"); | ||
const { | ||
getWorkDir, | ||
createWorkDir, | ||
removeWorkDir, | ||
captureStream, | ||
nockUp, | ||
nockDown | ||
} = require("./utils"); | ||
|
||
describe("cmd-deps.js", function() { | ||
const options = { | ||
parent: { | ||
registry: "http://example.com", | ||
chdir: getWorkDir("test-openupm-cli") | ||
} | ||
}; | ||
describe("deps", function() { | ||
let stdout; | ||
let stderr; | ||
const remotePkgInfoA = { | ||
name: "com.example.package-a", | ||
versions: { | ||
"1.0.0": { | ||
name: "com.example.package-a", | ||
version: "1.0.0", | ||
dependencies: { | ||
"com.example.package-b": "1.0.0" | ||
} | ||
} | ||
}, | ||
"dist-tags": { | ||
latest: "1.0.0" | ||
} | ||
}; | ||
const remotePkgInfoB = { | ||
name: "com.example.package-b", | ||
versions: { | ||
"1.0.0": { | ||
name: "com.example.package-b", | ||
version: "1.0.0", | ||
dependencies: { | ||
"com.example.package-up": "1.0.0" | ||
} | ||
} | ||
}, | ||
"dist-tags": { | ||
latest: "1.0.0" | ||
} | ||
}; | ||
const remotePkgInfoUp = { | ||
name: "com.example.package-up", | ||
versions: { | ||
"1.0.0": { | ||
name: "com.example.package-up", | ||
version: "1.0.0", | ||
dependencies: {} | ||
} | ||
}, | ||
"dist-tags": { | ||
latest: "1.0.0" | ||
} | ||
}; | ||
beforeEach(function() { | ||
removeWorkDir("test-openupm-cli"); | ||
createWorkDir("test-openupm-cli", { manifest: true }); | ||
nockUp(); | ||
nock("http://example.com") | ||
.get("/com.example.package-a") | ||
.reply(200, remotePkgInfoA, { "Content-Type": "application/json" }); | ||
nock("http://example.com") | ||
.get("/com.example.package-b") | ||
.reply(200, remotePkgInfoB, { "Content-Type": "application/json" }); | ||
nock("http://example.com") | ||
.get("/pkg-not-exist") | ||
.reply(404); | ||
nock("http://example.com") | ||
.get("/com.example.package-up") | ||
.reply(404); | ||
nock("https://api.bintray.com") | ||
.get("/npm/unity/unity/com.example.package-up") | ||
.reply(200, remotePkgInfoUp, { | ||
"Content-Type": "application/json" | ||
}); | ||
nock("https://api.bintray.com") | ||
.get("/npm/unity/unity/pkg-not-exist") | ||
.reply(404); | ||
stdout = captureStream(process.stdout); | ||
stderr = captureStream(process.stderr); | ||
}); | ||
afterEach(function() { | ||
removeWorkDir("test-openupm-cli"); | ||
nockDown(); | ||
stdout.unhook(); | ||
stderr.unhook(); | ||
}); | ||
it("deps pkg", async function() { | ||
const retCode = await deps("com.example.package-a", options); | ||
retCode.should.equal(0); | ||
const stdoutContent = stdout.captured(); | ||
stdoutContent.includes("com.example.package-b").should.be.ok(); | ||
}); | ||
it("deps pkg --deep", async function() { | ||
const retCode = await deps("com.example.package-a", { | ||
...options, | ||
deep: true | ||
}); | ||
retCode.should.equal(0); | ||
const stdoutContent = stdout.captured(); | ||
stdoutContent.includes("com.example.package-b").should.be.ok(); | ||
stdoutContent.includes("com.example.package-up").should.be.ok(); | ||
}); | ||
it("deps pkg@latest", async function() { | ||
const retCode = await deps("com.example.package-a@latest", options); | ||
retCode.should.equal(0); | ||
const stdoutContent = stdout.captured(); | ||
stdoutContent.includes("com.example.package-b").should.be.ok(); | ||
}); | ||
it("deps [email protected]", async function() { | ||
const retCode = await deps("[email protected]", options); | ||
retCode.should.equal(0); | ||
const stdoutContent = stdout.captured(); | ||
stdoutContent.includes("com.example.package-b").should.be.ok(); | ||
}); | ||
it("deps pkg@not-exist-version", async function() { | ||
const retCode = await deps("[email protected]", options); | ||
retCode.should.equal(0); | ||
stderr | ||
.captured() | ||
.includes("is not a valid choice") | ||
.should.be.ok(); | ||
console.log(stdout.captured()); | ||
}); | ||
it("deps pkg-not-exist", async function() { | ||
const retCode = await deps("pkg-not-exist", options); | ||
retCode.should.equal(0); | ||
stderr | ||
.captured() | ||
.includes("package not found") | ||
.should.be.ok(); | ||
}); | ||
it("deps pkg upstream", async function() { | ||
const retCode = await deps("com.example.package-up", options); | ||
retCode.should.equal(0); | ||
}); | ||
}); | ||
}); |