first upload

This commit is contained in:
2026-02-24 12:43:16 +08:00
commit c05aaa5e08
88904 changed files with 3936503 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,22 @@
[package]
edition = "2021"
name = "tauri-cli-node"
version = "0.0.0"
[lib]
crate-type = ["cdylib"]
[dependencies]
# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
napi = { version = "2.16", default-features = false, features = ["napi4"] }
napi-derive = "2.16"
tauri-cli = { path = "../../crates/tauri-cli", default-features = false }
log = "0.4.21"
[build-dependencies]
napi-build = "2.1"
[features]
default = ["tauri-cli/default"]
native-tls = ["tauri-cli/native-tls"]
native-tls-vendored = ["tauri-cli/native-tls-vendored"]

View File

@@ -0,0 +1,177 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS

View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2017 - Present Tauri Apps Contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,52 @@
# @tauri-apps/cli
<img align="right" src="https://github.com/tauri-apps/tauri/raw/dev/.github/icon.png" height="128" width="128">
[![status](https://img.shields.io/badge/status-stable-blue.svg)](https://github.com/tauri-apps/tauri/tree/dev)
[![License](https://img.shields.io/badge/License-MIT%20or%20Apache%202-green.svg)](https://opencollective.com/tauri)
[![test cli](https://img.shields.io/github/actions/workflow/status/tauri-apps/tauri/test-cli-js.yml?label=test%20cli&logo=github)](https://github.com/tauri-apps/tauri/actions/workflows/test-cli-js.yml)
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Ftauri-apps%2Ftauri.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Ftauri-apps%2Ftauri?ref=badge_shield)
[![Chat Server](https://img.shields.io/badge/chat-discord-7289da.svg)](https://discord.gg/SpmNs4S)
[![website](https://img.shields.io/badge/website-tauri.app-purple.svg)](https://tauri.app)
[![https://good-labs.github.io/greater-good-affirmation/assets/images/badge.svg](https://good-labs.github.io/greater-good-affirmation/assets/images/badge.svg)](https://good-labs.github.io/greater-good-affirmation)
[![support](https://img.shields.io/badge/sponsor-Open%20Collective-blue.svg)](https://opencollective.com/tauri)
| Component | Version |
| --------------- | ----------------------------------------------------- |
| @tauri-apps/cli | ![](https://img.shields.io/npm/v/@tauri-apps/cli.svg) |
## About Tauri
Tauri is a polyglot and generic system that is very composable and allows engineers to make a wide variety of applications. It is used for building applications for Desktop Computers using a combination of Rust tools and HTML rendered in a Webview. Apps built with Tauri can ship with any number of pieces of an optional JS API / Rust API so that webviews can control the system via message passing. In fact, developers can extend the default API with their own functionality and bridge the Webview and Rust-based backend easily.
Tauri apps can have custom menus and have tray-type interfaces. They can be updated, and are managed by the user's operating system as expected. They are very small, because they use the system's webview. They do not ship a runtime, since the final binary is compiled from rust. This makes the reversing of Tauri apps not a trivial task.
## This module
Written in Typescript and packaged such that it can be used with `npm`, `pnpm`, `yarn`, and `bun`, this library provides a node.js runner for common tasks when using Tauri, like `pnpm tauri dev`. For the most part it is a wrapper around [tauri-cli](https://github.com/tauri-apps/tauri/blob/dev/crates/tauri-cli).
To learn more about the details of how all of these pieces fit together, please consult this [ARCHITECTURE.md](https://github.com/tauri-apps/tauri/blob/dev/ARCHITECTURE.md) document.
## Installation
The preferred method is to install this module locally as a development dependency:
```
$ pnpm add -D @tauri-apps/cli
$ yarn add -D @tauri-apps/cli
$ npm add -D @tauri-apps/cli
```
## Semver
**tauri** is following [Semantic Versioning 2.0](https://semver.org/).
## Licenses
Code: (c) 2019 - 2021 - The Tauri Programme within The Commons Conservancy.
MIT or MIT/Apache 2.0 where applicable.
Logo: CC-BY-NC-ND
- Original Tauri Logo Designs by [Daniel Thompson-Yvetot](https://github.com/nothingismagick) and [Guillaume Chau](https://github.com/akryum)

View File

@@ -0,0 +1,6 @@
<!DOCTYPE html>
<html>
<body>
<div></div>
</body>
</html>

View File

@@ -0,0 +1,5 @@
{
"scripts": {
"build": ""
}
}

View File

@@ -0,0 +1,89 @@
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
import { resolve } from 'node:path'
import { spawnSync } from 'node:child_process'
import {
existsSync,
readFileSync,
writeFileSync,
rmSync,
renameSync
} from 'node:fs'
import { beforeAll, describe, it } from 'vitest'
// Build CLI before tests, for local usage only.
// CI builds the CLI on different platforms and architectures
if (!process.env.CI) {
beforeAll(() => {
const cliDir = resolve(__dirname, '..')
exec('pnpm', ['build:debug'], { cwd: cliDir })
})
}
describe('[CLI] @tauri-apps/cli template', () => {
it('init a project and builds it', { timeout: 15 * 60 * 1000 }, async () => {
const cwd = process.cwd()
const fixturePath = resolve(__dirname, './fixtures/empty')
const tauriFixturePath = resolve(fixturePath, 'src-tauri')
const outPath = resolve(tauriFixturePath, 'target')
const cacheOutPath = resolve(fixturePath, 'target')
process.chdir(fixturePath)
const outExists = existsSync(outPath)
if (outExists) {
if (existsSync(cacheOutPath)) {
rmSync(cacheOutPath, { recursive: true, force: true })
}
renameSync(outPath, cacheOutPath)
}
const cli = await import('../main.js')
await cli.run([
'init',
'-vvv',
'--directory',
process.cwd(),
'--force',
'--tauri-path',
resolve(__dirname, '../../..'),
'--before-build-command',
'',
'--before-dev-command',
'',
'--ci'
])
if (outExists) {
renameSync(cacheOutPath, outPath)
}
process.chdir(tauriFixturePath)
const manifestPath = resolve(tauriFixturePath, 'Cargo.toml')
const manifestFile = readFileSync(manifestPath).toString()
writeFileSync(manifestPath, `workspace = { }\n${manifestFile}`)
const configPath = resolve(tauriFixturePath, 'tauri.conf.json')
const config = readFileSync(configPath).toString()
writeFileSync(configPath, config.replace('com.tauri.dev', 'com.tauri.test'))
await cli.run(['build', '-vvv'])
process.chdir(cwd)
})
})
function exec(
bin: string,
args?: string[],
opts?: {
cwd?: string
}
) {
process.platform === 'win32'
? spawnSync('cmd', ['/c', bin, ...(args ?? [])], { cwd: opts?.cwd })
: spawnSync(bin, args, { cwd: opts?.cwd })
}

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

@@ -0,0 +1,7 @@
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
fn main() {
::napi_build::setup();
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,11 @@
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
/* tslint:disable */
/* eslint-disable */
/* auto-generated by NAPI-RS */
export declare function run(args: Array<string>, binName: string | undefined | null, callback: (...args: any[]) => any): void
export declare function logError(error: string): void

View File

@@ -0,0 +1,320 @@
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
/* tslint:disable */
/* eslint-disable */
/* prettier-ignore */
/* auto-generated by NAPI-RS */
const { existsSync, readFileSync } = require('fs')
const { join } = require('path')
const { platform, arch } = process
let nativeBinding = null
let localFileExisted = false
let loadError = null
function isMusl() {
// For Node 10
if (!process.report || typeof process.report.getReport !== 'function') {
try {
const lddPath = require('child_process').execSync('which ldd').toString().trim()
return readFileSync(lddPath, 'utf8').includes('musl')
} catch (e) {
return true
}
} else {
const { glibcVersionRuntime } = process.report.getReport().header
return !glibcVersionRuntime
}
}
switch (platform) {
case 'android':
switch (arch) {
case 'arm64':
localFileExisted = existsSync(join(__dirname, 'cli.android-arm64.node'))
try {
if (localFileExisted) {
nativeBinding = require('./cli.android-arm64.node')
} else {
nativeBinding = require('@tauri-apps/cli-android-arm64')
}
} catch (e) {
loadError = e
}
break
case 'arm':
localFileExisted = existsSync(join(__dirname, 'cli.android-arm-eabi.node'))
try {
if (localFileExisted) {
nativeBinding = require('./cli.android-arm-eabi.node')
} else {
nativeBinding = require('@tauri-apps/cli-android-arm-eabi')
}
} catch (e) {
loadError = e
}
break
default:
throw new Error(`Unsupported architecture on Android ${arch}`)
}
break
case 'win32':
switch (arch) {
case 'x64':
localFileExisted = existsSync(
join(__dirname, 'cli.win32-x64-msvc.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./cli.win32-x64-msvc.node')
} else {
nativeBinding = require('@tauri-apps/cli-win32-x64-msvc')
}
} catch (e) {
loadError = e
}
break
case 'ia32':
localFileExisted = existsSync(
join(__dirname, 'cli.win32-ia32-msvc.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./cli.win32-ia32-msvc.node')
} else {
nativeBinding = require('@tauri-apps/cli-win32-ia32-msvc')
}
} catch (e) {
loadError = e
}
break
case 'arm64':
localFileExisted = existsSync(
join(__dirname, 'cli.win32-arm64-msvc.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./cli.win32-arm64-msvc.node')
} else {
nativeBinding = require('@tauri-apps/cli-win32-arm64-msvc')
}
} catch (e) {
loadError = e
}
break
default:
throw new Error(`Unsupported architecture on Windows: ${arch}`)
}
break
case 'darwin':
localFileExisted = existsSync(join(__dirname, 'cli.darwin-universal.node'))
try {
if (localFileExisted) {
nativeBinding = require('./cli.darwin-universal.node')
} else {
nativeBinding = require('@tauri-apps/cli-darwin-universal')
}
break
} catch {}
switch (arch) {
case 'x64':
localFileExisted = existsSync(join(__dirname, 'cli.darwin-x64.node'))
try {
if (localFileExisted) {
nativeBinding = require('./cli.darwin-x64.node')
} else {
nativeBinding = require('@tauri-apps/cli-darwin-x64')
}
} catch (e) {
loadError = e
}
break
case 'arm64':
localFileExisted = existsSync(
join(__dirname, 'cli.darwin-arm64.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./cli.darwin-arm64.node')
} else {
nativeBinding = require('@tauri-apps/cli-darwin-arm64')
}
} catch (e) {
loadError = e
}
break
default:
throw new Error(`Unsupported architecture on macOS: ${arch}`)
}
break
case 'freebsd':
if (arch !== 'x64') {
throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
}
localFileExisted = existsSync(join(__dirname, 'cli.freebsd-x64.node'))
try {
if (localFileExisted) {
nativeBinding = require('./cli.freebsd-x64.node')
} else {
nativeBinding = require('@tauri-apps/cli-freebsd-x64')
}
} catch (e) {
loadError = e
}
break
case 'linux':
switch (arch) {
case 'x64':
if (isMusl()) {
localFileExisted = existsSync(
join(__dirname, 'cli.linux-x64-musl.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./cli.linux-x64-musl.node')
} else {
nativeBinding = require('@tauri-apps/cli-linux-x64-musl')
}
} catch (e) {
loadError = e
}
} else {
localFileExisted = existsSync(
join(__dirname, 'cli.linux-x64-gnu.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./cli.linux-x64-gnu.node')
} else {
nativeBinding = require('@tauri-apps/cli-linux-x64-gnu')
}
} catch (e) {
loadError = e
}
}
break
case 'arm64':
if (isMusl()) {
localFileExisted = existsSync(
join(__dirname, 'cli.linux-arm64-musl.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./cli.linux-arm64-musl.node')
} else {
nativeBinding = require('@tauri-apps/cli-linux-arm64-musl')
}
} catch (e) {
loadError = e
}
} else {
localFileExisted = existsSync(
join(__dirname, 'cli.linux-arm64-gnu.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./cli.linux-arm64-gnu.node')
} else {
nativeBinding = require('@tauri-apps/cli-linux-arm64-gnu')
}
} catch (e) {
loadError = e
}
}
break
case 'arm':
if (isMusl()) {
localFileExisted = existsSync(
join(__dirname, 'cli.linux-arm-musleabihf.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./cli.linux-arm-musleabihf.node')
} else {
nativeBinding = require('@tauri-apps/cli-linux-arm-musleabihf')
}
} catch (e) {
loadError = e
}
} else {
localFileExisted = existsSync(
join(__dirname, 'cli.linux-arm-gnueabihf.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./cli.linux-arm-gnueabihf.node')
} else {
nativeBinding = require('@tauri-apps/cli-linux-arm-gnueabihf')
}
} catch (e) {
loadError = e
}
}
break
case 'riscv64':
if (isMusl()) {
localFileExisted = existsSync(
join(__dirname, 'cli.linux-riscv64-musl.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./cli.linux-riscv64-musl.node')
} else {
nativeBinding = require('@tauri-apps/cli-linux-riscv64-musl')
}
} catch (e) {
loadError = e
}
} else {
localFileExisted = existsSync(
join(__dirname, 'cli.linux-riscv64-gnu.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./cli.linux-riscv64-gnu.node')
} else {
nativeBinding = require('@tauri-apps/cli-linux-riscv64-gnu')
}
} catch (e) {
loadError = e
}
}
break
case 's390x':
localFileExisted = existsSync(
join(__dirname, 'cli.linux-s390x-gnu.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./cli.linux-s390x-gnu.node')
} else {
nativeBinding = require('@tauri-apps/cli-linux-s390x-gnu')
}
} catch (e) {
loadError = e
}
break
default:
throw new Error(`Unsupported architecture on Linux: ${arch}`)
}
break
default:
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
}
if (!nativeBinding) {
if (loadError) {
throw loadError
}
throw new Error(`Failed to load native binding`)
}
const { run, logError } = nativeBinding
module.exports.run = run
module.exports.logError = logError

View File

@@ -0,0 +1,11 @@
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
/* tslint:disable */
/* eslint-disable */
export function run(
args: Array<string>,
binName?: string | undefined | null
): Promise<void>

View File

@@ -0,0 +1,19 @@
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
const { run, logError } = require('./index')
module.exports.run = (args, binName) => {
return new Promise((resolve, reject) => {
run(args, binName, (error, res) => {
if (error) {
reject(error)
} else {
resolve(res)
}
})
})
}
module.exports.logError = logError

View File

@@ -0,0 +1,78 @@
{
"name": "@tauri-apps/cli",
"version": "2.6.1",
"description": "Command line interface for building Tauri apps",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/tauri"
},
"repository": {
"type": "git",
"url": "git+https://github.com/tauri-apps/tauri.git"
},
"contributors": [
"Tauri Programme within The Commons Conservancy"
],
"license": "Apache-2.0 OR MIT",
"bugs": {
"url": "https://github.com/tauri-apps/tauri/issues"
},
"homepage": "https://github.com/tauri-apps/tauri#readme",
"publishConfig": {
"access": "public"
},
"main": "main.js",
"types": "main.d.ts",
"napi": {
"name": "cli",
"triples": {
"additional": [
"aarch64-apple-darwin",
"aarch64-unknown-linux-gnu",
"aarch64-unknown-linux-musl",
"armv7-unknown-linux-gnueabihf",
"x86_64-unknown-linux-musl",
"riscv64gc-unknown-linux-gnu",
"i686-pc-windows-msvc",
"aarch64-pc-windows-msvc"
]
}
},
"devDependencies": {
"@napi-rs/cli": "2.18.4",
"@types/node": "^22.15.32",
"cross-env": "7.0.3",
"vitest": "^3.2.4"
},
"engines": {
"node": ">= 10"
},
"bin": {
"tauri": "./tauri.js"
},
"scripts": {
"artifacts": "napi artifacts",
"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",
"test": "vitest run",
"tauri": "node ./tauri.js"
},
"optionalDependencies": {
"@tauri-apps/cli-win32-x64-msvc": "2.6.1",
"@tauri-apps/cli-darwin-x64": "2.6.1",
"@tauri-apps/cli-linux-x64-gnu": "2.6.1",
"@tauri-apps/cli-darwin-arm64": "2.6.1",
"@tauri-apps/cli-linux-arm64-gnu": "2.6.1",
"@tauri-apps/cli-linux-arm64-musl": "2.6.1",
"@tauri-apps/cli-linux-arm-gnueabihf": "2.6.1",
"@tauri-apps/cli-linux-x64-musl": "2.6.1",
"@tauri-apps/cli-linux-riscv64-gnu": "2.6.1",
"@tauri-apps/cli-win32-ia32-msvc": "2.6.1",
"@tauri-apps/cli-win32-arm64-msvc": "2.6.1"
}
}

View File

@@ -0,0 +1,50 @@
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
#![cfg(any(target_os = "macos", target_os = "linux", windows))]
use napi::{
threadsafe_function::{ErrorStrategy, ThreadsafeFunction, ThreadsafeFunctionCallMode},
Error, JsFunction, Result, Status,
};
#[napi_derive::napi]
pub fn run(args: Vec<String>, bin_name: Option<String>, callback: JsFunction) -> Result<()> {
let function: ThreadsafeFunction<bool, ErrorStrategy::CalleeHandled> = callback
.create_threadsafe_function(0, |ctx| ctx.env.get_boolean(ctx.value).map(|v| vec![v]))?;
// we need to run in a separate thread so Node.js consumers
// can do work while `tauri dev` is running.
std::thread::spawn(move || {
let res = match std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
tauri_cli::try_run(args, bin_name).inspect_err(|e| eprintln!("{e:#}"))
})) {
Ok(t) => t,
Err(_) => {
return function.call(
Err(Error::new(
Status::GenericFailure,
"Tauri CLI unexpected panic",
)),
ThreadsafeFunctionCallMode::Blocking,
);
}
};
match res {
Ok(_) => function.call(Ok(true), ThreadsafeFunctionCallMode::Blocking),
Err(e) => function.call(
Err(Error::new(Status::GenericFailure, format!("{:#}", e))),
ThreadsafeFunctionCallMode::Blocking,
),
}
});
Ok(())
}
#[napi_derive::napi]
pub fn log_error(error: String) {
log::error!("{}", error);
}

View File

@@ -0,0 +1,57 @@
#!/usr/bin/env node
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
const cli = require('./main')
const path = require('path')
const [bin, script, ...args] = process.argv
const binStem = path.parse(bin).name.toLowerCase()
// We want to make a helpful binary name for the underlying CLI helper, if we
// can successfully detect what command likely started the execution.
let binName
// deno run -A npm:@tauri-apps/cli or deno task tauri
if (globalThis.navigator?.userAgent?.includes('Deno')) {
binName = bin
}
// Even if started by a package manager, the binary will be NodeJS.
// Some distribution still use "nodejs" as the binary name.
else if (binStem.match(/(nodejs|node|bun)\-?([0-9]*)*$/g)) {
const managerStem = process.env.npm_execpath
? path.parse(process.env.npm_execpath).name.toLowerCase()
: null
if (managerStem) {
let manager
switch (managerStem) {
// Only supported package manager that has a different filename is npm.
case 'npm-cli':
manager = 'npm'
break
// Yarn, pnpm, and bun have the same stem name as their bin.
// We assume all unknown package managers do as well.
default:
manager = managerStem
break
}
binName = `${manager} run ${process.env.npm_lifecycle_event}`
} else {
// Assume running NodeJS if we didn't detect a manager from the env.
// We normalize the path to prevent the script's absolute path being used.
const scriptNormal = path.normalize(path.relative(process.cwd(), script))
binName = `${binStem} ${scriptNormal}`
}
} else {
// We don't know what started it, assume it's already stripped.
args.unshift(bin)
}
cli.run(args, binName).catch((err) => {
cli.logError(err.message)
process.exit(1)
})