Repository: vercel/next.js
File: packages/next/src/build/webpack/loaders/next-app-loader/index.ts (TypeScript)

Code before:
    )

    return checks.find((result) => result)
  }

  const metadataResolver: MetadataResolver = async (
    dirname,
    filename,
    exts
  ) => {
    const absoluteDir = createAbsolutePath(appDir, dirname)

    const checks = await Promise.all(
      exts.map(async (ext) => {
        // Compared to `resolver` above the exts do not have the `.` included already, so it's added here.
        const filenameWithExt = `${filename}.${ext}`
        const absolutePathWithExtension = `${absoluteDir}${path.sep}${filenameWithExt}`
        const exists = await fileExistsInDirectory(dirname, filenameWithExt)
        // Call `addMissingDependency` for all files even if they didn't match,
        // because they might be added or removed during development.
        this.addMissingDependency(absolutePathWithExtension)
        return exists ? absolutePathWithExtension : undefined
      })
    )

    return checks.filter((result): result is string => result !== undefined)
  }

  if (isAppRouteRoute(name)) {
    return createAppRouteCode({
      appDir,
      // TODO: investigate if the local `page` is the same as the loaderOptions.page
      page: loaderOptions.page,
      name,
      pagePath,
      resolveAppRoute,
      pageExtensions,
      nextConfigOutput,
    })
  }

  let treeCodeResult = await createTreeCodeFromPath(pagePath, {
    page,
    resolveDir,
    resolver,
    metadataResolver,
    resolveParallelSegments,
    hasChildRoutesForSegment,
    getStaticSiblingSegments,
    loaderContext: this,
    pageExtensions,

Review comment (suggestion):
this is odd, if you want to know it's a string you should probably check `typeof === 'string'`

Code after:
    )

    return checks.find((result) => result)
  }

  const metadataResolver: MetadataResolver = async (
    dirname,
    filename,
    exts
  ) => {
    const absoluteDir = createAbsolutePath(appDir, dirname)

    const checks = await Promise.all(
      exts.map(async (ext) => {
        // Compared to `resolver` above the exts do not have the `.` included already, so it's added here.
        const filenameWithExt = `${filename}.${ext}`
        const absolutePathWithExtension = `${absoluteDir}${path.sep}${filenameWithExt}`
        const exists = await fileExistsInDirectory(dirname, filenameWithExt)
        // Call `addMissingDependency` for all files even if they didn't match,
        // because they might be added or removed during development.
        this.addMissingDependency(absolutePathWithExtension)
        return exists ? absolutePathWithExtension : undefined
      })
    )

    return checks.filter((result) => result !== undefined)
  }

  if (isAppRouteRoute(name)) {
    return createAppRouteCode({
      appDir,
      // TODO: investigate if the local `page` is the same as the loaderOptions.page
      page: loaderOptions.page,
      name,
      pagePath,
      resolveAppRoute,
      pageExtensions,
      nextConfigOutput,
    })
  }

  let treeCodeResult = await createTreeCodeFromPath(pagePath, {
    page,
    resolveDir,
    resolver,
    metadataResolver,
    resolveParallelSegments,
    hasChildRoutesForSegment,
    getStaticSiblingSegments,
    loaderContext: this,
    pageExtensions,