From 7c2f070d36616df1f55b3a41d6a65190fd7e4bb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A0=81=E5=86=9C=E5=B0=8F=E6=98=93?= <237972113@qq.com> Date: Thu, 7 Mar 2024 13:30:08 +0800 Subject: [PATCH 1/4] fix: createContentLoader issue by changing pattern mapping from config.root to config.srcDir. (#3622) --- src/node/contentLoader.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node/contentLoader.ts b/src/node/contentLoader.ts index c213f794b0bb..5e4f456565ec 100644 --- a/src/node/contentLoader.ts +++ b/src/node/contentLoader.ts @@ -98,7 +98,7 @@ export function createContentLoader( } if (typeof pattern === 'string') pattern = [pattern] - pattern = pattern.map((p) => normalizePath(path.join(config.root, p))) + pattern = pattern.map((p) => normalizePath(path.join(config.srcDir, p))) let md: MarkdownRenderer From 3f6008d396c2e249afeb4aff99e39ecbb981a172 Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Thu, 7 Mar 2024 13:04:04 +0530 Subject: [PATCH 2/4] adjust comment --- src/node/contentLoader.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node/contentLoader.ts b/src/node/contentLoader.ts index 5e4f456565ec..dc8651ac84e0 100644 --- a/src/node/contentLoader.ts +++ b/src/node/contentLoader.ts @@ -75,7 +75,7 @@ export interface ContentData { */ export function createContentLoader( /** - * files to glob / watch - relative to + * files to glob / watch - relative to srcDir */ pattern: string | string[], { From b2dff54dc97e3d4857423f037ba755285aeeca04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A0=81=E5=86=9C=E5=B0=8F=E6=98=93?= <237972113@qq.com> Date: Thu, 7 Mar 2024 19:21:57 +0800 Subject: [PATCH 3/4] feat(build): add validation when initializing VitePress configuration --- src/node/init/init.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/node/init/init.ts b/src/node/init/init.ts index 774e528b72ab..d8d1dd617aaf 100644 --- a/src/node/init/init.ts +++ b/src/node/init/init.ts @@ -46,7 +46,14 @@ export async function init() { message: 'Where should VitePress initialize the config?', initialValue: './', validate(value) { - // TODO make sure directory is inside + const inputRoot = path.resolve(value) + const currentRoot = path.resolve() + if (!inputRoot.startsWith(currentRoot)) { + return 'Please make sure directory is inside' + } + if (fs.pathExistsSync(inputRoot)) { + return `${value} already exists` + } } }), From 8695c2731599c7fa0aeb3e1516edf55a0386ed3f Mon Sep 17 00:00:00 2001 From: Timothy Lau Date: Fri, 8 Mar 2024 17:07:58 +0800 Subject: [PATCH 4/4] fix: Fix directory validation logic and error message --- src/node/init/init.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/node/init/init.ts b/src/node/init/init.ts index d8d1dd617aaf..1197c7f93a2b 100644 --- a/src/node/init/init.ts +++ b/src/node/init/init.ts @@ -44,6 +44,7 @@ export async function init() { root: () => text({ message: 'Where should VitePress initialize the config?', + defaultValue: './', initialValue: './', validate(value) { const inputRoot = path.resolve(value) @@ -51,7 +52,7 @@ export async function init() { if (!inputRoot.startsWith(currentRoot)) { return 'Please make sure directory is inside' } - if (fs.pathExistsSync(inputRoot)) { + if (inputRoot != currentRoot && fs.pathExistsSync(inputRoot)) { return `${value} already exists` } }