Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

User configurable cache folder for binary download #1714

Merged
merged 1 commit into from
Oct 3, 2016

Conversation

nschonni
Copy link
Contributor

@nschonni nschonni commented Sep 9, 2016

New order of operations

  1. Look for existing binary in vendor folder
  2. Create target vendor folder
  3. Look to see if we’ve cached a copy in the configured or NPM cache
  4. Download to current version’s /CACHE/node-sass/version/binding_file
  5. Copy the cached download to the regular vendor directory

Closes #1566

@nschonni
Copy link
Contributor Author

nschonni commented Sep 9, 2016

@mriehema I think I figured out a version that will play nice with npm cache clean

@nschonni
Copy link
Contributor Author

nschonni commented Sep 9, 2016

@xzyfer here is what I tried for manual testing

  • Download/Install dev version when the version doesn't exist yet, then run a regular install overtop. OK
  • Install multiple times. OK
  • If you have a bad download, it just falls back to the build. OK
  • Run npm cache clean node-sass@3.9.3, verify the folder is empty, re-run install. OK

Not sure what automated tests can be setup for this one though

@nschonni
Copy link
Contributor Author

nschonni commented Sep 9, 2016

Arg, Node 0.10 support strikes again https://travis-ci.org/nschonni/node-sass/jobs/158644756#L308
Wonder if some of our other failures may be related, but swallowing the message

@mriehema
Copy link

mriehema commented Sep 9, 2016

@nschonni I will take a look the next days ASAP. Thank you for supporting my topic.

@xzyfer
Copy link
Contributor

xzyfer commented Sep 9, 2016

Using the npm cache was discussed (maybe offline, my bad). The problem is a lot of environments will clear the npm cache. This super common on CI and containers because the npm cache can cause weird side-effects between builds. So counter intuitively the places that would likely benefit the most from local binary caching wouldn't use it.

Caching the binaries in /tmp was nice because it isn't commonly clear, and it's easy for containerised/CI envs to opt-in to keeping it around without risking npm side effects.

My preference would be to have a location configurable using ENV vars like the rest of the binary download config. The npm config dir could be good default location, but I expect to really see much value you'd need to set it to something distinct from npm.

@xzyfer
Copy link
Contributor

xzyfer commented Sep 9, 2016

Wonder if some of our other failures may be related, but swallowing the message

No. This is a known limitation with cross-spawn. We just don't use sync. From their docs

If you are using spawnSync on node 0.10 or older, you will also need to install spawn-sync

@nschonni
Copy link
Contributor Author

nschonni commented Sep 9, 2016

Caching the binaries in /tmp was nice because it isn't commonly clear, and it's easy for containerised/CI envs to opt-in to keeping it around without risking npm side effects.

Containers would lose the TMP the same why as the NPM cache. CI wise-its the same logic as we currently use

- '%AppData%\npm-cache'
. The CI systems usually have their own settings now for keeping the project's node_modules, which means this won't hit either.

My preference would be to have a location configurable using ENV vars like the rest of the binary download config. The npm config dir could be good default location, but I expect to really see much value you'd need to set it to something distinct from npm.

That case already got covered by our other binary path options, this just adds resilincy for offline NPM installs without having an external setup.


That said, i'm not married to the approach, but I think this addresses the original concern in #1554 without adding more switches 😉

@nschonni
Copy link
Contributor Author

nschonni commented Sep 9, 2016

No. This is a known limitation with cross-spawn. We just don't use sync. From their docs

Thansk, I'll change my spawn to the async version, and replace the fs.existsSync since I didn't realize it was depricated.

@xzyfer
Copy link
Contributor

xzyfer commented Sep 9, 2016

Containers would lose the TMP the same why as the NPM cache

Correct, but to my point, containerised/CI envs can easily to opt-in to keeping it around without risking npm side effects. Keeping the npm cache around is much more troublesome so you want these two decoupled.

That case already got covered by our other binary path options

These don't provide the fallback to vendor which is the big win here. I would expect this to fallback to SASS_BINARY_PATH instead of our vendor because that's the semantics of SASS_BINARY_PATH.

without adding more switches

Sane defaults are always better than switches, but giving users the ability to do what's best for their environment via switches when the defaults aren't sane for them is necessary.

@nschonni
Copy link
Contributor Author

Sorry ignore the last push, it's not done yet. Forgot to set git config --global push.default current on this machine

@nschonni nschonni added this to the 3.11.0 milestone Sep 15, 2016
@nschonni nschonni changed the title Use NPM cache folder for binary download User configurable cache folder for binary download Sep 16, 2016
@nschonni
Copy link
Contributor Author

@xzyfer should be good to go now. The Appveyor failure seems like a weird unrelated npm issue where it can't find right version request for some reason.

  • cleared out the spawn stuff by using the same process.env lookup for the npm cache directory.
  • left in the fs.existsync for now since it is still used in a few places already.

Copy link

@mriehema mriehema left a comment

Choose a reason for hiding this comment

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

Hi, just checked out your branch and tested it on my Win7, 64bit machine. Works online, offline, with cleaned vendor directory, cleaned npm-cache.

Works perfectly and is so much faster. Thank you!
👍 🎉

});
var cachePath = path.join(sass.getCachePath(), pkg.name, pkg.version);
var cacheBinary = path.join(cachePath, sass.getBinaryName());
if (!fs.existsSync(cacheBinary)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: avoid negative conditional with an else branch. Inverting this if makes it much easier to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@xzyfer
Copy link
Contributor

xzyfer commented Sep 25, 2016

lgtm

@xzyfer
Copy link
Contributor

xzyfer commented Sep 26, 2016

Is it possible to get some test coverage over these changes? I'd hate to break installs in the future.

New order of operations
1. Look for existing binary in vendor folder
2. Create target vendor folder
3. Look to see if we’ve cached a copy in the configured or NPM cache
4. Download to current version’s /CACHE/node-sass/version/binding_file
5. Copy the cached download to the regular vendor directory
Closes sass#1566
@nschonni nschonni force-pushed the npm-download-cache branch from 415e74d to b655852 Compare October 2, 2016 21:21
@nschonni
Copy link
Contributor Author

nschonni commented Oct 2, 2016

I added a small test and slightly renamed the config key so it's less likely to be confused with the Ruby Sass cache stuff. I'll look at breaking the scripts in a separate PR.

Copy link
Contributor

@xzyfer xzyfer left a comment

Choose a reason for hiding this comment

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

lgtm

@xzyfer xzyfer merged commit abce8c1 into sass:master Oct 3, 2016
xzyfer added a commit that referenced this pull request Oct 3, 2016
This was removed #1733 but was depended on by #1714.
@nschonni nschonni deleted the npm-download-cache branch October 3, 2016 18:06
jiongle1 pushed a commit to scantist-ossops-m2/node-sass that referenced this pull request Apr 7, 2024
This was incorrectly changed in 610acbf to show relative paths.

Fixes sass#1714
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants