()
| 1 | import { InvariantError } from '../shared/lib/invariant-error' |
| 2 | |
| 3 | export function getAssetPrefix() { |
| 4 | const currentScript = document.currentScript |
| 5 | |
| 6 | if (!(currentScript instanceof HTMLScriptElement)) { |
| 7 | throw new InvariantError( |
| 8 | `Expected document.currentScript to be a <script> element. Received ${currentScript} instead.` |
| 9 | ) |
| 10 | } |
| 11 | |
| 12 | const { pathname } = new URL(currentScript.src) |
| 13 | const nextIndex = pathname.indexOf('/_next/') |
| 14 | |
| 15 | if (nextIndex === -1) { |
| 16 | throw new InvariantError( |
| 17 | `Expected document.currentScript src to contain '/_next/'. Received ${currentScript.src} instead.` |
| 18 | ) |
| 19 | } |
| 20 | |
| 21 | return pathname.slice(0, nextIndex) |
| 22 | } |
no test coverage detected