Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(angular): change rxjs migration to conditional migration
- Loading branch information
Showing
3 changed files
with
91 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
packages/angular/src/migrations/update-14-5-7/update-rxjs.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { readJson, Tree, writeJson } from '@nrwl/devkit'; | ||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; | ||
import updateRxjs from './update-rxjs'; | ||
|
||
describe('update-rxjs migration', () => { | ||
let tree: Tree; | ||
|
||
beforeEach(() => { | ||
tree = createTreeWithEmptyWorkspace(); | ||
}); | ||
|
||
it('should update rxjs version when defined as a dev dependency and greater than 7.0.0', async () => { | ||
writeJson(tree, 'package.json', { | ||
devDependencies: { rxjs: '~7.0.0' }, | ||
}); | ||
|
||
await updateRxjs(tree); | ||
|
||
const { devDependencies } = readJson(tree, 'package.json'); | ||
expect(devDependencies['rxjs']).toEqual('~7.5.0'); | ||
}); | ||
|
||
it('should update rxjs version when defined as a dependency and greater than 7.0.0', async () => { | ||
writeJson(tree, 'package.json', { | ||
dependencies: { rxjs: '~7.0.0' }, | ||
}); | ||
|
||
await updateRxjs(tree); | ||
|
||
const { dependencies } = readJson(tree, 'package.json'); | ||
expect(dependencies['rxjs']).toEqual('~7.5.0'); | ||
}); | ||
|
||
it('should not update rxjs when it is less than 7.0.0', async () => { | ||
writeJson(tree, 'package.json', { | ||
dependencies: { rxjs: '~6.5.0' }, | ||
}); | ||
|
||
await updateRxjs(tree); | ||
|
||
const { dependencies } = readJson(tree, 'package.json'); | ||
expect(dependencies['rxjs']).toEqual('~6.5.0'); | ||
}); | ||
|
||
it('should not update rxjs when it is less than 7.0.0', async () => { | ||
writeJson(tree, 'package.json', { | ||
devDependencies: { rxjs: '~6.5.0' }, | ||
}); | ||
|
||
await updateRxjs(tree); | ||
|
||
const { devDependencies } = readJson(tree, 'package.json'); | ||
expect(devDependencies['rxjs']).toEqual('~6.5.0'); | ||
}); | ||
}); |
30 changes: 30 additions & 0 deletions
30
packages/angular/src/migrations/update-14-5-7/update-rxjs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { formatFiles, Tree, updateJson } from '@nrwl/devkit'; | ||
import { gte, minVersion } from 'semver'; | ||
|
||
const rxjsVersion = '~7.5.0'; | ||
|
||
export default async function (tree: Tree) { | ||
let shouldFormat = false; | ||
|
||
updateJson(tree, 'package.json', (json) => { | ||
if ( | ||
json.devDependencies?.['rxjs'] && | ||
gte(minVersion(json.devDependencies?.['rxjs']), '7.0.0') | ||
) { | ||
json.devDependencies['rxjs'] = rxjsVersion; | ||
shouldFormat = true; | ||
} else if ( | ||
json.dependencies?.['rxjs'] && | ||
gte(minVersion(json.dependencies?.['rxjs']), '7.0.0') | ||
) { | ||
json.dependencies['rxjs'] = rxjsVersion; | ||
shouldFormat = true; | ||
} | ||
|
||
return json; | ||
}); | ||
|
||
if (shouldFormat) { | ||
await formatFiles(tree); | ||
} | ||
} |