From 8be69d41f5244c58b41ac7259a4d24665987f953 Mon Sep 17 00:00:00 2001 From: Favo Yang Date: Wed, 8 Jan 2020 23:50:54 +0800 Subject: [PATCH] fix: search command no longer query upstream Unity registry --- README.md | 2 +- lib/cmd-search.js | 10 ++++---- lib/core.js | 2 +- test/test-cmd-add.js | 8 +++--- test/test-cmd-deps.js | 8 +++--- test/test-cmd-search.js | 54 ----------------------------------------- test/test-cmd-view.js | 8 +++--- test/test-core.js | 2 +- 8 files changed, 20 insertions(+), 74 deletions(-) diff --git a/README.md b/README.md index 60b01d13..56408665 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ openupm search 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 ``` diff --git a/lib/cmd-search.js b/lib/cmd-search.js index bef38c42..09a75169 100644 --- a/lib/cmd-search.js +++ b/lib/cmd-search.js @@ -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()); diff --git a/lib/core.js b/lib/core.js index 32b8c2df..a356d737 100644 --- a/lib/core.js +++ b/lib/core.js @@ -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); diff --git a/test/test-cmd-add.js b/test/test-cmd-add.js index 691a019b..e056f2e0 100644 --- a/test/test-cmd-add.js +++ b/test/test-cmd-add.js @@ -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); diff --git a/test/test-cmd-deps.js b/test/test-cmd-deps.js index 340c39f2..3250e156 100644 --- a/test/test-cmd-deps.js +++ b/test/test-cmd-deps.js @@ -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); diff --git a/test/test-cmd-search.js b/test/test-cmd-search.js index e624c36a..15d40d58 100644 --- a/test/test-cmd-search.js +++ b/test/test-cmd-search.js @@ -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, @@ -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(); @@ -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() { diff --git a/test/test-cmd-view.js b/test/test-cmd-view.js index dd90845e..7025a733 100644 --- a/test/test-cmd-view.js +++ b/test/test-cmd-view.js @@ -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); diff --git a/test/test-core.js b/test/test-core.js index de7f529b..ec7c2bcd 100644 --- a/test/test-core.js +++ b/test/test-core.js @@ -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("");