Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli-plugin-metro): ensure bundle destination directory exist #2040

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions packages/cli-plugin-metro/src/commands/bundle/buildBundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@
*
*/

import {logger} from '@react-native-community/cli-tools';
import type {Config} from '@react-native-community/cli-types';
import chalk from 'chalk';
import fs from 'fs';
import type {ConfigT} from 'metro-config';
import Server from 'metro/src/Server';
import outputBundle from 'metro/src/shared/output/bundle';
import type {BundleOptions} from 'metro/src/shared/types';
import type {ConfigT} from 'metro-config';
import path from 'path';
import chalk from 'chalk';
import {default as loadMetroConfig} from '../../tools/loadMetroConfig';
import {CommandLineArgs} from './bundleCommandLineArgs';
import type {Config} from '@react-native-community/cli-types';
import saveAssets from './saveAssets';
import {default as loadMetroConfig} from '../../tools/loadMetroConfig';
import {logger} from '@react-native-community/cli-tools';

interface RequestOptions {
entryFile: string;
Expand Down Expand Up @@ -91,6 +92,10 @@ export async function buildBundleWithConfig(
try {
const bundle = await output.build(server, requestOpts);

// Ensure destination directory exists before saving the bundle
const mkdirOptions = {recursive: true, mode: 0o755} as const;
fs.mkdirSync(path.dirname(args.bundleOutput), mkdirOptions);

await output.save(bundle, args, logger.info);

// Save the assets of the bundle
Expand Down