From 1856495a6448a2640544ec58ed08b552e4946036 Mon Sep 17 00:00:00 2001 From: leegeunhyeok Date: Tue, 24 Oct 2023 00:38:41 +0900 Subject: [PATCH] feat: reset cache after initialize --- packages/cli/lib/index.ts | 5 +---- packages/core/lib/bundler/bundler.ts | 7 +++++++ types/index.d.ts | 2 ++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/cli/lib/index.ts b/packages/cli/lib/index.ts index e82c14fa..385b54ae 100644 --- a/packages/cli/lib/index.ts +++ b/packages/cli/lib/index.ts @@ -13,10 +13,7 @@ import { logger } from './shared'; ReactNativeEsbuildBundler.setGlobalLogLevel( options.verbose ? LogLevel.Trace : LogLevel.Info, ); - - if (options['reset-cache']) { - await ReactNativeEsbuildBundler.resetCache(); - } + self.shouldResetCache = options['reset-cache']; switch (getCommand(argv)) { case 'start': diff --git a/packages/core/lib/bundler/bundler.ts b/packages/core/lib/bundler/bundler.ts index 2df36da6..c483778f 100644 --- a/packages/core/lib/bundler/bundler.ts +++ b/packages/core/lib/bundler/bundler.ts @@ -370,6 +370,8 @@ export class ReactNativeEsbuildBundler extends BundlerEventEmitter { logger.warn('bundler already initialized'); return this; } + + // Initialize. const spinner = ora({ discardStdin: false }).start( 'Bundler initializing...', ); @@ -381,6 +383,11 @@ export class ReactNativeEsbuildBundler extends BundlerEventEmitter { this.initialized = true; spinner.stop(); + // Post initialize. + if (self.shouldResetCache) { + await ReactNativeEsbuildBundler.resetCache(); + } + return this; } diff --git a/types/index.d.ts b/types/index.d.ts index ef9bac30..96201309 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -4,6 +4,8 @@ declare global { // core config // eslint-disable-next-line @typescript-eslint/no-explicit-any -- `BundlerConfig` in @react-native-esbuild/core. _config: any; + // core + shouldResetCache?: boolean; // logger logEnabled: boolean; logLevel: number;