mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-21 05:50:55 +08:00
97 lines
3.1 KiB
Plaintext
97 lines
3.1 KiB
Plaintext
---
|
|
title: "Quickstart"
|
|
---
|
|
|
|
Install scriptc, compile a TypeScript file, and run the resulting executable.
|
|
|
|
## Prerequisites
|
|
|
|
- macOS 15+ on arm64 or x64, Linux on arm64 or x64, or Windows on x64. See [Platform Support](/docs/platforms) for target details.
|
|
- Node.js 24 or later and npm for installation. The installed native compiler and its output run without Node.js. Standalone distributions are available from [GitHub Releases](https://github.com/vercel-labs/scriptc/releases).
|
|
- A platform linker and SDK for executable builds. On macOS, install the Xcode Command Line Tools. IR, LLVM IR, assembly, and object output use bundled tools and do not require an external linker or SDK.
|
|
|
|
## Install
|
|
|
|
```console
|
|
$ npm install -g scriptc
|
|
```
|
|
|
|
Keep optional dependencies and installation scripts enabled so npm can install the native command for your platform. For development from a source checkout, see the [repository](https://github.com/vercel-labs/scriptc).
|
|
|
|
## Create a program
|
|
|
|
Create `hello.ts`:
|
|
|
|
```ts:hello.ts
|
|
const who: string = process.argv.length > 2 ? process.argv[2] : "world";
|
|
console.log(`hello, ${who}`);
|
|
```
|
|
|
|
This program reads the first command-line argument, or uses `"world"` when no argument is provided.
|
|
|
|
## Compile and run
|
|
|
|
Use `scriptc run` to compile and execute the program:
|
|
|
|
```console
|
|
$ scriptc run hello.ts
|
|
hello, world
|
|
```
|
|
|
|
To pass arguments, build an executable and invoke it directly:
|
|
|
|
```console
|
|
$ scriptc build hello.ts -o hello >/dev/null
|
|
$ ./hello scriptc
|
|
hello, scriptc
|
|
```
|
|
|
|
This program compiles statically, so the executable does not include a JavaScript engine. The shell examples use POSIX syntax; on Windows, build `hello.exe` and invoke it with `.\hello.exe`.
|
|
|
|
## Check compilation support
|
|
|
|
`scriptc coverage` analyzes a program without creating an executable:
|
|
|
|
```console
|
|
$ cat hello.ts
|
|
const who: string = process.argv.length > 2 ? process.argv[2] : "world";
|
|
console.log(`hello, ${who}`);
|
|
|
|
$ scriptc coverage hello.ts
|
|
|
|
statements analyzed 2
|
|
compile statically 2 (100%)
|
|
|
|
fully static — this program has no dynamic remainder.
|
|
```
|
|
|
|
For programs that need dynamic execution or contain unsupported operations, the report lists the affected sites and diagnostic codes. See [Coverage Reports](/docs/coverage).
|
|
|
|
## Use an npm dependency
|
|
|
|
Create `cli.ts`:
|
|
|
|
```ts:cli.ts
|
|
import pc from "picocolors";
|
|
|
|
console.log(pc.green("hello"));
|
|
```
|
|
|
|
Install the package and enable the embedded engine with `--dynamic`:
|
|
|
|
```console
|
|
$ npm install picocolors
|
|
$ scriptc build cli.ts --dynamic -o demo >/dev/null
|
|
$ ./demo
|
|
hello
|
|
```
|
|
|
|
The package's JavaScript is embedded at build time. The executable does not read `node_modules` at runtime. See [npm Dependencies](/docs/dependencies) for package resolution, type declarations, and runtime behavior.
|
|
|
|
## Next steps
|
|
|
|
- [CLI Reference](/docs/cli): commands and options, including output formats and sanitizers.
|
|
- [Native Program Objects](/docs/native-objects): use program objects in external builds.
|
|
- [Platform Support](/docs/platforms): supported hosts and cross-compilation.
|
|
- [Limitations](/docs/limitations): compilation restrictions and runtime differences.
|