Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,108 @@ addEventListener("fetch", event => {
});
```

### CLI Flags and configuration

The CLI is typically invoked by the `build` script defined in your project's `package.json` scripts.

```json
{
"scripts": {
"build": "js-compute-runtime src/index.js bin/main.wasm"
}
}
```

The CLI is invoked as follows:

```sh
js-compute-runtime [OPTIONS] <input-js-file> <output-wasm-file>
```

Options can be specified on the command line or added to a persistent configuration file for the project. The CLI will search for a configuration starting from the current directory in the following order:

* A `fastlycompute` property in `package.json`
* `.fastlycomputerc.json`
* `fastlycompute.config.js`

<details>
<summary>Click here to see full list</summary>

The CLI will search for a configuration starting from the current directory in the following order:

- A `fastlycompute` property in `package.json`
- `.fastlycomputerc` (JSON or YAML)
- `.fastlycomputerc.json`, `.fastlycomputerc.yaml`, `.fastlycomputerc.yml`
- `.fastlycomputerc.js`, `.fastlycomputerc.mjs`
- `fastlycompute.config.js`, `fastlycompute.config.mjs`

</details>

If an option is defined in both the command line and the configuration file, the command line option takes precedence.

#### Supported Options

| Config Key | CLI Flag | Type | Description |
|:----------------------------------------------|:-----------------------------------------------------|:----------------------------|:----------------------------------------------------------------------------------------------------------------------------------------------------------|
| `enableAOT` | `--enable-aot` | `boolean` | Enable AOT compilation for performance |
| `aotCache` | `--aot-cache` | `string` (path) | Specify a path to the AOT cache file |
| `enableHttpCache` | `--enable-http-cache` | `boolean` | Enable the [HTTP cache hook API](https://www.fastly.com/documentation/guides/concepts/cache/#modifying-a-request-as-it-is-forwarded-to-a-backend) |
| `enableExperimentalHighResolutionTimeMethods` | `--enable-experimental-high-resolution-time-methods` | `boolean` | Enable experimental fastly.now() method |
| `enableExperimentalTopLevelAwait` | `--enable-experimental-top-level-await` | `boolean` | Enable experimental top level await |
| `enableStackTraces` | `--enable-stack-traces` | `boolean` | Enable stack traces |
| `excludeSources` | `--exclude-sources` | `boolean` | Don't include sources in stack traces |
| `debugIntermediateFiles` | `--debug-intermediate-files` | `string` (path) | Output intermediate files in directory |
| `debugBuild` | `--debug-build` | `boolean` | Use debug build of the SDK runtime |
| `engineWasm` | `--engine-wasm` | `string` (path) | Specify a custom Wasm engine (advanced) |
| `wevalBin` | `--weval-bin` | `string` (path) | Specify a custom weval binary (advanced) |
| `env` | `--env` | `string \| object \| array` | Set environment variables, possibly inheriting from the current environment. Multiple variables can be comma-separated (e.g., --env ENV_VAR,OVERRIDE=val) |

NOTE: The `env` field is additive. Values defined on the command-line values append to, rather than replace, the values defined in any configuration file.

#### Example command-line options

```sh
js-compute-runtime --enable-aot --enable-stack-traces --enable-top-level-await --env=LOG_LEVEL=debug ./src/index.js ./bin/main.wasm
```

#### Example `.fastlycomputerc.json`

```json
{
"enableAOT": true,
"enableStackTraces": true,
"enableTopLevelAwait": true,
"env": {
"LOG_LEVEL": "debug"
}
}
```

#### Example `package.json`

```json
{
"name": "my-fastly-service",
"type": "module",
"dependencies": {
"@fastly/cli": "^13.0.0"
},
"scripts": {
"build": "js-compute-runtime ./src/index.js ./bin/main.wasm",
"dev": "fastly compute serve",
"deploy": "fastly compute publish"
},
"fastlycompute": {
"enableAOT": true,
"enableStackTraces": true,
"enableTopLevelAwait": true,
"env": {
"LOG_LEVEL": "debug"
}
}
}
```

### API documentation

The API documentation for the JavaScript SDK is located at [https://js-compute-reference-docs.edgecompute.app](https://js-compute-reference-docs.edgecompute.app).
Expand Down
61 changes: 37 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"@jridgewell/trace-mapping": "^0.3.31",
"acorn": "^8.13.0",
"acorn-walk": "^8.3.4",
"cosmiconfig": "^9.0.1",
"esbuild": "^0.25.0",
"magic-string": "^0.30.12",
"picomatch": "^4.0.3",
Expand Down
5 changes: 4 additions & 1 deletion src/cli/js-compute-runtime-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import { parseInputs } from '../parseInputs.js';
import { printHelp, printVersion } from '../printHelp.js';
import { addSdkMetadataField } from '../addSdkMetadataField.js';
import { readConfigFileAndCliArguments } from '../config.js';

const parsedInputs = await parseInputs(process.argv.slice(2));
const argv = await readConfigFileAndCliArguments(process.argv.slice(2));

const parsedInputs = await parseInputs(argv);

if (parsedInputs === 'version') {
await printVersion();
Expand Down
Loading
Loading