MCPcopy Create free account
hub / github.com/webpack/webpack-cli / findInExtensions

Method findInExtensions

packages/webpack-cli/src/webpack-cli.ts:2780–2805  ·  view source on GitHub ↗
(
      resolvedBase: string,
      basename: string,
      entries: Set<string> | null,
      extensions: string[],
    )

Source from the content-addressed store, hash-verified

2778 };
2779
2780 const findInExtensions = async (
2781 resolvedBase: string,
2782 basename: string,
2783 entries: Set<string> | null,
2784 extensions: string[],
2785 ): Promise<string | undefined> => {
2786 for (const ext of extensions) {
2787 // Skip candidates absent from the listing, but when the directory can't be listed (`entries` is `null`) probe every candidate directly.
2788 if (entries && !entries.has((basename + ext).toLowerCase())) {
2789 continue;
2790 }
2791
2792 const candidate = resolvedBase + ext;
2793
2794 // Confirm with `access` to preserve exact existence semantics (e.g.
2795 // broken symlinks are listed by `readdir` but fail `access`).
2796 try {
2797 await fs.promises.access(candidate, fs.constants.F_OK);
2798 return candidate;
2799 } catch {
2800 // Listed but not accessible, keep looking
2801 }
2802 }
2803
2804 return undefined;
2805 };
2806
2807 // Order defines the priority, in decreasing order. Within each filename,
2808 // common extensions take priority over the exotic ones (matching the

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected