soundscript-lang/soundscript
GitHub: soundscript-lang/soundscript
SoundScript 是一个 TypeScript 健全性检查器和语言工具层,通过引入更严格的 `.sts` 文件类型来消除 TS 中不安全的类型路径,支持渐进式采纳。
Stars: 1 | Forks: 0
# soundscript
` 标签
- 创建 GitHub release
- 附上平台 CLI 存档和校验和
该工作流设置为从 GitHub Actions 进行 npm 可信发布。必须将 npm 配置为信任此仓库中 `publish-release.yml` 工作流文件,以用于发布集中的每个包:
- `@soundscript/cli-darwin-arm64`
- `@soundscript/cli-darwin-x64`
- `@soundscript/cli-linux-arm64`
- `@soundscript/cli-linux-x64`
- `@soundscript/cli-win32-x64`
- `@soundscript/soundscript`
- `soundscript`
如果在 `npm publish` 期间 npm 返回 `404`,通常的原因是尚未添加该包的可信发布者设置。该工作流还需要 GitHub 的 `id-token: write` 权限,这已在工作流文件中配置。
在使用对所有七个包具有写入权限的账户登录 npm 后,您可以从 shell 批量配置包集:
```
for package in \
@soundscript/cli-darwin-arm64 \
@soundscript/cli-darwin-x64 \
@soundscript/cli-linux-arm64 \
@soundscript/cli-linux-x64 \
@soundscript/cli-win32-x64 \
@soundscript/soundscript \
soundscript
do
npm trust github "$package" \
--repo soundscript-lang/soundscript \
--file publish-release.yml \
--yes
sleep 2
done
```
如果您需要将 CLI 存档重新附加到现有 release,请使用单独的 `Backfill CLI Assets` 工作流。
## `.sts` 的含义
`.sts` 文件在 soundscript 中进行检查。
`.ts` 文件保持原样。
当 `.sts` 代码导入普通的 TypeScript、JavaScript 或仅声明的包时,该导入需要 `// #[interop]`:
```
// #[interop]
import { readConfig } from './legacy.ts';
```
从另一个方向来看,`.ts` 可以在没有任何注解的情况下导入 `.sts`。它会看到 `.sts` 模块的一个投影的公共 TypeScript 接口。
这就是采用模型。现有的 TypeScript 保留在原位。新的或关键的代码可以移入 `.sts`。
## 剩余的粗糙边缘
soundscript 移除了大量 TypeScript 不健全的路径,但它仍然存在于 JS/TS 运行时语义中。主要剩余的粗糙边缘是:
- `null` 与 `undefined`,尤其是在 JSON、regex 和可信的 interop 边界处
- 任意的外部抛出和拒绝;启用扩展的源码将 `catch (error)` 和内置的 Promise 拒绝处理程序规范化为普通的 `Error`,但其他边界仍然需要显式规范化,例如 `sts:failures.normalizeThrown(...)`
- 稳定的 v1 仍然默认使用普通的 JS `number` 行为,包括 `NaN`、`Infinity` 和 `-0`;该仓库还包含在 `sts:numerics` 下的实验性机器数值工作,但这超出了稳定的 v1 合约
- 稳定的 v1 在处理相同形状的 interface 和 object 值时仍然严重依赖于结构化类型;类名义性加上 `#[newtype]` 和 `#[value]` 存在于仓库中,但更广泛的名义和值语义故事仍超出了稳定的 v1 合约
- 目前没有积极努力从语言中移除原始的 `null`;它仍然是诚实平台模型的一部分
这些边界的面向发布的合约在
[docs/reference/v1-user-contract.md](docs/reference/v1-user-contract.md) 中。
## 示例
```
// src/math.sts
export function area(radius: number): number {
return Math.PI * radius * radius;
}
const raw = JSON.parse('{"radius": 3}');
if (
typeof raw === 'object' &&
raw !== null &&
'radius' in raw &&
typeof raw.radius === 'number'
) {
console.log(area(raw.radius));
}
```
这里没有新语法。区别在于检查器。
## 命令
主要命令包括:
- `soundscript init`
- `soundscript check`
- `soundscript build`
- `soundscript expand`
- `soundscript deno`
- `soundscript explain`
- `soundscript lsp`
该仓库还附带了 `soundscript compile`。`compile` 和更广泛的编译器 / Wasm 接口仍处于实验阶段;检查器仍然是主要入口点。
## 编辑器支持
语言服务器通过 stdio 运行:
```
soundscript lsp
```
在单独的 editors 仓库中还有一个 VS Code 客户端:
```
git clone https://github.com/soundscript-lang/editors.git ../editors
cd ../editors/packages/vscode
npm install
npm run compile
```
然后:
1. 在 VS Code 中打开 `editors` 仓库根目录
2. 运行 `Run soundscript extension` 启动配置
3. 在生成的 Extension Development Host 中,使用 `File -> Open Folder...` 打开您要测试的工作区,例如 `soundscript-example`
4. 打开一个 `.sts` 文件以确认 `soundscript` 语言模式和 TextMate 语法处于活动状态
注意:
- VS Code 扩展和 `@soundscript/tsserver-plugin` 位于
[soundscript-lang/editors](https://github.com/soundscript-lang/editors)
- 在本地开发扩展时,请使用 `../editors/packages/vscode`
- 该扩展优先使用工作区安装的 `soundscript` 二进制文件,除非您覆盖 `soundscript.server.command`,否则它会回退到 PATH
- `soundscript.server.*` 设置仅配置已加载的扩展如何启动语言服务器;这些设置不会让 VS Code 发现该扩展
- 当前基于自定义语法的语法高亮仅适用于 `.sts`;`.ts` 和 `.tsx` 使用内置的 TypeScript 语法,并且仅从 soundscript 获取 LSP 功能
当前 LSP 支持包括诊断、悬停提示、签名帮助、定义、引用、重命名、补全、文档符号、格式化、语义 token 以及代码操作/快速修复。
## 仓库布局
该仓库还包含:
- 检查器和 CLI
- `.ts` / `.sts` 互操作
- LSP
- 宏工作
- 编译器 / Wasm 工作
您不需要宏或 Wasm 即可将 soundscript 用作检查器。
## 开发
维护者工具链是 Deno:
```
deno task build
deno task check
deno task fmt
deno task lint
deno task test
deno task verify
```
## 文档
从这里开始:
- [docs/architecture/spec.md](docs/architecture/spec.md)
- [docs/project/roadmap.md](docs/project/roadmap.md)
- [docs/README.md](docs/README.md)
- [docs/reference/v1-user-contract.md](docs/reference/v1-user-contract.md)
标签:CLI 工具, LSP, MITM代理, npm包, TypeScript, VS Code 扩展, Wasm, WebAssembly, 云安全监控, 代码分析, 代码重构, 健全性检查, 凭证管理, 前后端协同, 后端开发, 增量迁移, 安全插件, 宏, 编程语言, 编译器, 语言工具链, 静态分析, 静态类型检查