11import fs from 'fs-extra' ;
22import path from 'path' ;
3- import { v4 as uuid } from 'uuid' ;
3+ import { v4 as uuid , validate as uuidValidate } from 'uuid' ;
44import semver from 'semver' ;
55import { log , readPackageJson , writePackageJson } from 'ern-core' ;
66import { getNodeModuleVersion } from './getNodeModuleVersion' ;
@@ -56,7 +56,11 @@ export async function createBabelRc({
5656 // it messing with other module-resolver plugin configurations that could
5757 // be defined in the .babelrc config of individual MiniApps
5858 // 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+ }
6064 // Copy over module-resolver plugin & config to top level composite .babelrc
6165 log . debug (
6266 `Taking care of module-resolver Babel plugin for ${ miniAppName } MiniApp` ,
@@ -68,6 +72,14 @@ export async function createBabelRc({
6872 for ( const x of babelPlugin ) {
6973 if ( x instanceof Object && x . alias ) {
7074 moduleResolverAliases = x . alias ;
75+ Object . keys ( moduleResolverAliases ) . map ( ( key ) => {
76+ if ( ! moduleResolverAliases [ key ] . startsWith ( miniAppName ) )
77+ moduleResolverAliases [
78+ key
79+ ] = `${ miniAppName } /${ moduleResolverAliases [
80+ key
81+ ] . replace ( './' , '' ) } `;
82+ } ) ;
7183 break ;
7284 }
7385 }
@@ -105,7 +117,6 @@ export async function createBabelRc({
105117 log . debug (
106118 `Removing babel object from ${ miniAppName } MiniApp package.json` ,
107119 ) ;
108- delete miniAppPackageJson . babel ;
109120 await writePackageJson ( p , miniAppPackageJson ) ;
110121 }
111122 }
0 commit comments