> ## Documentation Index
> Fetch the complete documentation index at: https://bun.ll1025.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# 对 macOS 单文件 JavaScript 可执行文件进行代码签名

> 修复运行 JavaScript 可执行文件时出现的"无法打开，因为来自未识别开发者"的 Gatekeeper 警告。

使用 `--compile` 标志编译你的可执行文件。

```sh theme={null}
bun build --compile ./path/to/entry.ts --outfile myapp
```

***

列出可用的签名身份。你将在后续步骤中将其中一个传递给 `codesign`。此命令需要 macOS。

```sh terminal icon="terminal" theme={null}
security find-identity -v -p codesigning
```

```txt theme={null}
1. XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX "Developer ID Application: Your Name (ZZZZZZZZZZ)"
   1 valid identities found
```

***

可选但推荐：创建一个 `entitlements.plist` 文件，为 JavaScript 引擎正常运转提供必要的权限。

```xml entitlements.plist icon="file-code" theme={null}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.security.cs.allow-jit</key>
    <true/>
    <key>com.apple.security.cs.allow-unsigned-executable-memory</key>
    <true/>
    <key>com.apple.security.cs.disable-executable-page-protection</key>
    <true/>
    <key>com.apple.security.cs.allow-dyld-environment-variables</key>
    <true/>
    <key>com.apple.security.cs.disable-library-validation</key>
    <true/>
</dict>
</plist>
```

***

使用 `codesign` 命令签名你的可执行文件并验证其是否有效。

```bash terminal icon="terminal" theme={null}
codesign --entitlements entitlements.plist -vvvv --deep --sign "XXXXXXXXXX" ./myapp --force
codesign -vvv --verify ./myapp
```

***

有关 macOS 代码签名的更多信息，请参阅 [Apple 的代码签名文档](https://developer.apple.com/documentation/security/code_signing_services)。有关使用 Bun 创建单文件可执行文件的详细信息，请参见 [独立可执行文件](/bundler/executables)。本指南需要 Bun v1.2.4 或更新版本。
