Skip to main content

typescript_config/
tsconfig_elements.rs

1use super::*;
2
3/// A Typescript plugin definition.
4#[derive(Deserialize, Serialize, Debug, Clone, Default, PartialEq, Eq)]
5#[cfg_attr(feature = "schemars", derive(JsonSchema))]
6pub struct TsPlugin {
7	pub name: String,
8	#[serde(flatten, skip_serializing_if = "BTreeMap::is_empty")]
9	pub extras: JsonValueBTreeMap,
10}
11
12impl PartialOrd for TsPlugin {
13	fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
14		Some(self.cmp(other))
15	}
16}
17
18impl Ord for TsPlugin {
19	fn cmp(&self, other: &Self) -> std::cmp::Ordering {
20		self.name.cmp(&other.name)
21	}
22}
23
24/// A reference to a Typescript project. Requires TypeScript version 3.0 or later.
25#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
26#[cfg_attr(feature = "schemars", derive(JsonSchema))]
27#[serde(deny_unknown_fields)]
28pub struct TsConfigReference {
29	/// Path to referenced tsconfig or to folder containing tsconfig.
30	pub path: String,
31}
32
33/// Set the newline character for emitting files. See more: https://www.typescriptlang.org/tsconfig#newLine
34#[derive(Deserialize, Debug, Clone, Serialize, PartialEq, Eq)]
35#[cfg_attr(feature = "schemars", derive(JsonSchema))]
36#[serde(rename_all = "lowercase")]
37pub enum NewLine {
38	Lf,
39	Crlf,
40}
41
42impl Display for NewLine {
43	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
44		match self {
45			Self::Lf => write!(f, "lf"),
46			Self::Crlf => write!(f, "crlf"),
47		}
48	}
49}
50
51/// Specify how the TypeScript watch mode works. See more: https://www.typescriptlang.org/tsconfig#watchFile
52#[derive(Deserialize, Debug, Clone, Serialize, PartialEq, Eq)]
53#[cfg_attr(feature = "schemars", derive(JsonSchema))]
54#[serde(rename_all = "camelCase")]
55pub enum WatchFile {
56	#[serde(alias = "fixedpollinginterval")]
57	FixedPollingInterval,
58	#[serde(alias = "prioritypollinginterval")]
59	PriorityPollingInterval,
60	#[serde(alias = "dynamicprioritypolling")]
61	DynamicPriorityPolling,
62	#[serde(alias = "usefsevents")]
63	UseFsEvents,
64	#[serde(alias = "usefseventsonparentdirectory")]
65	UseFsEventsOnParentDirectory,
66	#[serde(alias = "fixedchunksizepolling")]
67	FixedChunkSizePolling,
68}
69
70impl Display for WatchFile {
71	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
72		match self {
73			Self::FixedPollingInterval => write!(f, "fixedPollingInterval"),
74			Self::PriorityPollingInterval => write!(f, "priorityPollingInterval"),
75			Self::DynamicPriorityPolling => write!(f, "dynamicPriorityPolling"),
76			Self::UseFsEvents => write!(f, "useFsEvents"),
77			Self::UseFsEventsOnParentDirectory => write!(f, "useFsEventsOnParentDirectory"),
78			Self::FixedChunkSizePolling => write!(f, "fixedChunkSizePolling"),
79		}
80	}
81}
82
83/// Specify how directories are watched on systems that lack recursive file-watching functionality. See more: https://www.typescriptlang.org/tsconfig#watchDirectory
84#[derive(Deserialize, Debug, Clone, Serialize, PartialEq, Eq)]
85#[cfg_attr(feature = "schemars", derive(JsonSchema))]
86#[serde(rename_all = "camelCase")]
87pub enum WatchDirectory {
88	#[serde(alias = "usefsevents")]
89	UseFsEvents,
90	#[serde(alias = "fixedpollinginterval")]
91	FixedPollingInterval,
92	#[serde(alias = "dynamicprioritypolling")]
93	DynamicPriorityPolling,
94	#[serde(alias = "fixedchunksizepolling")]
95	FixedChunkSizePolling,
96}
97
98impl Display for WatchDirectory {
99	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
100		match self {
101			Self::FixedPollingInterval => write!(f, "fixedPollingInterval"),
102			Self::DynamicPriorityPolling => write!(f, "dynamicPriorityPolling"),
103			Self::UseFsEvents => write!(f, "useFsEvents"),
104			Self::FixedChunkSizePolling => write!(f, "fixedChunkSizePolling"),
105		}
106	}
107}
108
109/// Specify what approach the watcher should use if the system runs out of native file watchers. See more: https://www.typescriptlang.org/tsconfig#fallbackPolling
110#[derive(Deserialize, Debug, Clone, Serialize, PartialEq, Eq)]
111#[cfg_attr(feature = "schemars", derive(JsonSchema))]
112#[serde(rename_all = "camelCase")]
113pub enum FallbackPolling {
114	#[serde(alias = "fixedpollinginterval")]
115	FixedPollingInterval,
116	#[serde(alias = "prioritypollinginterval")]
117	PriorityPollingInterval,
118	#[serde(alias = "dynamicprioritypolling")]
119	DynamicPriorityPolling,
120	#[serde(alias = "fixedinterval")]
121	FixedInterval,
122	#[serde(alias = "priorityinterval")]
123	PriorityInterval,
124	#[serde(alias = "dynamicpriority")]
125	DynamicPriority,
126	#[serde(alias = "fixedchunksize")]
127	FixedChunkSize,
128}
129
130impl Display for FallbackPolling {
131	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
132		match self {
133			Self::FixedPollingInterval => write!(f, "fixedPollingInterval"),
134			Self::PriorityPollingInterval => write!(f, "priorityPollingInterval"),
135			Self::DynamicPriorityPolling => write!(f, "dynamicPriorityPolling"),
136			Self::DynamicPriority => write!(f, "dynamicPriority"),
137			Self::PriorityInterval => write!(f, "priorityInterval"),
138			Self::FixedInterval => write!(f, "fixedInterval"),
139			Self::FixedChunkSize => write!(f, "fixedChunkSize"),
140		}
141	}
142}
143
144/// Specify what JSX code is generated. See more: https://www.typescriptlang.org/tsconfig/#jsx
145#[derive(Deserialize, Serialize, Debug, PartialEq, Copy, Clone, Eq)]
146#[cfg_attr(feature = "schemars", derive(JsonSchema))]
147#[serde(rename_all = "kebab-case")]
148pub enum Jsx {
149	/// Emit .js files with JSX changed to the equivalent React.createElement calls
150	React,
151	/// Emit .js files with the JSX changed to _jsx calls optimized for production
152	ReactJsx,
153	/// Emit .js files with the JSX changed to _jsx calls for development only
154	ReactJsxdev,
155	/// Emit .js files with the JSX unchanged
156	ReactNative,
157	/// Emit .jsx files with the JSX unchanged
158	Preserve,
159}
160
161impl Display for Jsx {
162	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
163		match self {
164			Self::React => write!(f, "react"),
165			Self::ReactJsx => write!(f, "react-jsx"),
166			Self::ReactJsxdev => write!(f, "react-jsxdev"),
167			Self::ReactNative => write!(f, "react-native"),
168			Self::Preserve => write!(f, "preserve"),
169		}
170	}
171}
172
173/// Specify a set of bundled library declaration files that describe the target runtime environment. See more: https://www.typescriptlang.org/tsconfig#lib
174#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Eq, PartialOrd, Ord)]
175#[cfg_attr(feature = "schemars", derive(JsonSchema))]
176pub enum Lib {
177	/// Core definitions for all ES5 functionality
178	#[serde(alias = "ES5")]
179	Es5,
180	/// Additional APIs available in ES2015 (also known as ES6) - array.find, Promise, Proxy, Symbol, Map, Set, Reflect, etc.
181	#[serde(alias = "ES2015", alias = "Es6", alias = "ES6")]
182	Es2015,
183	/// Additional APIs available in ES2016 - array.include, etc.
184	#[serde(alias = "ES2016", alias = "Es7", alias = "ES7")]
185	Es2016,
186	/// Additional APIs available in ES2017 - Object.entries, Object.values, Atomics, SharedArrayBuffer, date.formatToParts, typed arrays, etc.
187	#[serde(alias = "ES2017")]
188	Es2017,
189	/// Additional APIs available in ES2018 - async iterables, promise.finally, Intl.PluralRules, regexp.groups, etc.
190	#[serde(alias = "ES2018")]
191	Es2018,
192	/// Additional APIs available in ES2019 - array.flat, array.flatMap, Object.fromEntries, string.trimStart, string.trimEnd, etc.
193	#[serde(alias = "ES2019")]
194	Es2019,
195	/// Additional APIs available in ES2020 - string.matchAll, etc.
196	#[serde(alias = "ES2020")]
197	Es2020,
198	/// Additional APIs available in ES2021 - promise.any, string.replaceAll etc.
199	#[serde(alias = "ES2021")]
200	Es2021,
201	/// Additional APIs available in ES2022 - array.at, RegExp.hasIndices, etc.
202	#[serde(alias = "ES2022")]
203	Es2022,
204	/// Additional APIs available in ES2023 - array.with, array.findLast, array.findLastIndex, array.toSorted, array.toReversed, etc.
205	#[serde(alias = "ES2023")]
206	Es2023,
207	/// Additional APIs available in ESNext - This changes as the JavaScript specification evolves
208	#[serde(alias = "ESNext")]
209	EsNext,
210	/// DOM definitions - window, document, etc.
211	#[serde(alias = "DOM")]
212	Dom,
213	/// APIs available in WebWorker contexts
214	WebWorker,
215	/// APIs for the Windows Script Hosting System
216	ScriptHost,
217}
218
219impl Display for Lib {
220	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
221		match self {
222			Self::Es5 => write!(f, "ES5"),
223			Self::Es2015 => write!(f, "ES2015"),
224			Self::Es2016 => write!(f, "ES2016"),
225			Self::Es2017 => write!(f, "ES2017"),
226			Self::Es2018 => write!(f, "ES2018"),
227			Self::Es2019 => write!(f, "ES2019"),
228			Self::Es2020 => write!(f, "ES2020"),
229			Self::Es2021 => write!(f, "ES2021"),
230			Self::Es2022 => write!(f, "ES2022"),
231			Self::Es2023 => write!(f, "ES2023"),
232			Self::EsNext => write!(f, "ESNext"),
233			Self::Dom => write!(f, "DOM"),
234			Self::WebWorker => write!(f, "WebWorker"),
235			Self::ScriptHost => write!(f, "ScriptHost"),
236		}
237	}
238}
239
240/// Specify how TypeScript determine a file as module. See more: https://www.typescriptlang.org/tsconfig/#moduleDetection
241#[derive(Deserialize, Serialize, Debug, PartialEq, Eq, Copy, Clone, Default)]
242#[cfg_attr(feature = "schemars", derive(JsonSchema))]
243#[serde(rename_all = "lowercase")]
244pub enum ModuleDetection {
245	/// TypeScript will not only look for import and export statements, but it will also check whether the "type" field in a package.json is set to "module" when running with module: nodenext or node16, and check whether the current file is a JSX file when running under jsx: react-jsx
246	#[default]
247	Auto,
248	/// The same behavior as 4.6 and prior, usings import and export statements to determine whether a file is a module.
249	Legacy,
250	/// Ensures that every non-declaration file is treated as a module.
251	Force,
252}
253
254impl Display for ModuleDetection {
255	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
256		match self {
257			Self::Auto => write!(f, "auto"),
258			Self::Legacy => write!(f, "legacy"),
259			Self::Force => write!(f, "force"),
260		}
261	}
262}
263
264#[derive(Deserialize, Serialize, Debug, PartialEq, Copy, Clone, Eq)]
265#[cfg_attr(feature = "schemars", derive(JsonSchema))]
266pub enum ModuleResolution {
267	/// When combined with the corresponding module values, picks the right algorithm for each resolution based on whether Node.js will see an import or require in the output JavaScript code
268	#[serde(rename = "node16", alias = "Node16")]
269	Node16,
270	/// When combined with the corresponding module values, picks the right algorithm for each resolution based on whether Node.js will see an import or require in the output JavaScript code
271	#[serde(rename = "node20", alias = "Node20")]
272	Node20,
273	/// When combined with the corresponding module values, picks the right algorithm for each resolution based on whether Node.js will see an import or require in the output JavaScript code
274	#[serde(rename = "nodenext", alias = "NodeNext", alias = "nodeNext")]
275	NodeNext,
276	/// For use with bundlers. Like node16 and nodenext, this mode supports package.json "imports" and "exports", but unlike the Node.js resolution modes, bundler never requires file extensions on relative paths in imports.
277	#[serde(rename = "bundler", alias = "Bundler")]
278	Bundler,
279}
280
281impl Display for ModuleResolution {
282	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
283		match self {
284			Self::Node16 => write!(f, "Node16"),
285			Self::Node20 => write!(f, "Node20"),
286			Self::NodeNext => write!(f, "NodeNext"),
287			Self::Bundler => write!(f, "Bundler"),
288		}
289	}
290}
291
292/// Specify what module code is generated. See more: https://www.typescriptlang.org/tsconfig#module
293#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
294#[cfg_attr(feature = "schemars", derive(JsonSchema))]
295pub enum Module {
296	#[serde(alias = "none")]
297	None,
298	#[serde(alias = "commonJs", alias = "commonjs")]
299	CommonJs,
300	#[serde(alias = "umd")]
301	Umd,
302	#[serde(alias = "amd")]
303	Amd,
304	#[serde(alias = "system")]
305	System,
306	#[serde(alias = "es6")]
307	Es6,
308	#[serde(alias = "es2015")]
309	Es2015,
310	#[serde(alias = "es2020")]
311	Es2020,
312	#[serde(alias = "es2022")]
313	Es2022,
314	#[serde(alias = "ESNext", alias = "esnext", alias = "esNext")]
315	EsNext,
316	#[serde(alias = "node16")]
317	Node16,
318	#[serde(alias = "node18")]
319	Node18,
320	#[serde(alias = "node20")]
321	Node20,
322	#[serde(alias = "nodenext", alias = "nodeNext")]
323	NodeNext,
324	#[serde(alias = "preserve")]
325	Preserve,
326}
327
328impl Display for Module {
329	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
330		match self {
331			Self::None => write!(f, "none"),
332			Self::Umd => write!(f, "Umd"),
333			Self::Amd => write!(f, "Amd"),
334			Self::CommonJs => write!(f, "CommonJs"),
335			Self::Es6 => write!(f, "Es6"),
336			Self::Es2015 => write!(f, "Es2015"),
337			Self::Es2020 => write!(f, "Es2020"),
338			Self::Es2022 => write!(f, "Es2022"),
339			Self::EsNext => write!(f, "EsNext"),
340			Self::System => write!(f, "System"),
341			Self::Node16 => write!(f, "Node16"),
342			Self::Node18 => write!(f, "Node18"),
343			Self::Node20 => write!(f, "Node20"),
344			Self::NodeNext => write!(f, "NodeNext"),
345			Self::Preserve => write!(f, "Preserve"),
346		}
347	}
348}
349
350/// Set the JavaScript language version for emitted JavaScript and include compatible library declarations. See more: https://www.typescriptlang.org/tsconfig#target
351#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
352#[cfg_attr(feature = "schemars", derive(JsonSchema))]
353pub enum Target {
354	#[serde(alias = "es3")]
355	Es3,
356	#[serde(alias = "es5")]
357	Es5,
358	#[serde(alias = "es6")]
359	Es6,
360	#[serde(alias = "es7")]
361	Es7,
362	#[serde(alias = "es2015")]
363	Es2015,
364	#[serde(alias = "es2016")]
365	Es2016,
366	#[serde(alias = "es2017")]
367	Es2017,
368	#[serde(alias = "es2018")]
369	Es2018,
370	#[serde(alias = "es2019")]
371	Es2019,
372	#[serde(alias = "es2020")]
373	Es2020,
374	#[serde(alias = "esnext", alias = "ESNext")]
375	EsNext,
376}
377
378impl Display for Target {
379	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
380		match self {
381			Self::Es3 => write!(f, "Es3"),
382			Self::Es5 => write!(f, "Es5"),
383			Self::Es2015 => write!(f, "Es2015"),
384			Self::Es6 => write!(f, "Es6"),
385			Self::Es2016 => write!(f, "Es2016"),
386			Self::Es7 => write!(f, "Es7"),
387			Self::Es2017 => write!(f, "Es2017"),
388			Self::Es2018 => write!(f, "Es2018"),
389			Self::Es2019 => write!(f, "Es2019"),
390			Self::Es2020 => write!(f, "Es2020"),
391			Self::EsNext => write!(f, "EsNext"),
392		}
393	}
394}