Skip to content
This repository has been archived by the owner on Sep 1, 2022. It is now read-only.

Commit

Permalink
fix: use yarn latest version link (#365)
Browse files Browse the repository at this point in the history
* fix: use yarn self update version url for stable version

https://github.com/yarnpkg/yarn/search?q=SELF_UPDATE_VERSION_URL&unscoped_q=SELF_UPDATE_VERSION_URL

* test: alias stable

* docs: add wip to changelog
  • Loading branch information
iamogbz authored Apr 14, 2019
1 parent fff14b5 commit b9ba1ba
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/).

* unload yvm from PATH command
* unload yvm from shell command
* use yarn self update version url for stable version

## [v3.2.0](https://github.com/tophat/yvm/compare/v3.0.1...v3.0.2) (2019-04-12)

Expand Down
7 changes: 3 additions & 4 deletions src/util/alias.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import memoize from 'lodash.memoize'
import log from './log'
import { getRequest, getVersionsFromTags } from './utils'
import { getPathEntries, yvmPath as defaultYvmPath } from './path'
import { YARN_INSTALL_PAGE_URL, YARN_INSTALL_STABLE_REGEX } from './constants'
import { YARN_STABLE_VERSION_URL } from './constants'

export const STORAGE_FILE = '.aliases'

Expand All @@ -26,9 +26,8 @@ export const resolveLatest = memoize(
)

export const resolveStable = memoize(async () => {
const body = await getRequest(YARN_INSTALL_PAGE_URL)
const matches = body.match(YARN_INSTALL_STABLE_REGEX)
return matches ? matches[1] : UNRESOLVED
const version = await getRequest(YARN_STABLE_VERSION_URL)
return (version && version.trim()) || UNRESOLVED
})

export const resolveSystem = memoize(
Expand Down
5 changes: 2 additions & 3 deletions src/util/constants.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
export const USER_AGENT = 'YVM'

export const YARN_DOWNLOAD_URL = 'https://yarnpkg.com/downloads'
export const YARN_INSTALL_PAGE_URL = 'https://yarnpkg.com/lang/en/docs/install/'
export const YARN_INSTALL_STABLE_REGEX = /stable \(([\w.-]+)\)/i
export const YARN_PUBLIC_KEY_URL = 'https://dl.yarnpkg.com/debian/pubkey.gpg'
export const YARN_RELEASE_TAGS_URL =
'https://github.com/yarnpkg/yarn/releases/tag'
export const YARN_RELEASES_API_URL =
'https://d236jo9e8rrdox.cloudfront.net/yarn-releases'
export const YARN_PUBLIC_KEY_URL = 'https://dl.yarnpkg.com/debian/pubkey.gpg'
export const YARN_STABLE_VERSION_URL = 'https://yarnpkg.com/latest-version'
11 changes: 5 additions & 6 deletions test/util/alias.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,15 @@ describe('alias', () => {
})

it('gets stable version', async () => {
utils.getRequest.mockReturnValueOnce(
'<html><body><span>Stable (1.15.2)</span></body></html>',
)
utils.getRequest.mockReturnValueOnce(' 1.15.2 ')
expect(await alias.resolveStable()).toBe('1.15.2')
expect(utils.getRequest).toHaveBeenCalledWith(
'https://yarnpkg.com/latest-version',
)
})

it('does not get stable version', async () => {
utils.getRequest.mockReturnValueOnce(
'<html><body><span></span></body></html>',
)
utils.getRequest.mockReturnValueOnce(' ')
expect(await alias.resolveStable()).toBe(alias.UNRESOLVED)
})
})
Expand Down

0 comments on commit b9ba1ba

Please sign in to comment.