Skip to content

AutoImportProvider doesn’t work with pnpm unless there are project references #42094

Closed
@andrewbranch

Description

@andrewbranch

Discovered while investigating #40584, but is not directly related, and a fix for this is irrelevant to that issue on the whole. Fourslash server test:

/// <reference path="../fourslash.ts" />

// @Filename: /tsconfig.json
//// { "compilerOptions": { "module": "commonjs" } }

// @Filename: /package.json
//// { "dependencies": { "mobx": "*" } }

// @Filename: /node_modules/.pnpm/mobx@6.0.4/node_modules/mobx/package.json
//// { "types": "dist/mobx.d.ts" }

// @Filename: /node_modules/.pnpm/mobx@6.0.4/node_modules/mobx/dist/mobx.d.ts
//// export declare function autorun(): void;

// @Filename: /index.ts
//// autorun/**/

// @link: /node_modules/.pnpm/mobx@6.0.4/node_modules/mobx -> /node_modules/mobx

goTo.marker("");
verify.importFixAtPosition([`import { autorun } from "mobx";\r\n\r\nautorun`]);

The problem is that the pnpm symlink doesn’t make it into the symlink cache, which is coincidentally fixed if there are project references due to:

function handleDirectoryCouldBeSymlink(directory: string) {
if (!host.getResolvedProjectReferences()) return;

The proper fix would probably be to save an originalPath on ResolvedTypeReferenceDirective during module resolution, and then do something with it in AutoImportProviderHost.getRootFileNames().

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

    Development

    Participants

    @andrewbranch

    Issue actions

      AutoImportProvider doesn’t work with pnpm unless there are project references · Issue #42094 · microsoft/TypeScript