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;