Skip to content

Commit

Permalink
Setting to avoid manually configuring decoupledLocalDependencies acro…
Browse files Browse the repository at this point in the history
…ss subspaces (#5072)

Co-authored-by: Lincoln <[email protected]>
  • Loading branch information
L-Qun and L-Qun authored Jan 10, 2025
1 parent e5560f2 commit bd759e4
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 5 deletions.
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
// 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

0 comments on commit bd759e4

Please sign in to comment.