function getWebpackResolver(
  resolverFactory,
  implementation,
  includePaths = [],
) {
  const isModernSass =
    implementation && typeof implementation.compileStringAsync !== "undefined";
  // We only have one difference with the built-in sass resolution logic and out resolution logic:
  // First, we look at the files starting with `_`, then without `_` (i.e. `_name.sass`, `_name.scss`, `_name.css`, `name.sass`, `name.scss`, `name.css`),
  // although `sass` look together by extensions (i.e. `_name.sass`/`name.sass`/`_name.scss`/`name.scss`/`_name.css`/`name.css`).
  // It shouldn't be a problem because `sass` throw errors:
  // - on having `_name.sass` and `name.sass` (extension can be `sass`, `scss` or `css`) in the same directory
  // - on having `_name.sass` and `_name.scss` in the same directory
  //
  // Also `sass` prefer `sass`/`scss` over `css`.
  const sassModuleResolve = promiseResolve(
    resolverFactory({
      alias: [],
      aliasFields: [],
      conditionNames: [],
      descriptionFiles: [],
      extensions: [".sass", ".scss", ".css"],
      exportsFields: [],
      mainFields: [],
      mainFiles: ["_index", "index"],
      modules: [],
      restrictions: [/\.((sa|sc|c)ss)$/i],
      preferRelative: true,
    }),
  );
  const sassImportResolve = promiseResolve(
    resolverFactory({
      alias: [],
      aliasFields: [],
      conditionNames: [],
      descriptionFiles: [],
      extensions: [".sass", ".scss", ".css"],
      exportsFields: [],
      mainFields: [],
      mainFiles: ["_index.import", "_index", "index.import", "index"],
      modules: [],
      restrictions: [/\.((sa|sc|c)ss)$/i],
      preferRelative: true,
    }),
  );
  const webpackModuleResolve = promiseResolve(
    resolverFactory({
      dependencyType: "sass",
      conditionNames: ["sass", "style", "..."],
      mainFields: ["sass", "style", "main", "..."],
      mainFiles: ["_index", "index", "..."],
      extensions: [".sass", ".scss", ".css"],
      restrictions: [/\.((sa|sc|c)ss)$/i],
      preferRelative: true,
    }),
  );
  const webpackImportResolve = promiseResolve(
    resolverFactory({
      dependencyType: "sass",
      conditionNames: ["sass", "style", "..."],
      mainFields: ["sass", "style", "main", "..."],
      mainFiles: ["_index.import", "_index", "index.import", "index", "..."],
      extensions: [".sass", ".scss", ".css"],
      restrictions: [/\.((sa|sc|c)ss)$/i],
      preferRelative: true,
    }),
  );

  return (context, request, fromImport) => {
    // See https://github.com/webpack/webpack/issues/12340
    // Because `node-sass` calls our importer before `1. Filesystem imports relative to the base file.`
    // custom importer may not return `{ file: '/path/to/name.ext' }` and therefore our `context` will be relative
    if (!isModernSass && !path.isAbsolute(context)) {
      return Promise.reject();
    }

    const originalRequest = request;
    const isFileScheme = originalRequest.slice(0, 5).toLowerCase() === "file:";

    if (isFileScheme) {
      try {
        // eslint-disable-next-line no-param-reassign
        request = url.fileURLToPath(originalRequest);
      } catch (ignoreError) {
        // eslint-disable-next-line no-param-reassign
        request = request.slice(7);
      }
    }

    let resolutionMap = [];

    const needEmulateSassResolver =
      // `sass` doesn't support module import
      !IS_SPECIAL_MODULE_IMPORT.test(request) &&
      // don't handle `pkg:` scheme
      !IS_PKG_SCHEME.test(request) &&
      // We need improve absolute paths handling.
      // Absolute paths should be resolved:
      // - Server-relative URLs - `<context>/path/to/file.ext` (where `<context>` is root context)
      // - Absolute path - `/full/path/to/file.ext` or `C:\\full\path\to\file.ext`
      !isFileScheme &&
      !originalRequest.startsWith("/") &&
      !IS_NATIVE_WIN32_PATH.test(originalRequest);

    if (includePaths.length > 0 && needEmulateSassResolver) {
      // The order of import precedence is as follows:
      //
      // 1. Filesystem imports relative to the base file.
      // 2. Custom importer imports.
      // 3. Filesystem imports relative to the working directory.
      // 4. Filesystem imports relative to an `includePaths` path.
      // 5. Filesystem imports relative to a `SASS_PATH` path.
      //
      // `sass` run custom importers before `3`, `4` and `5` points, we need to emulate this behavior to avoid wrong resolution.
      const sassPossibleRequests = getPossibleRequests(
        request,
        false,
        fromImport,
      );

      // `node-sass` calls our importer before `1. Filesystem imports relative to the base file.`, so we need emulate this too
      if (!isModernSass) {
        resolutionMap = resolutionMap.concat({
          resolve: fromImport ? sassImportResolve : sassModuleResolve,
          context: path.dirname(context),
          possibleRequests: sassPossibleRequests,
        });
      }

      resolutionMap = resolutionMap.concat(
        // eslint-disable-next-line no-shadow
        includePaths.map((context) => {
          return {
            resolve: fromImport ? sassImportResolve : sassModuleResolve,
            context,
            possibleRequests: sassPossibleRequests,
          };
        }),
      );
    }

    const webpackPossibleRequests = getPossibleRequests(
      request,
      true,
      fromImport,
    );

    resolutionMap = resolutionMap.concat({
      resolve: fromImport ? webpackImportResolve : webpackModuleResolve,
      context: path.dirname(context),
      possibleRequests: webpackPossibleRequests,
    });

    return startResolving(resolutionMap);
  };
}
@public
Create the resolve function used in the custom Sass importer.

Can be used by external tools to mimic how `sass-loader` works, for example
in a Jest transform. Such usages will want to wrap `resolve.create` from
[`enhanced-resolve`]{@link https://github.com/webpack/enhanced-resolve} to
pass as the `resolverFactory` argument.

@param {Function} resolverFactory - A factory function for creating a Webpack
  resolver.
@param {Object} implementation - The imported Sass implementation, both
  `sass` (Dart Sass) and `node-sass` are supported.
@param {string[]} [includePaths] - The list of include paths passed to Sass.

@throws If a compatible Sass implementation cannot be found.