File tree Expand file tree Collapse file tree 6 files changed +2312
-54
lines changed Expand file tree Collapse file tree 6 files changed +2312
-54
lines changed Original file line number Diff line number Diff line change 1
1
node_modules /
2
+ * .swp
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ function haveBabelrc(functionsDir) {
31
31
32
32
function webpackConfig ( dir , additionalConfig ) {
33
33
var config = conf . load ( ) ;
34
- var envConfig = config . build . environment || config . build . Environment || { } ;
34
+ var envConfig = conf . loadContext ( config ) . environment ;
35
35
var babelOpts = { cacheDirectory : true } ;
36
36
if ( ! haveBabelrc ( dir ) ) {
37
37
babelOpts . presets = [
Original file line number Diff line number Diff line change @@ -13,3 +13,30 @@ exports.load = function() {
13
13
14
14
return toml . parse ( fs . readFileSync ( configPath ) ) ;
15
15
} ;
16
+
17
+ exports . loadContext = function ( config ) {
18
+ var buildConfig = config . build ;
19
+ var contextConfig = (
20
+ process . env . CONTEXT &&
21
+ config . context &&
22
+ config . context [ process . env . CONTEXT ]
23
+ ) || { } ;
24
+ var branchConfig = (
25
+ process . env . BRANCH &&
26
+ config . context &&
27
+ config . context [ process . env . BRANCH ]
28
+ ) || { } ;
29
+ var buildEnv = buildConfig . environment || buildConfig . Environment || { } ;
30
+ var contextEnv = contextConfig . environment || contextConfig . Environment || { } ;
31
+ var branchEnv = branchConfig . environment || branchConfig . Environment || { } ;
32
+ return {
33
+ ...buildConfig ,
34
+ ...contextConfig ,
35
+ ...branchConfig ,
36
+ environment : {
37
+ ...buildEnv ,
38
+ ...contextEnv ,
39
+ ...branchEnv ,
40
+ }
41
+ } ;
42
+ } ;
Original file line number Diff line number Diff line change
1
+ var conf = require ( './config' ) ;
2
+
3
+ beforeAll ( function ( ) {
4
+ process . env . CONTEXT = 'branch-deploy' ;
5
+ process . env . BRANCH = 'foo-branch' ;
6
+ } ) ;
7
+
8
+ describe ( 'loadContext' , function ( ) {
9
+ it ( 'should merge in context config' , function ( ) {
10
+ var config = {
11
+ build : {
12
+ publish : '/default' ,
13
+ environment : {
14
+ SOME_VAR : true ,
15
+ } ,
16
+ } ,
17
+ context : {
18
+ 'branch-deploy' : {
19
+ publish : '/branch-deploy' ,
20
+ environment : {
21
+ SOME_VAR : false ,
22
+ } ,
23
+ } ,
24
+ 'foo-branch' : {
25
+ publish : '/foo-branch' ,
26
+ environment : {
27
+ SOME_OTHER_VAR : 10 ,
28
+ } ,
29
+ } ,
30
+ } ,
31
+ } ;
32
+ var contextConfig = conf . loadContext ( config ) ;
33
+ expect ( contextConfig ) . toEqual ( {
34
+ publish : '/foo-branch' ,
35
+ environment : {
36
+ SOME_VAR : false ,
37
+ SOME_OTHER_VAR : 10 ,
38
+ } ,
39
+ } ) ;
40
+ } ) ;
41
+ } ) ;
Original file line number Diff line number Diff line change 8
8
"netlify-lambda" : " bin/cmd.js"
9
9
},
10
10
"scripts" : {
11
- "test" : " echo \" Error: no test specified \" && exit 1 "
11
+ "test" : " jest "
12
12
},
13
13
"author" : " Mathias Biilmann Christensen" ,
14
14
"license" : " MIT" ,
34
34
"toml" : " ^2.3.3" ,
35
35
"webpack" : " ^4.17.1" ,
36
36
"webpack-merge" : " ^4.1.4"
37
+ },
38
+ "devDependencies" : {
39
+ "jest" : " ^23.6.0"
37
40
}
38
41
}
You can’t perform that action at this time.
0 commit comments