-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(plugin-dependencies): update version only in dependencies and dev…
…Dependencies
- Loading branch information
Simon Mollweide
committed
Oct 31, 2019
1 parent
241fd77
commit 13b4368
Showing
3 changed files
with
54 additions
and
2 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
31 changes: 31 additions & 0 deletions
31
plugins/plugin-dependencies/src/server/update-dependency-in-package.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,31 @@ | ||
/// <reference types="@types/jest" /> | ||
import { updateDependencyInPackage } from './update-dependency-in-package'; | ||
|
||
const mockPackage = { | ||
dependencies: { | ||
'@dash4/server': '0.5.2', | ||
}, | ||
devDependencies: { | ||
'cross-env': '6.0.0', | ||
}, | ||
}; | ||
|
||
describe('updateVersionInPackage', () => { | ||
test('exists', () => { | ||
expect(typeof updateDependencyInPackage).toBe('function'); | ||
}); | ||
test('update dependency', () => { | ||
const result = updateDependencyInPackage(mockPackage, '@dash4/server', '0.5.3'); | ||
if (!result || !result.dependencies) { | ||
return; | ||
} | ||
expect(result.dependencies['@dash4/server']).toBe('0.5.3'); | ||
}); | ||
test('update devDependency', () => { | ||
const result = updateDependencyInPackage(mockPackage, 'cross-env', '6.0.1'); | ||
if (!result || !result.devDependency) { | ||
return; | ||
} | ||
expect(result.devDependency['cross-env']).toBe('6.0.1'); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
plugins/plugin-dependencies/src/server/update-dependency-in-package.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,13 @@ | ||
import { IPackageJson } from '../shared-types'; | ||
|
||
export function updateDependencyInPackage(packageData: IPackageJson, dependencyName: string, newVersion: string) { | ||
if (packageData.dependencies && packageData.dependencies[dependencyName]) { | ||
packageData.dependencies[dependencyName] = newVersion; | ||
} | ||
|
||
if (packageData.devDependencies && packageData.devDependencies[dependencyName]) { | ||
packageData.devDependencies[dependencyName] = newVersion; | ||
} | ||
|
||
return packageData; | ||
} |