Skip to content

Resolver option cache doesn't take into account process.cwd() #217

Closed
@kingston

Description

@kingston

In version 3.5.0 of the plugin, the comparison for the cached resolver options was updated to use the object hash instead of referential equality. However, this led to a subtle bug with monorepo setups in VSCode where the import resolver would cache the path map from one project for all projects resulting in continual errors for all other projects.

I went into the rabbit hole and figured out that it was because the initMappers function relies on process.cwd():


However, the logic for checking whether to initMappers only check options:
if (mappers && mappersCachedOptions === options) {
) and does not check if process.cwd() has changed as well. Therefore, the cache for mappers is never updated resulting in an error when the process.cwd() is changed. This is something that the VSCode ESLint plugin does to support multiple working directories (https://github.com/microsoft/vscode-eslint/blob/560df864580a9381d84b2f1e408f46f6600fda48/server/src/eslint.ts#L1056).

It seems a simple solution is to also check if process.cwd() has changed in initMappers. I can put together a quick PR for that if it seems like a reasonable solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions