refactor: fix a few places of path handling (#7023)

This commit is contained in:
Joshua Chen 2022-03-26 22:49:50 +08:00 committed by GitHub
parent e6838dd7a6
commit 4957ec947b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 9 additions and 15 deletions

View file

@ -181,7 +181,7 @@ describe('docsVersion', () => {
DEFAULT_OPTIONS,
),
).rejects.toThrowErrorMatchingInlineSnapshot(
`"[docs]: there is no docs to version!"`,
`"[docs]: no docs found in <PROJECT_ROOT>/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/empty-site/docs."`,
);
});

View file

@ -117,7 +117,7 @@ export async function cliDocsVersionCommand(
const {path: docsPath, sidebarPath} = options;
// Copy docs files.
const docsDir = path.join(siteDir, docsPath);
const docsDir = path.resolve(siteDir, docsPath);
if (
(await fs.pathExists(docsDir)) &&
@ -127,7 +127,7 @@ export async function cliDocsVersionCommand(
const newVersionDir = path.join(versionedDir, `version-${version}`);
await fs.copy(docsDir, newVersionDir);
} else {
throw new Error(`${pluginIdLogPrefix}: there is no docs to version!`);
throw new Error(`${pluginIdLogPrefix}: no docs found in ${docsDir}.`);
}
await createVersionedSidebarFile({

View file

@ -14,7 +14,7 @@ import type {
SidebarItemCategoryLinkConfig,
} from './types';
import _ from 'lodash';
import {addTrailingSlash, posixPath} from '@docusaurus/utils';
import {addTrailingSlash} from '@docusaurus/utils';
import logger from '@docusaurus/logger';
import path from 'path';
import {createDocsByIdIndex, toCategoryIndexMatcherParam} from '../docs';
@ -157,7 +157,7 @@ Available doc IDs:
folderName: string,
): WithPosition<NormalizedSidebarItemCategory> {
const categoryMetadata =
categoriesMetadata[posixPath(path.join(autogenDir, fullPath))];
categoriesMetadata[path.posix.join(autogenDir, fullPath)];
const allItems = Object.entries(dir).map(([key, content]) =>
dirToItem(content, key, `${fullPath}/${key}`),
);