diff --git a/packages/cli-tools/src/launchPackager.command b/packages/cli-tools/src/launchPackager.command index 2e3587924..615c2fac0 100755 --- a/packages/cli-tools/src/launchPackager.command +++ b/packages/cli-tools/src/launchPackager.command @@ -2,11 +2,14 @@ THIS_DIR=$(cd -P "$(dirname "$(readlink "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}")")" && pwd) -source "$THIS_DIR/.packager.env" -cd "$PROJECT_ROOT" -"$REACT_NATIVE_PATH/cli.js" start --port $RCT_METRO_PORT +source "$THIS_DIR/.packager.env" || exit 1 +cd "$PROJECT_ROOT" || exit 1 +"$REACT_NATIVE_PATH/cli.js" start --port "$RCT_METRO_PORT" +CLI_EXIT_CODE=$? if [[ -z "$CI" ]]; then echo "Process terminated. Press to close the window" read -r fi + +exit "$CLI_EXIT_CODE" diff --git a/packages/cli-tools/src/startServerInNewWindow.ts b/packages/cli-tools/src/startServerInNewWindow.ts index 6a2180f1c..a83eed7b0 100644 --- a/packages/cli-tools/src/startServerInNewWindow.ts +++ b/packages/cli-tools/src/startServerInNewWindow.ts @@ -9,6 +9,8 @@ const ERROR = `a dev server manually by running ${pico.bold( 'npm start', )} or ${pico.bold('yarn start')} in other terminal window.`; +const quoteShellPath = (value: string) => `'${value.replace(/'/g, "'\\''")}'`; + function startServerInNewWindow( port: number, projectRoot: string, @@ -33,7 +35,9 @@ function startServerInNewWindow( const packagerEnvFilename = isWindows ? '.packager.bat' : '.packager.env'; const packagerEnvFileExportContent = isWindows ? `set RCT_METRO_PORT=${port}\nset PROJECT_ROOT=${projectRoot}\nset REACT_NATIVE_PATH=${reactNativePath}` - : `export RCT_METRO_PORT=${port}\nexport PROJECT_ROOT="${projectRoot}"\nexport REACT_NATIVE_PATH="${reactNativePath}"`; + : `export RCT_METRO_PORT=${port}\nexport PROJECT_ROOT=${quoteShellPath( + projectRoot, + )}\nexport REACT_NATIVE_PATH=${quoteShellPath(reactNativePath)}`; let generatedPath = findPackageDependencyDir('.generated', { startDir: projectRoot, }); @@ -109,13 +113,17 @@ function startServerInNewWindow( } if (process.platform === 'linux') { try { - return execa.sync(terminal, ['-e', `sh ${launchPackagerScript}`], { - ...procConfig, - detached: true, - }); + return execa.sync( + terminal, + ['-e', `bash ${quoteShellPath(launchPackagerScript)}`], + { + ...procConfig, + detached: true, + }, + ); } catch (error) { // By default, the child shell process will be attached to the parent - return execa.sync('sh', [launchPackagerScript], procConfig); + return execa.sync('bash', [launchPackagerScript], procConfig); } } if (isWindows) {