Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

refactor: switch to @electron/get #59

Merged
merged 4 commits into from
May 8, 2020

Conversation

codebytere
Copy link
Contributor

@codebytere codebytere commented Apr 22, 2020

This PR updates gulp-atom-electron to use Electron's recommended @electron/get for simpler downloading and automatic caching. Some other benefits include the ability to download nightly releases as well as specify custom mirrors.

Tested locally with Electron versions v7.2.1 and v7.2.3 to confirm efficacy of change when running yarn electron in vscode itself.

cc @deepak1556

@deepak1556
Copy link
Collaborator

/cc @joaomoreno @bpasero

function download(opts, cb) {
var repo = opts.repo || 'atom/electron';
var github = new GitHub({ repo: repo, token: opts.token });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need to support this configuration for the internal builds.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see that we can specify a mirror, that should do the trick

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to do that?

@deepak1556
Copy link
Collaborator

Thanks for working on this @codebytere

@bpasero
Copy link
Contributor

bpasero commented Apr 22, 2020

Cool!

@joaomoreno
Copy link
Owner

@deepak1556 Would you like to drive this PR's adoption in VS Code? I've invited you as a collaborator.

@deepak1556
Copy link
Collaborator

Thanks @joaomoreno , would be happy to do it.

@joaomoreno
Copy link
Owner

Another idea @bpasero and I just discussed about: how about just dropping this? Do we still need this module at all?

@bpasero
Copy link
Contributor

bpasero commented Apr 22, 2020

I was referring to https://github.com/electron-userland/electron-forge in the standup today.

@codebytere
Copy link
Contributor Author

codebytere commented Apr 22, 2020

What do you all envision the alternate path looking like, should we choose to take it? I'm happy to switch up my approach or try to PR something into vscode itself

@joaomoreno
Copy link
Owner

@codebytere No, no, this was more of a comment for us, VS Code team.

@codebytere
Copy link
Contributor Author

👋 hey folks, is there anything i can do to help move this PR forward this week?

@deepak1556
Copy link
Collaborator

@codebytere last week was testing in vscode during which the master branch will be frozen, I plan to move this forward tomorrow.

src/download.js Outdated Show resolved Hide resolved
src/download.js Show resolved Hide resolved
src/download.js Outdated Show resolved Hide resolved
src/download.js Outdated Show resolved Hide resolved
src/util.js Outdated Show resolved Hide resolved
src/util.js Outdated Show resolved Hide resolved
src/util.js Outdated Show resolved Hide resolved
@deepak1556
Copy link
Collaborator

Thanks @codebytere for the fast turnaround, the following changes are also needed

diff --git a/src/download.js b/src/download.js
index f408555..5363fdd 100644
--- a/src/download.js
+++ b/src/download.js
@@ -1,7 +1,8 @@
 'use strict';
 
 var path = require('path');
-const { downloadArtifact, getDownloadUrl } = require('@electron/get');
+const { downloadArtifact } = require('@electron/get');
+const { getDownloadUrl } = require('./util')
 var semver = require('semver');
 var rename = require('gulp-rename');
 var es = require('event-stream');
@@ -31,15 +32,20 @@ function download(opts, cb) {
 		version: opts.version,
 		platform: opts.platform,
 		arch,
-		token
+		token: opts.token
 	};
 
 	if (opts.repo) {
 		getDownloadUrl(opts.repo, downloadOptions)
-		.then(({err, downloadUrl}) => {
+		.then(({err, downloadUrl, assetName}) => {
 			if (err) return cb(err)
 	
-			downloadOptions['mirrorOptions'] = { mirror: downloadUrl }
+			downloadOptions['mirrorOptions'] = {
+				mirror: downloadUrl,
+				customFilename: assetName
+			};
+			downloadOptions['artifactName'] = assetName;
+			downloadOptions['unsafelyDisableChecksums'] = true;
 	
 			downloadArtifact(downloadOptions).then(zipFilePath => {
 				return cb(null, zipFilePath)
diff --git a/src/util.js b/src/util.js
index 54499fa..2ace0fb 100644
--- a/src/util.js
+++ b/src/util.js
@@ -7,8 +7,8 @@ function startsWith (haystack, needle) {
 	return haystack.substr(0, needle.length) === needle;
 };
 
-async function getDownloadUrl(repo, { version, platform, arch, token }) {
-	const [owner, repo] = repo.split('/');
+async function getDownloadUrl(repo_url, { version, platform, arch, token }) {
+	const [owner, repo] = repo_url.split('/');
 	const octokit = new Octokit({ auth: token });
 
 	const { data: release } = await octokit.repos.getReleaseByTag({
@@ -46,7 +46,7 @@ async function getDownloadUrl(repo, { version, platform, arch, token }) {
 	});
 
 	const { url, headers } = requestOptions;
-  headers.authorization = `token ${token}`;
+	headers.authorization = `token ${token}`;
 
 	const response = await got(url, {
 		followRedirect: false,
@@ -54,7 +54,7 @@ async function getDownloadUrl(repo, { version, platform, arch, token }) {
 		headers
 	});
 
-	return { error: null, location: response.headers.location };
+	return { error: null, location: response.headers.location, assetName: asset.name };
 }
 
 module.exports = {

@deepak1556
Copy link
Collaborator

deepak1556 commented May 6, 2020

features from the previous version are preserved now,

  • Caching
  • downloads from custom repo

There are two issues that still needs addressing

  • the artifact filename in the cache folder has mangled various names together and looks like
    httpsgithub.comelectronelectronreleasesdownloadv7.2.4electron-v7.2.4-darwin-x64.zip when downloaded from custom repo

  • Although the default behavior is to display progress bar only if the download is greater than 30s , which is mostly not the case here as I don't see it in my testing. I would still like some feedback when its less than 30s.

@codebytere codebytere force-pushed the swap-to-electron-get branch 2 times, most recently from 99a2415 to d9a070a Compare May 6, 2020 20:28
Copy link
Collaborator

@deepak1556 deepak1556 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with minor style changes.

package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
src/download.js Outdated Show resolved Hide resolved
src/download.js Outdated Show resolved Hide resolved
src/download.js Outdated Show resolved Hide resolved
@codebytere codebytere force-pushed the swap-to-electron-get branch 2 times, most recently from 9708956 to e582f5e Compare May 7, 2020 03:44
src/download.js Outdated Show resolved Hide resolved
src/download.js Outdated Show resolved Hide resolved
Copy link
Collaborator

@deepak1556 deepak1556 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working through my review 😄

Good to go now. @joaomoreno if you can make a new release, will adopt this in VSCode. Thanks!

@deepak1556 deepak1556 merged commit 93e6619 into joaomoreno:master May 8, 2020
deepak1556 added a commit that referenced this pull request Aug 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants