After export, feature dependencies are not prefixed with project name which is causing phpcs to constantly give warnings:
All dependencies must be prefixed with the project name, for example "drupal:
If fixed manually on next export dependencies are duplicated (dependencies without prefix are readded).
| Comment | File | Size | Author |
|---|---|---|---|
| #21 | interdiff.txt | 1.48 KB | nedjo |
| #21 | features_dependencies_prefix-3044307-21.patch | 17.16 KB | nedjo |
Comments
Comment #2
pagach commentedCreated patch. project attribute from .info.yml file is used for prefix and 'drupal' if that attribute is not set (core and custom modules).
Comment #3
fagolooks good, this needs review!
Comment #5
nedjoThanks for the draft patch!
We need to update the relevant test or tests to expect the prefixed form.
In subsequent reads, will we be loading already prefixed dependencies, then adding a duplicate prefix?
::addInfoFile()doesn't seem like the right place to do this. Can we instead ensure the dependencies are always prefixed (for example,Package::getDependencies()returns prefixed dependencies)?Comment #6
bkosborneThe patch assumes that any module without a "project" key in the info file is Drupal core module, but that's not true. Custom modules don't have the project key, so the patch incorrectly assigns them the "drupal" project. The project key is added by Drupal.org's packaging scripts for contrib modules only.
I'm not sure how else to determine the correct prefix here.
Comment #7
mpotter commentedI believe for custom modules it can use the format:
modulename:modulenameThis won't handle custom modules that have submodules, but there isn't any good way to easily determine the parent module of a submodule without searching parent directories for *.info.yml files.
Also, ideally Features would look for the existing dependency and not modify it if found. For example, if Features exported:
submodule:submoduleand then this was manually fixed in the Feature info.yml to be
parentmodule:submodulethen Features needs to see that "submodule" is already listed and NOT overwrite this with the previous "submodule:submodule" when exporting again.
Comment #8
nedjoThe
UpdateManager::getProjects()method does what we need here, using the coreProjectInfoclass. We could either crib from there or introduce a dependency on the update module and call its method directly.Comment #9
mpotter commentedHere is a patch that handles all of this with normal core services. No dependency on update module needed. Even with `getProjects` there is no ideal way to determine if a module is part of "core" or not, other than looking at the path. The only case this doesn't handle is if the exported feature is placed as a submodule within a parent custom module. In that case the custom submodule should add a `project:` key to the info.yml file similar to if the module was packaged.
I'm actually using Features on a client project (Platform build) for the first time in years and needed this functionality. Tested it on that project.
Comment #10
mpotter commentedComment #11
mpotter commentedHmm, this doesn't preserve existing constraint strings on module dependencies. New patch coming.
Comment #12
mpotter commentedHere is a patch that properly merges the dependencies during the export process itself in the mergeInfo method. It basically creates a helper function for constructing dependency strings that is missing from core and which handles the missing project while preserving constraints.
Comment #13
vladimirausI'm getting the following error after applying
Comment #14
vladimirausComment #15
vladimirausTo be applied after #12.
Comment #17
nedjoThanks for the patches!
Updated with some fixes. Interdiff is from the combination of patches from #12 and #15.
Comment #19
nedjoFurther updates to tests, minor tweak to test for core module to follow what's done in
ProjectInfo::getProjectName().Comment #21
nedjoFix up mocking in unit test addition.
Comment #24
nedjoApplied, thx all!
Comment #25
nedjoTests were passing on 9.1.x with PHP 7.4 but the default branch test on 8.x-3.x - 8.9.x with PHP 7.2 - is failing.
Comment #26
bkosborneAfter upgrading to 3.12 and exporting an existing feature, the dependencies listed in the info file now are using the project prefix, but they are ALL using "drupal:" as the prefix instead of the correct contrib module. For example: "drupal:smtp" when it should be "smtp:smtp". Anyone else have this issue?Interestingly enough, it doesn't seem to affect new installs of the feature module. The contrib modules are still enabled despite the wrong project prefix.
Nevermind, re-exporting fixed it after manually removing the bad "drupal"prefix. Not sure what happened there.
Comment #27
dave reid