Skip to content

Commit

Permalink
fix(cta): stop react recipe from opening in browser, closes #2793 (#2988
Browse files Browse the repository at this point in the history
)
  • Loading branch information
amrbashir committed Nov 30, 2021
1 parent 1c7ee6e commit ea51504
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changes/cta-react-disable-open-browser.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-tauri-app": patch
---

Stop react recipe from opening in browser by default.
11 changes: 9 additions & 2 deletions tooling/create-tauri-app/src/helpers/update-package-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ import { join } from 'path'

interface Package {
name?: string
scripts?: {}
scripts?: Record<string, string>
}

export function updatePackageJson(appDirectory: string, appName: string): void {
export function updatePackageJson(
appDirectory: string,
appName: string,
recipeShortName: string
): void {
const pkgPath = join(appDirectory, 'package.json')
const pkgString = readFileSync(pkgPath, 'utf8')
const pkg = JSON.parse(pkgString) as Package
Expand All @@ -19,6 +23,9 @@ export function updatePackageJson(appDirectory: string, appName: string): void {
name: appName,
scripts: {
...pkg.scripts,
start: `${recipeShortName === 'cra' ? 'cross-env BROWSER=none ' : ''}${
pkg.scripts?.start as string
}`,
tauri: 'tauri'
}
}
Expand Down
2 changes: 1 addition & 1 deletion tooling/create-tauri-app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ const runInit = async (argv: Argv): Promise<void> => {
})

logStep(`Updating ${reset(yellow('"package.json"'))}`)
updatePackageJson(appDirectory, appName)
updatePackageJson(appDirectory, appName, recipe.shortName)

logStep(`Running ${reset(yellow('"tauri init"'))}`)
const binary = !argv.b ? packageManager : resolve(appDirectory, argv.b)
Expand Down
2 changes: 1 addition & 1 deletion tooling/create-tauri-app/src/recipes/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const cra: Recipe = {
packageManager === 'npm' ? 'npm run' : packageManager
} build`
}),
extraNpmDevDependencies: [],
extraNpmDevDependencies: ['cross-env'],
extraNpmDependencies: [],
extraQuestions: ({ ci }) => {
return [
Expand Down

0 comments on commit ea51504

Please sign in to comment.