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

[rush] Setting to avoid manually configuring decoupledLocalDependencies across subspaces #5072

Merged
merged 1 commit into from
Jan 10, 2025
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft/rush",
"comment": "Add a configuration option to avoid manually configuring decoupledLocalDependencies across subspaces.",
"type": "none"
}
],
"packageName": "@microsoft/rush"
}
9 changes: 9 additions & 0 deletions common/config/rush/experiments.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,13 @@
* When this toggle is enabled, Rush will only scan specific paths, significantly speeding up Git operations.
*/
// "enableSubpathScan": true

/**
* Rush has a policy that normally requires Rush projects to specify `workspace:*` in package.json when depending
* on other projects in the workspace, unless they are explicitly declared as `decoupledLocalDependencies`
* in rush.json. Enabling this experiment will remove that requirement for dependencies belonging to a different
* subspace. This is useful for large product groups who work in separate subspaces and generally prefer to consume
* each other's packages via the NPM registry.
*/
// "exemptDecoupledDependenciesBetweenSubspaces": true
}
1 change: 1 addition & 0 deletions common/reviews/api/rush-lib.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ export interface IExperimentsJson {
buildSkipWithAllowWarningsInSuccessfulBuild?: boolean;
cleanInstallAfterNpmrcChanges?: boolean;
enableSubpathScan?: boolean;
exemptDecoupledDependenciesBetweenSubspaces?: boolean;
forbidPhantomResolvableNodeModulesFolders?: boolean;
generateProjectImpactGraphDuringRushUpdate?: boolean;
noChmodFieldInTarHeaderNormalization?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,14 @@
* By default, rush perform a full scan of the entire repository. For example, Rush runs `git status` to check for local file changes.
* When this toggle is enabled, Rush will only scan specific paths, significantly speeding up Git operations.
*/
/*[LINE "HYPOTHETICAL"]*/ "enableSubpathScan": true
/*[LINE "HYPOTHETICAL"]*/ "enableSubpathScan": true,

/**
* Rush has a policy that normally requires Rush projects to specify `workspace:*` in package.json when depending
* on other projects in the workspace, unless they are explicitly declared as `decoupledLocalDependencies`
* in rush.json. Enabling this experiment will remove that requirement for dependencies belonging to a different
* subspace. This is useful for large product groups who work in separate subspaces and generally prefer to consume
* each other's packages via the NPM registry.
*/
/*[LINE "HYPOTHETICAL"]*/ "exemptDecoupledDependenciesBetweenSubspaces": false
}
9 changes: 9 additions & 0 deletions libraries/rush-lib/src/api/ExperimentsConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ export interface IExperimentsJson {
* When this toggle is enabled, Rush will only scan specific paths, significantly speeding up Git operations.
*/
enableSubpathScan?: boolean;

/**
* Rush has a policy that normally requires Rush projects to specify `workspace:*` in package.json when depending
* on other projects in the workspace, unless they are explicitly declared as `decoupledLocalDependencies`
* in rush.json. Enabling this experiment will remove that requirement for dependencies belonging to a different
* subspace. This is useful for large product groups who work in separate subspaces and generally prefer to consume
* each other's packages via the NPM registry.
*/
exemptDecoupledDependenciesBetweenSubspaces?: boolean;
}

const _EXPERIMENTS_JSON_SCHEMA: JsonSchema = JsonSchema.fromLoadedObject(schemaJson);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,19 @@ export class WorkspaceInstallManager extends BaseInstallManager {
const dependencySpecifier: DependencySpecifier = new DependencySpecifier(name, version);

// Is there a locally built Rush project that could satisfy this dependency?
const referencedLocalProject: RushConfigurationProject | undefined =
let referencedLocalProject: RushConfigurationProject | undefined =
this.rushConfiguration.getProjectByName(name);

// If we enable exemptDecoupledDependenciesBetweenSubspaces, it will only check dependencies within the subspace.
if (
this.rushConfiguration.experimentsConfiguration.configuration
.exemptDecoupledDependenciesBetweenSubspaces
) {
if (referencedLocalProject && !subspace.contains(referencedLocalProject)) {
referencedLocalProject = undefined;
}
}

// Validate that local projects are referenced with workspace notation. If not, and it is not a
// cyclic dependency, then it needs to be updated to specify `workspace:*` explicitly. Currently only
Copy link
Collaborator

@octogonz octogonz Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that this message is still referring to the old terminology "cyclic dependency" which we later renamed to "decoupled local dependency":

console.log(
  Colorize.red(
    `"${rushProject.packageName}" depends on package "${name}" (${version}) which exists ` +
      'within the workspace but cannot be fulfilled with the specified version range. Either ' +
      'specify a valid version range, or add the package as a cyclic dependency.'
  )
);

Could you update that string to something like:

console.log(
  Colorize.red(
    `"${rushProject.packageName}" depends on package "${name}" (${version}) which belongs to ` +
      'the workspace but cannot be fulfilled with the specified version range. Either ' +
      'specify a valid version range, or add the package to "decoupledLocalDependencies" in rush.json.'
  )
);

// supporting versions and version ranges for specifying a local project.
Expand All @@ -248,9 +258,9 @@ export class WorkspaceInstallManager extends BaseInstallManager {
// eslint-disable-next-line no-console
console.log(
Colorize.red(
`"${rushProject.packageName}" depends on package "${name}" (${version}) which exists ` +
'within the workspace but cannot be fulfilled with the specified version range. Either ' +
'specify a valid version range, or add the package as a cyclic dependency.'
`"${rushProject.packageName}" depends on package "${name}" (${version}) which belongs to ` +
'the workspace but cannot be fulfilled with the specified version range. Either ' +
'specify a valid version range, or add the package to "decoupledLocalDependencies" in rush.json.'
)
);
throw new AlreadyReportedError();
Expand Down
4 changes: 4 additions & 0 deletions libraries/rush-lib/src/schemas/experiments.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
"enableSubpathScan": {
"description": "By default, rush perform a full scan of the entire repository. For example, Rush runs `git status` to check for local file changes. When this toggle is enabled, Rush will only scan specific paths, significantly speeding up Git operations.",
"type": "boolean"
},
"exemptDecoupledDependenciesBetweenSubspaces": {
"description": "Rush has a policy that normally requires Rush projects to specify `workspace:*` in package.json when depending on other projects in the workspace, unless they are explicitly declared as `decoupledLocalDependencies in rush.json. Enabling this experiment will remove that requirement for dependencies belonging to a different subspace. This is useful for large product groups who work in separate subspaces and generally prefer to consume each other's packages via the NPM registry.",
"type": "boolean"
}
},
"additionalProperties": false
Expand Down
Loading