From c885f6d7dc9a252d2fd5312112f2e368f5f8d13c Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Sat, 7 Nov 2020 08:28:32 +0530 Subject: [PATCH 1/3] feat: add pnpm support for installing CLI --- bin/webpack.js | 12 +++++++++++- cspell.json | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/bin/webpack.js b/bin/webpack.js index 4cc7a26519f..2d5fd67a663 100755 --- a/bin/webpack.js +++ b/bin/webpack.js @@ -83,8 +83,18 @@ if (!cli.installed) { console.error(notify); const isYarn = fs.existsSync(path.resolve(process.cwd(), "yarn.lock")); + const isPnpm = fs.existsSync(path.resolve(process.cwd(), "pnpm-lock.yaml")); + + let packageManager; + + if (isYarn) { + packageManager = "yarn"; + } else if (isPnpm) { + packageManager = "pnpm"; + } else { + packageManager = "npm"; + } - const packageManager = isYarn ? "yarn" : "npm"; const installOptions = [isYarn ? "add" : "install", "-D"]; console.error( diff --git a/cspell.json b/cspell.json index 9055c063f65..d09878316b3 100644 --- a/cspell.json +++ b/cspell.json @@ -221,7 +221,8 @@ "opencollective", "dependabot", "browserslist", - "samsunginternet" + "samsunginternet", + "pnpm" ], "ignoreRegExpList": ["/Author.+/", "/data:.*/", "/\"mappings\":\".+\"/"], "ignorePaths": ["**/dist/**", "examples/**/README.md"] From e827f4fc44b4fb94c7ae471a17a254545daf2fed Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Sat, 7 Nov 2020 17:43:38 +0530 Subject: [PATCH 2/3] refactor: packageManager logic for perf improvement --- bin/webpack.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/bin/webpack.js b/bin/webpack.js index 2d5fd67a663..5661c0129ec 100755 --- a/bin/webpack.js +++ b/bin/webpack.js @@ -82,8 +82,19 @@ if (!cli.installed) { console.error(notify); - const isYarn = fs.existsSync(path.resolve(process.cwd(), "yarn.lock")); - const isPnpm = fs.existsSync(path.resolve(process.cwd(), "pnpm-lock.yaml")); + const isNpm = fs.existsSync(path.resolve(process.cwd(), "package-lock.json")); + + let isYarn = false; + + if (!isNpm) { + isYarn = fs.existsSync(path.resolve(process.cwd(), "yarn.lock")); + } + + let isPnpm = false; + + if (!isYarn) { + isPnpm = fs.existsSync(path.resolve(process.cwd(), "pnpm-lock.yaml")); + } let packageManager; From fa7686c0f9aaa9e4c04444ed2fc502d81e0cbd8a Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Fri, 20 Nov 2020 18:03:05 +0530 Subject: [PATCH 3/3] refactor: logic suggestions from code review Co-authored-by: Tobias Koppers --- bin/webpack.js | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/bin/webpack.js b/bin/webpack.js index 5661c0129ec..98a0b72d691 100755 --- a/bin/webpack.js +++ b/bin/webpack.js @@ -82,31 +82,17 @@ if (!cli.installed) { console.error(notify); - const isNpm = fs.existsSync(path.resolve(process.cwd(), "package-lock.json")); - - let isYarn = false; - - if (!isNpm) { - isYarn = fs.existsSync(path.resolve(process.cwd(), "yarn.lock")); - } - - let isPnpm = false; - - if (!isYarn) { - isPnpm = fs.existsSync(path.resolve(process.cwd(), "pnpm-lock.yaml")); - } - let packageManager; - if (isYarn) { + if (fs.existsSync(path.resolve(process.cwd(), "yarn.lock"))) { packageManager = "yarn"; - } else if (isPnpm) { + } else if (fs.existsSync(path.resolve(process.cwd(), "pnpm-lock.yaml"))) { packageManager = "pnpm"; } else { packageManager = "npm"; } - const installOptions = [isYarn ? "add" : "install", "-D"]; + const installOptions = [packageManager === "yarn" ? "add" : "install", "-D"]; console.error( `We will use "${packageManager}" to install the CLI via "${packageManager} ${installOptions.join(