diff --git a/common/changes/@microsoft/rush/jmaher-prevent-decoupled-workspace-deps_2024-07-30-15-46.json b/common/changes/@microsoft/rush/jmaher-prevent-decoupled-workspace-deps_2024-07-30-15-46.json new file mode 100644 index 00000000000..605eef1e917 --- /dev/null +++ b/common/changes/@microsoft/rush/jmaher-prevent-decoupled-workspace-deps_2024-07-30-15-46.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "comment": "Emit an error if a `workspace:` specifier is used in a dependency that is listed in `decoupledLocalDependencies`.", + "type": "none", + "packageName": "@microsoft/rush" + } + ], + "packageName": "@microsoft/rush", + "email": "jamesmaher-dd@users.noreply.github.com" +} \ No newline at end of file diff --git a/libraries/rush-lib/src/logic/installManager/WorkspaceInstallManager.ts b/libraries/rush-lib/src/logic/installManager/WorkspaceInstallManager.ts index 5098f48e4d1..00db90249ed 100644 --- a/libraries/rush-lib/src/logic/installManager/WorkspaceInstallManager.ts +++ b/libraries/rush-lib/src/logic/installManager/WorkspaceInstallManager.ts @@ -279,7 +279,20 @@ export class WorkspaceInstallManager extends BaseInstallManager { shrinkwrapIsUpToDate = false; continue; } - } else if (dependencySpecifier.specifierType === DependencySpecifierType.Workspace) { + } else if ( + dependencySpecifier.specifierType === DependencySpecifierType.Workspace && + rushProject.decoupledLocalDependencies.has(name) + ) { + // If the dependency is a local project that is decoupled, then we need to ensure that it is not specified + // as a workspace project. If it is, then we need to update the package.json to remove the workspace notation. + this._terminal.writeWarningLine( + `"${rushProject.packageName}" depends on package ${name}@${version}, but also lists it in ` + + `its "decoupledLocalDependencies" array. Either update the host project's package.json to use ` + + `a version from an external feed instead of "workspace:" notation, or remove the dependency from the ` + + `host project's "decoupledLocalDependencies" array in rush.json.` + ); + throw new AlreadyReportedError(); + } else if (!rushProject.decoupledLocalDependencies.has(name)) { // Already specified as a local project. Allow the package manager to validate this continue; }