1 | import { Stats } from "fs";
|
2 | import { Diagnostic } from "typescript";
|
3 | import { TypescriptConfig } from "./generated/typescript-config";
|
4 | export * from "./generated/typescript-config";
|
5 |
|
6 | export type CompilerOptionsConfig = TypescriptConfig["compilerOptions"];
|
7 |
|
8 | export interface NormalizedOptions {
|
9 | workingPath: AbsolutePath;
|
10 | rootPath: AbsolutePath;
|
11 | projectPath: AbsolutePath;
|
12 | buildPath: AbsolutePath | undefined;
|
13 | configFileName: string | undefined;
|
14 | rawConfig: CompilerOptionsConfig | undefined;
|
15 | compilerOptions: CompilerOptionsConfig | undefined;
|
16 | throwOnError: boolean;
|
17 | }
|
18 |
|
19 | export interface DiagnosticsHandler {
|
20 | /**
|
21 | * Check for diagnostics and handle diagnostics.
|
22 | *
|
23 | * Returns true if there are errors.
|
24 | */
|
25 | check(
|
26 | diagnostics: ReadonlyArray<Diagnostic> | Diagnostic | undefined,
|
27 | throwOnError?: boolean
|
28 | ): boolean;
|
29 | }
|
30 |
|
31 | export interface TypescriptCompilerOptions {
|
32 | /**
|
33 | * Acts as the current working directory for compilation.
|
34 | *
|
35 | * This affects how file paths are made relative for errors reporting.
|
36 | *
|
37 | * Defaults to `process.cwd()`.
|
38 | */
|
39 | workingPath?: string;
|
40 |
|
41 | /**
|
42 | * Used as the rootPath for relative paths within the input node.
|
43 | *
|
44 | * This affects type resolution for files outside the input node
|
45 | * like node_modules.
|
46 | *
|
47 | * The input node will act as though it is mounted at this location.
|
48 | *
|
49 | * The rootPath must contain the emitted files, since a broccoli node
|
50 | * cannot write outside of its outputPath.
|
51 | *
|
52 | * Defaults to options.workingPath.
|
53 | */
|
54 | rootPath?: string;
|
55 |
|
56 | /**
|
57 | * Used as the starting search path for the tsconfig file or the basePath for
|
58 | * config parsing if the options.tsconfig is an object.
|
59 | *
|
60 | * Most the time this is the same as the rootPath. The only time this is
|
61 | * important is if the project writes above its directory since the rootPath
|
62 | * needs to contain all emitted files.
|
63 | *
|
64 | * Acts like the -p option to tsc.
|
65 | *
|
66 | * Defaults to options.rootPath.
|
67 | */
|
68 | projectPath?: string;
|
69 |
|
70 | /**
|
71 | * Used as the base for output. This should be set to your broccoli output.
|
72 | *
|
73 | * Your outDir should be at or beneath this path. The emitted files will be
|
74 | * written to the output relative to this path.
|
75 | *
|
76 | * Defaults to compilerOptions.outDir (assumption is your outDir is set to where
|
77 | * you place your broccoli output) or options.rootPath.
|
78 | *
|
79 | * Set this to where the broccoli output will go. It must contain all emitted files
|
80 | * and the broccoli node output will be relative to it.
|
81 | *
|
82 | * If your outDir is 'dist' and your broccoli output is written to 'dist' then this
|
83 | * will by default write output relative to 'dist'.
|
84 | *
|
85 | * If your broccoli output is written to 'dist' and your outDir is 'dist/a', then this
|
86 | * should be set to 'dist' so that your emitted output will be 'a' and ultimately 'dist/a'.
|
87 | */
|
88 | buildPath?: string;
|
89 |
|
90 | /**
|
91 | * The tsconfig file name search for from the projectPath
|
92 | * or the JSON that would be in a tsconfig.
|
93 | *
|
94 | * If it is the JSON config itself, the base path will be set to the
|
95 | * projectPath during parse.
|
96 | */
|
97 | tsconfig?: string | TypescriptConfig;
|
98 |
|
99 | /**
|
100 | * The compilerOptions of tsconfig.
|
101 | *
|
102 | * This allows you to override compilerOptions in the tsconfig.
|
103 | *
|
104 | * This acts like if you specify --project plus additional options to tsc.
|
105 | */
|
106 | compilerOptions?: CompilerOptionsConfig;
|
107 |
|
108 | /**
|
109 | * Throw if an error occurs during compilation.
|
110 | */
|
111 | throwOnError?: boolean;
|
112 |
|
113 | /**
|
114 | * Broccoli node annotation.
|
115 | */
|
116 | annotation?: string;
|
117 | }
|
118 |
|
119 | export interface PathInfo {
|
120 | /**
|
121 | * The absolute path.
|
122 | */
|
123 | path: AbsolutePath;
|
124 |
|
125 | /**
|
126 | * The canonical form of the absolute path.
|
127 | */
|
128 | canonicalPath: CanonicalPath;
|
129 |
|
130 | /**
|
131 | * The corresponding absolute path in the input node if within root.
|
132 | */
|
133 | pathInInput: AbsolutePath | undefined;
|
134 |
|
135 | /**
|
136 | * The canonical form of `pathInInput`.
|
137 | */
|
138 | canonicalPathInInput: CanonicalPath | undefined;
|
139 |
|
140 | /**
|
141 | * Path relative to root.
|
142 | */
|
143 | relativePath: string | undefined;
|
144 | }
|
145 |
|
146 | /**
|
147 | * An AbsolutePath is a path that has been normalized and provides the following
|
148 | * guarantees:
|
149 | *
|
150 | * 1. The path is absolute.
|
151 | * 2. Path separators have been normalized to slashes.
|
152 | * 3. Any trailing slash has been removed.
|
153 | *
|
154 | * Generally speaking, AbsolutePaths should be preferred because they preserve
|
155 | * casing, even on case-insensitive file systems. The exception is that
|
156 | * CanonicalPaths should be used for things like cache keys, where the same file
|
157 | * may be referred to by multiple casing permutations.
|
158 | */
|
159 | export type AbsolutePath = string & {
|
160 | __absolutePathBrand: any;
|
161 | };
|
162 |
|
163 | /**
|
164 | * A CanonicalPath is an AbsolutePath that has been canonicalized. Primarily,
|
165 | * this means that in addition to the guarantees of AbsolutePath, it has also
|
166 | * had casing normalized on case-insensitive file systems. This is an alias of
|
167 | * `ts.Path` type.
|
168 | */
|
169 | export type CanonicalPath = string & {
|
170 | __pathBrand: any;
|
171 | };
|
172 |
|
173 | export interface Resolution extends PathInfo {
|
174 | stats: Stats | undefined;
|
175 | otherStats: Stats | undefined;
|
176 |
|
177 | isFile(): this is FileResolution | InputFileResolution;
|
178 | isDirectory(): this is DirectoryResolution | InputDirectoryResolution;
|
179 | isInput(): this is InputDirectoryResolution | InputFileResolution;
|
180 | isMerged(): this is MergedDirectoryResolution;
|
181 |
|
182 | exists(): this is FileResolution | DirectoryResolution;
|
183 | }
|
184 |
|
185 | export interface FileResolution extends Resolution {
|
186 | stats: Stats;
|
187 | otherStats: undefined;
|
188 |
|
189 | isFile(): this is FileResolution | InputFileResolution;
|
190 | isDirectory(): false;
|
191 | isInput(): this is InputFileResolution;
|
192 | isMerged(): false;
|
193 | }
|
194 |
|
195 | export interface InputFileResolution extends FileResolution {
|
196 | pathInInput: AbsolutePath;
|
197 | relativePath: string;
|
198 |
|
199 | isFile(): this is InputFileResolution;
|
200 | }
|
201 |
|
202 | export interface DirectoryResolution extends Resolution {
|
203 | stats: Stats;
|
204 |
|
205 | isFile(): false;
|
206 | isDirectory(): this is DirectoryResolution | InputDirectoryResolution;
|
207 | isInput(): this is InputDirectoryResolution;
|
208 | }
|
209 |
|
210 | export interface InputDirectoryResolution extends DirectoryResolution {
|
211 | pathInInput: AbsolutePath;
|
212 | canonicalPathInInput: CanonicalPath;
|
213 | relativePath: string;
|
214 |
|
215 | isFile(): false;
|
216 | isDirectory(): this is InputDirectoryResolution;
|
217 | }
|
218 |
|
219 | export interface MergedDirectoryResolution extends InputDirectoryResolution {
|
220 | otherStats: Stats;
|
221 | }
|
222 |
|
223 | export interface FileContent {
|
224 | version: string;
|
225 | buffer: Buffer;
|
226 | }
|
227 |
|
228 | export interface DirEntries {
|
229 | files: string[];
|
230 | directories: string[];
|
231 | }
|
232 |
|
233 | export interface CacheDelegate<K, CK, V> {
|
234 | cacheKey(key: K): CK;
|
235 | create(key: K): V;
|
236 | }
|
237 |
|
238 | export interface PathResolver {
|
239 | resolve(path: string): Resolution;
|
240 | }
|