UNPKG

5.31 kBTypeScriptView Raw
1import * as ts from 'typescript';
2import { Emitter } from './emitter';
3import { ProjectInfo } from './project-info';
4import { TypeScriptConfigValidationRuleSet } from './tsconfig';
5export declare const DIAGNOSTICS = "diagnostics";
6export declare const JSII_DIAGNOSTICS_CODE = 9999;
7export interface CompilerOptions {
8 /** The information about the project to be built */
9 projectInfo: ProjectInfo;
10 /** Whether the compiler should watch for changes or just compile once */
11 watch?: boolean;
12 /** Whether to detect and generate TypeScript project references */
13 projectReferences?: boolean;
14 /** Whether to fail when a warning is emitted */
15 failOnWarnings?: boolean;
16 /** Whether to strip deprecated members from emitted artifacts */
17 stripDeprecated?: boolean;
18 /** The path to an allowlist of FQNs to strip if stripDeprecated is set */
19 stripDeprecatedAllowListFile?: string;
20 /** Whether to add warnings for deprecated elements */
21 addDeprecationWarnings?: boolean;
22 /**
23 * The name of the tsconfig file to generate.
24 * Cannot be used at the same time as `typeScriptConfig`.
25 * @default "tsconfig.json"
26 */
27 generateTypeScriptConfig?: string;
28 /**
29 * The name of the tsconfig file to use.
30 * Cannot be used at the same time as `generateTypeScriptConfig`.
31 * @default - generate the tsconfig file
32 */
33 typeScriptConfig?: string;
34 /**
35 * The ruleset to validate the provided tsconfig file against.
36 * Can only be used when `typeScriptConfig` is provided.
37 * @default TypeScriptConfigValidationRuleSet.STRICT - if `typeScriptConfig` is provided
38 */
39 validateTypeScriptConfig?: TypeScriptConfigValidationRuleSet;
40 /**
41 * Whether to compress the assembly
42 * @default false
43 */
44 compressAssembly?: boolean;
45}
46export declare class Compiler implements Emitter {
47 private readonly options;
48 private readonly system;
49 private readonly compilerHost;
50 private readonly userProvidedTypeScriptConfig;
51 private readonly tsconfig;
52 private rootFiles;
53 private readonly configPath;
54 private readonly projectRoot;
55 constructor(options: CompilerOptions);
56 /**
57 * Compiles the configured program.
58 *
59 * @param files can be specified to override the standard source code location logic. Useful for example when testing "negatives".
60 */
61 emit(...files: string[]): ts.EmitResult;
62 /**
63 * Watches for file-system changes and dynamically recompiles the project as needed. In blocking mode, this results
64 * in a never-resolving promise.
65 */
66 watch(): Promise<never>;
67 /**
68 * Prepares the project for build, by creating the necessary configuration
69 * file(s), and assigning the relevant root file(s).
70 *
71 * @param files the files that were specified as input in the CLI invocation.
72 */
73 private configureTypeScript;
74 /**
75 * Final preparations of the project for build.
76 *
77 * These are preparations that either
78 * - must happen immediately before the build, or
79 * - can be different for every build like assigning the relevant root file(s).
80 *
81 * @param files the files that were specified as input in the CLI invocation.
82 */
83 private prepareForBuild;
84 /**
85 * Do a single build
86 */
87 private buildOnce;
88 private consumeProgram;
89 /**
90 * Build the TypeScript config object from jsii config
91 *
92 * This is the object that will be written to disk
93 * unless an existing tsconfig was provided.
94 */
95 private buildTypeScriptConfig;
96 /**
97 * Load the TypeScript config object from a provided file
98 */
99 private readTypeScriptConfig;
100 /**
101 * Creates a `tsconfig.json` file to improve the IDE experience.
102 *
103 * @return the fully qualified path to the `tsconfig.json` file
104 */
105 private writeTypeScriptConfig;
106 /**
107 * Find all dependencies that look like TypeScript projects.
108 *
109 * Enumerate all dependencies, if they have a tsconfig.json file with
110 * "composite: true" we consider them project references.
111 *
112 * (Note: TypeScript seems to only correctly find transitive project references
113 * if there's an "index" tsconfig.json of all projects somewhere up the directory
114 * tree)
115 */
116 private findProjectReferences;
117 /**
118 * Find source files using the same mechanism that the TypeScript compiler itself uses.
119 *
120 * Respects includes/excludes/etc.
121 *
122 * This makes it so that running 'typescript' and running 'jsii' has the same behavior.
123 */
124 private determineSources;
125 /**
126 * Resolve the given dependency name from the current package, and find the associated tsconfig.json location
127 *
128 * Because we have the following potential directory layout:
129 *
130 * package/node_modules/some_dependency
131 * package/tsconfig.json
132 *
133 * We resolve symlinks and only find a "TypeScript" dependency if doesn't have 'node_modules' in
134 * the path after resolving symlinks (i.e., if it's a peer package in the same monorepo).
135 *
136 * Returns undefined if no such tsconfig could be found.
137 */
138 private findMonorepoPeerTsconfig;
139 private diagsHaveAbortableErrors;
140}
141//# sourceMappingURL=compiler.d.ts.map
\No newline at end of file