Skip to content

Commit f10c92c

Browse files
elylucasimhoffd
authored andcommitted
fix(react): Disable CRA from opening window so two windows don't open (#4119)
1 parent 0e662e7 commit f10c92c

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

packages/ionic/src/commands/config/get.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ This command will sanitize config output for known sensitive fields (disabled wh
7878
} else {
7979
if (global && v && typeof v === 'object') {
8080
const columns = lodash.entries(v)
81-
.map(([k, v]) => [k, this.sanitizeEntry(k, v)])
82-
.map(([k, v]) => [strong(k), util.inspect(v, { colors: chalk.enabled })]);
81+
.map(([key, value]) => [key, this.sanitizeEntry(key, value)])
82+
.map(([key, value]) => [strong(key), util.inspect(value, { colors: chalk.enabled })]);
8383

8484
columns.sort((a, b) => strcmp(a[0], b[0]));
8585

packages/ionic/src/commands/deploy/manifest.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,19 @@ export class DeployManifestCommand extends DeployCoreCommand {
4545
private async getFilesAndSizesAndHashesForGlobPattern(buildDir: string): Promise<DeployManifestItem[]> {
4646
const contents = await readdirp(buildDir);
4747
const stats = await map(contents, async (f): Promise<[string, fs.Stats]> => [f, await stat(f)]);
48-
const files = stats.filter(([ , stat ]) => !stat.isDirectory());
48+
const files = stats.filter(([ , s ]) => !s.isDirectory());
4949

50-
const items = await Promise.all(files.map(([f, stat]) => this.getFileAndSizeAndHashForFile(buildDir, f, stat)));
50+
const items = await Promise.all(files.map(([f, s]) => this.getFileAndSizeAndHashForFile(buildDir, f, s)));
5151

5252
return items.filter(item => item.href !== 'pro-manifest.json');
5353
}
5454

55-
private async getFileAndSizeAndHashForFile(buildDir: string, file: string, stat: fs.Stats): Promise<DeployManifestItem> {
55+
private async getFileAndSizeAndHashForFile(buildDir: string, file: string, s: fs.Stats): Promise<DeployManifestItem> {
5656
const buffer = await this.readFile(file);
5757

5858
return {
5959
href: path.relative(buildDir, file),
60-
size: stat.size,
60+
size: s.size,
6161
integrity: this.getIntegrity(buffer),
6262
};
6363
}

packages/ionic/src/lib/project/react/serve.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { findClosestOpenPort } from '@ionic/utils-network';
44

55
import { CommandMetadata, ReactServeOptions, ServeDetails } from '../../../definitions';
66
import { input, strong } from '../../color';
7-
import { BIND_ALL_ADDRESS, LOCAL_ADDRESSES, SERVE_SCRIPT, ServeCLI, ServeRunner, ServeRunnerDeps } from '../../serve';
7+
import { BIND_ALL_ADDRESS, DEFAULT_ADDRESS, LOCAL_ADDRESSES, SERVE_SCRIPT, ServeCLI, ServeRunner, ServeRunnerDeps } from '../../serve';
88

99
export class ReactServeRunner extends ServeRunner<ReactServeOptions> {
1010
constructor(protected readonly e: ServeRunnerDeps) {
@@ -69,7 +69,7 @@ export class ReactServeRunner extends ServeRunner<ReactServeOptions> {
6969
}
7070

7171
async serveProject(options: ReactServeOptions): Promise<ServeDetails> {
72-
const [ externalIP, availableInterfaces ] = await this.selectExternalIP(options);
72+
const [externalIP, availableInterfaces] = await this.selectExternalIP(options);
7373

7474
const port = options.port = await findClosestOpenPort(options.port);
7575

@@ -137,21 +137,25 @@ export class ReactServeCLI extends ServeCLI<ReactServeOptions> {
137137
if (this.resolvedProgram === this.program) {
138138
return ['start'];
139139
} else {
140-
const [ , ...pkgArgs ] = await pkgManagerArgs(this.e.config.get('npmClient'), { command: 'run', script: this.script });
140+
const [, ...pkgArgs] = await pkgManagerArgs(this.e.config.get('npmClient'), { command: 'run', script: this.script });
141141
return pkgArgs;
142142
}
143143
}
144144

145145
protected async buildEnvVars(options: ReactServeOptions): Promise<NodeJS.ProcessEnv> {
146146
const envVars: NodeJS.ProcessEnv = {};
147147

148-
if (options.browser) {
149-
envVars.BROWSER = options.browser;
150-
}
151-
if (options.open !== true) {
152-
envVars.BROWSER = 'none';
148+
envVars.BROWSER = 'none';
149+
150+
/*
151+
By default, CRA binds to localhost,
152+
but if you specify it, it puts a warning in the console,
153+
so don't set the HOST if the address is set to 'localhost'
154+
*/
155+
if (options.address !== DEFAULT_ADDRESS) {
156+
envVars.HOST = options.address;
153157
}
154-
envVars.HOST = options.address;
158+
155159
envVars.PORT = String(options.port);
156160
envVars.HTTPS = (options.https === true) ? 'true' : 'false';
157161
envVars.CI = (options.ci === true) ? 'true' : 'false';

0 commit comments

Comments
 (0)