From 7d783657203d9058c29b7e91c5c1ec2156e11b1f Mon Sep 17 00:00:00 2001 From: confused-Techie Date: Thu, 7 Sep 2023 19:53:50 -0700 Subject: [PATCH 1/6] Avoid hitting the API for packages if they are bundled --- packages/settings-view/lib/package-card.js | 52 +++++++++++++--------- src/atom-environment.js | 3 +- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/packages/settings-view/lib/package-card.js b/packages/settings-view/lib/package-card.js index 15845201cd..6b31a5059c 100644 --- a/packages/settings-view/lib/package-card.js +++ b/packages/settings-view/lib/package-card.js @@ -280,31 +280,39 @@ export default class PackageCard { } loadCachedMetadata () { - this.client.avatar(ownerFromRepository(this.pack.repository), (err, avatarPath) => { - if (!err && avatarPath) { - this.refs.avatar.src = `file://${avatarPath}` - } - }) - - this.client.package(this.pack.name, (err, data) => { - // We don't need to actually handle the error here, we can just skip - // showing the download count if there's a problem. - if (!err) { - if (data == null) { - data = {} + if (this.pack.repository === atom.branding.urlCoreRepo) { + // Don't hit the web for our bundled packages. Just use the local image. + this.refs.avatar.src = `file://${path.join(process.execPath, "..", "resources", "pulsar.png")}`; + } else { + this.client.avatar(ownerFromRepository(this.pack.repository), (err, avatarPath) => { + if (!err && avatarPath) { + this.refs.avatar.src = `file://${avatarPath}` } + }) + } - if (this.pack.apmInstallSource && this.pack.apmInstallSource.type === 'git') { - this.refs.downloadIcon.classList.remove('icon-cloud-download') - this.refs.downloadIcon.classList.add('icon-git-branch') - this.refs.downloadCount.textContent = this.pack.apmInstallSource.sha.substr(0, 8) - } else { - - this.refs.stargazerCount.textContent = data.stargazers_count ? parseInt(data.stargazers_count).toLocaleString() : '' - this.refs.downloadCount.textContent = data.downloads ? parseInt(data.downloads).toLocaleString() : '' + // We don't want to hit the API for this data, if it's a bundled package + if (this.pack.repository !== atom.branding.urlCoreRepo) { + this.client.package(this.pack.name, (err, data) => { + // We don't need to actually handle the error here, we can just skip + // showing the download count if there's a problem. + if (!err) { + if (data == null) { + data = {} + } + + if (this.pack.apmInstallSource && this.pack.apmInstallSource.type === 'git') { + this.refs.downloadIcon.classList.remove('icon-cloud-download') + this.refs.downloadIcon.classList.add('icon-git-branch') + this.refs.downloadCount.textContent = this.pack.apmInstallSource.sha.substr(0, 8) + } else { + + this.refs.stargazerCount.textContent = data.stargazers_count ? parseInt(data.stargazers_count).toLocaleString() : '' + this.refs.downloadCount.textContent = data.downloads ? parseInt(data.downloads).toLocaleString() : '' + } } - } - }) + }) + } } updateInterfaceState () { diff --git a/src/atom-environment.js b/src/atom-environment.js index 13682f3e76..cf20b2c870 100644 --- a/src/atom-environment.js +++ b/src/atom-environment.js @@ -222,7 +222,8 @@ class AtomEnvironment { name: packagejson.branding.name, urlWeb: packagejson.branding.urlWeb, urlGH: packagejson.branding.urlGH, - urlForum: packagejson.branding.urlForum + urlForum: packagejson.branding.urlForum, + urlCoreRepo: packagejson.repository.url }; // Keep instances of HistoryManager in sync From 07b50d9751526b7432aac110ecf008ff7f812e6a Mon Sep 17 00:00:00 2001 From: confused_techie Date: Mon, 11 Sep 2023 07:57:26 -0700 Subject: [PATCH 2/6] Remove `.git` from `repository.url` in the `package.json` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a85921a742..bf7430237d 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "main": "./src/main-process/main.js", "repository": { "type": "git", - "url": "https://github.com/pulsar-edit/pulsar.git" + "url": "https://github.com/pulsar-edit/pulsar" }, "bugs": { "url": "https://github.com/pulsar-edit/pulsar/issues" From 7312ae4f8301c509b7dd512c2a176ba7b440738a Mon Sep 17 00:00:00 2001 From: confused_techie Date: Mon, 11 Sep 2023 08:58:40 -0700 Subject: [PATCH 3/6] Import path correctly --- packages/settings-view/lib/package-card.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/settings-view/lib/package-card.js b/packages/settings-view/lib/package-card.js index 6b31a5059c..4affeb3676 100644 --- a/packages/settings-view/lib/package-card.js +++ b/packages/settings-view/lib/package-card.js @@ -5,6 +5,7 @@ import {CompositeDisposable, Disposable} from 'atom' import {shell} from 'electron' import etch from 'etch' import BadgeView from './badge-view' +import path from 'path' import {ownerFromRepository} from './utils' From b79644e90b2e271c46b798ecad2ad4a659ec2567 Mon Sep 17 00:00:00 2001 From: confused_techie Date: Thu, 14 Sep 2023 22:40:26 -0700 Subject: [PATCH 4/6] Update packages/settings-view/lib/package-card.js Co-authored-by: DeeDeeG --- packages/settings-view/lib/package-card.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/settings-view/lib/package-card.js b/packages/settings-view/lib/package-card.js index 4affeb3676..f19f4eba95 100644 --- a/packages/settings-view/lib/package-card.js +++ b/packages/settings-view/lib/package-card.js @@ -283,7 +283,7 @@ export default class PackageCard { loadCachedMetadata () { if (this.pack.repository === atom.branding.urlCoreRepo) { // Don't hit the web for our bundled packages. Just use the local image. - this.refs.avatar.src = `file://${path.join(process.execPath, "..", "resources", "pulsar.png")}`; + this.refs.avatar.src = `file://${path.join(process.resourcesPath, "pulsar.png")}`; } else { this.client.avatar(ownerFromRepository(this.pack.repository), (err, avatarPath) => { if (!err && avatarPath) { From 5dec09add06e3ac87e4dd727b032f90e71d746f1 Mon Sep 17 00:00:00 2001 From: confused-Techie Date: Thu, 14 Sep 2023 23:43:57 -0700 Subject: [PATCH 5/6] Use helper function to ensure we always get repository URL --- packages/settings-view/lib/package-card.js | 4 ++-- packages/settings-view/lib/utils.js | 14 +++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/settings-view/lib/package-card.js b/packages/settings-view/lib/package-card.js index f19f4eba95..76cf45a0b3 100644 --- a/packages/settings-view/lib/package-card.js +++ b/packages/settings-view/lib/package-card.js @@ -7,7 +7,7 @@ import etch from 'etch' import BadgeView from './badge-view' import path from 'path' -import {ownerFromRepository} from './utils' +import {ownerFromRepository, repoUrlFromRepository} from './utils' let marked = null @@ -281,7 +281,7 @@ export default class PackageCard { } loadCachedMetadata () { - if (this.pack.repository === atom.branding.urlCoreRepo) { + if (repoUrlFromRepository(this.pack.repository) === atom.branding.urlCoreRepo) { // Don't hit the web for our bundled packages. Just use the local image. this.refs.avatar.src = `file://${path.join(process.resourcesPath, "pulsar.png")}`; } else { diff --git a/packages/settings-view/lib/utils.js b/packages/settings-view/lib/utils.js index 0bd3c4b8e3..e3fcb8585c 100644 --- a/packages/settings-view/lib/utils.js +++ b/packages/settings-view/lib/utils.js @@ -19,6 +19,18 @@ const ownerFromRepository = repository => { return match ? match[1] : '' } +const repoUrlFromRepository = repository => { + if (!repository) return '' + + if (typeof repository === 'string') { + return repository + } else if (typeof repository === 'object' && typeof repository.url === 'string') { + return repository.url + } else { + return '' + } +} + const packageComparatorAscending = (left, right) => { const leftStatus = atom.packages.isPackageDisabled(left.name) const rightStatus = atom.packages.isPackageDisabled(right.name) @@ -37,4 +49,4 @@ const packageComparatorAscending = (left, right) => { } } -module.exports = {ownerFromRepository, packageComparatorAscending} +module.exports = {ownerFromRepository, repoUrlFromRepository, packageComparatorAscending} From 9e94ca1b6c4df2f564f843f044c58a5a0252787b Mon Sep 17 00:00:00 2001 From: confused-Techie Date: Fri, 15 Sep 2023 00:04:04 -0700 Subject: [PATCH 6/6] Ensure we strip the repo of `.git` --- packages/settings-view/lib/utils.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/settings-view/lib/utils.js b/packages/settings-view/lib/utils.js index e3fcb8585c..70974cacf2 100644 --- a/packages/settings-view/lib/utils.js +++ b/packages/settings-view/lib/utils.js @@ -22,13 +22,21 @@ const ownerFromRepository = repository => { const repoUrlFromRepository = repository => { if (!repository) return '' + let repo = repository + if (typeof repository === 'string') { - return repository + repo = repository } else if (typeof repository === 'object' && typeof repository.url === 'string') { - return repository.url + repo = repository.url } else { - return '' + repo = '' } + + if (repo.endsWith('.git')) { + repo = repo.replace('.git', '') + } + + return repo } const packageComparatorAscending = (left, right) => {