Skip to content

fix(plugin-npm): mark fetchFromNetwork private to fix TypeScript issue #6764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

vinzscam
Copy link

What's the problem this PR addresses?

As part of developing a Yarn plugin for our project, we introduced @yarnpkg/plugin-npm as a dependency. However when running typescript, the package raises the following error:

node_modules/@yarnpkg/plugin-npm/lib/NpmHttpFetcher.d.ts:12:76 - error TS2307: Cannot find module '/home/runner/work/berry/berry/.yarn/__virtual__/@yarnpkg-libzip-virtual-4957b34c08/1/packages/yarnpkg-libzip' or its corresponding type declarations.

12     fetchFromNetwork(locator: Locator, opts: FetchOptions): Promise<import("/home/runner/work/berry/berry/.yarn/__virtual__/@yarnpkg-libzip-virtual-4957b34c08/1/packages/yarnpkg-libzip").ZipFS>;

I've looked at the generated lib/NpmHttpFetcher.d.ts file https://www.npmjs.com/package/@yarnpkg/plugin-npm?activeTab=code, I found that the issue was in the fetchFromNetwork signature which includes a path generated during CI (/home/runner/work/berry/berry/...), which cannot be resolved locally.

export declare class NpmHttpFetcher implements Fetcher {
    supports(locator: Locator, opts: MinimalFetchOptions): boolean;
    getLocalPath(locator: Locator, opts: FetchOptions): null;
    fetch(locator: Locator, opts: FetchOptions): Promise<{
        packageFs: import("@yarnpkg/fslib").FakeFS<import("@yarnpkg/fslib").PortablePath>;
        releaseFs: () => void;
        prefixPath: import("@yarnpkg/fslib").PortablePath;
        checksum: string | null;
    }>;
    fetchFromNetwork(locator: Locator, opts: FetchOptions): Promise<import("/home/runner/work/berry/berry/.yarn/__virtual__/@yarnpkg-libzip-virtual-4957b34c08/1/packages/yarnpkg-libzip").ZipFS>;

How did you fix it?

As the fetchFromNetwork method seems to be intended for local use only, I've marked it as private so that TypeScript skips inferring the return type, marking the change as minor. But please let me know if you would prefer to keep the method public and explicitly define the return type.

I've spotted a similar error in:

happy to fix those as well.

Checklist

  • I have set the packages that need to be released for my changes to be effective.
  • I will check that all automated PR checks pass before the PR gets reviewed.

Signed-off-by: Vincenzo Scamporlino <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant