Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/tests/smoke/build-ts-extension/src/test-engine.ts
6442 views
1
import type {
2
ExecutionEngineDiscovery,
3
ExecutionEngineInstance,
4
QuartoAPI,
5
EngineProjectContext,
6
MappedString,
7
ExecutionTarget,
8
ExecuteOptions,
9
ExecuteResult,
10
DependenciesOptions,
11
DependenciesResult,
12
PostProcessOptions,
13
PartitionedMarkdown,
14
} from "@quarto/types";
15
import { extname } from "path";
16
17
let quarto: QuartoAPI;
18
19
const testEngineDiscovery: ExecutionEngineDiscovery = {
20
init: (quartoAPI: QuartoAPI) => {
21
quarto = quartoAPI;
22
},
23
24
name: "test",
25
26
defaultExt: ".qmd",
27
28
defaultYaml: () => ["engine: test"],
29
30
defaultContent: () => ["# Test Engine Document", "", "This is a test."],
31
32
validExtensions: () => [".qmd"],
33
34
claimsFile: (_file: string, _ext: string) => false,
35
36
claimsLanguage: (language: string) => language === "test",
37
38
canFreeze: false,
39
40
generatesFigures: false,
41
42
launch: (context: EngineProjectContext): ExecutionEngineInstance => {
43
return {
44
name: "test",
45
canFreeze: false,
46
47
markdownForFile: async (file: string): Promise<MappedString> => {
48
return quarto.mappedString.fromFile(file);
49
},
50
51
target: async (
52
file: string,
53
_quiet?: boolean,
54
markdown?: MappedString,
55
): Promise<ExecutionTarget | undefined> => {
56
if (!markdown) {
57
markdown = await quarto.mappedString.fromFile(file);
58
}
59
const metadata = quarto.markdownRegex.extractYaml(markdown.value);
60
return {
61
source: file,
62
input: file,
63
markdown,
64
metadata,
65
};
66
},
67
68
partitionedMarkdown: async (
69
file: string,
70
): Promise<PartitionedMarkdown> => {
71
const markdown = await quarto.mappedString.fromFile(file);
72
return quarto.markdownRegex.partition(markdown.value);
73
},
74
75
execute: async (options: ExecuteOptions): Promise<ExecuteResult> => {
76
// Simple passthrough - no actual execution
77
// Use extname to ensure it gets bundled
78
const _ext = extname(options.target.input);
79
return {
80
markdown: options.target.markdown.value,
81
supporting: [],
82
filters: [],
83
};
84
},
85
86
dependencies: async (
87
_options: DependenciesOptions,
88
): Promise<DependenciesResult> => {
89
return {
90
includes: {},
91
};
92
},
93
94
postprocess: async (_options: PostProcessOptions): Promise<void> => {
95
// No post-processing needed
96
},
97
};
98
},
99
};
100
101
export default testEngineDiscovery;
102
103