@@ -24,7 +24,7 @@ if (!nodecgiodir) {
24
24
* }
25
25
* ~~~
26
26
*/
27
- const npm = JSON . parse ( child_process . execSync ( "npm ls --json" ) ) ;
27
+ const npm = JSON . parse ( child_process . execSync ( "npm ls --json" ) . toString ( ) ) ;
28
28
29
29
// Filter out any dependencies which are not resolved locally in samples or services because the other npm packages will not be loaded by NodeCG
30
30
let bundles = Object . entries ( npm . dependencies )
@@ -33,7 +33,8 @@ let bundles = Object.entries(npm.dependencies)
33
33
( j ) =>
34
34
j [ 0 ] === "resolved" &&
35
35
( `${ j [ 1 ] } ` . startsWith ( "file:../samples/" ) ||
36
- `${ j [ 1 ] } ` . startsWith ( "file:../services/" || `${ j [ 1 ] } ` === "file:../nodecg-io-core" ) ) ,
36
+ `${ j [ 1 ] } ` . startsWith ( "file:../services/" ) ||
37
+ `${ j [ 1 ] } ` === "file:../nodecg-io-core" ) ,
37
38
) ,
38
39
)
39
40
. map ( ( v ) => v [ 0 ] ) ;
@@ -44,31 +45,47 @@ console.log("");
44
45
console . log ( "NodeCG sterr" ) ;
45
46
console . log ( "--------------------------------------------------------------------------------" ) ;
46
47
47
- // expects a NodeCG folder be the parent of the cwd needs timeout
48
- const log = child_process
49
- . execSync ( "timeout --preserve-status 15s node " + cwd . dir + path . sep + "index.js" , { cwd : cwd . dir } )
50
- . toString ( "utf8" ) ;
48
+ // Spawn a process that runs NodeCG
49
+ const child = child_process . spawn ( "node" , [ "index.js" ] , { cwd : cwd . dir } ) ;
51
50
52
- const lines = log . split ( "\n" ) ;
51
+ // Store stdout in lines and stream stderr to stderr of this process
52
+ const lines = [ ] ;
53
+ child . stdout . on ( "data" , ( data ) => lines . push ( data . toString ( ) ) ) ;
54
+ child . stderr . on ( "data" , ( data ) => console . error ( data . toString ( ) ) ) ;
53
55
54
- // Try to find each bundle in the logs.
55
- const missing = bundles . filter (
56
- /*Using endsWith here to remove possible ansi styling of "[info]" caused by ModeCG's logger when run locally*/
57
- ( i ) => ! lines . some ( ( j ) => j . endsWith ( "[nodecg/lib/server/extensions] Mounted " + i + " extension" ) ) ,
58
- ) ;
56
+ // Let NodeCG run for 15 seconds to load all bundles
57
+ setTimeout ( ( ) => {
58
+ // We don't want to leave NodeCG running, if it was loaded successfully.
59
+ // If it has errored, it will not be running anymore.
60
+ if ( child . pid ) {
61
+ child . kill ( ) ;
62
+ }
59
63
60
- // Fail the run if there are missing bundles.
61
- if ( missing . length > 0 ) {
62
- // Only log stout if the run has failed because otherwise its unimportant and everything important should be in stderr
63
- console . log ( "" ) ;
64
- console . log ( "NodeCG stout" ) ;
65
- console . log ( "--------------------------------------------------------------------------------" ) ;
66
- console . log ( log ) ;
64
+ // Check exit code for failure
65
+ const exitCode = child . exitCode ;
66
+ if ( exitCode !== null && exitCode !== 0 ) {
67
+ throw new Error ( `NodeCG exited with code ${ exitCode } ` ) ;
68
+ }
67
69
68
- console . log ( "" ) ;
69
- console . log ( "Missing Bundles" ) ;
70
- console . log ( "--------------------------------------------------------------------------------" ) ;
71
- console . log ( missing ) ;
70
+ // Try to find each bundle in the logs.
71
+ const missing = bundles . filter (
72
+ /*Using endsWith here to remove possible ansi styling of "[info]" caused by ModeCG's logger when run locally*/
73
+ ( i ) => ! lines . some ( ( j ) => j . includes ( "[nodecg/lib/server/extensions] Mounted " + i + " extension" ) ) ,
74
+ ) ;
72
75
73
- throw new Error ( `NodeCG did not mount ${ missing . length } bundle(s).` ) ;
74
- }
76
+ // Fail the run if there are missing bundles.
77
+ if ( missing . length > 0 ) {
78
+ // Only log stout if the run has failed because otherwise its unimportant and everything important should be in stderr
79
+ console . log ( "" ) ;
80
+ console . log ( "NodeCG stout" ) ;
81
+ console . log ( "--------------------------------------------------------------------------------" ) ;
82
+ console . log ( lines . join ( "" ) ) ;
83
+
84
+ console . log ( "" ) ;
85
+ console . log ( "Missing Bundles" ) ;
86
+ console . log ( "--------------------------------------------------------------------------------" ) ;
87
+ console . log ( missing ) ;
88
+
89
+ throw new Error ( `NodeCG did not mount ${ missing . length } bundle(s).` ) ;
90
+ }
91
+ } , 15000 ) ;
0 commit comments