Skip to content

Commit

Permalink
refactor: fix a few places of path handling (#7023)
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena authored Mar 26, 2022
1 parent e6838dd commit 4957ec9
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 15 deletions.
6 changes: 1 addition & 5 deletions packages/docusaurus-plugin-content-blog/src/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {Feed, type Author as FeedAuthor, type Item as FeedItem} from 'feed';
import type {BlogPost} from './types';
import {
normalizeUrl,
posixPath,
mapAsyncSequential,
readOutputHTMLFile,
} from '@docusaurus/utils';
Expand Down Expand Up @@ -128,10 +127,7 @@ async function createBlogFeedFile({
}
})();
try {
await fs.outputFile(
posixPath(path.join(generatePath, feedPath)),
feedContent,
);
await fs.outputFile(path.join(generatePath, feedPath), feedContent);
} catch (err) {
throw new Error(`Generating ${feedType} feed failed: ${err}.`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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."`,
);
});

Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-content-docs/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) &&
Expand All @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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}`),
);
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-utils/src/dataFileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export async function getDataFilePath({
filePath,
);
if (contentPath) {
return path.join(contentPath, filePath);
return path.resolve(contentPath, filePath);
}
return undefined;
}
Expand Down
4 changes: 1 addition & 3 deletions packages/docusaurus/src/commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ export default async function serve(
siteDir: string,
cliOptions: ServeCLIOptions,
): Promise<void> {
let dir = path.isAbsolute(cliOptions.dir)
? cliOptions.dir
: path.join(siteDir, cliOptions.dir);
let dir = path.resolve(siteDir, cliOptions.dir);

if (cliOptions.build) {
dir = await build(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ Maybe you should remove them? ${unknownKeys}`;

// should we make this configurable?
function getTranslationsDirPath(context: TranslationContext): string {
return path.resolve(path.join(context.siteDir, I18N_DIR_NAME));
return path.join(context.siteDir, I18N_DIR_NAME);
}
export function getTranslationsLocaleDirPath(
context: TranslationContext,
Expand Down

0 comments on commit 4957ec9

Please sign in to comment.