1
1
import ansiColors from 'ansi-colors' ;
2
- import { rm } from 'fs/promises' ;
3
- import { resolve } from 'path' ;
2
+ import { resolve } from 'node:path' ;
4
3
import { mergeDeepRight } from 'rambda' ;
5
4
import { UnpluginOptions , createUnplugin } from 'unplugin' ;
6
5
7
6
import { retrieveHostConfig } from './configurations/hostPlugin' ;
8
7
import { retrieveRemoteConfig } from './configurations/remotePlugin' ;
9
8
import { HostOptions } from './interfaces/HostOptions' ;
10
9
import { RemoteOptions } from './interfaces/RemoteOptions' ;
11
- import { createTypesArchive , downloadTypesArchive } from './lib/archiveHandler' ;
10
+ import {
11
+ createTypesArchive ,
12
+ deleteTypesFolder ,
13
+ downloadTypesArchive ,
14
+ } from './lib/archiveHandler' ;
12
15
import {
13
16
compileTs ,
14
17
retrieveMfTypesPath ,
@@ -19,6 +22,7 @@ export const NativeFederationTypeScriptRemote = createUnplugin(
19
22
( options : RemoteOptions ) => {
20
23
const { remoteOptions, tsConfig, mapComponentsToExpose } =
21
24
retrieveRemoteConfig ( options ) ;
25
+ const typesPath = retrieveMfTypesPath ( tsConfig , remoteOptions ) ;
22
26
return {
23
27
name : 'native-federation-typescript/remote' ,
24
28
async writeBundle ( ) {
@@ -27,12 +31,8 @@ export const NativeFederationTypeScriptRemote = createUnplugin(
27
31
28
32
await createTypesArchive ( tsConfig , remoteOptions ) ;
29
33
30
- if ( remoteOptions . deleteTypesFolder ) {
31
- await rm ( retrieveMfTypesPath ( tsConfig , remoteOptions ) , {
32
- recursive : true ,
33
- force : true ,
34
- } ) ;
35
- }
34
+ await deleteTypesFolder ( remoteOptions , typesPath ) ;
35
+
36
36
console . log ( ansiColors . green ( 'Federated types created correctly' ) ) ;
37
37
} catch ( error ) {
38
38
console . error (
@@ -79,21 +79,10 @@ export const NativeFederationTypeScriptRemote = createUnplugin(
79
79
export const NativeFederationTypeScriptHost = createUnplugin (
80
80
( options : HostOptions ) => {
81
81
const { hostOptions, mapRemotesToDownload } = retrieveHostConfig ( options ) ;
82
+ const typesDownloader = downloadTypesArchive ( hostOptions ) ;
82
83
return {
83
84
name : 'native-federation-typescript/host' ,
84
85
async writeBundle ( ) {
85
- if ( hostOptions . deleteTypesFolder ) {
86
- await rm ( hostOptions . typesFolder , {
87
- recursive : true ,
88
- force : true ,
89
- } ) . catch ( ( error ) =>
90
- console . error (
91
- ansiColors . red ( `Unable to remove types folder, ${ error } ` ) ,
92
- ) ,
93
- ) ;
94
- }
95
-
96
- const typesDownloader = downloadTypesArchive ( hostOptions ) ;
97
86
const downloadPromises =
98
87
Object . entries ( mapRemotesToDownload ) . map ( typesDownloader ) ;
99
88
0 commit comments