Skip to content

composer init generates an incorrect default package name #12276

@bobonov

Description

@bobonov

composer init propose an invalid package name if the directory begin/contain invalid character for package name

When I run:

composer init -vvv

I get the following output (I just anonimized some sensitive information):

Running 2.8.4 (2024-12-11 11:57:47) with PHP 8.4.2 on Windows NT / 10.0
Reading C:/Users/myuser/AppData/Roaming/Composer/composer.json (C:\Users\myuser\AppData\Roaming\Composer\composer.json)
Loading config file C:/Users/myuser/AppData/Roaming/Composer/composer.json (C:\Users\myuser\AppData\Roaming\Composer\composer.json)
Checked CA file /etc/pki/tls/certs/ca-bundle.crt does not exist or it is not a file.
Checked directory /etc/pki/tls/certs/ca-bundle.crt does not exist or it is not a directory.
Checked CA file /etc/ssl/certs/ca-certificates.crt does not exist or it is not a file.
Checked directory /etc/ssl/certs/ca-certificates.crt does not exist or it is not a directory.
Checked CA file /etc/ssl/ca-bundle.pem does not exist or it is not a file.
Checked directory /etc/ssl/ca-bundle.pem does not exist or it is not a directory.
Checked CA file /usr/ssl/certs/ca-bundle.crt does not exist or it is not a file.
Checked directory /usr/ssl/certs/ca-bundle.crt does not exist or it is not a directory.
Checked CA file /opt/local/share/curl/curl-ca-bundle.crt does not exist or it is not a file.
Checked directory /opt/local/share/curl/curl-ca-bundle.crt does not exist or it is not a directory.
Checked CA file /usr/local/share/curl/curl-ca-bundle.crt does not exist or it is not a file.
Checked directory /usr/local/share/curl/curl-ca-bundle.crt does not exist or it is not a directory.
Checked CA file /usr/share/ssl/certs/ca-bundle.crt does not exist or it is not a file.
Checked directory /usr/share/ssl/certs/ca-bundle.crt does not exist or it is not a directory.
Checked CA file /etc/ssl/cert.pem does not exist or it is not a file.
Checked directory /etc/ssl/cert.pem does not exist or it is not a directory.
Checked CA file /usr/local/etc/openssl/cert.pem does not exist or it is not a file.
Checked directory /usr/local/etc/openssl/cert.pem does not exist or it is not a directory.
Checked CA file /usr/local/etc/openssl@1.1/cert.pem does not exist or it is not a file.
Checked directory /usr/local/etc/openssl@1.1/cert.pem does not exist or it is not a directory.
Checked CA file /opt/homebrew/etc/openssl@3/cert.pem does not exist or it is not a file.
Checked directory /opt/homebrew/etc/openssl@3/cert.pem does not exist or it is not a directory.
Checked CA file /opt/homebrew/etc/openssl@1.1/cert.pem does not exist or it is not a file.
Checked directory /opt/homebrew/etc/openssl@1.1/cert.pem does not exist or it is not a directory.
Checked CA file /etc/pki/tls/certs does not exist or it is not a file.
Checked directory /etc/pki/tls/certs does not exist or it is not a directory.
Checked CA file /etc/ssl/certs does not exist or it is not a file.
Checked directory /etc/ssl/certs does not exist or it is not a directory.
Checked CA file C:\Users\myuser\AppData\Local\Temp\opeCB74.tmp: valid
Executing command (C:/Users/myuser/AppData/Roaming/Composer): git branch -a --no-color --no-abbrev -v
Executing command (C:/Users/myuser/AppData/Roaming/Composer): git describe --exact-match --tags
Executing command (CWD): git --version
Executing command (C:/Users/myuser/AppData/Roaming/Composer): git log --pretty=%H -n1 HEAD --no-show-signature
Executing command (C:/Users/myuser/AppData/Roaming/Composer): hg branch
Executing command (C:/Users/myuser/AppData/Roaming/Composer): fossil branch list
Executing command (C:/Users/myuser/AppData/Roaming/Composer): fossil tag list
Executing command (C:/Users/myuser/AppData/Roaming/Composer): svn info --xml
Reading C:/Users/myuser/AppData/Roaming/Composer/composer.json (C:\Users\myuser\AppData\Roaming\Composer\composer.json)
Loading config file C:/Users/myuser/AppData/Roaming/Composer/composer.json (C:\Users\myuser\AppData\Roaming\Composer\composer.json)
Reading C:/Users/myuser/AppData/Roaming/Composer/composer.lock (C:\Users\myuser\AppData\Roaming\Composer\composer.lock)
Reading C:/Users/myuser/AppData/Roaming/Composer/vendor/composer/installed.json (C:\Users\myuser\AppData\Roaming\Composer\vendor\composer\installed.json)
Reading C:/Users/myuser/AppData/Roaming/Composer/vendor/composer/installed.json (C:\Users\myuser\AppData\Roaming\Composer\vendor\composer\installed.json)
Executing command (CWD): git config -l


  Welcome to the Composer config generator



This command will guide you through creating your composer.json config.

Package name (<vendor>/<name>) [myuser/_utility]:
Description []:
Author [My Name <myuser@mymail.com>, n to skip]:
Minimum Stability []:
Package Type (e.g. library, project, metapackage, composer-plugin) []:
License []:

Define your dependencies.

Would you like to define your dependencies (require) interactively [yes]? no
Would you like to define your dev dependencies (require-dev) interactively [yes]? no
Add PSR-4 autoload mapping? Maps namespace "myuser\Utility" to the entered relative path. [src/, n to skip]:

{
    "name": "myuser/_utility",
    "autoload": {
        "psr-4": {
            "myuser\\Utility\\": "src/"
        }
    },
    "authors": [
        {
            "name": "My Name",
            "email": "myuser@mymail.com"
        }
    ],
    "require": {}
}

Do you confirm generation [yes]?
Schema validation error, aborting
"./composer.json" does not match the expected JSON schema:
 - name : Does not match the regex pattern ^[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9](([_.]|-{1,2})?[a-z0-9]+)*$

I expected composer to propose a valid package name

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions