From 8b6656efb100ba0370c0c49a511b6bb89cb8a087 Mon Sep 17 00:00:00 2001 From: smouillour Date: Thu, 12 Oct 2023 19:50:25 +0200 Subject: [PATCH] try something to inprove findPackagesFromScopeFolder for PNPM --- fork/dynamic-cdn-webpack-plugin/src/find.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/fork/dynamic-cdn-webpack-plugin/src/find.js b/fork/dynamic-cdn-webpack-plugin/src/find.js index b2c9a2c7d16..5abd520e4c6 100644 --- a/fork/dynamic-cdn-webpack-plugin/src/find.js +++ b/fork/dynamic-cdn-webpack-plugin/src/find.js @@ -22,9 +22,12 @@ function findPackage(info) { }); } let warnPNPMonce = true; +let pnpmMaxSubLevel = 0; function findPackagesFromScopeFolder(scope, name, scopeFolderPath) { const isWantedScope = scopeFolderPath.endsWith(`${path.sep}${scope}`); + const isPNPMProcess = + process.env.npm_config_user_agent && process.env.npm_config_user_agent.includes('pnpm'); return fs .readdirSync(scopeFolderPath, { withFileTypes: true }) .filter(f => f.isDirectory() || f.isSymbolicLink()) @@ -35,9 +38,12 @@ function findPackagesFromScopeFolder(scope, name, scopeFolderPath) { // just add the path to the found list return accu.concat(subFolderPath); } - if ( - !(process.env.npm_config_user_agent && process.env.npm_config_user_agent.includes('pnpm')) - ) { + + if ((isPNPMProcess && pnpmMaxSubLevel < 4) || !isPNPMProcess) { + if (isPNPMProcess) { + pnpmMaxSubLevel++; + console.warn('Executed with PNPM: !!'); + } // TODO NOT COMPATIBLE WITH PNPM // the scope or package name is not the one we look for // if there is a nested node modules folder, we dive into it for the search @@ -64,9 +70,6 @@ function findPackagesFromNonScopeFolder(scope, name, nonScopeFolderPath) { if (subFolder.name === '.bin') { return accu; } - // if (subFolder.name === '.pnpm') { - // return accu; - // } if (subFolder.name.startsWith('@')) { // for scope folders, we need a special treatment to avoid getting scoped packages when we don't want a scoped one. // ex: search for `classnames`, we don't want to find `@types/classnames` in the result