Skip to content

Array of paths for moduleNameMapper aliases #8461

Closed
@Telokis

Description

@Telokis

🚀 Feature Proposal

Allows the values of the config moduleNameMapper to be an array of paths.
When attempting to resolve module aliases, the match will try to consecutively find using each path from the array, in order. It will silently ignore failures from the first paths as long as there is a match along the way.
Similarly, it will ignore remaining paths if a match is found early in the array.

Motivation

This pattern will allow more flexible alias matching. Relying on another tool to do this work isn't feasible since Jest uses its own require implementation. (See ilearnio/module-alias#46)

Example

{
    "moduleNameMapper": {
        "\\$directory$": ["<rootDir>/directory", "<rootDir>/../directory]
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions