MCPcopy
hub / github.com/vercel/next.js / normalizeManifest

Function normalizeManifest

test/lib/next-test-utils.ts:1994–2022  ·  view source on GitHub ↗
(
  manifest: unknown,
  replacements: [search: string, replace: string][]
)

Source from the content-addressed store, hash-verified

1992 * @returns The normalized manifest.
1993 */
1994export function normalizeManifest<T>(
1995 manifest: unknown,
1996 replacements: [search: string, replace: string][]
1997): T {
1998 return JSON.parse(
1999 replacements.reduce(
2000 (acc, [search, replace]) =>
2001 acc.replace(
2002 new RegExp(
2003 // We want to match the literal string, so we need to escape it
2004 // again
2005 escapeRegex(
2006 JSON.stringify(
2007 // The output has already been escaped, so we need to escape our
2008 // search string.
2009 escapeRegex(search)
2010 )
2011 // Remove the quotes added by the JSON.stringify call.
2012 .replace(/^"(.*)"/, '$1')
2013 ),
2014 'g'
2015 ),
2016 replace
2017 ),
2018 // We'll perform the replacements on the JSON stringified manifest.
2019 JSON.stringify(manifest)
2020 )
2021 )
2022}
2023
2024export function getDistDir(): '.next' | '.next/dev' {
2025 // global.isNextDev is set in e2e/development/production tests.

Callers 2

runTestsFunction · 0.90
runTestsFunction · 0.90

Calls 5

escapeRegexFunction · 0.85
reduceMethod · 0.80
replaceMethod · 0.65
parseMethod · 0.45
stringifyMethod · 0.45

Tested by 2

runTestsFunction · 0.72
runTestsFunction · 0.72