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
This commit is contained in:
Amr Bashir 2024-09-19 23:11:40 +03:00 committed by GitHub
parent a247170e1f
commit 62b52f60a2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 101 additions and 57 deletions

7
.changes/cli-add-npm.md Normal file
View File

@ -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.

View File

@ -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
@ -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
@ -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 }}
@ -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

View File

@ -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,
@ -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}")

View File

@ -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"
}
}

View File

@ -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"

View File

@ -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')
}

View File

@ -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",

View File

@ -35,7 +35,7 @@ importers:
version: 1.1.14
'@sveltejs/vite-plugin-svelte':
specifier: ^3.1.1
version: 3.1.1(svelte@4.2.19)(vite@5.4.2(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6))
version: 3.1.1(svelte@4.2.19)(vite@5.4.6(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6))
'@unocss/extractor-svelte':
specifier: ^0.61.0
version: 0.61.9
@ -44,10 +44,10 @@ importers:
version: 4.2.19
unocss:
specifier: ^0.61.0
version: 0.61.9(postcss@8.4.41)(rollup@4.21.0)(vite@5.4.2(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6))
version: 0.61.9(postcss@8.4.47)(rollup@4.21.0)(vite@5.4.6(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6))
vite:
specifier: ^5.4.1
version: 5.4.2(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6)
specifier: ^5.4.6
version: 5.4.6(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6)
examples/file-associations: {}
@ -1831,6 +1831,9 @@ packages:
picocolors@1.0.1:
resolution: {integrity: sha512-anP1Z8qwhkbmu7MFP5iTt+wQKXgwzf7zTyGlcdzabySa9vd0Xt392U0rVmz9poOaBj0uHJKyyo9/upk0HrEQew==}
picocolors@1.1.0:
resolution: {integrity: sha512-TQ92mBOW0l3LeMeyLV6mzy/kWr8lkd/hp3mTg7wYK7zJhuBStmGMBG0BdeDZS/dZx1IukaX6Bk11zcln25o1Aw==}
picomatch@2.3.1:
resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==}
engines: {node: '>=8.6'}
@ -1838,8 +1841,8 @@ packages:
pkg-types@1.1.3:
resolution: {integrity: sha512-+JrgthZG6m3ckicaOB74TwQ+tBWsFl3qVQg7mN8ulwSOElJ7gBhKzj2VkCPnZ4NlF6kEquYU+RIYNVAvzd54UA==}
postcss@8.4.41:
resolution: {integrity: sha512-TesUflQ0WKZqAvg52PWL6kHgLKP6xB6heTOdoYM0Wt2UHyxNa4K25EZZMgKns3BH1RLVbZCREPpLY0rhnNoHVQ==}
postcss@8.4.47:
resolution: {integrity: sha512-56rxCq7G/XfB4EkXq9Egn5GCqugWvDFjafDOThIdMBsI15iqPqR5r15TfSr1YPYeEI19YeaXMCbY6u88Y76GLQ==}
engines: {node: ^10 || ^12 || >=14}
prelude-ls@1.2.1:
@ -1965,6 +1968,10 @@ packages:
resolution: {integrity: sha512-itJW8lvSA0TXEphiRoawsCksnlf8SyvmFzIhltqAHluXd88pkCd+cXJVHTDwdCr0IzwptSm035IHQktUu1QUMg==}
engines: {node: '>=0.10.0'}
source-map-js@1.2.1:
resolution: {integrity: sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==}
engines: {node: '>=0.10.0'}
source-map-support@0.5.21:
resolution: {integrity: sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==}
@ -2135,8 +2142,8 @@ packages:
engines: {node: ^18.0.0 || >=20.0.0}
hasBin: true
vite@5.4.2:
resolution: {integrity: sha512-dDrQTRHp5C1fTFzcSaMxjk6vdpKvT+2/mIdE07Gw2ykehT49O0z/VHS3zZ8iV/Gh8BJJKHWOe5RjaNrW5xf/GA==}
vite@5.4.6:
resolution: {integrity: sha512-IeL5f8OO5nylsgzd9tq4qD2QqI0k2CQLGrWD0rCN0EQJZpBK5vJAx0I+GDkMOXxQX/OfFHMuLIx6ddAxGX/k+Q==}
engines: {node: ^18.0.0 || >=20.0.0}
hasBin: true
peerDependencies:
@ -2891,26 +2898,26 @@ snapshots:
'@rollup/rollup-win32-x64-msvc@4.21.0':
optional: true
'@sveltejs/vite-plugin-svelte-inspector@2.1.0(@sveltejs/vite-plugin-svelte@3.1.1(svelte@4.2.19)(vite@5.4.2(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6)))(svelte@4.2.19)(vite@5.4.2(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6))':
'@sveltejs/vite-plugin-svelte-inspector@2.1.0(@sveltejs/vite-plugin-svelte@3.1.1(svelte@4.2.19)(vite@5.4.6(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6)))(svelte@4.2.19)(vite@5.4.6(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6))':
dependencies:
'@sveltejs/vite-plugin-svelte': 3.1.1(svelte@4.2.19)(vite@5.4.2(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6))
'@sveltejs/vite-plugin-svelte': 3.1.1(svelte@4.2.19)(vite@5.4.6(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6))
debug: 4.3.6
svelte: 4.2.19
vite: 5.4.2(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6)
vite: 5.4.6(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6)
transitivePeerDependencies:
- supports-color
'@sveltejs/vite-plugin-svelte@3.1.1(svelte@4.2.19)(vite@5.4.2(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6))':
'@sveltejs/vite-plugin-svelte@3.1.1(svelte@4.2.19)(vite@5.4.6(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6))':
dependencies:
'@sveltejs/vite-plugin-svelte-inspector': 2.1.0(@sveltejs/vite-plugin-svelte@3.1.1(svelte@4.2.19)(vite@5.4.2(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6)))(svelte@4.2.19)(vite@5.4.2(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6))
'@sveltejs/vite-plugin-svelte-inspector': 2.1.0(@sveltejs/vite-plugin-svelte@3.1.1(svelte@4.2.19)(vite@5.4.6(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6)))(svelte@4.2.19)(vite@5.4.6(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6))
debug: 4.3.6
deepmerge: 4.3.1
kleur: 4.1.5
magic-string: 0.30.11
svelte: 4.2.19
svelte-hmr: 0.16.0(svelte@4.2.19)
vite: 5.4.2(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6)
vitefu: 0.2.5(vite@5.4.2(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6))
vite: 5.4.6(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6)
vitefu: 0.2.5(vite@5.4.6(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6))
transitivePeerDependencies:
- supports-color
@ -3012,13 +3019,13 @@ snapshots:
'@typescript-eslint/types': 8.2.0
eslint-visitor-keys: 3.4.3
'@unocss/astro@0.61.9(rollup@4.21.0)(vite@5.4.2(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6))':
'@unocss/astro@0.61.9(rollup@4.21.0)(vite@5.4.6(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6))':
dependencies:
'@unocss/core': 0.61.9
'@unocss/reset': 0.61.9
'@unocss/vite': 0.61.9(rollup@4.21.0)(vite@5.4.2(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6))
'@unocss/vite': 0.61.9(rollup@4.21.0)(vite@5.4.6(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6))
optionalDependencies:
vite: 5.4.2(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6)
vite: 5.4.6(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6)
transitivePeerDependencies:
- rollup
- supports-color
@ -3064,7 +3071,7 @@ snapshots:
gzip-size: 6.0.0
sirv: 2.0.4
'@unocss/postcss@0.61.9(postcss@8.4.41)':
'@unocss/postcss@0.61.9(postcss@8.4.47)':
dependencies:
'@unocss/config': 0.61.9
'@unocss/core': 0.61.9
@ -3072,7 +3079,7 @@ snapshots:
css-tree: 2.3.1
fast-glob: 3.3.2
magic-string: 0.30.11
postcss: 8.4.41
postcss: 8.4.47
transitivePeerDependencies:
- supports-color
@ -3157,7 +3164,7 @@ snapshots:
dependencies:
'@unocss/core': 0.61.9
'@unocss/vite@0.61.9(rollup@4.21.0)(vite@5.4.2(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6))':
'@unocss/vite@0.61.9(rollup@4.21.0)(vite@5.4.6(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6))':
dependencies:
'@ampproject/remapping': 2.3.0
'@rollup/pluginutils': 5.1.0(rollup@4.21.0)
@ -3169,7 +3176,7 @@ snapshots:
chokidar: 3.6.0
fast-glob: 3.3.2
magic-string: 0.30.11
vite: 5.4.2(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6)
vite: 5.4.6(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6)
transitivePeerDependencies:
- rollup
- supports-color
@ -3181,13 +3188,13 @@ snapshots:
chai: 5.1.1
tinyrainbow: 1.2.0
'@vitest/mocker@2.1.1(@vitest/spy@2.1.1)(vite@5.4.2(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6))':
'@vitest/mocker@2.1.1(@vitest/spy@2.1.1)(vite@5.4.6(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6))':
dependencies:
'@vitest/spy': 2.1.1
estree-walker: 3.0.3
magic-string: 0.30.11
optionalDependencies:
vite: 5.4.2(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6)
vite: 5.4.6(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6)
'@vitest/pretty-format@2.1.1':
dependencies:
@ -3946,6 +3953,8 @@ snapshots:
picocolors@1.0.1: {}
picocolors@1.1.0: {}
picomatch@2.3.1: {}
pkg-types@1.1.3:
@ -3954,11 +3963,11 @@ snapshots:
mlly: 1.7.1
pathe: 1.1.2
postcss@8.4.41:
postcss@8.4.47:
dependencies:
nanoid: 3.3.7
picocolors: 1.0.1
source-map-js: 1.2.0
picocolors: 1.1.0
source-map-js: 1.2.1
prelude-ls@1.2.1: {}
@ -4082,6 +4091,8 @@ snapshots:
source-map-js@1.2.0: {}
source-map-js@1.2.1: {}
source-map-support@0.5.21:
dependencies:
buffer-from: 1.1.2
@ -4221,13 +4232,13 @@ snapshots:
pathe: 1.1.2
ufo: 1.5.4
unocss@0.61.9(postcss@8.4.41)(rollup@4.21.0)(vite@5.4.2(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6)):
unocss@0.61.9(postcss@8.4.47)(rollup@4.21.0)(vite@5.4.6(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6)):
dependencies:
'@unocss/astro': 0.61.9(rollup@4.21.0)(vite@5.4.2(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6))
'@unocss/astro': 0.61.9(rollup@4.21.0)(vite@5.4.6(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6))
'@unocss/cli': 0.61.9(rollup@4.21.0)
'@unocss/core': 0.61.9
'@unocss/extractor-arbitrary-variants': 0.61.9
'@unocss/postcss': 0.61.9(postcss@8.4.41)
'@unocss/postcss': 0.61.9(postcss@8.4.47)
'@unocss/preset-attributify': 0.61.9
'@unocss/preset-icons': 0.61.9
'@unocss/preset-mini': 0.61.9
@ -4242,9 +4253,9 @@ snapshots:
'@unocss/transformer-compile-class': 0.61.9
'@unocss/transformer-directives': 0.61.9
'@unocss/transformer-variant-group': 0.61.9
'@unocss/vite': 0.61.9(rollup@4.21.0)(vite@5.4.2(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6))
'@unocss/vite': 0.61.9(rollup@4.21.0)(vite@5.4.6(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6))
optionalDependencies:
vite: 5.4.2(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6)
vite: 5.4.6(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6)
transitivePeerDependencies:
- postcss
- rollup
@ -4265,7 +4276,7 @@ snapshots:
cac: 6.7.14
debug: 4.3.6
pathe: 1.1.2
vite: 5.4.2(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6)
vite: 5.4.6(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6)
transitivePeerDependencies:
- '@types/node'
- less
@ -4277,10 +4288,10 @@ snapshots:
- supports-color
- terser
vite@5.4.2(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6):
vite@5.4.6(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6):
dependencies:
esbuild: 0.21.5
postcss: 8.4.41
postcss: 8.4.47
rollup: 4.21.0
optionalDependencies:
'@types/node': 20.16.1
@ -4288,14 +4299,14 @@ snapshots:
sass: 1.77.8
terser: 5.31.6
vitefu@0.2.5(vite@5.4.2(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6)):
vitefu@0.2.5(vite@5.4.6(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6)):
optionalDependencies:
vite: 5.4.2(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6)
vite: 5.4.6(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6)
vitest@2.1.1(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6):
dependencies:
'@vitest/expect': 2.1.1
'@vitest/mocker': 2.1.1(@vitest/spy@2.1.1)(vite@5.4.2(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6))
'@vitest/mocker': 2.1.1(@vitest/spy@2.1.1)(vite@5.4.6(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6))
'@vitest/pretty-format': 2.1.1
'@vitest/runner': 2.1.1
'@vitest/snapshot': 2.1.1
@ -4310,7 +4321,7 @@ snapshots:
tinyexec: 0.3.0
tinypool: 1.0.1
tinyrainbow: 1.2.0
vite: 5.4.2(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6)
vite: 5.4.6(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6)
vite-node: 2.1.1(@types/node@20.16.1)(sass@1.77.8)(terser@5.31.6)
why-is-node-running: 2.3.0
optionalDependencies: