Repository: cypress-io/cypress
File: packages/driver/src/cy/commands/fixtures.ts (TypeScript)

Code before:
 *
 * Used so invalidation can match both "foo.json" and "foo".
 *
 * @returns [pathWithExtension, pathWithoutExtension] if extension exists, otherwise [path].
 */
const withAndWithoutExt = (path: string) => {
  const extension = extname(path)

  return extension ? [path, path.slice(0, -extension.length)] : [path]
}

/**
 * Builds path prefixes that might have been used in a cache key's fixture
 * portion. Includes forward and backslash variants, with and without
 * extensions, and lowercase variants on Windows.
 */
const buildPrefixes = (rawPath: string): string[] => {
  const forward = rawPath.split(sep).join('/')
  const backslash = forward.replace(/\//g, '\\')

  const bases = [
    ...withAndWithoutExt(forward),
    ...withAndWithoutExt(backslash),
  ]

  if (process?.platform === 'win32') {
    bases.push(
      ...withAndWithoutExt(forward.toLowerCase()),
      ...withAndWithoutExt(backslash.toLowerCase()),
    )
  }

  return Array.from(new Set(bases))
}

/** Turn fixture path prefixes into matchable key prefixes. */
const makeKeyPrefixes = (fixturePath: string): string[] => {
  return buildPrefixes(fixturePath).map((prefix) => `${prefix}${NULL_SEP}`)
}

export default (Commands, Cypress, cy, state, config) => {
  // this is called at the beginning of run, so clear the cache
  let cache = {}

  const clearCache = () => {
    cache = {}
  }

  /**
   * Removes all cached fixture entries that correspond to the given path,
   * across all encodings.

Review comment (suggestion):
The polyfill actually doesn't include the platform in the browser so this never gets called. By the Cypress global does provide it
```suggestion
  if (Cypress.platform === 'win32') {
```

Code after:
 *
 * Used so invalidation can match both "foo.json" and "foo".
 *
 * @returns [pathWithExtension, pathWithoutExtension] if extension exists, otherwise [path].
 */
const withAndWithoutExt = (path: string) => {
  const extension = extname(path)

  return extension ? [path, path.slice(0, -extension.length)] : [path]
}

/**
 * Builds path prefixes that might have been used in a cache key's fixture
 * portion. Includes forward and backslash variants, with and without
 * extensions, and lowercase variants on Windows.
 */
const buildPrefixes = (rawPath: string): string[] => {
  const forward = rawPath.split(sep).join('/')
  const backslash = forward.replace(/\//g, '\\')

  const bases = [
    ...withAndWithoutExt(forward),
    ...withAndWithoutExt(backslash),
  ]

  if (Cypress.platform === 'win32') {
    bases.push(
      ...withAndWithoutExt(forward.toLowerCase()),
      ...withAndWithoutExt(backslash.toLowerCase()),
    )
  }

  return Array.from(new Set(bases))
}

/** Turn fixture path prefixes into matchable key prefixes. */
const makeKeyPrefixes = (fixturePath: string): string[] => {
  return buildPrefixes(fixturePath).map((prefix) => `${prefix}${NULL_SEP}`)
}

export default (Commands, Cypress, cy, state, config) => {
  // this is called at the beginning of run, so clear the cache
  let cache = {}

  const clearCache = () => {
    cache = {}
  }

  /**
   * Removes all cached fixture entries that correspond to the given path,
   * across all encodings.