Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save cache to standard directory #37

Merged
merged 10 commits into from
Mar 30, 2017
Merged

Save cache to standard directory #37

merged 10 commits into from
Mar 30, 2017

Conversation

Siilwyn
Copy link
Contributor

@Siilwyn Siilwyn commented Oct 15, 2016

The cache is saved to a standard cache directory using the "env-paths"
module, rather than saving in the home directory.
The old cache directory will automatically be migrated to the new
location.

BREAKING CHANGE: Cache is no longer stored in ~/.electron.

@Siilwyn
Copy link
Contributor Author

Siilwyn commented Nov 4, 2016

The failing tests do not seem related to this but have to do with older Node.js versions. Maybe bundle this change with removing 0.10 and 0.12 support and then do a major version bump?

@malept
Copy link
Member

malept commented Nov 17, 2016

Maybe bundle this change with removing 0.10 and 0.12 support and then do a major version bump?

Removing Node 0.12 support won't happen until LTS is over for that series. I learned that the hard way.

@malept
Copy link
Member

malept commented Nov 17, 2016

I don't suppose there is an env-paths version (or similar module) that has Node 0.12 support?

@Siilwyn
Copy link
Contributor Author

Siilwyn commented Nov 17, 2016

Unfortunately not, it's ES6 from the start. :*)
I can make a compatible one very easily or we have to wait for next year, your call...

@malept
Copy link
Member

malept commented Nov 17, 2016

Personally, I'm OK with waiting. In the meantime though, is it possible to add tests, particularly for the cache directory migration behavior?

@Siilwyn
Copy link
Contributor Author

Siilwyn commented Nov 20, 2016

Great idea, I discovered my implementation only to be working partially! Now it's all good, added a test. 💡

Copy link
Member

@malept malept left a comment

Choose a reason for hiding this comment

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

I have a few conceptual questions, aside from the CI failure.

lib/index.js Outdated
@@ -37,7 +38,8 @@ class ElectronDownloader {
}

get cache () {
return this.opts.cache || path.join(homePath(), './.electron')
// use passed argument or XDG environment variable fallback to OS default
return this.opts.cache || envPaths('electron-download', {suffix: ''}).cache
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if it should be electron rather than electron-download.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure since this is for the module electron-download thought it would make sense to name it like that... But since it's for electron it might make sense to name it like that.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, ultimately the electron module uses this. Now that you've reminded me, it's worth documenting where the default cache directory is on Windows/macOS/Linux in the README.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, added locations to the readme and renamed it to 'electron'.

test/test.js Outdated
@@ -15,3 +17,27 @@ test('Basic test', (t) => {
t.end()
})
})

test('Cache directory is moved to new location', (t) => {
// Download to old cache directory location
Copy link
Member

Choose a reason for hiding this comment

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

I don't know whether this is the right way to write this test. Perhaps if the user specifies a custom cache directory, the migration code shouldn't be triggered.

Regardless of the decision reached for the above question, I think a better test would be:

  1. Create $HOME/.electron if it doesn't exist, and put a temporary file in that folder
  2. Invoke download()
  3. Assert that the temporary file exists in the new default cache directory
  4. Delete temporary file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤔 It's only temporary code though just for migrating, after some time it will be removed... Already spent a lot of time on it, apart from cleaning up the file it does the same as the steps you proposed right?

Thoughts on how important this is? Not saying I don't want to do it at all but I'm just considering the time it costs versus value that comes out of it.

Copy link
Member

Choose a reason for hiding this comment

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

I don't know about "temporary". I think the migration code is going to stick around for at least six months after release, since not everyone immediately upgrades.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So ...? Apart from cleaning up the file it does the same as the steps you proposed right?

Copy link
Member

Choose a reason for hiding this comment

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

I would prefer it if it was more explicit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright will rewrite it a bit then.

@malept
Copy link
Member

malept commented Dec 12, 2016

FWIW, cachedir provides the same functionality (as of today 😄) and works on Node < 4.

@Siilwyn
Copy link
Contributor Author

Siilwyn commented Dec 12, 2016

Think env-paths is a better fit because it's used in more modules which has multiple advantages. Also a module to only return a path to the cache directory is a bit too minimal for my taste. Thanks for the heads-up though! 2016-12-31 is almost there! :-)

@odensc
Copy link

odensc commented Dec 23, 2016

Just checking, is this scheduled to be merged once 0.12 is no longer supported (end of the month)?

@malept
Copy link
Member

malept commented Dec 24, 2016

That's my plan, unless one of the other maintainers has concerns.

test/test.js Outdated
@@ -15,3 +19,31 @@ test('Basic test', (t) => {
t.end()
})
})

test.only('Cache directory is moved to new location', (t) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This .only call should be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops, fixed. :D

@malept
Copy link
Member

malept commented Jan 11, 2017

@Siilwyn There seems to be a merge conflict.

(If you're wondering why this hasn't gotten merged yet, aside from the merge conflict, the Electron maintainers are taking removal of Node version support very seriously, because this affects the electron module on NPM, and a fair amount of discussion has been generated. We'll know more next week.)

@odensc
Copy link

odensc commented Jan 11, 2017

Another alternative is using a module compatible with Node 0.12, if the maintainers don't feel comfortable removing support.

@malept
Copy link
Member

malept commented Jan 11, 2017

@TheSBros I mentioned a 0.12-compatible module in #37 (comment), with the response right below it.

@Siilwyn
Copy link
Contributor Author

Siilwyn commented Jan 11, 2017

Hey also tuning in. :)
Let's await next week's outcome. I hope they choose to move forward and leave 0.12 behind us, I also suggested writing a 0.12 compatible module earlier. However I think it's better to depend on a wildly used module.

The cache is saved to a standard cache directory using the "env-paths"
module, rather than saving in the home directory.
The old cache directory will automatically be migrated to the new
location.

Resolves #24

BREAKING CHANGE: Cache is no longer stored in `~/.electron`.
@Siilwyn
Copy link
Contributor Author

Siilwyn commented Jan 11, 2017

Ugh, just tried rebasing, every commit gives a different merge conflict.
Will look into it later again, reverted the rebase for now.

@Siilwyn
Copy link
Contributor Author

Siilwyn commented Jan 19, 2017

Not sure if I did or not but it seems there are no conflicts with master anymore. :)

Any news from the discussion?

@malept
Copy link
Member

malept commented Jan 19, 2017

Maintainer update: discussion is still ongoing, I expect to have more information next week.

@Siilwyn
Copy link
Contributor Author

Siilwyn commented Jan 19, 2017

Alright, thanks for the quick reply @malept !

@Siilwyn
Copy link
Contributor Author

Siilwyn commented Feb 2, 2017

Any update? Can I read the discussion anywhere or is it a closed discussion?

@malept
Copy link
Member

malept commented Feb 2, 2017

@Siilwyn
We've agreed to move to drop Node < 4 support (an official announcement will hopefully be in the near future), and so I've opened #45 as a result.

During that discussion, we discussed this PR in particular. Some of the maintainers have reservations about accepting this from a conceptual point of view. @kevinsawicki or @zeke, could one of you chime in so I don't misconstrue what was said during the meeting?

@Siilwyn
Copy link
Contributor Author

Siilwyn commented Mar 13, 2017

Any update on this?

@malept
Copy link
Member

malept commented Mar 13, 2017

@kevinsawicki ping

@Siilwyn
Copy link
Contributor Author

Siilwyn commented Mar 26, 2017

@kevinsawicki could you please review this again?

@kevinsawicki
Copy link
Contributor

could you please review this again?

I'm not a huge fan of moving a directory each time this runs. Other apps or libraries could be using ~/.electron and it would seem confusing and hard to track down why this directory is disappearing each time you npm install electron.

Could we instead just use ~/.electron as a fallback location if the file isn't in the new cache location and write any new files to the new location?

That way it would be backwards compatible still but we wouldn't have to worry about moving directories around.

@kevinsawicki
Copy link
Contributor

It also looks like there are conflicts here as well that need to be resolved.

@Siilwyn
Copy link
Contributor Author

Siilwyn commented Mar 29, 2017

Sounds good to me, will remove the migration code and when I have some time later this week I'll add the fallback logic.

I don't want to be pointing fingers and get negative but would really like to get this off my chest: the migration of the directory was suggested to me and I spent a lot of time getting that working and covered by a test. Solving the merge conflicts is something that happened multiple times now on this PR because of the slow responses. Overall it would be beneficial for 'other' contributors if core contributors are on one line.

@zeke
Copy link

zeke commented Mar 29, 2017

Sorry to leave this hanging for so long @Siilwyn, and thank you for patiently rebasing and making suggested changes.

I see one failure on Travis:

not ok 17 Zip path should end with -dsym.zip
  ---
    operator: ok
    expected: true
    actual:   false
    at: download (/Users/travis/build/electron-userland/electron-download/test/test_dsym.js:16:7)

@Siilwyn
Copy link
Contributor Author

Siilwyn commented Mar 30, 2017

Thank you for your reply Zeke, I just added some fallback code all tests are passing now!

readme.md Outdated
@@ -25,7 +25,7 @@ download({
version: '0.25.1',
arch: 'ia32',
platform: 'win32',
cache: './zips' // defaults to <user's home directory>/.electron
cache: './zips' // defaults to <user's cache directory>/electron-download
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be defaults to <user's cache directory>/electron instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, sharp eye!
This is a leftover from before the 'Cache location' section got added so I removed it as it's duplicate.

@kevinsawicki kevinsawicki merged commit e1a1fe0 into electron:master Mar 30, 2017
@kevinsawicki
Copy link
Contributor

Thanks for this @Siilwyn, apologies for the mixed signals, and appreciate the resiliency 👍 🚀

@Siilwyn
Copy link
Contributor Author

Siilwyn commented Apr 2, 2017

Nice to see this getting merged! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants