Skip to content

Commit 62b52f6

Browse files
authored
fix(cli/add): use >= for npm and ~ for other package managers (#11064)
* fix(cli/add): use `>=` for npm and `~` for other package managers closes #10906 * headers * fix audit * fix headers
1 parent a247170 commit 62b52f6

File tree

8 files changed

+101
-57
lines changed

8 files changed

+101
-57
lines changed

.changes/cli-add-npm.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"tauri-cli": "patch:bug"
3+
"@tauri-apps/cli": "patch:bug"
4+
---
5+
6+
Fix `tauri add` failing to add NPM depenency with `npm` package manager.
7+

.github/workflows/publish-cli-js.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,45 +30,45 @@ jobs:
3030
target: x86_64-apple-darwin
3131
architecture: x64
3232
build: |
33-
pnpm build:release --target=x86_64-apple-darwin
33+
pnpm build --target=x86_64-apple-darwin
3434
strip -x *.node
3535
- host: windows-latest
36-
build: pnpm build:release
36+
build: pnpm build
3737
target: x86_64-pc-windows-msvc
3838
architecture: x64
3939
- host: windows-latest
40-
build: pnpm build:release --target i686-pc-windows-msvc
40+
build: pnpm build --target i686-pc-windows-msvc
4141
target: i686-pc-windows-msvc
4242
architecture: x64
4343
- host: windows-latest
4444
architecture: x64
4545
target: aarch64-pc-windows-msvc
46-
build: pnpm build:release --target aarch64-pc-windows-msvc --features native-tls-vendored --cargo-flags="--no-default-features"
46+
build: pnpm build --target aarch64-pc-windows-msvc --features native-tls-vendored --cargo-flags="--no-default-features"
4747
- host: ubuntu-20.04
4848
target: x86_64-unknown-linux-gnu
4949
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian
5050
build: |
5151
cd packages/cli
52-
pnpm build:release --target x86_64-unknown-linux-gnu
52+
pnpm build --target x86_64-unknown-linux-gnu
5353
strip *.node
5454
- host: ubuntu-20.04
5555
target: x86_64-unknown-linux-musl
5656
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
5757
build: |
5858
cd packages/cli
59-
pnpm build:release
59+
pnpm build
6060
strip *.node
6161
- host: macos-latest
6262
target: aarch64-apple-darwin
6363
build: |
64-
pnpm build:release --features native-tls-vendored --target=aarch64-apple-darwin
64+
pnpm build --features native-tls-vendored --target=aarch64-apple-darwin
6565
strip -x *.node
6666
- host: ubuntu-20.04
6767
target: aarch64-unknown-linux-gnu
6868
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-aarch64
6969
build: |
7070
cd packages/cli
71-
pnpm build:release --target aarch64-unknown-linux-gnu
71+
pnpm build --target aarch64-unknown-linux-gnu
7272
aarch64-unknown-linux-gnu-strip *.node
7373
- host: ubuntu-20.04
7474
architecture: x64
@@ -77,7 +77,7 @@ jobs:
7777
sudo apt-get update
7878
sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf -y
7979
build: |
80-
pnpm build:release --target=armv7-unknown-linux-gnueabihf
80+
pnpm build --target=armv7-unknown-linux-gnueabihf
8181
arm-linux-gnueabihf-strip *.node
8282
- host: ubuntu-20.04
8383
architecture: x64
@@ -86,7 +86,7 @@ jobs:
8686
build: |
8787
cd packages/cli
8888
rustup target add aarch64-unknown-linux-musl
89-
pnpm build:release --target aarch64-unknown-linux-musl
89+
pnpm build --target aarch64-unknown-linux-musl
9090
/aarch64-linux-musl-cross/bin/aarch64-linux-musl-strip *.node
9191
name: stable - ${{ matrix.settings.target }} - node@20
9292
runs-on: ${{ matrix.settings.host }}
@@ -175,7 +175,7 @@ jobs:
175175
# freebsd-version
176176
# cd ./packages/cli/
177177
# pnpm i --frozen-lockfile --ignore-scripts
178-
# pnpm build:release
178+
# pnpm build
179179
# strip -x *.node
180180
# rm -rf node_modules
181181
# rm -rf ../../target

crates/tauri-cli/src/add.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@ pub fn run(options: Options) -> Result<()> {
6969
});
7070

7171
let cargo_version_req = version.or(metadata.version_req.as_deref());
72-
let npm_version_req = version
73-
.map(ToString::to_string)
74-
.or(metadata.version_req.as_ref().map(|v| format!("^{v}")));
7572

7673
cargo::install_one(cargo::CargoInstallOptions {
7774
name: &crate_name,
@@ -88,6 +85,13 @@ pub fn run(options: Options) -> Result<()> {
8885
.map(PackageManager::from_project)
8986
.and_then(|managers| managers.into_iter().next())
9087
{
88+
let npm_version_req = version
89+
.map(ToString::to_string)
90+
.or(metadata.version_req.as_ref().map(|v| match manager {
91+
PackageManager::Npm => format!(">={v}"),
92+
_ => format!("~{v}"),
93+
}));
94+
9195
let npm_spec = match (npm_version_req, options.tag, options.rev, options.branch) {
9296
(Some(version), _, _, _) => {
9397
format!("{npm_name}@{version}")

examples/api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020
"unocss": "^0.61.0",
2121
"@sveltejs/vite-plugin-svelte": "^3.1.1",
2222
"svelte": "^4.2.19",
23-
"vite": "^5.4.1"
23+
"vite": "^5.4.6"
2424
}
2525
}

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
"format": "prettier --write .",
1515
"format:check": "prettier --check .",
1616
"eslint:check": "pnpm run -r eslint:check",
17-
"ts:check": "pnpm run -r ts:check"
17+
"ts:check": "pnpm run -r ts:check",
18+
"build": "pnpm run -r build",
19+
"build:api": "pnpm run --filter \"@tauri-apps/api\" build",
20+
"build:cli": "pnpm run --filter \"@tauri-apps/cli\" build",
21+
"build:cli:debug": "pnpm run --filter \"@tauri-apps/cli\" build:debug",
22+
"test": "pnpm run -r build"
1823
},
1924
"devDependencies": {
2025
"prettier": "^3.3.3"

packages/cli/append-headers.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
2+
// SPDX-License-Identifier: Apache-2.0
3+
// SPDX-License-Identifier: MIT
4+
5+
const HEADERS = `// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
6+
// SPDX-License-Identifier: Apache-2.0
7+
// SPDX-License-Identifier: MIT`
8+
9+
const fs = require('fs')
10+
11+
for (const file of ['index.js', 'index.d.ts']) {
12+
const content = fs.readFileSync(file, 'utf8')
13+
const newContent = `${HEADERS}\n\n${content}`
14+
fs.writeFileSync(file, newContent, 'utf8')
15+
}

packages/cli/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@
5151
},
5252
"scripts": {
5353
"artifacts": "napi artifacts",
54-
"build:release": "cross-env TARGET=node napi build --platform --profile release-size-optimized",
55-
"build": "cross-env TARGET=node napi build --platform",
54+
"build": "cross-env TARGET=node napi build --platform --profile release-size-optimized",
55+
"postbuild": "node append-headers.js",
56+
"build:debug": "cross-env TARGET=node napi build --platform",
57+
"postbuild:debug": "node append-headers.js",
5658
"prepublishOnly": "napi prepublish -t npm --gh-release-id $RELEASE_ID",
5759
"prepack": "cp ../../crates/tauri-schema-generator/schemas/config.schema.json .",
5860
"version": "napi version",

0 commit comments

Comments
 (0)