File size: 765 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const replacementRegExes = [
  /^webpack-internal:\/\/\/(\([\w-]+\)\/)?/,
  /^(webpack:\/\/\/|webpack:\/\/(_N_E\/)?)(\([\w-]+\)\/)?/,
]

export function isWebpackInternalResource(file: string) {
  for (const regex of replacementRegExes) {
    if (regex.test(file)) return true

    file = file.replace(regex, '')
  }

  return false
}

/**
 * Format the webpack internal id to original file path
 *
 * webpack-internal:///./src/hello.tsx => ./src/hello.tsx
 * webpack://_N_E/./src/hello.tsx => ./src/hello.tsx
 * webpack://./src/hello.tsx => ./src/hello.tsx
 * webpack:///./src/hello.tsx => ./src/hello.tsx
 */
export function formatFrameSourceFile(file: string) {
  for (const regex of replacementRegExes) {
    file = file.replace(regex, '')
  }

  return file
}