async function getStylesheet(document, filepath, options = {}) {
  const {rebase = {}, css, strict, media} = options;
  const originalPath = filepath;

  const exists = await fileExists(filepath, options);

  if (!exists) {
    const searchPaths = await getAssetPaths(document, filepath, options);
    try {
      filepath = await resolve(filepath, searchPaths, options);
    } catch (error) {
      if (!isRemote(filepath) || strict) {
        throw error;
      }

      return new Vinyl();
    }
  }

  // Create absolute file paths for local files passed via css option
  // to prevent document relative stylesheet paths if they are not relative specified
  if (!Buffer.isBuffer(originalPath) && !isVinyl(filepath) && !isRemote(filepath) && checkCssOption(css)) {
    filepath = path.resolve(filepath);
  }

  const file = await vinylize({filepath}, options);
  if (media) {
    file.contents = Buffer.from(`@media ${media} { ${file.contents.toString()} }`);
  }

  // Restore original path for local files referenced from document and not from options
  if (!Buffer.isBuffer(originalPath) && !isRemote(originalPath) && !checkCssOption(css)) {
    file.path = originalPath;
  }

  // Get stylesheet path. Keeps stylesheet url if it differs from document url
  const stylepath = await getStylesheetPath(document, file, options);
  if (Buffer.isBuffer(originalPath)) {
    file.path = stylepath;
    file.virtualPath = stylepath;
  }

  debug('(getStylesheet) Virtual Stylesheet Path:', stylepath);
  // We can safely rebase assets if we have:
  // - a url to the stylesheet
  // - if rebase.from and rebase.to is specified
  // - a valid document path and a stylesheet path
  // - an absolute positioned stylesheet so we can make the images absolute
  // - and rebase is not disabled (#359)
  // First respect the user input
  if (rebase === false) {
    return file;
  }

  if (rebase.from && rebase.to) {
    file.contents = await rebaseAssets(file.contents, rebase.from, rebase.to, {
      method: 'rebase',
      strict: options.strict,
      inlined: Buffer.isBuffer(originalPath),
    });
  } else if (typeof rebase === 'function') {
    file.contents = await rebaseAssets(file.contents, stylepath, document.virtualPath, {
      method: rebase,
      strict: options.strict,
      inlined: Buffer.isBuffer(originalPath),
    });
    // Next rebase to the stylesheet url
  } else if (isRemote(rebase.to || stylepath)) {
    const from = rebase.from || stylepath;
    const to = rebase.to || stylepath;
    const method = (asset) => (isRemote(asset.originUrl) ? asset.originUrl : urlResolve(to, asset.originUrl));
    file.contents = await rebaseAssets(file.contents, from, to, {
      method,
      strict: options.strict,
      inlined: Buffer.isBuffer(originalPath),
    });

    // Use relative path to document (local)
  } else if (document.virtualPath) {
    file.contents = await rebaseAssets(file.contents, rebase.from || stylepath, rebase.to || document.virtualPath, {
      method: 'rebase',
      strict: options.strict,
      inlined: Buffer.isBuffer(originalPath),
    });
  } else if (document.remote) {
    const {pathname} = document.urlObj;
    file.contents = await rebaseAssets(file.contents, rebase.from || stylepath, rebase.to || pathname, {
      method: 'rebase',
      strict: options.strict,
      inlined: Buffer.isBuffer(originalPath),
    });

    // Make images absolute if we have an absolute positioned stylesheet
  } else if (isAbsolute(stylepath)) {
    file.contents = await rebaseAssets(file.contents, rebase.from || stylepath, rebase.to || '/index.html', {
      method: (asset) => normalizePath(asset.absolutePath),
      strict: options.strict,
      inlined: Buffer.isBuffer(originalPath),
    });
  } else {
    warn(`Not rebasing assets for ${originalPath}. Use "rebase" option`);
  }

  debug('(getStylesheet) Result:', file);

  return file;
}
Get stylesheet file object
@param {Vinyl} document Document vinyl object
@param {string} filepath Path/Url to css file
@param {object} options Critical options
@returns {Promise<Vinyl>} Vinyl representation fo the stylesheet