1
1
/**
2
2
* Install adapter
3
3
*
4
- * Copyright 2013-2023 bluefox <[email protected] >
4
+ * Copyright 2013-2024 bluefox <[email protected] >
5
5
*
6
6
* MIT License
7
7
*
@@ -187,7 +187,7 @@ export class Install {
187
187
packetName = parts [ 0 ] ;
188
188
version = parts [ 1 ] ;
189
189
} else {
190
- // always take version from repository
190
+ // always take a version from repository
191
191
if ( sources [ packetName ] ?. version ) {
192
192
version = sources [ packetName ] . version ;
193
193
} else {
@@ -272,7 +272,7 @@ export class Install {
272
272
}
273
273
274
274
console . error (
275
- `host.${ hostname } Unknown packetName ${ packetName } . Please install packages from outside the repository using "${ tools . appNameLowerCase } url <url-or-package>"!`
275
+ `host.${ hostname } Unknown packet name ${ packetName } . Please install packages from outside the repository using "${ tools . appNameLowerCase } url <url-or-package>"!`
276
276
) ;
277
277
throw new IoBrokerError ( {
278
278
code : EXIT_CODES . UNKNOWN_PACKET_NAME ,
@@ -359,7 +359,7 @@ export class Install {
359
359
npmUrl = npmUrl . substring ( 0 , npmUrl . indexOf ( '#' ) ) ;
360
360
}
361
361
if ( npmUrl . includes ( '/' ) && ! npmUrl . startsWith ( '@' ) ) {
362
- // only scoped packages (e.g. @types/node ) may have a slash in their path
362
+ // only scoped packages (e.g., @types/node) may have a slash in their path
363
363
npmUrl = npmUrl . substring ( npmUrl . lastIndexOf ( '/' ) + 1 ) ;
364
364
}
365
365
if ( ! npmUrl . startsWith ( '@' ) ) {
@@ -397,7 +397,7 @@ export class Install {
397
397
unsafePerm : ! ! options . unsafePerm
398
398
} ) ;
399
399
400
- // code 1 is sometimes a real error and sometimes a strange error, where everything is installed but error
400
+ // code 1 is sometimes a real error and sometimes a strange error, where everything is installed but still the error
401
401
const isSuccess = result . success || ( result . exitCode === 1 && ! result . stderr . startsWith ( 'npm ERR!' ) ) ;
402
402
403
403
if ( isSuccess ) {
@@ -530,7 +530,7 @@ export class Install {
530
530
531
531
if ( dName === 'js-controller' ) {
532
532
const version = allDeps [ dName ] ;
533
- // Check only if version not *, else we dont have to read io-pack unnecessarily
533
+ // Check only if version not *, else we don't have to read io-pack unnecessarily
534
534
if ( version !== '*' ) {
535
535
const packJson = fs . readJSONSync ( `${ tools . getControllerDir ( ) } /package.json` ) ;
536
536
if ( ! semver . satisfies ( packJson . version , version , { includePrerelease : true } ) ) {
@@ -554,7 +554,7 @@ export class Install {
554
554
gInstances = objs . rows . filter ( obj => obj . value . common && obj . value . common . name === dName ) ;
555
555
}
556
556
if ( deps [ dName ] !== undefined ) {
557
- // local dep get all instances on same host
557
+ // local dependencies: get all instances on the same host
558
558
locInstances = objs . rows . filter (
559
559
obj =>
560
560
obj . value . common &&
@@ -566,7 +566,7 @@ export class Install {
566
566
}
567
567
}
568
568
569
- // we check, that all existing instances match - respect different versions for local and global deps
569
+ // we check that all existing instances match - respect different versions for local and global deps
570
570
for ( const instance of locInstances ) {
571
571
const instanceVersion = instance . value . common . version ;
572
572
if (
@@ -698,7 +698,7 @@ export class Install {
698
698
699
699
const { stoppedList } = await this . downloadPacket ( repoUrl , fullName ) ;
700
700
await this . installAdapter ( adapter , repoUrl , _installCount ) ;
701
- await this . enableInstances ( stoppedList , true ) ; // even if unlikely make sure to reenable disabled instances
701
+ await this . enableInstances ( stoppedList , true ) ; // even if unlikely make sure to re-enable disabled instances
702
702
return adapter ;
703
703
}
704
704
let adapterConf : ioBroker . AdapterObject ;
@@ -1097,7 +1097,7 @@ export class Install {
1097
1097
. filter ( row => ! ! row . value . _id )
1098
1098
// ... that matches the pattern
1099
1099
. filter ( row => instanceRegex . test ( row . value . _id ) )
1100
- // if instance given also delete from foreign host else only instance on this host
1100
+ // if instance given, also delete it from foreign host else only instance on this host
1101
1101
. filter ( row => {
1102
1102
if ( instance !== undefined || ! row . value . common ?. host || row . value . common ?. host === hostname ) {
1103
1103
return true ;
@@ -1471,14 +1471,14 @@ export class Install {
1471
1471
1472
1472
while ( stateIDs . length > 0 ) {
1473
1473
if ( stateIDs . length % 200 === 0 ) {
1474
- // write progress report
1474
+ // write a progress report
1475
1475
console . log ( `host.${ hostname } : Only ${ stateIDs . length } states left to be deleted.` ) ;
1476
1476
}
1477
1477
// try to delete the current state
1478
1478
try {
1479
1479
await this . states . delState ( stateIDs . pop ( ) ! ) ;
1480
1480
} catch ( e ) {
1481
- // yep that works!
1481
+ // yep, that works!
1482
1482
e !== tools . ERRORS . ERROR_NOT_FOUND &&
1483
1483
e . message !== tools . ERRORS . ERROR_NOT_FOUND &&
1484
1484
console . error ( `host.${ hostname } Cannot delete states: ${ e . message } ` ) ;
@@ -1506,7 +1506,7 @@ export class Install {
1506
1506
1507
1507
while ( objIDs . length > 0 ) {
1508
1508
if ( objIDs . length % 200 === 0 ) {
1509
- // write progress report
1509
+ // write a progress report
1510
1510
console . log ( `host.${ hostname } : Only ${ objIDs . length } objects left to be deleted.` ) ;
1511
1511
}
1512
1512
// try to delete the current object
@@ -1543,7 +1543,7 @@ export class Install {
1543
1543
1544
1544
if ( ! ioPack . common || ! ioPack . common . nondeletable ) {
1545
1545
await this . _npmUninstall ( adapterNpm , false ) ;
1546
- // after uninstalling we have to restart the defined adapters
1546
+ // after uninstalling, we have to restart the defined adapters
1547
1547
if ( ioPack . common . restartAdapters ) {
1548
1548
if ( ! Array . isArray ( ioPack . common . restartAdapters ) ) {
1549
1549
// it's not an array, now it can only be a single adapter as string
@@ -1602,7 +1602,7 @@ export class Install {
1602
1602
await this . _removeCustomFromObjects ( [ adapter ] ) ;
1603
1603
await _uninstallNpm ( ) ;
1604
1604
} else {
1605
- // we are not allowed to delete last instance if another instance depends on us
1605
+ // we are not allowed to delete the last instance if another instance depends on us
1606
1606
const dependentInstance = await this . _hasDependentInstances ( adapter ) ;
1607
1607
1608
1608
if ( dependentInstance ) {
@@ -1649,7 +1649,7 @@ export class Install {
1649
1649
const knownObjectIDs : string [ ] = [ ] ;
1650
1650
const knownStateIDs : string [ ] = [ ] ;
1651
1651
1652
- // we are not allowed to delete last instance if another instance depends on us
1652
+ // we are not allowed to delete the last instance if another instance depends on us
1653
1653
const dependentInstance = await this . _hasDependentInstances ( adapter , instance ) ;
1654
1654
1655
1655
if ( dependentInstance ) {
@@ -1677,7 +1677,7 @@ export class Install {
1677
1677
}
1678
1678
1679
1679
/**
1680
- * Remove all node modules which has been installed by this instance
1680
+ * Remove all node modules that has been installed by this instance
1681
1681
*
1682
1682
* @param adapter adapter name like hm-rpc
1683
1683
* @param instance e.g. 1, if undefined deletes all instances
@@ -1703,7 +1703,7 @@ export class Install {
1703
1703
* @param ids - id of the adapter/instance to check for
1704
1704
*/
1705
1705
private async _removeCustomFromObjects ( ids : string [ ] ) : Promise < void > {
1706
- // get all objects which have a custom attribute
1706
+ // get all objects that have a custom attribute
1707
1707
const res = await this . objects . getObjectViewAsync ( 'system' , 'custom' , {
1708
1708
startkey : '' ,
1709
1709
endkey : '\u9999'
@@ -1739,7 +1739,7 @@ export class Install {
1739
1739
* @param name package name
1740
1740
*/
1741
1741
async installAdapterFromUrl ( url : string , name : string ) : Promise < void > {
1742
- // If the user provided an URL, try to parse it into known ways to represent a Github URL
1742
+ // If the user provided a URL, try to parse it into known ways to represent a GitHub URL
1743
1743
let parsedUrl ;
1744
1744
try {
1745
1745
parsedUrl = new URL ( url ) ;
@@ -1764,7 +1764,7 @@ export class Install {
1764
1764
const result = await axios ( `http://api.github.com/repos/${ user } /${ repo } /commits` , {
1765
1765
headers : {
1766
1766
'User-Agent' : 'ioBroker Adapter install' ,
1767
- // @ts -expect-error should be okay..
1767
+ // @ts -expect-error should be okay...
1768
1768
validateStatus : status => status === 200
1769
1769
}
1770
1770
} ) ;
@@ -1793,14 +1793,14 @@ export class Install {
1793
1793
1794
1794
// Try to extract name from URL
1795
1795
if ( ! name ) {
1796
- const reNpmPacket = new RegExp ( '^' + tools . appName + ' \\.([-_\\w\\d]+)(@.*)?$' , 'i' ) ;
1796
+ const reNpmPacket = new RegExp ( `^ ${ tools . appName } \\.([-_\\w\\d]+)(@.*)?$` , 'i' ) ;
1797
1797
const match = reNpmPacket . exec ( url ) ; // we have [email protected]
1798
1798
if ( match ) {
1799
1799
name = match [ 1 ] ;
1800
1800
} else if ( url . match ( / \. ( t g z | g z | z i p | t a r \. g z ) $ / ) ) {
1801
1801
const parts = url . split ( '/' ) ;
1802
1802
const last = parts . pop ( ) ! ;
1803
- const mm = last . match ( / \. ( [ - _ \w \d ] + ) - [ . \d ] + / ) ;
1803
+ const mm = last . match ( / \. ( [ - _ \w ] + ) - [ . \d ] + / ) ;
1804
1804
if ( mm ) {
1805
1805
name = mm [ 1 ] ;
1806
1806
}
@@ -1814,7 +1814,7 @@ export class Install {
1814
1814
name = url ;
1815
1815
}
1816
1816
// Remove the leading `iobroker.` from the name
1817
- const reG = new RegExp ( tools . appName + ' \\.([-_\\w\\d]+)$' , 'i' ) ;
1817
+ const reG = new RegExp ( ` ${ tools . appName } \\.([-_\\w\\d]+)$` , 'i' ) ;
1818
1818
const match = reG . exec ( name ) ;
1819
1819
if ( match ) {
1820
1820
name = match [ 1 ] ;
@@ -1883,7 +1883,7 @@ export class Install {
1883
1883
*
1884
1884
* @param adapter adapter name
1885
1885
* @param instance instance, like 1
1886
- * @returns if dependent exists returns adapter name
1886
+ * @returns if dependent exists, returns adapter name
1887
1887
*/
1888
1888
private async _hasDependentInstances ( adapter : string , instance ?: number ) : Promise < void | string > {
1889
1889
try {
@@ -1907,7 +1907,7 @@ export class Install {
1907
1907
1908
1908
for ( const row of doc . rows ) {
1909
1909
if ( ! row . value ?. common ) {
1910
- // this object seems to be corrupted so it will not need our adapter
1910
+ // this object seems to be corrupted, so it will not need our adapter
1911
1911
continue ;
1912
1912
}
1913
1913
@@ -1919,7 +1919,7 @@ export class Install {
1919
1919
// this adapter needs us locally and all instances should be deleted
1920
1920
return `${ row . value . common . name } .${ row . id . split ( '.' ) . pop ( ) } ` ;
1921
1921
} else {
1922
- // check if other instance of us exists on this host
1922
+ // check if another instance of us exists on this host
1923
1923
if ( this . _checkDependencyFulfilledThisHost ( adapter , instance , doc . rows , scopedHostname ) ) {
1924
1924
// there are other instances of our adapter - ok
1925
1925
break ;
@@ -1935,7 +1935,7 @@ export class Install {
1935
1935
for ( const globalDep of Object . keys ( globalDeps ) ) {
1936
1936
if ( globalDep === adapter ) {
1937
1937
if ( instance === undefined ) {
1938
- // all instances on this host should be removed so check if there are some on other hosts
1938
+ // all instances on this host should be removed, so check if there are some on other hosts
1939
1939
if ( this . _checkDependencyFulfilledForeignHosts ( adapter , doc . rows , scopedHostname ) ) {
1940
1940
break ;
1941
1941
} else {
@@ -1964,7 +1964,7 @@ export class Install {
1964
1964
* @param adapter adapter name
1965
1965
* @param instancesRows all instances objects view rows
1966
1966
* @param scopedHostname hostname which should be assumed as local
1967
- * @returns true if an instance is present on other host
1967
+ * @returns true if an instance is present on another host
1968
1968
*/
1969
1969
private _checkDependencyFulfilledForeignHosts (
1970
1970
adapter : string ,
0 commit comments