Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion lib/modules/manager/npm/post-update/npm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -549,6 +560,9 @@ describe('modules/manager/npm/post-update/npm', () => {
{
cmd: 'npm install --package-lock-only --no-audit --ignore-scripts --workspace=web/b [email protected] [email protected]',
},
{
cmd: 'npm install --package-lock-only --no-audit --ignore-scripts --workspace=docs/dir.has.period [email protected]',
},

{
cmd: 'npm install --package-lock-only --no-audit --ignore-scripts [email protected] [email protected]',
Expand Down Expand Up @@ -584,6 +598,9 @@ describe('modules/manager/npm/post-update/npm', () => {
{
cmd: 'npm install --package-lock-only --no-audit --ignore-scripts --workspace=web/b [email protected] [email protected]',
},
{
cmd: 'npm install --package-lock-only --no-audit --ignore-scripts --workspace=docs/dir.has.period [email protected]',
},

{
cmd: 'npm install --package-lock-only --no-audit --ignore-scripts [email protected] [email protected]',
Expand Down Expand Up @@ -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(['[email protected]', '[email protected]']),
});
});
Expand Down
6 changes: 5 additions & 1 deletion lib/modules/manager/npm/post-update/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down