Score:0

How can I remove test directories when deploying?

cn flag

When deploying Drupal, there are a lot of files in test directories, none of which are needed in a production environment. There's an ongoing issue to Exclude test files from release packages, but how can I get rid of the test files now?

Score:1
cn flag

After trying to configure drupal-core-vendor-hardening to do this, I realized that it's too much of a pain to add each individual module.

So I wrote a simple bash script instead.

cd "$my_git_root"
# Delete Drupal test directories.
# https://unix.stackexchange.com/a/89937
find . -type d -name tests -exec rm -rf {} +
# Delete testing and demo profiles.
find web/core/profiles -type d -name 'testing*' -exec rm -rf {} +
find web/core/profiles -type d -name 'nightwatch_testing' -exec rm -rf {} +
find web/core/profiles -type d -name 'demo_umami' -exec rm -rf {} +
# Delete README files.
find . -type f -name 'README*' -delete
find . -type f -name 'CHANGELOG*' -delete
# Delete patch records.
find . -type f -name 'PATCHES.txt' -delete
# Delete markdown files except licenses.
find web -type f -name "*.md" -not -name "LICENSE*" -delete
# Delete txt files except licenses.
find web -type f -name "*.txt" -not -name "LICENSE*" -not -name "COPYRIGHT*" -delete

Doing this, I managed to reduce my build size from 213 MB to 172 MB.

Score:0
cn flag

core-vendor-hardening can clean up test files and any other directories you want.

The only downside is that you have to make an entry per module in composer.json.

"extra": {
    "drupal-core-vendor-hardening": {
        "drupal/core": ["tests","profiles/demo_umami"],
        "drupal/json_field": ["tests"]
    },
}

The above example also shows how to delete the umami profile-- you need to insert the directory path. So, if you want to delete tests from all modules of core, you are looking at a very extensive list.

Note: To actually delete the files after modifying composer.json, you can delete the relevant directory and then run composer.install. If you change composer.json and then run composer update, the files will remain.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.