Skip to content

Commit 1ee390e

Browse files
fix(rush): don't update injected state hash on devDep change
Signed-off-by: Aramis Sennyey <aramissennyeydd@users.noreply.github.com>
1 parent ded4068 commit 1ee390e

6 files changed

Lines changed: 117 additions & 4 deletions

File tree

common/reviews/api/node-core-library.api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ export class Async {
4242
static mapAsync<TEntry extends IWeighted, TRetVal>(iterable: Iterable<TEntry> | AsyncIterable<TEntry>, callback: (entry: TEntry, arrayIndex: number) => Promise<TRetVal>, options: IAsyncParallelismOptions & {
4343
weighted: true;
4444
}): Promise<TRetVal[]>;
45-
static runWithRetriesAsync<TResult>(input: IRunWithRetriesOptions<TResult>): Promise<TResult>;
46-
static runWithTimeoutAsync<TResult>(input: IRunWithTimeoutOptions<TResult>): Promise<TResult>;
45+
static runWithRetriesAsync<TResult>({ action, maxRetries, retryDelayMs }: IRunWithRetriesOptions<TResult>): Promise<TResult>;
46+
static runWithTimeoutAsync<TResult>({ action, timeoutMs, timeoutMessage }: IRunWithTimeoutOptions<TResult>): Promise<TResult>;
4747
static sleepAsync(ms: number): Promise<void>;
4848
static validateWeightedIterable(operation: IWeighted): void;
4949
}

libraries/rush-lib/src/api/Subspace.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,6 @@ export class Subspace {
478478
name,
479479
bin,
480480
dependencies,
481-
devDependencies,
482481
peerDependencies,
483482
optionalDependencies,
484483
dependenciesMeta,
@@ -500,7 +499,6 @@ export class Subspace {
500499
name,
501500
bin,
502501
dependencies,
503-
devDependencies,
504502
peerDependencies,
505503
optionalDependencies,
506504
dependenciesMeta,

libraries/rush-lib/src/api/test/Subspace.test.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,80 @@ describe(Subspace.name, () => {
7474
expect(hashWithCatalogs).toBeDefined();
7575
});
7676
});
77+
78+
describe('getPackageJsonInjectedDependenciesHash', () => {
79+
it('returns undefined when no injected dependencies exist', () => {
80+
const rushJsonFilename: string = path.resolve(__dirname, 'repo', 'rush-pnpm.json');
81+
const rushConfiguration: RushConfiguration =
82+
RushConfiguration.loadFromConfigurationFile(rushJsonFilename);
83+
const defaultSubspace: Subspace = rushConfiguration.defaultSubspace;
84+
85+
const hash: string | undefined = defaultSubspace.getPackageJsonInjectedDependenciesHash();
86+
expect(hash).toBeUndefined();
87+
});
88+
89+
it('computes a hash when injected dependencies exist', () => {
90+
const rushJsonFilename: string = path.resolve(__dirname, 'repoInjectedDeps', 'rush.json');
91+
const rushConfiguration: RushConfiguration =
92+
RushConfiguration.loadFromConfigurationFile(rushJsonFilename);
93+
const defaultSubspace: Subspace = rushConfiguration.defaultSubspace;
94+
95+
const hash: string | undefined = defaultSubspace.getPackageJsonInjectedDependenciesHash();
96+
expect(hash).toBeDefined();
97+
expect(typeof hash).toBe('string');
98+
expect(hash).toHaveLength(40); // SHA1 hash
99+
});
100+
101+
it('does not change when devDependencies of the injected package change', () => {
102+
const rushJsonFilename: string = path.resolve(__dirname, 'repoInjectedDeps', 'rush.json');
103+
const rushConfiguration: RushConfiguration =
104+
RushConfiguration.loadFromConfigurationFile(rushJsonFilename);
105+
const defaultSubspace: Subspace = rushConfiguration.defaultSubspace;
106+
107+
const hashBefore: string | undefined = defaultSubspace.getPackageJsonInjectedDependenciesHash();
108+
109+
// Mutate devDependencies of the injected provider package
110+
const providerProject = rushConfiguration.getProjectByName('provider')!;
111+
const originalDevDeps = providerProject.packageJson.devDependencies;
112+
providerProject.packageJson.devDependencies = {
113+
...originalDevDeps,
114+
jest: '^29.0.0'
115+
};
116+
117+
const hashAfter: string | undefined = defaultSubspace.getPackageJsonInjectedDependenciesHash();
118+
119+
expect(hashBefore).toBeDefined();
120+
expect(hashAfter).toBeDefined();
121+
expect(hashBefore).toBe(hashAfter);
122+
123+
// Restore
124+
providerProject.packageJson.devDependencies = originalDevDeps;
125+
});
126+
127+
it('changes when production dependencies of the injected package change', () => {
128+
const rushJsonFilename: string = path.resolve(__dirname, 'repoInjectedDeps', 'rush.json');
129+
const rushConfiguration: RushConfiguration =
130+
RushConfiguration.loadFromConfigurationFile(rushJsonFilename);
131+
const defaultSubspace: Subspace = rushConfiguration.defaultSubspace;
132+
133+
const hashBefore: string | undefined = defaultSubspace.getPackageJsonInjectedDependenciesHash();
134+
135+
// Mutate dependencies of the injected provider package
136+
const providerProject = rushConfiguration.getProjectByName('provider')!;
137+
const originalDeps = providerProject.packageJson.dependencies;
138+
providerProject.packageJson.dependencies = {
139+
...originalDeps,
140+
axios: '^1.6.0'
141+
};
142+
143+
const hashAfter: string | undefined = defaultSubspace.getPackageJsonInjectedDependenciesHash();
144+
145+
expect(hashBefore).toBeDefined();
146+
expect(hashAfter).toBeDefined();
147+
expect(hashBefore).not.toBe(hashAfter);
148+
149+
// Restore
150+
providerProject.packageJson.dependencies = originalDeps;
151+
});
152+
});
77153
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "consumer",
3+
"version": "1.0.0",
4+
"dependencies": {
5+
"provider": "workspace:*"
6+
},
7+
"dependenciesMeta": {
8+
"provider": {
9+
"injected": true
10+
}
11+
}
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "provider",
3+
"version": "1.0.0",
4+
"dependencies": {
5+
"lodash": "^4.17.21"
6+
},
7+
"devDependencies": {
8+
"typescript": "~5.3.0"
9+
}
10+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"pnpmVersion": "9.5.0",
3+
"rushVersion": "5.46.1",
4+
"projectFolderMinDepth": 1,
5+
"projectFolderMaxDepth": 99,
6+
7+
"projects": [
8+
{
9+
"packageName": "consumer",
10+
"projectFolder": "consumer"
11+
},
12+
{
13+
"packageName": "provider",
14+
"projectFolder": "provider"
15+
}
16+
]
17+
}

0 commit comments

Comments
 (0)