Skip to content
Open
Show file tree
Hide file tree
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
9 changes: 6 additions & 3 deletions packages/cli-tools/src/launchPackager.command
Original file line number Diff line number Diff line change
Expand Up @@ -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 <enter> to close the window"
read -r
fi

exit "$CLI_EXIT_CODE"
20 changes: 14 additions & 6 deletions packages/cli-tools/src/startServerInNewWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
});
Expand Down Expand Up @@ -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) {
Expand Down
Loading