fix(npm): better detect workspace packages (#25692)

This commit is contained in:
Rhys Arkins 2023-11-10 20:29:10 +01:00 committed by GitHub
parent 3788950167
commit 16b3862821
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 8 deletions

View file

@ -459,6 +459,17 @@ describe('modules/manager/npm/post-update/npm', () => {
workspacesPackages: ['docs/*', 'web/*'],
},
},
{
packageFile: 'some-missing-dir/docs/a/package.json',
packageName: 'hello',
depType: 'dependencies',
newVersion: '1.1.1',
newValue: '^1.0.0',
isLockfileUpdate: true,
managerData: {
workspacesPackages: ['docs/*', 'web/*'],
},
},
];
it('workspace in sub-folder', async () => {

View file

@ -265,19 +265,29 @@ export function divideWorkspaceAndRootDeps(
// stop when the first match is found and
// add workspaceDir to workspaces set and upgrade object
for (const workspacePattern of workspacePatterns) {
if (minimatch(workspacePattern).match(workspaceDir)) {
const massagedPattern = (workspacePattern as string).replace(
/^\.\//,
'',
);
if (minimatch(massagedPattern).match(workspaceDir)) {
workspaceName = workspaceDir;
break;
}
}
if (workspaceName) {
if (
workspaceName &&
!rootDeps.has(upgrade.managerData.packageKey) // prevent same dep from existing in root and workspace
) {
workspaces.add(workspaceName);
upgrade.workspace = workspaceName;
lockWorkspacesUpdates.push(upgrade);
}
} else {
logger.warn(
{ workspacePatterns, workspaceDir },
'workspaceDir not found',
);
}
continue;
}
}