---
title: "CompileOptions: interface in Authoring, TypeShade API"
description: "CompileOptions, an interface in Authoring. How one compile() call is set up."
url: https://typeshade.dev/api/compileoptions/
language: en
---

# `CompileOptions`

Interface in Authoring

How one compile() call is set up.

`import type { CompileOptions } from 'typeshade'`

The signature, the description and the examples come from the compiler's own source at commit af54ddad5.

## Syntax

```ts
interface CompileOptions {
  readonly fileName?: string;
  readonly consoleSink?: ConsoleSink;
  readonly deprecations?: boolean;
  readonly console?: 'cpu' | 'gpu';
  readonly readDocument?: (fileName: string) => string | undefined;
  readonly resolveImport?: (fromFile: string, specifier: string) => string | undefined;
}
```

## Description

Every field is optional, and the defaults are what `compile(source)` did before this interface existed.

## Instance properties

**`fileName` optional read only `string`**

The name this source is compiled under. It is the `file` of every `SourceSpan` the front end stamps on the IR, and the `fileName` of every diagnostic, so it is how a consumer that holds a span says which of the author’s files a statement came from.

That default is fine for a compile whose output is shader text, since nothing reads the name, but not for one whose output is stepped: a `DebugBreakpoint` carries the path the editor knows the file by, and matches it against `span.file`, so a session compiled under the placeholder silently arms no breakpoint at all. An adapter that has a path should pass it.

Nothing resolves or reads it: it is a label carried to the spans, not a path the compiler opens. An adapter does not have to care: a `DebugBreakpoint`’s path is normalized the same way before it is compared, so either spelling matches.

**`consoleSink` optional read only `ConsoleSink`**

Host sink for `console.*` calls made by CPU/debug evaluation.

**`deprecations` optional read only `boolean`**

Report deprecation warnings for spellings whose meaning is scheduled to change (Rule 13.10). No window is open today, so the option reports nothing.

Off by default, and off is the whole of the compiler’s behaviour: the flag adds `category: 'warning'` diagnostics and moves no emitted byte, so `wgsl` and `glsl` are byte-identical with it on and with it off. It is how a build finds the lines a change of meaning will move, one release ahead of it.

**`console` optional read only `'cpu' | 'gpu'`**

Where a `console` call is recorded. `'cpu'`, the default, is what `compile()` always did: the CPU run delivers each call to [`CompileOptions.consoleSink`](https://typeshade.dev/api/compileoptions/), and the WGSL and GLSL record nothing, so no emitted byte depends on a console call. `'gpu'` makes the WGSL also record each call a compute or fragment entry reaches, in a `_console` storage buffer the compiler binds at group 0 past the module’s own bindings; [`CompileResult.console`](https://typeshade.dev/api/compileresult/) says where, and [`decodeConsole`](https://typeshade.dev/api/decodeconsole/) turns the buffer the host copies back into the same events. A call the WGSL cannot record is a [`TS8071`](https://typeshade.dev/reference/errors/ts8071/) warning. GLSL ES 3.00 records nothing either way. Surface §66, [Rule 11.9](https://typeshade.dev/reference/rules/11-9/).

**`readDocument` optional read only `(fileName: string) => string | undefined`**

Reads a file this source imports ([Rule 3.9](https://typeshade.dev/reference/rules/3-9/), surface §68): its text, or `undefined` when there is none. The source and every shader file it imports, directly or through another, are one program, compiled into one module, and a diagnostic located in an imported file carries that file’s name and offsets. It is asked for a package’s `package.json` too, which the default `resolveImport` reads to find a package in `node_modules`, so a `readDocument` that reads from disk follows a package with no change. Without it nothing is read: a source with no import compiles as it always has, and an import is [`TS8072`](https://typeshade.dev/reference/errors/ts8072/). The same hook as the language service’s `TypeshadeLanguageServiceHost.readDocument`, so both halves read one program.

**`resolveImport` optional read only `(fromFile: string, specifier: string) => string | undefined`**

The file a specifier written in `fromFile` names, or `undefined` when it names none. The default, which the language service applies too, resolves a relative specifier against the importing file (`fileName` for the source), reads `.js` and `.mjs` as `.ts`, and appends `.ts` to any other path. Any other specifier names a package: the first `node_modules/<name>/package.json` from the importing file’s directory up, read through `readDocument`, and the file its `exports` publishes under the `typeshade` condition (surface §68, change 0024). A hook passed here replaces the rule for every specifier.

## See also

- [`CompileResult`](https://typeshade.dev/api/compileresult/)
- [`decodeConsole`](https://typeshade.dev/api/decodeconsole/)

## Source

[`src/compiler/ts/compile.ts`, line 97](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/compile.ts#L97), at commit af54ddad5
