How to check if libraries are unused in Symfony? - symfony

I have a lot of libraries listed in my package.json and I know that most of them are unused. How could I know the ones I use and the other one I do not use ?
I am using Symfony 3.4 and Yarn as Dependency Manager
Thanks !

If you want to know why a packages is installed, you can run the command why. As example, see this list:
>composer show
doctrine/instantiator 1.0.5 A small, lightweight utility to instantiate objects in PHP without invoking their constructors
phpdocumentor/reflection-common 1.0.1 Common reflection classes used by
.....
input/output with nice error messages.
See the instantiator package
>composer why doctrine/instantiator
phpspec/prophecy 1.8.0 requires doctrine/instantiator (^1.0.2)
phpunit/phpunit-mock-objects 2.3.8 requires doctrine/instantiator (^1.0.2)
You can also try the tree version:
>composer why -t doctrine/instantiator
doctrine/instantiator 1.0.5 A small, lightweight utility to instantiate objects in PHP without invoking their constructors
├──phpspec/prophecy 1.8.0 (requires doctrine/instantiator ^1.0.2)
│ └──phpunit/phpunit 4.8.36 (requires phpspec/prophecy ^1.3.1)
│ └──XXXXXXXX dev-master (requires (for development) phpunit/phpunit ~4.6)
└──phpunit/phpunit-mock-objects 2.3.8 (requires doctrine/instantiator ^1.0.2)
└──phpunit/phpunit 4.8.36 (requires phpunit/phpunit-mock-objects ~2.3)
└──XXXXXXXX dev-master (requires (for development) phpunit/phpunit ~4.6)

In Symfony front-end and back-end dependencies are kept separately by two different systems. Therefore, unused dependencies are able to be detected with two different tools. The following tools are just an example as more tools with the same functionality exist.
Front-end: package.json
https://yarnpkg.com/package/depcheck for yarn
https://www.npmjs.com/package/npm-check for npm
Back-end: composer.json
https://github.com/composer-unused/composer-unused

Related

Deprecated debug package:

I have found a PHP Notice in the logs:
[info] User Deprecated: The "Symfony\Component\Debug\ErrorHandler" class is deprecated since Symfony 4.4, use "Symfony\Component\ErrorHandler\ErrorHandler" instead.
This code is invoked from Vendor folder, so I have been checking what package is using this package. I have found that the package symfony/monolog-bundle is the problem.
I am using:
https://packagist.org/packages/symfony/monolog-bundle#v3.6.0
It requires: https://packagist.org/packages/symfony/http-kernel#v4.3.11
It requires the problematic package: https://packagist.org/packages/symfony/debug
I have been trying to upgrade the package http-kernel to a newest version which not using symfony debug, it means from http-kernel>v5.0
I am executing this code and receiving this error:
MacBook-Pro-de-Pablo-Garces:cp-igw pgarces$ composer require "symfony/error-handler:5.0.*"
./composer.json has been updated
Running composer update symfony/error-handler
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.
Problem 1
- symfony/http-kernel[v4.4.0, ..., v4.4.18] require symfony/error-handler ^4.4 -> found symfony/error-handler[v4.4.0, ..., v4.4.18] but it conflicts with your root composer.json require (5.0.*).
- Root composer.json requires symfony/http-kernel ^4.4 -> satisfiable by symfony/http-kernel[v4.4.0, ..., v4.4.18].
How can I solve it?

Meteor Atmosphere/Core Package Dependency Resolution Override (jquery, iron-router, blaze)

I have a meteor application with the following packages:
$ meteor list
accounts-password 1.5.3 Password support for accounts
accounts-ui 1.3.1 Simple templates to add login widget...
blaze-html-templates 1.1.2 Compile HTML templates into reactive...
ecmascript 0.14.2 Compiler plugin that supports ES201...
es5-shim 4.8.0 Shims and polyfills to improve ECMAS...
fourseven:scss 4.12.0 Style with attitude. Sass and SCSS ...
iron:router 1.1.2 Routing specifically designed for Me...
jquery 1.11.11* Manipulate the DOM using CSS selec...
meteor-base 1.4.0 Packages that every Meteor app needs
mobile-experience 1.0.5 Packages for a great mobile user exp...
mongo 1.8.1 Adaptor for using MongoDB and Minimo...
reactive-var 1.0.11 Reactive variable
shell-server 0.4.0 Server-side component of the `meteor...
standard-minifier-css 1.6.0 Standard css minifier used with Mete...
standard-minifier-js 2.6.0 Standard javascript minifiers used w...
tracker 1.2.0 Dependency tracker to allow reactive...
typescript 3.7.5 Compiler plugin that compiles TypeSc...
* New versions of these packages are available! Run 'meteor update'
to try to update those packages to their latest versions. If your
packages cannot be updated further, try typing
`meteor add <package>#<newVersion>` to see more information.
The atmosphere package jquery is available with version 3.0.0. I had that until installing iron-router. I was able to successfully get iron-router installed by following this advice: https://forums.meteor.com/t/iron-router-jquery-dependency/51374 (specifically meteor add iron:router --allow-incompatible-update).
I'd like to use the newer 3.0.0. I don't get the impression there is any true incompatibility within iron-router.
However, if I try to add it, I get:
$ meteor add jquery#3.0.0
-error: Conflict: Constraint jquery#1.0.0 is not satisfied by jquery
3.0.0.
Constraints on package "jquery":
* jquery#3.0.0 <- top level
* jquery#1.11.9 || 3.0.0 <- blaze 2.3.4 <- accounts-base 1.5.0 <-
accounts-password 1.5.3
* jquery#1.11.9 || 3.0.0 <- blaze 2.3.4 <- blaze-html-templates
1.1.2
* jquery#1.0.0 <- iron:dynamic-template 1.0.12 <- iron:controller
1.0.12 <- iron:router 1.1.2
* jquery#1.0.0 <- iron:location 1.0.11 <- iron:router 1.1.2
Initially, I had a hard time seeing where it was getting 1.0.0 from for the iron:* dependencies since there was no explicit version listed:
https://github.com/iron-meteor/iron-dynamic-template/blob/devel/package.js#L14
https://github.com/iron-meteor/iron-location/blob/master/package.js#L13
Then I found this in the documentation for api.versionsFrom(meteorRelease):
Use versions of core packages from a release. Unless provided, all packages will default to the versions released along with meteorRelease. This will save you from having to figure out the exact versions of the core packages you want to use. For example, if the newest release of meteor is `METEOR#0.9.0 and it includes jquery#1.0.0, you can write api.versionsFrom('METEOR#0.9.0') in your package, and when you later write api.use('jquery'), it will be equivalent to api.use('jquery#1.0.0').
So that seems to be what is happening -- jquery#1.0.0 was tied to METEOR#0.9.2.
So... aside from the option of checking out the iron-* packages into my local project as custom packages to override the api.versionsFrom(meteorRelease) in a custom fork to a modern release (or rather specify a specific jquery version since I believe it is no longer a core package)... is there any way forcefully update to jquery#3.0.0 despite what it thinks is a conflict?
Unfortunately --allow-incompatible-update does not seem to work in this instance.
This a bit of opinionated but if you want to have a router without dependencies to outdated packages you should go with ostrio:flow-router-extra which allows you even to omit jQuery or install jQuery using the npm package.
Since Meteor 1.8.3 there is also no hard dependency between Blaze and jQuery, allowing to install the latest jQuery from npm registry, which is important from a security perspective.
Check out:
https://github.com/VeliovGroup/flow-router
https://github.com/meteor/meteor/blob/devel/History.md
Use #= to install a specific pkg version. You'll need to remove the npm jquery pkg if you downgrade.
meteor add jquery#=1.11.11
meteor npm remove jquery
meteor add iron:router

Socially tutorial (Angular2 + Meteor)

URL: http://www.angular-meteor.com/tutorials/socially/angular2/search-sort-pagination-and-reactive-vars
While I am following the tutorial to section 12.4, the compiler always complains:
[web.browser] client/parties-list/parties-list.ts (28, 40): Cannot find name 'ReactiveVar
Then, I type "meteor list" in my command line and I have the following:
accounts-password 1.1.4 Password support for accounts
anti:fake 0.4.1 Random text and data generator
barbatus:ng2-meteor-accounts 0.1.6 Meteor Accounts for Angular2
barbatus:ng2-meteor-accounts-ui 0.1.3 Meteor Accounts UI for Angular2
barbatus:ng2-pagination 0.1.3 Angular2 Pagination Components
es5-shim 4.1.14 Shims and polyfills to improve ECMAScr...
jquery 1.11.4 Manipulate the DOM using CSS selectors
meteor-base 1.0.1 Packages that every Meteor app needs
mobile-experience 1.0.1 Packages for a great mobile user experi...
mongo 1.1.3 Adaptor for using MongoDB and Minimongo...
reactive-var 1.0.6 Reactive variable
session 1.1.1 Session variable
standard-minifiers 1.0.2 Standard minifiers used with Meteor app...
tracker 1.0.9 Dependency tracker to allow reactive ca...
urigo:angular2-meteor 0.4.4 Angular2 and Meteor integration
The reactive-var is clearly installed. But why the compiler still complain cannot find 'ReactiveVar'?
Make sure your typings are referenced correctly and are up to date.
I am using Meteor 1.2.1 and ionic2-meteor, so I have a typings folder.
Make sure you have typings NPM module installed.
npm install typings -g
And then install the typings for meteor
typings install meteor --ambient
typings install es6-promise --ambient
typings install es6-shim --ambient
Include the main.d.ts file in your tsconfig.json
"typings": [
"typings/ionic2-meteor/ionic-framework/ionic.d.ts",
"typings/ionic2-meteor/ionic2-meteor.d.ts",
"typings/angular2-meteor/angular2-meteor.d.ts",
"typings/main.d.ts"
]
Make sure the meteor.d.ts files installed contain the following:
declare var ReactiveVar: ReactiveVarStatic;
interface ReactiveVarStatic {
new<T>(initialValue: T, equalsFunc?: Function): ReactiveVar<T>;
}
interface ReactiveVar<T> {
get(): T;
set(newValue: T): void;
}
In my case I had to update my meteor.d.ts files (main and browser) because they did not contain the ReactiveVar declaration and interface.

Composer ignore minimum stable

I get following error on composer install for ebay bundle. dependency has old version of jms and I'm using new version. what can I do on this?
How can I ignore dependency?
- webconsul/ebay-api-bundle dev-master requires jms/serializer-bundle ~0.13 -> no matching package found.
my composer.json:
"jms/serializer-bundle": "^1.1",
...
"webconsul/ebay-api-bundle": "dev-master"
There is a reason why jms/serializer-bundle had a major release. They are simply incompatible. You can't ignore the version, because the code won't work anymore.
Either contribute the update to webconsul/ebay-api-bundle or create a working fork if it's not maintained anymore.
You cannot ignore version restriction required by a dependency that you are trying to install.
The classic way in this case is to look for a more recent version of the requested package (here webconsul/ebay-api-bundle).
But, you are using dev-master and it should be the most recent dev version.
You can just wait for a new version or adapt your jms/serializer-bundle version according to the webconsul/ebay-api-bundle requirement.
EDIT By using dev-master or #dev you will have a non stable release.

Symfony 2.3.6 and doctrine-fixtures-bundle?

I'm learning Symfony with a french tutorial.
I need then to install doctrine-fixtures-bundle, but here is the result of my composer.phar update : http://pastebin.com/55k3zKUQ (kind of big to shows it on stackoverflow)
It seems that the latest version of doctrine-fixtures-bundle doesn't support Symfony 2.3.6.
Am I right? How could I install doctrince fixture bundle on my symfony project?
Here's my composer.json : http://pastebin.com/CpccRyid
You problem isn't the doctrine fixtures bundle, another package (jms/di-extra-bundle) is complaining about the versions.
You should always skip a lot stuff from the composer error, the first thing you should read is:
jms/di-extra-bundle 1.1.0 requires symfony/framework-bundle 2.1.*
Here you see that the jms/di-extra-bundle version 1.1.0 package symfony/framework-bundle version 2.1.* required (in other words, it requires symfony 2.1). You have installed symfony 2.3.x.
Then you read further:
jms/di-extra-bundle 1.1.1 requires symfony/finder 2.1.*
So if we take version 1.1.1, it doesn't require symfony/framework-bundle 2.1, but symfony/finder 2.1.*. The result is the same: We should install symfony 2.1 and not 2.3.
Then you go to the package page to see if there is a version which supports symfony 2.3. And yes, for the latest stable version (1.4.0) the list of dependencies looks like:
jms/aop-bundle: >=1.0.0,<1.2-dev
jms/metadata: 1.*
symfony/framework-bundle: ~2.1
symfony/process: ~2.1
symfony/finder: ~2.1
~2.1 means at least 2.1.0. It will match each 2.* version, so 2.3 is supported to. So, you just need to replace 1.1.* in your composer.json for the jms/di-extra-bundle to 1.4.* and then update the packages with the update command.

Resources