Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
renovate
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SmartDataLab
public
applications
renovate
Commits
60af784e
Unverified
Commit
60af784e
authored
3 years ago
by
Sergei Zharinov
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
refactor(versioning/composer): Enable strict null checks (#14027)
parent
e57d2fa3
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/versioning/composer/index.ts
+67
-35
67 additions, 35 deletions
lib/versioning/composer/index.ts
tsconfig.strict.json
+0
-1
0 additions, 1 deletion
tsconfig.strict.json
with
67 additions
and
36 deletions
lib/versioning/composer/index.ts
+
67
−
35
View file @
60af784e
...
@@ -90,51 +90,79 @@ function composer2npm(input: string): string {
...
@@ -90,51 +90,79 @@ function composer2npm(input: string): string {
return
output
+
stability
;
return
output
+
stability
;
}
}
const
equals
=
(
a
:
string
,
b
:
string
):
boolean
=>
function
equals
(
a
:
string
,
b
:
string
):
boolean
{
npm
.
equals
(
composer2npm
(
a
),
composer2npm
(
b
));
return
npm
.
equals
(
composer2npm
(
a
),
composer2npm
(
b
));
}
const
getMajor
=
(
version
:
string
):
number
=>
function
getMajor
(
version
:
string
):
number
|
null
{
npm
.
getMajor
(
semver
.
coerce
(
composer2npm
(
version
)));
const
semverVersion
=
semver
.
coerce
(
composer2npm
(
version
));
return
semverVersion
?
npm
.
getMajor
(
semverVersion
)
:
null
;
}
const
getMinor
=
(
version
:
string
):
number
=>
function
getMinor
(
version
:
string
):
number
|
null
{
npm
.
getMinor
(
semver
.
coerce
(
composer2npm
(
version
)));
const
semverVersion
=
semver
.
coerce
(
composer2npm
(
version
));
return
semverVersion
?
npm
.
getMinor
(
semverVersion
)
:
null
;
}
const
getPatch
=
(
version
:
string
):
number
=>
function
getPatch
(
version
:
string
):
number
|
null
{
npm
.
getPatch
(
semver
.
coerce
(
composer2npm
(
version
)));
const
semverVersion
=
semver
.
coerce
(
composer2npm
(
version
));
return
semverVersion
?
npm
.
getPatch
(
semverVersion
)
:
null
;
}
const
isGreaterThan
=
(
a
:
string
,
b
:
string
):
boolean
=>
function
isGreaterThan
(
a
:
string
,
b
:
string
):
boolean
{
npm
.
isGreaterThan
(
composer2npm
(
a
),
composer2npm
(
b
));
return
npm
.
isGreaterThan
(
composer2npm
(
a
),
composer2npm
(
b
));
}
const
isLessThanRange
=
(
version
:
string
,
range
:
string
):
boolean
=>
function
isLessThanRange
(
version
:
string
,
range
:
string
):
boolean
{
npm
.
isLessThanRange
(
composer2npm
(
version
),
composer2npm
(
range
));
return
!!
npm
.
isLessThanRange
?.(
composer2npm
(
version
),
composer2npm
(
range
));
}
const
isSingleVersion
=
(
input
:
string
):
boolean
=>
function
isSingleVersion
(
input
:
string
):
boolean
{
!!
input
&&
npm
.
isSingleVersion
(
composer2npm
(
input
));
return
!!
input
&&
npm
.
isSingleVersion
(
composer2npm
(
input
));
}
const
isStable
=
(
version
:
string
):
boolean
=>
function
isStable
(
version
:
string
):
boolean
{
version
&&
npm
.
isStable
(
composer2npm
(
version
));
return
!!
(
version
&&
npm
.
isStable
(
composer2npm
(
version
)));
}
export
const
isValid
=
(
input
:
string
):
boolean
=>
export
function
isValid
(
input
:
string
):
boolean
{
!!
input
&&
npm
.
isValid
(
composer2npm
(
input
));
return
!!
input
&&
npm
.
isValid
(
composer2npm
(
input
));
}
export
const
isVersion
=
(
input
:
string
):
boolean
=>
export
function
isVersion
(
input
:
string
):
boolean
{
!!
input
&&
npm
.
isVersion
(
composer2npm
(
input
));
return
!!
input
&&
npm
.
isVersion
(
composer2npm
(
input
));
}
const
matches
=
(
version
:
string
,
range
:
string
):
boolean
=>
function
matches
(
version
:
string
,
range
:
string
):
boolean
{
npm
.
matches
(
composer2npm
(
version
),
composer2npm
(
range
));
return
npm
.
matches
(
composer2npm
(
version
),
composer2npm
(
range
));
}
const
getSatisfyingVersion
=
(
versions
:
string
[],
range
:
string
):
string
=>
function
getSatisfyingVersion
(
npm
.
getSatisfyingVersion
(
versions
.
map
(
composer2npm
),
composer2npm
(
range
));
versions
:
string
[],
range
:
string
):
string
|
null
{
return
npm
.
getSatisfyingVersion
(
versions
.
map
(
composer2npm
),
composer2npm
(
range
)
);
}
const
minSatisfyingVersion
=
(
versions
:
string
[],
range
:
string
):
string
=>
function
minSatisfyingVersion
(
npm
.
minSatisfyingVersion
(
versions
.
map
(
composer2npm
),
composer2npm
(
range
));
versions
:
string
[],
range
:
string
):
string
|
null
{
return
npm
.
minSatisfyingVersion
(
versions
.
map
(
composer2npm
),
composer2npm
(
range
)
);
}
function
getNewValue
({
function
getNewValue
({
currentValue
,
currentValue
,
rangeStrategy
,
rangeStrategy
,
currentVersion
,
currentVersion
,
newVersion
,
newVersion
,
}:
NewValueConfig
):
string
{
}:
NewValueConfig
):
string
|
null
{
if
(
rangeStrategy
===
'
pin
'
)
{
if
(
rangeStrategy
===
'
pin
'
)
{
return
newVersion
;
return
newVersion
;
}
}
...
@@ -149,9 +177,10 @@ function getNewValue({
...
@@ -149,9 +177,10 @@ function getNewValue({
newVersion
,
newVersion
,
});
});
}
}
const
currentMajor
=
currentVersion
?
getMajor
(
currentVersion
)
:
null
;
const
toMajor
=
getMajor
(
newVersion
);
const
toMajor
=
getMajor
(
newVersion
);
const
toMinor
=
getMinor
(
newVersion
);
const
toMinor
=
getMinor
(
newVersion
);
let
newValue
:
string
;
let
newValue
:
string
|
null
=
null
;
if
(
isVersion
(
currentValue
))
{
if
(
isVersion
(
currentValue
))
{
newValue
=
newVersion
;
newValue
=
newVersion
;
}
else
if
(
regEx
(
/^
[
~^
](
0
\.[
1-9
][
0-9
]
*
)
$/
).
test
(
currentValue
))
{
}
else
if
(
regEx
(
/^
[
~^
](
0
\.[
1-9
][
0-9
]
*
)
$/
).
test
(
currentValue
))
{
...
@@ -166,15 +195,19 @@ function getNewValue({
...
@@ -166,15 +195,19 @@ function getNewValue({
// handle ~4 case
// handle ~4 case
const
operator
=
currentValue
.
substr
(
0
,
1
);
const
operator
=
currentValue
.
substr
(
0
,
1
);
newValue
=
`
${
operator
}${
toMajor
}
`
;
newValue
=
`
${
operator
}${
toMajor
}
`
;
}
else
if
(
regEx
(
/^
[
~^
]([
0-9
]
*
(?:\.[
0-9
]
*
)?)
$/
).
test
(
currentValue
))
{
}
else
if
(
toMajor
&&
regEx
(
/^
[
~^
]([
0-9
]
*
(?:\.[
0-9
]
*
)?)
$/
).
test
(
currentValue
)
)
{
const
operator
=
currentValue
.
substr
(
0
,
1
);
const
operator
=
currentValue
.
substr
(
0
,
1
);
// handle ~4.1 case
// handle ~4.1 case
if
(
current
Version
&&
toMajor
>
getMajor
(
currentVersion
)
)
{
if
(
(
current
Major
&&
toMajor
>
currentMajor
)
||
!
toMinor
)
{
newValue
=
`
${
operator
}${
toMajor
}
.0`
;
newValue
=
`
${
operator
}${
toMajor
}
.0`
;
}
else
{
}
else
{
newValue
=
`
${
operator
}${
toMajor
}
.
${
toMinor
}
`
;
newValue
=
`
${
operator
}${
toMajor
}
.
${
toMinor
}
`
;
}
}
}
else
if
(
}
else
if
(
currentVersion
&&
npm
.
isVersion
(
padZeroes
(
normalizeVersion
(
newVersion
)))
&&
npm
.
isVersion
(
padZeroes
(
normalizeVersion
(
newVersion
)))
&&
npm
.
isValid
(
normalizeVersion
(
currentValue
))
&&
npm
.
isValid
(
normalizeVersion
(
currentValue
))
&&
composer2npm
(
currentValue
)
===
normalizeVersion
(
currentValue
)
composer2npm
(
currentValue
)
===
normalizeVersion
(
currentValue
)
...
@@ -192,18 +225,17 @@ function getNewValue({
...
@@ -192,18 +225,17 @@ function getNewValue({
}
else
{
}
else
{
const
hasOr
=
currentValue
.
includes
(
'
||
'
);
const
hasOr
=
currentValue
.
includes
(
'
||
'
);
if
(
hasOr
||
rangeStrategy
===
'
widen
'
)
{
if
(
hasOr
||
rangeStrategy
===
'
widen
'
)
{
const
lastValue
=
hasOr
const
splitValues
=
currentValue
.
split
(
'
||
'
);
?
currentValue
.
split
(
'
||
'
).
pop
().
trim
()
const
lastValue
=
splitValues
[
splitValues
.
length
-
1
];
:
currentValue
;
const
replacementValue
=
getNewValue
({
const
replacementValue
=
getNewValue
({
currentValue
:
lastValue
,
currentValue
:
lastValue
.
trim
()
,
rangeStrategy
:
'
replace
'
,
rangeStrategy
:
'
replace
'
,
currentVersion
,
currentVersion
,
newVersion
,
newVersion
,
});
});
if
(
rangeStrategy
===
'
replace
'
)
{
if
(
rangeStrategy
===
'
replace
'
)
{
newValue
=
replacementValue
;
newValue
=
replacementValue
;
}
else
{
}
else
if
(
replacementValue
)
{
const
parsedRange
=
parseRange
(
replacementValue
);
const
parsedRange
=
parseRange
(
replacementValue
);
const
element
=
parsedRange
[
parsedRange
.
length
-
1
];
const
element
=
parsedRange
[
parsedRange
.
length
-
1
];
if
(
element
.
operator
?.
startsWith
(
'
<
'
))
{
if
(
element
.
operator
?.
startsWith
(
'
<
'
))
{
...
...
This diff is collapsed.
Click to expand it.
tsconfig.strict.json
+
0
−
1
View file @
60af784e
...
@@ -389,7 +389,6 @@
...
@@ -389,7 +389,6 @@
"lib/versioning/api.ts"
,
"lib/versioning/api.ts"
,
"lib/versioning/aws-machine-image/index.ts"
,
"lib/versioning/aws-machine-image/index.ts"
,
"lib/versioning/common.ts"
,
"lib/versioning/common.ts"
,
"lib/versioning/composer/index.ts"
,
"lib/versioning/generic.ts"
,
"lib/versioning/generic.ts"
,
"lib/versioning/git/index.ts"
,
"lib/versioning/git/index.ts"
,
"lib/versioning/hashicorp/index.ts"
,
"lib/versioning/hashicorp/index.ts"
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment