1
1
import fs from 'fs-extra' ;
2
2
import path from 'path' ;
3
- import { v4 as uuid } from 'uuid' ;
3
+ import { v4 as uuid , validate as uuidValidate } from 'uuid' ;
4
4
import semver from 'semver' ;
5
5
import { log , readPackageJson , writePackageJson } from 'ern-core' ;
6
6
import { getNodeModuleVersion } from './getNodeModuleVersion' ;
@@ -56,7 +56,11 @@ export async function createBabelRc({
56
56
// it messing with other module-resolver plugin configurations that could
57
57
// be defined in the .babelrc config of individual MiniApps
58
58
// https://babeljs.io/docs/en/options#plugin-preset-merging
59
- babelPlugin . push ( uuid ( ) ) ;
59
+ // Check if lastItem of babel plugin is not uuid
60
+ const lastItem = babelPlugin . slice ( - 1 ) [ 0 ] ;
61
+ if ( typeof lastItem !== "string" || ! uuidValidate ( lastItem ) ) {
62
+ babelPlugin . push ( uuid ( ) ) ;
63
+ }
60
64
// Copy over module-resolver plugin & config to top level composite .babelrc
61
65
log . debug (
62
66
`Taking care of module-resolver Babel plugin for ${ miniAppName } MiniApp` ,
@@ -68,6 +72,10 @@ export async function createBabelRc({
68
72
for ( const x of babelPlugin ) {
69
73
if ( x instanceof Object && x . alias ) {
70
74
moduleResolverAliases = x . alias ;
75
+ Object . keys ( moduleResolverAliases ) . map ( ( key ) => {
76
+ if ( ! moduleResolverAliases [ key ] . startsWith ( miniAppName ) )
77
+ moduleResolverAliases [ key ] = `${ miniAppName } /${ moduleResolverAliases [ key ] . replace ( './' , '' ) } ` ;
78
+ } )
71
79
break ;
72
80
}
73
81
}
@@ -105,7 +113,6 @@ export async function createBabelRc({
105
113
log . debug (
106
114
`Removing babel object from ${ miniAppName } MiniApp package.json` ,
107
115
) ;
108
- delete miniAppPackageJson . babel ;
109
116
await writePackageJson ( p , miniAppPackageJson ) ;
110
117
}
111
118
}
0 commit comments