Skip to content

Commit a962ef8

Browse files
feat: detect bun in create-tauri-app (#481)
* feat: detect bun in create-tauri-app * Add changeset * add bun in CI * Update .scripts/generate-templates-matrix.js * replace bunx with bun x * fmt * fix bun cmds * fmt * fix bun vanilla --------- Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com>
1 parent 1afc006 commit a962ef8

12 files changed

Lines changed: 55 additions & 7 deletions

File tree

.changes/bun-pm.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"create-tauri-app": minor
3+
"create-tauri-app-js": minor
4+
---
5+
6+
Support and detect Bun package manager

.github/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ A template is a just combination of two fragments, [`_base_`](../packages/cli/fr
8383
tauri.svg = public/tauri.svg
8484
```
8585
- In `<repo-root>/packages/cli/src/template.rs`, add an entry in the `Template` enum, modify `post_init_info`, `flavors` and `from_flavor` if needed and modify `FromStr` and `Display` implementation
86-
- In `<repo-root>/packages/cli/src/package_manager.rs` add your new template to the appropraite package manager in the `templates` method
86+
- In `<repo-root>/packages/cli/src/package_manager.rs` add your new template to the appropriate package manager in the `templates` method
8787
- Modify `<repo-root>/.scripts/generate-templates-matrix.js` and append the template name inside the template list for the appropriate package manager so the CI would run tests for it.
8888
- If the template requires system dependencies, add a post init note in `<repo-root>/packages/cli/src/template.rs` in `post_init_info` method.
8989
- Before making a commit, make sure to run `cargo fmt --all` and `pnpm format` in the repo root.

.github/workflows/templates-test.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ jobs:
7373
with:
7474
version: 8
7575

76+
- uses: oven-sh/setup-bun@v1
77+
if: matrix.settings.manager == 'bun'
78+
with:
79+
bun-version: latest
80+
7681
- name: Install Node.js@16
7782
if: matrix.settings.manager != 'cargo'
7883
uses: actions/setup-node@v2

.scripts/generate-templates-matrix.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ const matrixConfig = [
4141
run_cmd: "cargo",
4242
templates: ["vanilla", "yew", "leptos"],
4343
},
44+
{
45+
manager: "bun",
46+
install_cmd: "bun install",
47+
run_cmd: "bun run",
48+
templates: nodeJsTemplates,
49+
},
4450
];
4551

4652
const outMatrix = [];

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ yarn create tauri-app
5454
pnpm create tauri-app
5555
```
5656

57+
## Bun:
58+
59+
```bash
60+
bunx create-tauri-app
61+
```
62+
5763
<br>
5864

5965
You can also directly specify the project name, package manager and the template you want to use via additional command line options. For example, to scaffold a Svelte project in a `my-tauri-app` directory, run:
@@ -75,6 +81,8 @@ npm create tauri-app@latest my-tauri-app -- --template svelte --manager pnpm
7581
yarn create tauri-app my-tauri-app --template svelte --manager pnpm
7682
# pnpm
7783
pnpm create tauri-app my-tauri-app --template svelte --manager pnpm
84+
# Bun
85+
bunx create-tauri-app my-tauri-app --template svelte --manager bun
7886
```
7987

8088
Currently supported template presets include:

packages/cli/fragments/fragment-vanilla/%(pnpm-yarn-npm-alpha-mobile)%package.json renamed to packages/cli/fragments/fragment-vanilla/%(pnpm-yarn-npm-bun-alpha-mobile)%package.json

File renamed without changes.

packages/cli/fragments/fragment-vanilla/%(pnpm-yarn-npm-stable)%package.json renamed to packages/cli/fragments/fragment-vanilla/%(pnpm-yarn-npm-bun-stable)%package.json

File renamed without changes.

packages/cli/node/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ yarn create tauri-app
2929
pnpm create tauri-app
3030
```
3131

32+
## Bun:
33+
34+
```bash
35+
bunx create-tauri-app
36+
```
37+
3238
<br>
3339

3440
You can also directly specify the project name, package manager and the template you want to use via additional command line options. For example, to scaffold a Svelte project in a `my-tauri-app` directory, run:
@@ -42,6 +48,8 @@ npm create tauri-app@latest my-tauri-app -- --template svelte --manager pnpm
4248
yarn create tauri-app my-tauri-app --template svelte --manager pnpm
4349
# pnpm
4450
pnpm create tauri-app my-tauri-app --template svelte --manager pnpm
51+
# Bun
52+
bunx create-tauri-app my-tauri-app --template svelte --manager bun
4553
```
4654

4755
Currently supported template presets include:

packages/cli/node/create-tauri-app.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ let binName;
1616
if (bin === "@tauri-apps/cli") {
1717
binName = "@tauri-apps/cli";
1818
}
19-
// Even if started by a package manager, the binary will be NodeJS.
19+
// Even if started by a package manager, the binary will be NodeJS or Bun.
2020
// Some distribution still use "nodejs" as the binary name.
21-
if (binStem.match(/(nodejs|node)-*([1-9]*)*$/g)) {
21+
if (binStem.match(/(nodejs|node|bun)-*([1-9]*)*$/g)) {
2222
const managerStem = process.env.npm_execpath
2323
? path.parse(process.env.npm_execpath).name.toLowerCase()
2424
: null;
@@ -30,7 +30,7 @@ if (binStem.match(/(nodejs|node)-*([1-9]*)*$/g)) {
3030
manager = "npm";
3131
break;
3232

33-
// Yarn and pnpm have the same stem name as their bin.
33+
// Yarn, pnpm, and Bun have the same stem name as their bin.
3434
// We assume all unknown package managers do as well.
3535
default:
3636
manager = managerStem;

packages/cli/src/category.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ impl<'a> Category {
2424
PackageManager::Pnpm,
2525
PackageManager::Yarn,
2626
PackageManager::Npm,
27+
PackageManager::Bun,
2728
],
2829
}
2930
}

0 commit comments

Comments
 (0)