async function checkVersionMetadataPaths()

in packages/docusaurus-plugin-content-docs/src/versions.ts [420:459]


async function checkVersionMetadataPaths({
  versionMetadata,
  context,
}: {
  versionMetadata: VersionMetadata;
  context: Pick<LoadContext, 'siteDir'>;
}) {
  const {versionName, contentPath, sidebarFilePath} = versionMetadata;
  const {siteDir} = context;
  const isCurrentVersion = versionName === CURRENT_VERSION_NAME;

  if (!(await fs.pathExists(contentPath))) {
    throw new Error(
      `The docs folder does not exist for version "${versionName}". A docs folder is expected to be found at ${path.relative(
        siteDir,
        contentPath,
      )}.`,
    );
  }

  // If the current version defines a path to a sidebar file that does not
  // exist, we throw! Note: for versioned sidebars, the file may not exist (as
  // we prefer to not create it rather than to create an empty file)
  // See https://github.com/facebook/docusaurus/issues/3366
  // See https://github.com/facebook/docusaurus/pull/4775
  if (
    isCurrentVersion &&
    typeof sidebarFilePath === 'string' &&
    !(await fs.pathExists(sidebarFilePath))
  ) {
    throw new Error(`The path to the sidebar file does not exist at "${path.relative(
      siteDir,
      sidebarFilePath,
    )}".
Please set the docs "sidebarPath" field in your config file to:
- a sidebars path that exists
- false: to disable the sidebar
- undefined: for Docusaurus to generate it automatically`);
  }
}