Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli/add): use >= for npm and ~ for other package managers #11064

Merged
merged 4 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changes/cli-add-npm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"tauri-cli": "patch:bug"
"@tauri-apps/cli": "patch:bug"
---

Fix `tauri add` failing to add NPM depenency with `npm` package manager.

22 changes: 11 additions & 11 deletions .github/workflows/publish-cli-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,45 +30,45 @@ jobs:
target: x86_64-apple-darwin
architecture: x64
build: |
pnpm build:release --target=x86_64-apple-darwin
pnpm build --target=x86_64-apple-darwin
strip -x *.node
- host: windows-latest
build: pnpm build:release
build: pnpm build
target: x86_64-pc-windows-msvc
architecture: x64
- host: windows-latest
build: pnpm build:release --target i686-pc-windows-msvc
build: pnpm build --target i686-pc-windows-msvc
target: i686-pc-windows-msvc
architecture: x64
- host: windows-latest
architecture: x64
target: aarch64-pc-windows-msvc
build: pnpm build:release --target aarch64-pc-windows-msvc --features native-tls-vendored --cargo-flags="--no-default-features"
build: pnpm build --target aarch64-pc-windows-msvc --features native-tls-vendored --cargo-flags="--no-default-features"
- host: ubuntu-20.04
target: x86_64-unknown-linux-gnu
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian
build: |
cd packages/cli
pnpm build:release --target x86_64-unknown-linux-gnu
pnpm build --target x86_64-unknown-linux-gnu
strip *.node
- host: ubuntu-20.04
target: x86_64-unknown-linux-musl
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
build: |
cd packages/cli
pnpm build:release
pnpm build
strip *.node
- host: macos-latest
target: aarch64-apple-darwin
build: |
pnpm build:release --features native-tls-vendored --target=aarch64-apple-darwin
pnpm build --features native-tls-vendored --target=aarch64-apple-darwin
strip -x *.node
- host: ubuntu-20.04
target: aarch64-unknown-linux-gnu
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-aarch64
build: |
cd packages/cli
pnpm build:release --target aarch64-unknown-linux-gnu
pnpm build --target aarch64-unknown-linux-gnu
aarch64-unknown-linux-gnu-strip *.node
- host: ubuntu-20.04
architecture: x64
Expand All @@ -77,7 +77,7 @@ jobs:
sudo apt-get update
sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf -y
build: |
pnpm build:release --target=armv7-unknown-linux-gnueabihf
pnpm build --target=armv7-unknown-linux-gnueabihf
arm-linux-gnueabihf-strip *.node
- host: ubuntu-20.04
architecture: x64
Expand All @@ -86,7 +86,7 @@ jobs:
build: |
cd packages/cli
rustup target add aarch64-unknown-linux-musl
pnpm build:release --target aarch64-unknown-linux-musl
pnpm build --target aarch64-unknown-linux-musl
/aarch64-linux-musl-cross/bin/aarch64-linux-musl-strip *.node
name: stable - ${{ matrix.settings.target }} - node@20
runs-on: ${{ matrix.settings.host }}
Expand Down Expand Up @@ -175,7 +175,7 @@ jobs:
# freebsd-version
# cd ./packages/cli/
# pnpm i --frozen-lockfile --ignore-scripts
# pnpm build:release
# pnpm build
# strip -x *.node
# rm -rf node_modules
# rm -rf ../../target
Expand Down
10 changes: 7 additions & 3 deletions crates/tauri-cli/src/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ pub fn run(options: Options) -> Result<()> {
});

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

cargo::install_one(cargo::CargoInstallOptions {
name: &crate_name,
Expand All @@ -88,6 +85,13 @@ pub fn run(options: Options) -> Result<()> {
.map(PackageManager::from_project)
.and_then(|managers| managers.into_iter().next())
{
let npm_version_req = version
.map(ToString::to_string)
.or(metadata.version_req.as_ref().map(|v| match manager {
PackageManager::Npm => format!(">={v}"),
_ => format!("~{v}"),
}));

let npm_spec = match (npm_version_req, options.tag, options.rev, options.branch) {
(Some(version), _, _, _) => {
format!("{npm_name}@{version}")
Expand Down
2 changes: 1 addition & 1 deletion examples/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
"unocss": "^0.61.0",
"@sveltejs/vite-plugin-svelte": "^3.1.1",
"svelte": "^4.2.19",
"vite": "^5.4.1"
"vite": "^5.4.6"
}
}
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
"format": "prettier --write .",
"format:check": "prettier --check .",
"eslint:check": "pnpm run -r eslint:check",
"ts:check": "pnpm run -r ts:check"
"ts:check": "pnpm run -r ts:check",
"build": "pnpm run -r build",
"build:api": "pnpm run --filter \"@tauri-apps/api\" build",
"build:cli": "pnpm run --filter \"@tauri-apps/cli\" build",
"build:cli:debug": "pnpm run --filter \"@tauri-apps/cli\" build:debug",
"test": "pnpm run -r build"
},
"devDependencies": {
"prettier": "^3.3.3"
Expand Down
15 changes: 15 additions & 0 deletions packages/cli/append-headers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

const HEADERS = `// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT`

const fs = require('fs')

for (const file of ['index.js', 'index.d.ts']) {
const content = fs.readFileSync(file, 'utf8')
const newContent = `${HEADERS}\n\n${content}`
fs.writeFileSync(file, newContent, 'utf8')
}
6 changes: 4 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@
},
"scripts": {
"artifacts": "napi artifacts",
"build:release": "cross-env TARGET=node napi build --platform --profile release-size-optimized",
"build": "cross-env TARGET=node napi build --platform",
"build": "cross-env TARGET=node napi build --platform --profile release-size-optimized",
"postbuild": "node append-headers.js",
"build:debug": "cross-env TARGET=node napi build --platform",
"postbuild:debug": "node append-headers.js",
"prepublishOnly": "napi prepublish -t npm --gh-release-id $RELEASE_ID",
"prepack": "cp ../../crates/tauri-schema-generator/schemas/config.schema.json .",
"version": "napi version",
Expand Down
Loading