@@ -1096,7 +1096,7 @@ function main() {
1096
1096
context . logWithLineInfo . error = context . logWithLineInfo . bind ( 1 , 'error' ) ;
1097
1097
context . logWithLineInfo . info = context . logWithLineInfo . bind ( 1 , 'info' ) ;
1098
1098
1099
- installLibraries ( ( ) => {
1099
+ installLibraries ( ) . then ( ( ) => {
1100
1100
1101
1101
// Load the TS declarations for Node.js and all 3rd party modules
1102
1102
loadTypeScriptDeclarations ( ) ;
@@ -1294,7 +1294,6 @@ function stopAllScripts(cb) {
1294
1294
setTimeout ( ( ) => cb ( ) , 0 ) ;
1295
1295
}
1296
1296
1297
- const attempts = { } ;
1298
1297
let globalScript = '' ;
1299
1298
/** Generated declarations for global TypeScripts */
1300
1299
let globalDeclarations = '' ;
@@ -1748,90 +1747,76 @@ function getName(id) {
1748
1747
return null ;
1749
1748
}
1750
1749
1751
- function installNpm ( npmLib , callback ) {
1752
- const path = __dirname ;
1753
- if ( typeof npmLib === 'function' ) {
1754
- callback = npmLib ;
1755
- npmLib = undefined ;
1756
- }
1750
+ async function installNpm ( npmLib ) {
1751
+ return new Promise ( ( resolve , reject ) => {
1752
+ const path = __dirname ;
1757
1753
1758
- // Also, set the working directory (cwd) of the process instead of using --prefix
1759
- // because that has ugly bugs on Windows
1760
- const cmd = `npm install ${ npmLib } --omit=dev` ;
1761
- adapter . log . info ( `Installing ${ npmLib } into ${ __dirname } - cmd: ${ cmd } ` ) ;
1754
+ // Also, set the working directory (cwd) of the process instead of using --prefix
1755
+ // because that has ugly bugs on Windows
1756
+ const cmd = `npm install ${ npmLib } --omit=dev` ;
1757
+ adapter . log . info ( `Installing ${ npmLib } into ${ __dirname } - cmd: ${ cmd } ` ) ;
1762
1758
1763
- // System call used for update of js-controller itself,
1764
- // because during installation npm packet will be deleted too, but some files must be loaded even during the installation process.
1765
- const child = mods [ 'child_process' ] . exec ( cmd , {
1766
- windowsHide : true ,
1767
- cwd : path ,
1768
- } ) ;
1759
+ // System call used for update of js-controller itself,
1760
+ // because during installation npm packet will be deleted too, but some files must be loaded even during the installation process.
1761
+ const child = mods [ 'child_process' ] . exec ( cmd , {
1762
+ windowsHide : true ,
1763
+ cwd : path ,
1764
+ } ) ;
1769
1765
1770
- child . stdout && child . stdout . on ( 'data' , buf =>
1771
- adapter . log . info ( buf . toString ( 'utf8' ) ) ) ;
1766
+ child . stdout && child . stdout . on ( 'data' , buf =>
1767
+ adapter . log . info ( buf . toString ( 'utf8' ) ) ) ;
1772
1768
1773
- child . stderr && child . stderr . on ( 'data' , buf =>
1774
- adapter . log . error ( buf . toString ( 'utf8' ) ) ) ;
1769
+ child . stderr && child . stderr . on ( 'data' , buf =>
1770
+ adapter . log . error ( buf . toString ( 'utf8' ) ) ) ;
1775
1771
1776
- child . on ( 'err' , err => {
1777
- adapter . log . error ( `Cannot install ${ npmLib } : ${ err } ` ) ;
1778
- typeof callback === 'function' && callback ( npmLib ) ;
1779
- callback = null ;
1780
- } ) ;
1781
- child . on ( 'error' , err => {
1782
- adapter . log . error ( `Cannot install ${ npmLib } : ${ err } ` ) ;
1783
- typeof callback === 'function' && callback ( npmLib ) ;
1784
- callback = null ;
1785
- } ) ;
1772
+ child . on ( 'err' , err => {
1773
+ adapter . log . error ( `Cannot install ${ npmLib } : ${ err } ` ) ;
1774
+ reject ( npmLib ) ;
1775
+ } ) ;
1776
+ child . on ( 'error' , err => {
1777
+ adapter . log . error ( `Cannot install ${ npmLib } : ${ err } ` ) ;
1778
+ reject ( npmLib ) ;
1779
+ } ) ;
1786
1780
1787
- child . on ( 'exit' , ( code /* , signal */ ) => {
1788
- if ( code ) {
1789
- adapter . log . error ( `Cannot install ${ npmLib } : ${ code } ` ) ;
1790
- }
1791
- // command succeeded
1792
- if ( typeof callback === 'function' ) callback ( npmLib ) ;
1793
- callback = null ;
1781
+ child . on ( 'exit' , ( code /* , signal */ ) => {
1782
+ if ( code ) {
1783
+ adapter . log . error ( `Cannot install ${ npmLib } : ${ code } ` ) ;
1784
+ reject ( code ) ;
1785
+ }
1786
+ // command succeeded
1787
+ resolve ( code ) ;
1788
+ } ) ;
1794
1789
} ) ;
1795
1790
}
1796
1791
1797
- function installLibraries ( callback ) {
1798
- let allInstalled = true ;
1792
+ async function installLibraries ( ) {
1799
1793
if ( adapter . config && adapter . config . libraries ) {
1800
1794
const libraries = adapter . config . libraries . split ( / [ , ; \s ] + / ) ;
1801
1795
1802
1796
for ( let lib = 0 ; lib < libraries . length ; lib ++ ) {
1803
1797
if ( libraries [ lib ] && libraries [ lib ] . trim ( ) ) {
1804
1798
libraries [ lib ] = libraries [ lib ] . trim ( ) ;
1805
- let libName = libraries [ lib ] ;
1799
+ let depName = libraries [ lib ] ;
1800
+ let version = 'latest' ;
1806
1801
1807
- const versionChunkPos = libName . indexOf ( '@' , 1 ) ;
1808
- if ( versionChunkPos > - 1 ) {
1809
- libName = libName . slice ( 0 , versionChunkPos ) ;
1802
+ if ( depName . includes ( '@' ) ) {
1803
+ [ depName , version ] = depName . split ( '@' , 2 ) ;
1810
1804
}
1811
1805
1812
- adapter . log . debug ( `Found custom dependency in config: "${ libraries [ lib ] } " (${ libName } )` ) ;
1813
-
1814
- if ( ! nodeFS . existsSync ( `${ __dirname } /node_modules/${ libName } /package.json` ) ) {
1815
- if ( ! attempts [ libraries [ lib ] ] ) {
1816
- attempts [ libraries [ lib ] ] = 1 ;
1817
- } else {
1818
- attempts [ libraries [ lib ] ] ++ ;
1819
- }
1820
- if ( attempts [ libraries [ lib ] ] > 3 ) {
1821
- adapter . log . error ( `Cannot install npm packet: ${ libraries [ lib ] } ` ) ;
1822
- continue ;
1823
- }
1806
+ adapter . log . debug ( `Found custom dependency in config: "${ libraries [ lib ] } " (${ depName } @${ version } )` ) ;
1824
1807
1825
- installNpm ( libraries [ lib ] , ( ) =>
1826
- installLibraries ( callback ) ) ;
1808
+ if ( ! nodeFS . existsSync ( ` ${ __dirname } /node_modules/ ${ depName } /package.json` ) ) {
1809
+ adapter . log . info ( `Installing custom dependency: " ${ libraries [ lib ] } " ( ${ depName } @ ${ version } )` ) ;
1827
1810
1828
- allInstalled = false ;
1829
- break ;
1811
+ try {
1812
+ await installNpm ( libraries [ lib ] ) ;
1813
+ } catch ( err ) {
1814
+ adapter . log . warn ( `Cannot install npm package ${ libraries [ lib ] } : ${ err } ` ) ;
1815
+ }
1830
1816
}
1831
1817
}
1832
1818
}
1833
1819
}
1834
- allInstalled && callback ( ) ;
1835
1820
}
1836
1821
1837
1822
function createVM ( source , name ) {
0 commit comments