-
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: 🐞 release since first commit if no version found (resolve #102)
Co-authored-by: Younes Jaaidi <yjaaidi@gmail.com>
- Loading branch information
Showing
11 changed files
with
105 additions
and
188 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
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
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
58 changes: 0 additions & 58 deletions
58
packages/semver/src/builders/version/utils/get-current-version.spec.ts
This file was deleted.
Oops, something went wrong.
58 changes: 0 additions & 58 deletions
58
packages/semver/src/builders/version/utils/get-current-version.ts
This file was deleted.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
packages/semver/src/builders/version/utils/get-last-version.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,34 @@ | ||
import * as gitSemverTags from 'git-semver-tags'; | ||
import { callbackify } from 'util'; | ||
|
||
import { getLastVersion } from './get-last-version'; | ||
|
||
jest.mock('git-semver-tags', () => jest.fn()); | ||
jest.mock('./project'); | ||
|
||
const tagPrefix = 'my-lib-'; | ||
|
||
describe(getLastVersion.name, () => { | ||
let mockGitSemverTags: jest.Mock; | ||
|
||
beforeEach(() => { | ||
mockGitSemverTags = jest.fn(); | ||
(gitSemverTags as jest.Mock).mockImplementation( | ||
callbackify(mockGitSemverTags) | ||
); | ||
}); | ||
|
||
it('should compute current version from previous semver tag', async () => { | ||
mockGitSemverTags.mockResolvedValue(['my-lib-2.1.0', 'my-lib-2.0.0', 'my-lib-1.0.0']); | ||
|
||
const tag = await getLastVersion({ tagPrefix }).toPromise(); | ||
|
||
expect(tag).toEqual('2.1.0'); | ||
}); | ||
|
||
it('should throw error if no tag available', async () => { | ||
mockGitSemverTags.mockResolvedValue([]); | ||
|
||
expect(getLastVersion({ tagPrefix }).toPromise()).rejects.toThrow('No semver tag found'); | ||
}); | ||
}); |
25 changes: 25 additions & 0 deletions
25
packages/semver/src/builders/version/utils/get-last-version.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,25 @@ | ||
import * as gitSemverTags from 'git-semver-tags'; | ||
import { from, Observable, of, throwError } from 'rxjs'; | ||
import { switchMap } from 'rxjs/operators'; | ||
import * as semver from 'semver'; | ||
import { promisify } from 'util'; | ||
|
||
export function getLastVersion({ | ||
tagPrefix, | ||
}: { | ||
tagPrefix: string; | ||
}): Observable<string> { | ||
return from(promisify(gitSemverTags)({ tagPrefix })).pipe( | ||
switchMap((tags: string[]) => { | ||
const versions = tags.map(tag => tag.substring(tagPrefix.length)); | ||
const [version] = versions.sort(semver.rcompare); | ||
|
||
if (version == null) { | ||
return throwError(new Error('No semver tag found')); | ||
} | ||
|
||
const tag =`${tagPrefix}${version}`; | ||
return of(tag.substring(tagPrefix.length)); | ||
}) | ||
); | ||
} |
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
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
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
Oops, something went wrong.