Skip to content

Commit

Permalink
feat: use splitDoubleVerticalBar
Browse files Browse the repository at this point in the history
  • Loading branch information
bluelovers committed Jul 1, 2021
1 parent f9dbcdd commit 502b4f4
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 46 deletions.
4 changes: 2 additions & 2 deletions packages/@lazy-node/semver-ampersand/lib/Range.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/@lazy-node/semver-ampersand/lib/Range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { toRangeString } from './range/toRangeString';
import { assertInvalidComparatorSet } from './util/assert';
import { fixComparatorSet } from './range/fixComparatorSet';
import { parseOptionsOrLoose } from './internal/parseOptionsOrLoose';
import { splitDoubleVerticalBar } from './util/split';

export class SemverRange<RAW extends ISemverRangeInput> extends classWithoutCallParentConstructor(semverRange)
{
Expand Down Expand Up @@ -59,8 +60,7 @@ export class SemverRange<RAW extends ISemverRangeInput> extends classWithoutCall

protected _buildComparatorsSet(range: string, options: IOptions): IComparatorSetInput
{
let comparatorsSet = range
.split(/\s*\|\|\s*/)
let comparatorsSet = splitDoubleVerticalBar(range)
// map the range to a 2d array of comparators
.map(range => this.parseRange.call({
// avoid false value to be cache key
Expand Down
11 changes: 5 additions & 6 deletions packages/@lazy-node/semver-ampersand/lib/validRange.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 7 additions & 8 deletions packages/@lazy-node/semver-ampersand/lib/validRange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,26 @@ import { hasInvalidCharacter } from './util/assert';
*/
export function validRange(range: string, optionsOrLoose?: IOptionsOrLoose)
{
optionsOrLoose = parseOptionsOrLoose(optionsOrLoose)

if (typeof range !== 'string')
{
throw new TypeError(`range should be string, but got ${range}`)
}

if (hasInvalidCharacter(range, optionsOrLoose))
{
return null
}
optionsOrLoose = parseOptionsOrLoose(optionsOrLoose)

try
{
return new SemverRange(range, optionsOrLoose).toRangeString()
if (!hasInvalidCharacter(range, optionsOrLoose))
{
return new SemverRange(range, optionsOrLoose).toRangeString()
}
}
catch (er)
{
return null

}

return null
}

export default validRange
10 changes: 4 additions & 6 deletions packages/@lazy-node/semver-ampersand/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@
"main": "index.js",
"scripts": {
"lint": "ynpx --quiet eslint -- **/*.ts",
"test": "echo \"Error: no test specified\"",
"test:jest": "ynpx --quiet jest -- --coverage",
"test:mocha": "ynpx --quiet -p ts-node -p mocha mocha -- --require ts-node/register \"!(node_modules)/**/*.{test,spec}.{ts,tsx}\"",
"test": "yarn run test:jest",
"test:jest": "jest",
"preversion": "yarn run test",
"prepublishOnly": "echo prepublishOnly",
"prepublishOnly:check-bin": "ynpx --quiet @yarn-tool/check-pkg-bin",
"prepublishOnly:update": "yarn run ncu && yarn run sort-package-json",
"ncu": "yarn-tool ncu -u",
"sort-package-json": "yarn-tool sort"
Expand All @@ -47,8 +45,8 @@
},
"gitHead": "02f74c14e885366e9be773564ea43f7425f9d97a",
"dependencies": {
"class-without-call-parent-constructor": "^2.0.1",
"split-smartly2": "^1.1.10",
"class-without-call-parent-constructor": "^2.0.4",
"split-smartly2": "^1.1.11",
"ts-type": "^1.2.35",
"tslib": "^2.3.0"
}
Expand Down
13 changes: 2 additions & 11 deletions packages/@lazy-node/semver-ampersand/test/classes/range.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Comparator } from 'semver';
import { SemverRange, Range } from '../../lib/Range';
import { Range } from '../../lib/Range';

import rangeIntersection from '../fixtures/range-intersection'
import rangeInclude from '../fixtures/range-include'
import rangeExclude from '../fixtures/range-exclude'
import rangeParse from '../fixtures/range-parse'
import { reDoubleVerticalBar, separatorDoubleVerticalBar } from '../../lib/const';

import { inspect } from 'util';
import { _replaceDoubleVerticalBar } from '../util';

//jest.setTimeout(5000 * 10);

Expand Down Expand Up @@ -123,12 +123,3 @@ test('missing range parameter in range intersect', () =>
}).toThrowError(new TypeError('a Range is required'))
})

function _replaceDoubleVerticalBar(expected: string)
{
if (expected != null)
{
return expected.replace(reDoubleVerticalBar, separatorDoubleVerticalBar)
}

return expected
}
11 changes: 0 additions & 11 deletions packages/@lazy-node/semver-ampersand/test/fixtures/range-parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@ export default [
['>=*', '*'],
['', '*'],
['*', '*'],
['*', '*'],
['>=1.0.0', '>=1.0.0'],
['>1.0.0', '>1.0.0'],
['<=2.0.0', '<=2.0.0'],
['1', '>=1.0.0 <2.0.0-0'],
['<=2.0.0', '<=2.0.0'],
['<=2.0.0', '<=2.0.0'],
['<2.0.0', '<2.0.0'],
['<2.0.0', '<2.0.0'],
['>= 1.0.0', '>=1.0.0'],
['>= 1.0.0', '>=1.0.0'],
Expand All @@ -33,25 +29,19 @@ export default [
['< 2.0.0', '<2.0.0'],
['<\t2.0.0', '<2.0.0'],
['>=0.1.97', '>=0.1.97'],
['>=0.1.97', '>=0.1.97'],
['0.1.20 || 1.2.4', '0.1.20||1.2.4'],
['>=0.2.3 || <0.0.1', '>=0.2.3||<0.0.1'],
['>=0.2.3 || <0.0.1', '>=0.2.3||<0.0.1'],
['>=0.2.3 || <0.0.1', '>=0.2.3||<0.0.1'],
['||', '*'],
['2.x.x', '>=2.0.0 <3.0.0-0'],
['1.2.x', '>=1.2.0 <1.3.0-0'],
['1.2.x || 2.x', '>=1.2.0 <1.3.0-0||>=2.0.0 <3.0.0-0'],
['1.2.x || 2.x', '>=1.2.0 <1.3.0-0||>=2.0.0 <3.0.0-0'],
['x', '*'],
['2.*.*', '>=2.0.0 <3.0.0-0'],
['1.2.*', '>=1.2.0 <1.3.0-0'],
['1.2.* || 2.*', '>=1.2.0 <1.3.0-0||>=2.0.0 <3.0.0-0'],
['*', '*'],
['2', '>=2.0.0 <3.0.0-0'],
['2.3', '>=2.3.0 <2.4.0-0'],
['~2.4', '>=2.4.0 <2.5.0-0'],
['~2.4', '>=2.4.0 <2.5.0-0'],
['~>3.2.1', '>=3.2.1 <3.3.0-0'],
['~1', '>=1.0.0 <2.0.0-0'],
['~>1', '>=1.0.0 <2.0.0-0'],
Expand All @@ -74,7 +64,6 @@ export default [
['>= 1', '>=1.0.0'],
['<1.2', '<1.2.0-0'],
['< 1.2', '<1.2.0-0'],
['1', '>=1.0.0 <2.0.0-0'],
['>01.02.03', '>1.2.3', true],
['>01.02.03', null],
['~1.2.3beta', '>=1.2.3-beta <1.3.0-0', { loose: true }],
Expand Down
13 changes: 13 additions & 0 deletions packages/@lazy-node/semver-ampersand/test/options.cache.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Range } from '../lib/Range';

test(`check cache is work`, () =>
{
let range = '>01.02.03';

expect(new Range(range, true)).toMatchSnapshot();
//expect(actual).toBeInstanceOf(Date);
expect(() => new Range(range)).toThrowErrorMatchingSnapshot();

});


11 changes: 11 additions & 0 deletions packages/@lazy-node/semver-ampersand/test/ranges/valid.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import rangeParse from '../fixtures/range-parse';
import validRange from '../../lib/validRange';
import { inspect } from 'util';
import { _replaceDoubleVerticalBar } from '../util';

describe('valid range test', () => {
// validRange(range) -> result
// translate ranges into their canonical form
rangeParse.forEach(([pre, wanted, options]) =>
test(`validRange(${pre}, ${inspect(options)}) === ${wanted = _replaceDoubleVerticalBar(wanted)}`, () => expect(validRange(pre, options)).toBe(wanted)))
})
11 changes: 11 additions & 0 deletions packages/@lazy-node/semver-ampersand/test/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { reDoubleVerticalBar, separatorDoubleVerticalBar } from '../lib/const';

export function _replaceDoubleVerticalBar(expected: string)
{
if (expected != null)
{
return expected.replace(reDoubleVerticalBar, separatorDoubleVerticalBar)
}

return expected
}

0 comments on commit 502b4f4

Please sign in to comment.