SpBowerBundle icon indicating copy to clipboard operation
SpBowerBundle copied to clipboard

add a configuration parameter for the bower cache storage directory

Open ghost opened this issue 11 years ago • 14 comments

during the bower installation phase it creates a cache directory here:

/path/to/bundles/AcmeBundle/Resources/config/bower/../../public/components/cache

I don't think it should attempt to write anywhere except the symfony cache and the target asset location.

It is possible to configure these directories via this entry in a .bowerrc:

{ "storage":{ "packages":"/path/to/cache" } }

as per this stackoverflow post: http://stackoverflow.com/questions/17881116/how-to-change-bower-default-cache-git-templates-completion-folder-locations/18564317#18564317

or this with the bower command itself:

--config.storage.packages=/path/to/cache

although there could be some problems with that as per this bower issue: https://github.com/bower/bower/issues/1043 if the build system is not connected to the internet.

This is my first time using bower, so my assessment of how to solve this problem could be incorrect.

ghost avatar Jul 12 '14 06:07 ghost

I think this command sp:bower:install could be used to prepare a server and without the obligation to reload it after each deploy.

So to have a different cache than symfony seem to me a good idea. As i can commit the spbower cache and leave the symfony cache clear. All my server don't have php and nodejs installed together (a security hole for now : debian having not yet a prod version of nodejs)

@jrobeson Or maybe are you right with this another solution :

Even without cache the bundle should give js and css corresponding only to package name.

nicodmf avatar Jul 14 '14 19:07 nicodmf

The cache from bower has nothing to do with the cache from this bundle. The cache from this bundle is used to store the mapping received from bower list --json, so it is not necessary to always execute this command when a registered asset is called.

Spea avatar Jul 15 '14 08:07 Spea

i know that, but i mean specifying the cache in the .bowerrc so bower won't try to write a cache in an unwriteable directory

ghost avatar Jul 15 '14 10:07 ghost

I agree. Every now and then I get the message: InvalidArgumentException: The directory "/foo/BarBundle/Resources/config/bower/../../public/components/cache" is not writable.

This cache folder should not be in my bundle directory structure but rather somewhere in app/cache.

Sander-Toonen avatar Jul 24 '14 08:07 Sander-Toonen

@xatoo You can already do that

sp_bower:
    bundles:
        FooBundle:
            cache: /path/do/different/cache-dir

The cache @jrobeson describes is the one from bower itself and has nothing to do with the cache you want to change :)

Spea avatar Jul 24 '14 09:07 Spea

@Spea Ow, that is awesome! Sorry for the confusion.

Sander-Toonen avatar Jul 24 '14 09:07 Sander-Toonen

@Spea : regarding your last response: but why is the default to ever write there?

ghost avatar Jul 24 '14 09:07 ghost

There were some errors when using the app/cache directory for this cache. Also it was kinda slow to recreate the asset-cache on every cache:warmup, thats why I decided to use another directory as the default one, but you can still change it ;)

Spea avatar Jul 24 '14 10:07 Spea

So i understand better as the cache works.

Event that, I have yet a problem with the actual cache :

Recreated the sp cache, demand bower list --json to be callable, and as the spcache store the absolute path, it seems to me that it is not possible to send it to a server without node.js installed.

nicodmf avatar Oct 07 '14 12:10 nicodmf

I will try to change this behaviour.

Spea avatar Oct 07 '14 13:10 Spea

What is the correct way to provide custom cache service? In order to fix our issue described in #123 I wanted to set service for cache:

sp_bower:
    bundles:
        OurBundle:
            cache:
                id: our_bundle.cache.bower_dependencies
our_bundle.cache.bower_dependencies:
        class: BPO\OurBundle\Service\Cache\BowerDependenciesCache
        arguments: [ "%kernel.cache_dir%/../bower_dependencies", ".sp_bower.data" ]

I always get exception:

[RuntimeException]
  Cache service with id [our_bundle.cache.bower_dependencies] not found

When I dump available services ($container->getDefinitions()) in Sp\BowerBundle\DependencyInjection\SpBowerExtension::createCache() I get:

array(9) {
  [0]=>
  string(25) "sp_bower.filesystem_cache"
  [1]=>
  string(32) "sp_bower.dependency_cache_warmer"
  [2]=>
  string(22) "sp_bower.exec_listener"
  [3]=>
  string(30) "sp_bower.cache_create_listener"
  [4]=>
  string(14) "sp_bower.bower"
  [5]=>
  string(22) "sp_bower.bower_manager"
  [6]=>
  string(32) "sp_bower.package_naming_strategy"
  [7]=>
  string(30) "sp_bower.assetic.config_loader"
  [8]=>
  string(31) "sp_bower.assetic.bower_resource"
}

So it's impossible to use custom (external) service?

Wirone avatar Feb 24 '15 07:02 Wirone

I tried using the default app/cache/(dev|env) folder, but it gets cleared on every app/console cache:clear, as @Spea mentioned.

So, I figured why not use something like app/cache/bower/(dev|env), since app/cache is already writeable and app/cache/bower does not get cleared automatically.

sp_bower:
    bundles:
        AppBundle:
            cache: %kernel.cache_dir%/../bower/%kernel.environment%

Could there be any downsides to this that I am unaware of?

Thanks!

liviucmg avatar Jun 06 '15 20:06 liviucmg

@liviucmg that's actually a really good idea! +1

AlmogBaku avatar Jun 07 '15 16:06 AlmogBaku

actually i discovered that @liviucmg is a very problematic solution, since the cache should not be created for every environment. this is the best solution that i found:

sp_bower:
    bundles:
        AppBundle:
            cache: %kernel.cache_dir%/../bower

AlmogBaku avatar Jun 08 '15 19:06 AlmogBaku