async function getSassOptions(
  loaderContext,
  loaderOptions,
  content,
  implementation,
  useSourceMap,
  apiType,
) {
  const options = loaderOptions.sassOptions
    ? typeof loaderOptions.sassOptions === "function"
      ? loaderOptions.sassOptions(loaderContext) || {}
      : loaderOptions.sassOptions
    : {};
  const sassOptions = {
    ...options,
    data: loaderOptions.additionalData
      ? typeof loaderOptions.additionalData === "function"
        ? await loaderOptions.additionalData(content, loaderContext)
        : `${loaderOptions.additionalData}\n${content}`
      : content,
  };

  if (!sassOptions.logger) {
    const needEmitWarning = loaderOptions.warnRuleAsWarning !== false;
    const logger = loaderContext.getLogger("sass-loader");
    const formatSpan = (span) =>
      `Warning on line ${span.start.line}, column ${span.start.column} of ${
        span.url || "-"
      }:${span.start.line}:${span.start.column}:\n`;
    const formatDebugSpan = (span) =>
      `[debug:${span.start.line}:${span.start.column}] `;

    sassOptions.logger = {
      debug(message, loggerOptions) {
        let builtMessage = "";

        if (loggerOptions.span) {
          builtMessage = formatDebugSpan(loggerOptions.span);
        }

        builtMessage += message;

        logger.debug(builtMessage);
      },
      warn(message, loggerOptions) {
        let builtMessage = "";

        if (loggerOptions.deprecation) {
          builtMessage += "Deprecation ";
        }

        if (loggerOptions.span) {
          builtMessage += formatSpan(loggerOptions.span);
        }

        builtMessage += message;

        if (loggerOptions.span && loggerOptions.span.context) {
          builtMessage += `\n\n${loggerOptions.span.start.line} | ${loggerOptions.span.context}`;
        }

        if (loggerOptions.stack && loggerOptions.stack !== "null") {
          builtMessage += `\n\n${loggerOptions.stack}`;
        }

        if (needEmitWarning) {
          const warning = new Error(builtMessage);

          warning.name = "SassWarning";
          warning.stack = null;

          loaderContext.emitWarning(warning);
        } else {
          logger.warn(builtMessage);
        }
      },
    };
  }

  const isModernAPI = apiType === "modern" || apiType === "modern-compiler";
  const { resourcePath } = loaderContext;

  if (isModernAPI) {
    sassOptions.url = url.pathToFileURL(resourcePath);

    // opt.outputStyle
    if (!sassOptions.style && isProductionLikeMode(loaderContext)) {
      sassOptions.style = "compressed";
    }

    if (useSourceMap) {
      sassOptions.sourceMap = true;
      sassOptions.sourceMapIncludeSources = true;
    }

    // If we are compiling sass and indentedSyntax isn't set, automatically set it.
    if (typeof sassOptions.syntax === "undefined") {
      const ext = path.extname(resourcePath);

      if (ext && ext.toLowerCase() === ".scss") {
        sassOptions.syntax = "scss";
      } else if (ext && ext.toLowerCase() === ".sass") {
        sassOptions.syntax = "indented";
      } else if (ext && ext.toLowerCase() === ".css") {
        sassOptions.syntax = "css";
      }
    }

    sassOptions.loadPaths = []
      .concat(
        // We use `loadPaths` in context for resolver, so it should be always absolute
        (sassOptions.loadPaths ? sassOptions.loadPaths.slice() : []).map(
          (includePath) =>
            path.isAbsolute(includePath)
              ? includePath
              : path.join(process.cwd(), includePath),
        ),
      )
      .concat(
        process.env.SASS_PATH
          ? process.env.SASS_PATH.split(
              process.platform === "win32" ? ";" : ":",
            )
          : [],
      );

    sassOptions.importers = sassOptions.importers
      ? Array.isArray(sassOptions.importers)
        ? sassOptions.importers.slice()
        : [sassOptions.importers]
      : [];
  } else {
    sassOptions.file = resourcePath;

    // opt.outputStyle
    if (!sassOptions.outputStyle && isProductionLikeMode(loaderContext)) {
      sassOptions.outputStyle = "compressed";
    }

    if (useSourceMap) {
      // Deliberately overriding the sourceMap option here.
      // node-sass won't produce source maps if the data option is used and options.sourceMap is not a string.
      // In case it is a string, options.sourceMap should be a path where the source map is written.
      // But since we're using the data option, the source map will not actually be written, but
      // all paths in sourceMap.sources will be relative to that path.
      // Pretty complicated... :(
      sassOptions.sourceMap = true;
      sassOptions.outFile = path.join(
        loaderContext.rootContext,
        "style.css.map",
      );
      sassOptions.sourceMapContents = true;
      sassOptions.omitSourceMapUrl = true;
      sassOptions.sourceMapEmbed = false;
    }

    const ext = path.extname(resourcePath);

    // If we are compiling sass and indentedSyntax isn't set, automatically set it.
    if (
      ext &&
      ext.toLowerCase() === ".sass" &&
      typeof sassOptions.indentedSyntax === "undefined"
    ) {
      sassOptions.indentedSyntax = true;
    } else {
      sassOptions.indentedSyntax = Boolean(sassOptions.indentedSyntax);
    }

    // Allow passing custom importers to `sass`/`node-sass`. Accepts `Function` or an array of `Function`s.
    sassOptions.importer = sassOptions.importer
      ? proxyCustomImporters(
          Array.isArray(sassOptions.importer)
            ? sassOptions.importer.slice()
            : [sassOptions.importer],
          loaderContext,
        )
      : [];

    // Regression on the `sass-embedded` side
    if (
      loaderOptions.webpackImporter === false &&
      sassOptions.importer.length === 0
    ) {
      // eslint-disable-next-line no-undefined
      sassOptions.importer = undefined;
    }

    sassOptions.includePaths = []
      .concat(process.cwd())
      .concat(
        // We use `includePaths` in context for resolver, so it should be always absolute
        (sassOptions.includePaths ? sassOptions.includePaths.slice() : []).map(
          (includePath) =>
            path.isAbsolute(includePath)
              ? includePath
              : path.join(process.cwd(), includePath),
        ),
      )
      .concat(
        process.env.SASS_PATH
          ? process.env.SASS_PATH.split(
              process.platform === "win32" ? ";" : ":",
            )
          : [],
      );

    if (typeof sassOptions.charset === "undefined") {
      sassOptions.charset = true;
    }
  }

  return sassOptions;
}
Derives the sass options from the loader context and normalizes its values with sane defaults.

@param {object} loaderContext
@param {object} loaderOptions
@param {string} content
@param {object} implementation
@param {boolean} useSourceMap
@param {"legacy" | "modern" | "modern-compiler"} apiType
@returns {Object}