From 738386e4bbf556779d14c3654e90cf97bdccc723 Mon Sep 17 00:00:00 2001 From: cabbage9 Date: Mon, 12 Jul 2021 17:05:00 +0800 Subject: [PATCH 1/4] fix(create-vite): distinguish pnpm pkgManager --- packages/create-vite/index.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/packages/create-vite/index.js b/packages/create-vite/index.js index 5e2b0e75b0296f..19f3afdeb8ac0b 100755 --- a/packages/create-vite/index.js +++ b/packages/create-vite/index.js @@ -254,14 +254,17 @@ async function init() { write('package.json', JSON.stringify(pkg, null, 2)) - const pkgManager = /yarn/.test(process.env.npm_execpath) ? 'yarn' : 'npm' + const pkgManager = + pmFromUserAgent(process.env.npm_config_user_agent)?.name || 'npm' console.log(`\nDone. Now run:\n`) if (root !== cwd) { console.log(` cd ${path.relative(cwd, root)}`) } - console.log(` ${pkgManager === 'yarn' ? `yarn` : `npm install`}`) - console.log(` ${pkgManager === 'yarn' ? `yarn dev` : `npm run dev`}`) + console.log(` ${pkgManager === 'yarn' ? `yarn` : `${pkgManager} install`}`) + console.log( + ` ${pkgManager === 'yarn' ? `yarn dev` : `${pkgManager} run dev`}` + ) console.log() } @@ -318,6 +321,20 @@ function emptyDir(dir) { } } +/** + * @param {string | undefined} userAgent process.env.npm_config_user_agent + * @returns object | undefined + */ +function pmFromUserAgent(userAgent) { + if (!userAgent) return undefined + const pmSpec = userAgent.split(' ')[0] + const pmSpecArr = pmSpec.split('/') + return { + name: pmSpecArr[0], + version: pmSpecArr[1] + } +} + init().catch((e) => { console.error(e) }) From fea1bfd211ad43de597545c3f1f6064c051cd8b5 Mon Sep 17 00:00:00 2001 From: cabbage9 Date: Wed, 14 Jul 2021 22:20:13 +0800 Subject: [PATCH 2/4] fix(create-vite): distinguish pkgManager --- packages/create-vite/index.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/create-vite/index.js b/packages/create-vite/index.js index 19f3afdeb8ac0b..caf943d33c3c48 100755 --- a/packages/create-vite/index.js +++ b/packages/create-vite/index.js @@ -254,8 +254,8 @@ async function init() { write('package.json', JSON.stringify(pkg, null, 2)) - const pkgManager = - pmFromUserAgent(process.env.npm_config_user_agent)?.name || 'npm' + const pkgInfo = pkgFromUserAgent(process.env.npm_config_user_agent) + const pkgManager = pkgInfo ? pkgInfo.name : 'npm' console.log(`\nDone. Now run:\n`) if (root !== cwd) { @@ -325,13 +325,13 @@ function emptyDir(dir) { * @param {string | undefined} userAgent process.env.npm_config_user_agent * @returns object | undefined */ -function pmFromUserAgent(userAgent) { +function pkgFromUserAgent(userAgent) { if (!userAgent) return undefined - const pmSpec = userAgent.split(' ')[0] - const pmSpecArr = pmSpec.split('/') + const pkgSpec = userAgent.split(' ')[0] + const pkgSpecArr = pkgSpec.split('/') return { - name: pmSpecArr[0], - version: pmSpecArr[1] + name: pkgSpecArr[0], + version: pkgSpecArr[1] } } From 40823e09dbe804dd0661f7365e8c5691a83ed914 Mon Sep 17 00:00:00 2001 From: Ryan Moyo Date: Fri, 30 Jul 2021 15:10:12 +0800 Subject: [PATCH 3/4] fix(create-vite): distinguish pkgManager Co-authored-by: Shinigami --- packages/create-vite/index.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/create-vite/index.js b/packages/create-vite/index.js index 286ee01edbfdd3..fa8d3d6b1b1e85 100755 --- a/packages/create-vite/index.js +++ b/packages/create-vite/index.js @@ -261,10 +261,16 @@ async function init() { if (root !== cwd) { console.log(` cd ${path.relative(cwd, root)}`) } - console.log(` ${pkgManager === 'yarn' ? `yarn` : `${pkgManager} install`}`) - console.log( - ` ${pkgManager === 'yarn' ? `yarn dev` : `${pkgManager} run dev`}` - ) + switch (pkgManager) { + case 'yarn': + console.log(' yarn') + console.log(' yarn dev') + break + default: + console.log(`${pkgManager} install`) + console.log(`${pkgManager} run dev`) + break + } console.log() } From 78deec2ad795461354ea8ef1c307fa8ae98d7263 Mon Sep 17 00:00:00 2001 From: patak Date: Fri, 30 Jul 2021 14:41:26 +0200 Subject: [PATCH 4/4] chore: missing spacing --- packages/create-vite/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/create-vite/index.js b/packages/create-vite/index.js index fa8d3d6b1b1e85..4c5879bdd0bd12 100755 --- a/packages/create-vite/index.js +++ b/packages/create-vite/index.js @@ -267,8 +267,8 @@ async function init() { console.log(' yarn dev') break default: - console.log(`${pkgManager} install`) - console.log(`${pkgManager} run dev`) + console.log(` ${pkgManager} install`) + console.log(` ${pkgManager} run dev`) break } console.log()