@@ -11,6 +11,28 @@ import astTransform from "./recursive-parser";
1111import runPrettier from "./run-prettier" ;
1212import { Node } from "./types/NodePath" ;
1313
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+
1436/**
1537 *
1638 * Maps back transforms that needs to be run using the configuration
@@ -45,17 +67,17 @@ export default function runTransform(transformConfig: TransformConfig, action: s
4567
4668 webpackConfig . forEach (
4769 ( scaffoldPiece : string ) : Promise < void > => {
48- const config : Config = transformConfig [ scaffoldPiece ] ;
70+ let config : Config = transformConfig [ scaffoldPiece ] ;
4971
50- const transformations = mapOptionsToTransform ( config ) ;
72+ let transformations = mapOptionsToTransform ( config ) ;
5173
5274 if ( config . topScope && transformations . indexOf ( "topScope" ) === - 1 ) {
5375 transformations . push ( "topScope" ) ;
5476 }
5577
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+ }
5981
6082 const ast : Node = j ( initActionNotDefined ? transformConfig . configFile : "module.exports = {}" ) ;
6183
0 commit comments