From 08eeac7cb8f9ae2e1675e1c06989641c7d8f6a49 Mon Sep 17 00:00:00 2001 From: pengzhanbo Date: Tue, 8 Oct 2024 11:46:34 +0800 Subject: [PATCH] fix(cli): incorrect `yarn` project creation process, close #254 (#255) * fix(cli): incorrect `yarn` project creation process, close #254 * chore: tweak --- cli/package.json | 4 +++- cli/src/generate.ts | 7 +++++++ cli/src/packageJson.ts | 11 ++++++++--- cli/src/run.ts | 6 +++--- plugins/plugin-md-power/package.json | 6 ++++++ pnpm-lock.yaml | 3 +++ 6 files changed, 30 insertions(+), 7 deletions(-) diff --git a/cli/package.json b/cli/package.json index 4979cbfc..7cfc91d6 100644 --- a/cli/package.json +++ b/cli/package.json @@ -41,6 +41,8 @@ "vuepress": "2.0.0-rc.17", "vue": "^3.5.10", "sass-embedded": "^1.79.4", - "sass-loader": "^16.0.2" + "sass-loader": "^16.0.2", + "http-server": "^14.1.1", + "typescript": "^5.6.2" } } diff --git a/cli/src/generate.ts b/cli/src/generate.ts index 830b3ad2..debcdf25 100644 --- a/cli/src/generate.ts +++ b/cli/src/generate.ts @@ -72,6 +72,13 @@ export async function generate(mode: Mode, data: ResolvedData): Promise { } // rewrite git files end ==================================== + if (data.packageManager === 'yarn') { + fileList.push({ + filepath: '.yarnrc.yml', + content: 'nodeLinker: \'node-modules\'\n', + }) + } + if (data.deploy !== DeployType.custom) { fileList.push(...await readFiles(getTemplate(`deploy/${data.deploy}`))) } diff --git a/cli/src/packageJson.ts b/cli/src/packageJson.ts index 3fefbc52..147fab0c 100644 --- a/cli/src/packageJson.ts +++ b/cli/src/packageJson.ts @@ -14,6 +14,7 @@ export async function createPackageJson( siteDescription, bundler, injectNpmScripts, + useTs, }: ResolvedData, ): Promise { if (mode === Mode.create) { @@ -23,8 +24,10 @@ export async function createPackageJson( pkg.description = siteDescription if (packageManager !== 'npm') { - const version = await getPackageManagerVersion(packageManager) + let version = await getPackageManagerVersion(packageManager) if (version) { + if (packageManager === 'yarn' && version.startsWith('1')) + version = '4.5.0' pkg.packageManager = `${packageManager}@${version}` } } @@ -61,9 +64,8 @@ export async function createPackageJson( pkg.devDependencies[`@vuepress/bundler-${bundler}`] = `${meta.vuepress}` pkg.devDependencies.vuepress = `${meta.vuepress}` pkg.devDependencies['vuepress-theme-plume'] = `${context.version}` - pkg.devDependencies['http-server'] = '^14.1.1' - const deps: string[] = [] + const deps: string[] = ['http-server'] if (!hasDep('vue')) deps.push('vue') @@ -73,6 +75,9 @@ export async function createPackageJson( if (!hasDep('sass-embedded')) deps.push('sass-embedded') + if (useTs) + deps.push('typescript') + for (const dep of deps) pkg.devDependencies[dep] = meta[dep] diff --git a/cli/src/run.ts b/cli/src/run.ts index b48b8535..117f43e8 100644 --- a/cli/src/run.ts +++ b/cli/src/run.ts @@ -49,7 +49,7 @@ export async function run(mode: Mode, root?: string) { if (data.install) { progress.message(t('spinner.install')) try { - await execaCommand(pm === 'yarn' ? 'yarn' : `${pm} install`, { cwd }) + await execaCommand(`${pm} install`, { cwd }) } catch (e) { console.error(`${colors.red('install dependencies error: ')}\n`, e) @@ -58,8 +58,8 @@ export async function run(mode: Mode, root?: string) { } const cdCommand = mode === Mode.create ? colors.green(`cd ${data.root}`) : '' - const runCommand = colors.green(pm === 'yarn' ? 'yarn docs:dev' : `${pm} run docs:dev`) - const installCommand = colors.green(pm === 'yarn' ? 'yarn' : `${pm} install`) + const runCommand = colors.green(`${pm} run docs:dev`) + const installCommand = colors.green(`${pm} install`) progress.stop(t('spinner.stop')) diff --git a/plugins/plugin-md-power/package.json b/plugins/plugin-md-power/package.json index 304a9479..cd112bc2 100644 --- a/plugins/plugin-md-power/package.json +++ b/plugins/plugin-md-power/package.json @@ -37,8 +37,14 @@ "tsup": "tsup --config tsup.config.ts" }, "peerDependencies": { + "markdown-it": "^14.0.0", "vuepress": "2.0.0-rc.17" }, + "peerDependenciesMeta": { + "markdown-it": { + "optional": true + } + }, "dependencies": { "@mdit/plugin-attrs": "^0.13.1", "@mdit/plugin-footnote": "^0.13.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bd1a2df7..a6a3474d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -189,6 +189,9 @@ importers: image-size: specifier: ^1.1.1 version: 1.1.1 + markdown-it: + specifier: ^14.0.0 + version: 14.1.0 markdown-it-container: specifier: ^4.0.0 version: 4.0.0