next.js/packages/next/src/shared/lib/turbopack/entry-key.ts
entry-key.ts35 lines813 B
/**
 * `app` -> app dir
 * `pages` -> pages dir
 * `root` -> middleware / instrumentation
 * `assets` -> assets
 */
export type EntryKeyType = 'app' | 'pages' | 'root' | 'assets'
export type EntryKeySide = 'client' | 'server'

// custom type to make sure you can't accidentally use a "generic" string
export type EntryKey =
  `{"type":"${EntryKeyType}","side":"${EntryKeyType}","page":"${string}"}`

/**
 * Get a key that's unique across all entrypoints.
 */
export function getEntryKey(
  type: EntryKeyType,
  side: EntryKeySide,
  page: string
): EntryKey {
  return JSON.stringify({ type, side, page }) as EntryKey
}

/**
 * Split an `EntryKey` up into its components.
 */
export function splitEntryKey(key: EntryKey): {
  type: EntryKeyType
  side: EntryKeySide
  page: string
} {
  return JSON.parse(key)
}
Quest for Codev2.0.0
/
SIGN IN