Skip to content

Commit

Permalink
fix: search command no longer query upstream Unity registry
Browse files Browse the repository at this point in the history
  • Loading branch information
favoyang committed Jan 8, 2020
1 parent 483ad5a commit 8be69d4
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 74 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ openupm search <keyword>

If the registry doesn't support the new search endpoint, it will fall back to old `/-/all` endpoint. If no package was found, it will search unity official registry instead.

However the search behavior may still performance various for different registries. As of December 2019, unity official registry won't return any results unless the full package name was provided. Make it useless.
Due to the fact that upstream unity registry doesn't support search endpoint as of December 2019, the search command will only query the current registry.

### View package information
```
Expand Down
10 changes: 5 additions & 5 deletions lib/cmd-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ module.exports = async function(keyword, options) {
// search old search
if (!results) results = (await searchOld(keyword)) || [];
// search upstream
if (env.upstream) {
const upstreamResults =
(await searchEndpoint(keyword, env.upstreamRegistry)) || [];
results.push(...upstreamResults);
}
// if (env.upstream) {
// const upstreamResults =
// (await searchEndpoint(keyword, env.upstreamRegistry)) || [];
// results.push(...upstreamResults);
// }
if (results.length) {
results.forEach(x => table.push(x.slice(0, -1)));
log.info(table.toString());
Expand Down
2 changes: 1 addition & 1 deletion lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const parseEnv = function(options, { checkPath }) {
env.cwd = "";
env.manifestPath = "";
env.upstream = true;
env.upstreamRegistry = "https://api.bintray.com/npm/unity/unity";
env.upstreamRegistry = "https://packages.unity.com";
// log level
const logLevel = options.parent.verbose ? "debug" : "info";
log.setLevel(logLevel);
Expand Down
8 changes: 4 additions & 4 deletions test/test-cmd-add.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,13 @@ describe("cmd-add.js", function() {
nock("http://example.com")
.get("/com.example.package-up")
.reply(404);
nock("https://api.bintray.com")
.get("/npm/unity/unity/com.example.package-up")
nock("https://packages.unity.com")
.get("/com.example.package-up")
.reply(200, remotePkgInfoUp, {
"Content-Type": "application/json"
});
nock("https://api.bintray.com")
.get("/npm/unity/unity/pkg-not-exist")
nock("https://packages.unity.com")
.get("/pkg-not-exist")
.reply(404);
stdout = captureStream(process.stdout);
stderr = captureStream(process.stderr);
Expand Down
8 changes: 4 additions & 4 deletions test/test-cmd-deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ describe("cmd-deps.js", function() {
nock("http://example.com")
.get("/com.example.package-up")
.reply(404);
nock("https://api.bintray.com")
.get("/npm/unity/unity/com.example.package-up")
nock("https://packages.unity.com")
.get("/com.example.package-up")
.reply(200, remotePkgInfoUp, {
"Content-Type": "application/json"
});
nock("https://api.bintray.com")
.get("/npm/unity/unity/pkg-not-exist")
nock("https://packages.unity.com")
.get("/pkg-not-exist")
.reply(404);
stdout = captureStream(process.stdout);
stderr = captureStream(process.stderr);
Expand Down
54 changes: 0 additions & 54 deletions test/test-cmd-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,35 +75,6 @@ describe("cmd-search.js", function() {
total: 1,
time: "Sat Dec 07 2019 04:57:11 GMT+0000 (UTC)"
};
const searchEndpointUpstreamResult = {
objects: [
{
package: {
name: "com.example.package-up",
scope: "unscoped",
version: "1.0.0",
description: "A demo package",
date: "2019-10-02T04:02:38.335Z",
links: {},
author: { name: "yo", url: "/~https://github.com/yo" },
publisher: { username: "yo", email: "yo@example.com" },
maintainers: [{ username: "yo", email: "yo@example.com" }]
},
flags: { unstable: true },
score: {
final: 0.31065598947261,
detail: {
quality: 0.64303646684878,
popularity: 0.0034858628087645178,
maintenance: 0.3329285640997383
}
},
searchScore: 0.000005798558
}
],
total: 1,
time: "Sat Dec 07 2019 04:57:11 GMT+0000 (UTC)"
};
const searchEndpointEmptyResult = {
objects: [],
total: 0,
Expand All @@ -121,11 +92,6 @@ describe("cmd-search.js", function() {
.reply(200, searchEndpointEmptyResult, {
"Content-Type": "application/json"
});
nock("https://api.bintray.com")
.get(/npm\/unity\/unity\/-\/v1\/search/)
.reply(200, searchEndpointUpstreamResult, {
"Content-Type": "application/json"
});
});
afterEach(function() {
nockDown();
Expand Down Expand Up @@ -158,26 +124,6 @@ describe("cmd-search.js", function() {
.includes("No matches found")
.should.be.ok();
});
it("upstream", async function() {
const retCode = await search("package-a", upstreamOptions);
retCode.should.equal(0);
stdout
.captured()
.includes("package-up")
.should.be.ok();
stdout
.captured()
.includes("1.0.0")
.should.be.ok();
stdout
.captured()
.includes("yo")
.should.be.ok();
stdout
.captured()
.includes("2019-10-02")
.should.be.ok();
});
});

describe("old search", function() {
Expand Down
8 changes: 4 additions & 4 deletions test/test-cmd-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ describe("cmd-view.js", function() {
nock("http://example.com")
.get("/com.example.package-up")
.reply(404);
nock("https://api.bintray.com")
.get("/npm/unity/unity/com.example.package-up")
nock("https://packages.unity.com")
.get("/com.example.package-up")
.reply(200, remotePkgInfoUp, {
"Content-Type": "application/json"
});
nock("https://api.bintray.com")
.get("/npm/unity/unity/pkg-not-exist")
nock("https://packages.unity.com")
.get("/pkg-not-exist")
.reply(404);
stdout = captureStream(process.stdout);
stderr = captureStream(process.stderr);
Expand Down
2 changes: 1 addition & 1 deletion test/test-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe("cmd-core.js", function() {
env.registry.should.equal("https://package.openupm.com");
env.upstream.should.be.ok();
env.upstreamRegistry.should.equal(
"https://api.bintray.com/npm/unity/unity"
"https://packages.unity.com"
);
env.namespace.should.equal("com.openupm");
env.cwd.should.equal("");
Expand Down

0 comments on commit 8be69d4

Please sign in to comment.