Skip to content

Commit

Permalink
try something to inprove findPackagesFromScopeFolder for PNPM
Browse files Browse the repository at this point in the history
  • Loading branch information
smouillour committed Oct 12, 2023
1 parent 4e7be57 commit 8b6656e
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions fork/dynamic-cdn-webpack-plugin/src/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 8b6656e

Please sign in to comment.