Skip to content

Imported package name / namespace only partially removed #194

Closed
@plachta11b

Description

@plachta11b

Importing a package into a package with a shorter package name that is simultaneously a prefix caused namespace removal to fail.

Original function:

if (config.no_namespace) {
    return removeRootParentName(name, packages.find(p => name.startsWith(p))).replace(/\./g, '');
}

Proposed fix:

if (config.no_namespace) {
    // Create a copy of the original array. Sort the array copy by length, from longest to shortest.
    const sortedPackages = packages.map(p => p).sort((a, b) => b.length - a.length);
    // Return the new package name with longest possible match removed from the name.
    return removeRootParentName(name, sortedPackages.find(p => name.startsWith(p))).replace(/\./g, '');
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions