mozart icon indicating copy to clipboard operation
mozart copied to clipboard

How to skip some dependencies

Open wppunk opened this issue 5 years ago • 7 comments

{
  "packages": [
     "symfony/dependency-injection",
     "symfony/config". 
  ],
  "extra": {
    "mozart": {
      "dep_namespace": "PluginName\\Dependencies\\",
      "dep_directory": "/src/Dependencies/",
      "classmap_prefix": "plugin_name_",
      "classmap_directory": "/classes/dependencies/",
      "packages": [
        "symfony/dependency-injection",
        "symfony/config"
      ],
      "delete_vendor_directories": false
    }
  }
}

After the run a mozart inside /classes/dependencies/ I have a symfony/polyfill-php80 package. I think that doesn't necessarily add prefixes to this package. I think need to add to the configuration a skip packages parameter or flag to skip function without prefixes.

wppunk avatar Sep 04 '20 20:09 wppunk

To skip dependencies, you can use override_autoload to ignore a package:

"override_autoload": {
  "symfony/polyfill-php80": {}
}

Try this:

{
  "require": {
    "symfony/dependency-injection": "*",
    "symfony/config": "*"
  },
  "require-dev": {
    "coenjacobs/mozart": "0.6.0-beta-3"
  },
  "extra": {
    "mozart": {
      "dep_namespace": "PluginName\\",
      "dep_directory": "/src/dep_directory/",
      "classmap_prefix": "PluginName_",
      "classmap_directory": "/src/classmap_directory/",
      "delete_vendor_directories": false,
      "override_autoload": {
        "symfony/polyfill-php80": {}
      }
    }
  },
  "scripts": {
    "post-install-cmd": [
      "\"vendor/bin/mozart\" compose"
    ],
    "post-update-cmd": [
      "\"vendor/bin/mozart\" compose"
    ]
  }
}

The actual symfony/polyfill-php80 key is:

"autoload": {
    "psr-4": { "Symfony\\Polyfill\\Php80\\": "" },
    "files": [ "bootstrap.php" ],
    "classmap": [ "Resources/stubs" ]
},

The classes copied into dep_directory are not changed because they have no namespace in the files.

The classes copied into the classmap_directory actually get prefixed twice, which is definitely a bug to fix. The regex in ClassmapReplacer needs to be updated to not match class names which already begin with ClassmapReplacer->classmap_prefix, in the same way that has already been done in NamespaceReplacer.

With that done, Mozart doesn't (yet?) handle files keys in packages' autoload keys, so bootstrap.php isn't getting copied or prefixed at all. And I see Php80.php in the root of that package which isn't even in the autoload key. What should be happening with these?

I hope that helps. This is a little beyond my knowledge.

BrianHenryIE avatar Sep 04 '20 22:09 BrianHenryIE

@BrianHenryIE Yep. It helps to me. Prefix just no need to these files.

wppunk avatar Sep 04 '20 22:09 wppunk

@BrianHenryIE But prefixes incorrect for some files:

use Symfony\Component\Config\Exception\FileLocatorFileNotFoundException;
use Symfony\Component\Config\Exception\LoaderLoadException;
use Symfony\Component\Config\FileLocatorInterface;
use Symfony\Component\Config\Loader\FileLoader as BaseFileLoader;
use Symfony\Component\Config\Loader\Loader;
use Symfony\Component\Config\Resource\GlobResource;
use PluginName\Dependencies\Symfony\Component\DependencyInjection\ChildDefinition;
use PluginName\Dependencies\Symfony\Component\DependencyInjection\ContainerBuilder;
use PluginName\Dependencies\Symfony\Component\DependencyInjection\Definition;
use PluginName\Dependencies\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;

/**
 * FileLoader is the abstract class used by all built-in loaders that are file based.
 *
 * @author Fabien Potencier <[email protected]>
 */
abstract class FileLoader extends BaseFileLoader

I think this happened because packages are separate. This bug inside package symfony/dependency-injection with classes/interfaces from symfony/config

wppunk avatar Sep 04 '20 22:09 wppunk

That's the same problem PR #42 was trying to fix and might be related to issue #58. I think a rewrite of the hierarchical/recursive/parent-child approach Mozart takes to packages to instead beginning with a flat list of all packages and subpackages might be a solution to this. #42 always felt hacky/incomplete. @coenjacobs thoughts?

BrianHenryIE avatar Sep 04 '20 23:09 BrianHenryIE

@BrianHenryIE I agree, this needs some extra attention. The reason why this isn't processed as a flat list, but rather as a hierarchical parent > child relation, is that the parent dependencies can contain a class definition or use statement from one or more children. This needs to be taken into account when rewriting the hierarchical processing of dependencies.

coenjacobs avatar Sep 12 '20 13:09 coenjacobs

@wppunk PR #82 is now merged into master and will soon be in the next beta release of 0.6. This PR specifically addresses the recursive tracking of packages and their dependencies (infinite number of levels deep). Please use the current master branch to see if this resolve this issue for you, or wait a couple days until the dust has settled and the next beta release is available (final 0.6 shouldn't follow much later). While you are on master branch, you can have a look at the exclude_packages parameter in the configuration part of the README.

coenjacobs avatar Nov 23 '20 22:11 coenjacobs

@coenjacobs Sounds good. I'll test it this week. Thanks

wppunk avatar Nov 23 '20 22:11 wppunk