UNPKG

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