Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/src/execute/types.ts
6458 views
1
/*
2
* types.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*/
6
import {
7
kIncludeAfterBody,
8
kIncludeBeforeBody,
9
kIncludeInHeader,
10
} from "../config/constants.ts";
11
import { Format, FormatPandoc, Metadata } from "../config/types.ts";
12
13
import { PartitionedMarkdown } from "../core/pandoc/types.ts";
14
import { RenderOptions, RenderResultFile } from "../command/render/types.ts";
15
import { MappedString } from "../core/lib/text-types.ts";
16
import { HandlerContextResults } from "../core/handlers/types.ts";
17
import { EngineProjectContext, ProjectContext } from "../project/types.ts";
18
import { Command } from "cliffy/command/mod.ts";
19
import type { QuartoAPI } from "../core/api/index.ts";
20
import type { CheckConfiguration } from "../command/check/check.ts";
21
22
export type { EngineProjectContext };
23
24
export const kQmdExtensions = [".qmd"];
25
26
export const kMarkdownEngine = "markdown";
27
export const kKnitrEngine = "knitr";
28
export const kJupyterEngine = "jupyter";
29
export const kJuliaEngine = "julia";
30
31
/**
32
* Interface for the static discovery phase of execution engines
33
* Used to determine which engine should handle a file
34
*/
35
export interface ExecutionEngineDiscovery {
36
/**
37
* Initialize the engine with the Quarto API (optional)
38
* May be called multiple times but always with the same QuartoAPI object.
39
* Engines should store the reference to use throughout their lifecycle.
40
*/
41
init?: (quarto: QuartoAPI) => void;
42
43
name: string;
44
defaultExt: string;
45
defaultYaml: (kernel?: string) => string[];
46
defaultContent: (kernel?: string) => string[];
47
validExtensions: () => string[];
48
claimsFile: (file: string, ext: string) => boolean;
49
/**
50
* Whether this engine can handle the given language
51
*
52
* @param language - The language identifier (e.g., "python", "r", "julia")
53
* @param firstClass - Optional first class from code block attributes (e.g., "marimo" from {python .marimo})
54
* @returns false to skip (don't claim), true to claim with priority 1, or any number for custom priority (higher wins)
55
*/
56
claimsLanguage: (language: string, firstClass?: string) => boolean | number;
57
canFreeze: boolean;
58
generatesFigures: boolean;
59
ignoreDirs?: () => string[] | undefined;
60
61
/**
62
* Semver range specifying the minimum required Quarto version for this engine
63
* Examples: ">= 1.6.0", "^1.5.0", "1.*"
64
*/
65
quartoRequired?: string;
66
67
/**
68
* Populate engine-specific CLI commands (optional)
69
*/
70
populateCommand?: (command: Command) => void;
71
72
/**
73
* Check installation and capabilities for this engine (optional)
74
* Used by `quarto check <engine-name>` command
75
*
76
* Engines implementing this method will automatically be available as targets
77
* for the check command (e.g., `quarto check jupyter`, `quarto check knitr`).
78
*
79
* @param conf - Check configuration with output settings and services
80
*/
81
checkInstallation?: (conf: CheckConfiguration) => Promise<void>;
82
83
/**
84
* Launch a dynamic execution engine with project context
85
*/
86
launch: (context: EngineProjectContext) => ExecutionEngineInstance;
87
}
88
89
/**
90
* Interface for the dynamic execution phase of execution engines
91
* Used after a file has been assigned to an engine
92
*/
93
export interface ExecutionEngineInstance {
94
name: string;
95
canFreeze: boolean;
96
97
markdownForFile(file: string): Promise<MappedString>;
98
99
target: (
100
file: string,
101
quiet?: boolean,
102
markdown?: MappedString,
103
) => Promise<ExecutionTarget | undefined>;
104
105
partitionedMarkdown: (
106
file: string,
107
format?: Format,
108
) => Promise<PartitionedMarkdown>;
109
110
filterFormat?: (
111
source: string,
112
options: RenderOptions,
113
format: Format,
114
) => Format;
115
116
execute: (options: ExecuteOptions) => Promise<ExecuteResult>;
117
118
executeTargetSkipped?: (
119
target: ExecutionTarget,
120
format: Format,
121
) => void;
122
123
dependencies: (options: DependenciesOptions) => Promise<DependenciesResult>;
124
125
postprocess: (options: PostProcessOptions) => Promise<void>;
126
127
canKeepSource?: (target: ExecutionTarget) => boolean;
128
129
intermediateFiles?: (input: string) => string[] | undefined;
130
131
run?: (options: RunOptions) => Promise<void>;
132
133
postRender?: (
134
file: RenderResultFile,
135
) => Promise<void>;
136
}
137
138
// execution target (filename and context 'cookie')
139
export interface ExecutionTarget {
140
source: string;
141
input: string;
142
markdown: MappedString;
143
metadata: Metadata;
144
data?: unknown;
145
preEngineExecuteResults?: HandlerContextResults;
146
}
147
148
// execute options
149
export interface ExecuteOptions {
150
target: ExecutionTarget;
151
format: Format;
152
resourceDir: string;
153
tempDir: string;
154
dependencies: boolean;
155
projectDir?: string;
156
libDir?: string;
157
cwd: string;
158
params?: { [key: string]: unknown };
159
quiet?: boolean;
160
previewServer?: boolean;
161
handledLanguages: string[]; // list of languages handled by cell language handlers, after the execution engine
162
project: ProjectContext;
163
}
164
165
// result of execution
166
export interface ExecuteResult {
167
markdown: string;
168
supporting: string[];
169
filters: string[];
170
metadata?: Metadata;
171
pandoc?: FormatPandoc;
172
includes?: PandocIncludes;
173
engine?: string;
174
engineDependencies?: Record<string, Array<unknown>>;
175
preserve?: Record<string, string>;
176
postProcess?: boolean;
177
resourceFiles?: string[];
178
}
179
180
// result of execution after restoring source map
181
export interface MappedExecuteResult {
182
markdown: MappedString;
183
supporting: string[];
184
filters: string[];
185
metadata?: Metadata;
186
pandoc?: FormatPandoc;
187
includes?: PandocIncludes;
188
engineDependencies?: Record<string, Array<unknown>>;
189
preserve?: Record<string, string>;
190
postProcess?: boolean;
191
resourceFiles?: string[];
192
}
193
194
export interface PandocIncludes {
195
[kIncludeBeforeBody]?: string[];
196
[kIncludeAfterBody]?: string[];
197
[kIncludeInHeader]?: string[];
198
}
199
200
// dependencies options
201
export interface DependenciesOptions {
202
target: ExecutionTarget;
203
format: Format;
204
output: string;
205
resourceDir: string;
206
tempDir: string;
207
projectDir?: string;
208
libDir?: string;
209
dependencies?: Array<unknown>;
210
quiet?: boolean;
211
}
212
213
// dependencies result
214
export interface DependenciesResult {
215
includes: PandocIncludes;
216
}
217
218
// post processing options
219
export interface PostProcessOptions {
220
engine: ExecutionEngineInstance;
221
target: ExecutionTarget;
222
format: Format;
223
output: string;
224
tempDir: string;
225
projectDir?: string;
226
preserve?: Record<string, string>;
227
quiet?: boolean;
228
}
229
230
// run options
231
export interface RunOptions {
232
input: string;
233
render: boolean;
234
browser: boolean;
235
tempDir: string;
236
reload?: boolean;
237
format?: string;
238
projectDir?: string;
239
port?: number;
240
host?: string;
241
quiet?: boolean;
242
onReady?: () => Promise<void>;
243
}
244
245