Skip to content

Commit 557632f

Browse files
szymonrybczaktido64Rexogamer
authored
fix: save .env files under node_modules/.generated (#2318)
* fix: save `.env` files under `node_modules/.generated` * Update packages/cli-tools/src/startServerInNewWindow.ts Co-authored-by: Tommy Nguyen <[email protected]> * chore: lint * Update packages/cli-tools/src/startServerInNewWindow.ts Co-authored-by: Sophie L <[email protected]> --------- Co-authored-by: Tommy Nguyen <[email protected]> Co-authored-by: Sophie L <[email protected]>
1 parent c5d2e93 commit 557632f

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

packages/cli-tools/src/startServerInNewWindow.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import path from 'path';
22
import fs from 'fs';
33
import execa from 'execa';
4-
import resolveNodeModuleDir from './resolveNodeModuleDir';
54
import logger from './logger';
65
import chalk from 'chalk';
6+
import {findPackageDependencyDir} from './findPackageDependencyDir';
77

88
const ERROR = `a dev server manually by running ${chalk.bold(
99
'npm start',
@@ -34,7 +34,16 @@ function startServerInNewWindow(
3434
const packagerEnvFileExportContent = isWindows
3535
? `set RCT_METRO_PORT=${port}\nset PROJECT_ROOT=${projectRoot}\nset REACT_NATIVE_PATH=${reactNativePath}`
3636
: `export RCT_METRO_PORT=${port}\nexport PROJECT_ROOT="${projectRoot}"\nexport REACT_NATIVE_PATH="${reactNativePath}"`;
37-
const nodeModulesPath = resolveNodeModuleDir(projectRoot, '.bin');
37+
let generatedPath = findPackageDependencyDir('.generated', {
38+
startDir: projectRoot,
39+
});
40+
41+
if (!generatedPath) {
42+
const newPath = path.join(projectRoot, 'node_modules', '.generated');
43+
fs.mkdirSync(newPath, {recursive: true, mode: 0o755});
44+
generatedPath = newPath;
45+
}
46+
3847
const cliPluginMetroPath = path.join(
3948
path.dirname(
4049
require.resolve('@react-native-community/cli-tools/package.json'),
@@ -45,13 +54,13 @@ function startServerInNewWindow(
4554
/**
4655
* Set up the `.packager.(env|bat)` file to ensure the packager starts on the right port and in right directory.
4756
*/
48-
const packagerEnvFile = path.join(nodeModulesPath, `${packagerEnvFilename}`);
57+
const packagerEnvFile = path.join(generatedPath, `${packagerEnvFilename}`);
4958

5059
/**
5160
* Set up the `launchPackager.(command|bat)` file.
5261
* It lives next to `.packager.(bat|env)`
5362
*/
54-
const launchPackagerScript = path.join(nodeModulesPath, scriptFile);
63+
const launchPackagerScript = path.join(generatedPath, scriptFile);
5564
const procConfig: execa.SyncOptions = {cwd: path.dirname(packagerEnvFile)};
5665

5766
/**
@@ -63,19 +72,19 @@ function startServerInNewWindow(
6372
});
6473

6574
/**
66-
* Copy files into `node_modules/.bin`.
75+
* Copy files into `node_modules/.generated`.
6776
*/
6877

6978
try {
7079
if (isWindows) {
7180
fs.copyFileSync(
7281
path.join(cliPluginMetroPath, 'launchPackager.bat'),
73-
path.join(nodeModulesPath, 'launchPackager.bat'),
82+
path.join(generatedPath, 'launchPackager.bat'),
7483
);
7584
} else {
7685
fs.copyFileSync(
7786
path.join(cliPluginMetroPath, 'launchPackager.command'),
78-
path.join(nodeModulesPath, 'launchPackager.command'),
87+
path.join(generatedPath, 'launchPackager.command'),
7988
);
8089
}
8190
} catch (error) {

0 commit comments

Comments
 (0)