Skip to content

Commit 48d4c29

Browse files
authored
fix(cli-plugin-metro): ensure bundle destination directory exist (#2040)
1 parent 9f45bea commit 48d4c29

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

packages/cli-plugin-metro/src/commands/bundle/buildBundle.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@
66
*
77
*/
88

9+
import {logger} from '@react-native-community/cli-tools';
10+
import type {Config} from '@react-native-community/cli-types';
11+
import chalk from 'chalk';
12+
import fs from 'fs';
13+
import type {ConfigT} from 'metro-config';
914
import Server from 'metro/src/Server';
1015
import outputBundle from 'metro/src/shared/output/bundle';
1116
import type {BundleOptions} from 'metro/src/shared/types';
12-
import type {ConfigT} from 'metro-config';
1317
import path from 'path';
14-
import chalk from 'chalk';
18+
import {default as loadMetroConfig} from '../../tools/loadMetroConfig';
1519
import {CommandLineArgs} from './bundleCommandLineArgs';
16-
import type {Config} from '@react-native-community/cli-types';
1720
import saveAssets from './saveAssets';
18-
import {default as loadMetroConfig} from '../../tools/loadMetroConfig';
19-
import {logger} from '@react-native-community/cli-tools';
2021

2122
interface RequestOptions {
2223
entryFile: string;
@@ -91,6 +92,10 @@ export async function buildBundleWithConfig(
9192
try {
9293
const bundle = await output.build(server, requestOpts);
9394

95+
// Ensure destination directory exists before saving the bundle
96+
const mkdirOptions = {recursive: true, mode: 0o755} as const;
97+
fs.mkdirSync(path.dirname(args.bundleOutput), mkdirOptions);
98+
9499
await output.save(bundle, args, logger.info);
95100

96101
// Save the assets of the bundle

0 commit comments

Comments
 (0)