fix(npm): don't break on npm workspace dir with a period (#30483)

This commit is contained in:
Trent Mick 2024-07-30 11:24:28 -07:00 committed by GitHub
parent 99ba29df74
commit 5bdaf47eeb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 35 additions and 2 deletions

View file

@ -514,6 +514,17 @@ describe('modules/manager/npm/post-update/npm', () => {
workspacesPackages: ['docs/*', 'web/*'],
},
},
{
packageFile: 'some-dir/docs/dir.has.period/package.json',
packageName: 'hello',
depType: 'dependencies',
newVersion: '1.1.1',
newValue: '^1.0.0',
isLockfileUpdate: true,
managerData: {
workspacesPackages: ['docs/*', 'web/*'],
},
},
{
packageFile: 'some-missing-dir/docs/a/package.json',
packageName: 'hello',
@ -549,6 +560,9 @@ describe('modules/manager/npm/post-update/npm', () => {
{
cmd: 'npm install --package-lock-only --no-audit --ignore-scripts --workspace=web/b xmldoc@2.2.0 hello@1.1.1',
},
{
cmd: 'npm install --package-lock-only --no-audit --ignore-scripts --workspace=docs/dir.has.period hello@1.1.1',
},
{
cmd: 'npm install --package-lock-only --no-audit --ignore-scripts chalk@9.4.8 postcss@8.4.8',
@ -584,6 +598,9 @@ describe('modules/manager/npm/post-update/npm', () => {
{
cmd: 'npm install --package-lock-only --no-audit --ignore-scripts --workspace=web/b xmldoc@2.2.0 hello@1.1.1',
},
{
cmd: 'npm install --package-lock-only --no-audit --ignore-scripts --workspace=docs/dir.has.period hello@1.1.1',
},
{
cmd: 'npm install --package-lock-only --no-audit --ignore-scripts chalk@9.4.8 postcss@8.4.8',
@ -689,8 +706,20 @@ describe('modules/manager/npm/post-update/npm', () => {
},
workspace: 'docs/a',
},
{
packageFile: 'docs/dir.has.period/package.json',
packageName: 'hello',
depType: 'dependencies',
newVersion: '1.1.1',
newValue: '^1.0.0',
isLockfileUpdate: true,
managerData: {
workspacesPackages: ['docs/*', 'web/*'],
},
workspace: 'docs/dir.has.period',
},
],
workspaces: new Set(['docs/a', 'web/b']),
workspaces: new Set(['docs/a', 'web/b', 'docs/dir.has.period']),
rootDeps: new Set(['chalk@9.4.8', 'postcss@8.4.8']),
});
});

View file

@ -291,7 +291,11 @@ export function divideWorkspaceAndRootDeps(
);
// workspaceDir = packageFileDir - lockFileDir
const workspaceDir = trimSlashes(packageFileDir.replace(lockFileDir, ''));
const workspaceDir = trimSlashes(
packageFileDir.startsWith(lockFileDir)
? packageFileDir.slice(lockFileDir.length)
: packageFileDir,
);
if (is.nonEmptyString(workspaceDir)) {
let workspaceName: string | undefined;