@@ -11,6 +11,28 @@ import astTransform from "./recursive-parser";
11
11
import runPrettier from "./run-prettier" ;
12
12
import { Node } from "./types/NodePath" ;
13
13
14
+
15
+
16
+ function mergeHandler ( config : Config , transformations : string [ ] ) : [ Config , string [ ] ] {
17
+ if ( transformations . indexOf ( "topScope" ) === - 1 )
18
+ {
19
+ config [ "topScope" ] = [
20
+ `const merge = require('webpack-merge')` ,
21
+ `const ${ config . merge [ 0 ] } = require(${ config . merge [ 1 ] } )`
22
+ ] ;
23
+ } else {
24
+ config . topScope . push (
25
+ `const merge = require('webpack-merge')` ,
26
+ `const ${ config . merge [ 0 ] } = require(${ config . merge [ 1 ] } )`
27
+ )
28
+ }
29
+
30
+ config . merge = config . merge [ 0 ] ;
31
+ transformations . push ( "merge" , "topScope" ) ;
32
+ return [ config , transformations ]
33
+ }
34
+
35
+
14
36
/**
15
37
*
16
38
* Maps back transforms that needs to be run using the configuration
@@ -45,17 +67,17 @@ export default function runTransform(transformConfig: TransformConfig, action: s
45
67
46
68
webpackConfig . forEach (
47
69
( scaffoldPiece : string ) : Promise < void > => {
48
- const config : Config = transformConfig [ scaffoldPiece ] ;
70
+ let config : Config = transformConfig [ scaffoldPiece ] ;
49
71
50
- const transformations = mapOptionsToTransform ( config ) ;
72
+ let transformations = mapOptionsToTransform ( config ) ;
51
73
52
74
if ( config . topScope && transformations . indexOf ( "topScope" ) === - 1 ) {
53
75
transformations . push ( "topScope" ) ;
54
76
}
55
77
56
- if ( config . merge && transformations . indexOf ( "merge" ) === - 1 ) {
57
- transformations . push ( "merge" ) ;
58
- }
78
+ if ( config . merge && transformations . indexOf ( "merge" ) === - 1 ) {
79
+ [ config , transformations ] = mergeHandler ( config , transformations ) ;
80
+ }
59
81
60
82
const ast : Node = j ( initActionNotDefined ? transformConfig . configFile : "module.exports = {}" ) ;
61
83
0 commit comments