@@ -5,6 +5,7 @@ const yerbamate = require('yerbamate');
5
5
6
6
const TaskStatus = require ( './task_status' ) ;
7
7
const { TaskTimer, InverseTaskTimer} = require ( './task_timer' ) ;
8
+ const EnvVariableHandler = require ( '../api/env_variables_handler' ) ;
8
9
9
10
const outputMaxSize = 6000 ;
10
11
@@ -13,7 +14,7 @@ class Task {
13
14
this . title = options . title . trim ( ) || "" ;
14
15
this . command = options . command || "" ;
15
16
this . path = options . path || "" ;
16
- this . env = options . env || [ ] ;
17
+ this . env = EnvVariableHandler . filterInvalidEnvVariables ( options . env || [ ] ) ;
17
18
this . status = TaskStatus . idle ;
18
19
this . scheduled = false ;
19
20
@@ -28,7 +29,7 @@ class Task {
28
29
return this . timer . elapsedSeconds ;
29
30
}
30
31
31
- run ( done ) {
32
+ run ( globalVariables , done ) {
32
33
this . _clearSchedulerTimeout ( ) ;
33
34
if ( this . isRunning ( ) ) {
34
35
throw new Error ( "Trying to run task without stopping it first" ) ;
@@ -47,7 +48,7 @@ class Task {
47
48
stderr : onOutput ,
48
49
stdout : onOutput ,
49
50
maxOutputSize : 1 ,
50
- env : this . _getEnvVariables ( )
51
+ env : this . _getEnvVariablesForExecution ( globalVariables )
51
52
} ,
52
53
( code ) => {
53
54
if ( this . status !== TaskStatus . stopped ) this . status = yerbamate . successCode ( code ) ? TaskStatus . ok : TaskStatus . error ;
@@ -80,7 +81,7 @@ class Task {
80
81
title : this . title ,
81
82
command : this . command
82
83
} ;
83
- if ( this . env && this . env . length > 0 ) res . env = this . env ;
84
+ if ( this . env && this . env . length > 0 ) res . env = this . env ; // EnvVariableHandler.filterInvalidEnvVariables(this.env);
84
85
if ( this . path !== "" ) res . path = this . path ;
85
86
return res ;
86
87
}
@@ -127,8 +128,9 @@ class Task {
127
128
this . scheduled = false ;
128
129
}
129
130
130
- _getEnvVariables ( ) {
131
- const res = this . env . reduce ( ( acc , envVar ) => {
131
+ _getEnvVariablesForExecution ( globalVariables ) {
132
+ const envVariables = globalVariables . concat ( this . env ) ; // Local env variables will override global env
133
+ const res = envVariables . reduce ( ( acc , envVar ) => {
132
134
if ( ! envVar [ 0 ] || ! envVar [ 1 ] ) return acc ;
133
135
acc [ envVar [ 0 ] ] = envVar [ 1 ] ;
134
136
return acc ;
0 commit comments