jsii 5.4.16-dev.6 → 5.4.16-dev.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/lib/case.d.ts +0 -1
  2. package/lib/case.js +1 -2
  3. package/lib/case.js.map +1 -1
  4. package/lib/compiler.d.ts +14 -38
  5. package/lib/compiler.js +114 -123
  6. package/lib/compiler.js.map +1 -1
  7. package/lib/jsii-diagnostic.d.ts +0 -3
  8. package/lib/jsii-diagnostic.js +1 -15
  9. package/lib/jsii-diagnostic.js.map +1 -1
  10. package/lib/main.js +2 -48
  11. package/lib/main.js.map +1 -1
  12. package/lib/project-info.d.ts +0 -5
  13. package/lib/project-info.js +0 -13
  14. package/lib/project-info.js.map +1 -1
  15. package/lib/version.d.ts +2 -2
  16. package/lib/version.js +2 -2
  17. package/lib/version.js.map +1 -1
  18. package/package.json +2 -2
  19. package/lib/tsconfig/compiler-options.d.ts +0 -54
  20. package/lib/tsconfig/compiler-options.js +0 -136
  21. package/lib/tsconfig/compiler-options.js.map +0 -1
  22. package/lib/tsconfig/index.d.ts +0 -18
  23. package/lib/tsconfig/index.js +0 -11
  24. package/lib/tsconfig/index.js.map +0 -1
  25. package/lib/tsconfig/rulesets/configurable-options.d.ts +0 -4
  26. package/lib/tsconfig/rulesets/configurable-options.js +0 -20
  27. package/lib/tsconfig/rulesets/configurable-options.js.map +0 -1
  28. package/lib/tsconfig/rulesets/deprecated-options.d.ts +0 -4
  29. package/lib/tsconfig/rulesets/deprecated-options.js +0 -9
  30. package/lib/tsconfig/rulesets/deprecated-options.js.map +0 -1
  31. package/lib/tsconfig/rulesets/generated.public.d.ts +0 -4
  32. package/lib/tsconfig/rulesets/generated.public.js +0 -28
  33. package/lib/tsconfig/rulesets/generated.public.js.map +0 -1
  34. package/lib/tsconfig/rulesets/incompatible-options.d.ts +0 -4
  35. package/lib/tsconfig/rulesets/incompatible-options.js +0 -11
  36. package/lib/tsconfig/rulesets/incompatible-options.js.map +0 -1
  37. package/lib/tsconfig/rulesets/jsii-configured-options.d.ts +0 -4
  38. package/lib/tsconfig/rulesets/jsii-configured-options.js +0 -21
  39. package/lib/tsconfig/rulesets/jsii-configured-options.js.map +0 -1
  40. package/lib/tsconfig/rulesets/minimal.public.d.ts +0 -4
  41. package/lib/tsconfig/rulesets/minimal.public.js +0 -11
  42. package/lib/tsconfig/rulesets/minimal.public.js.map +0 -1
  43. package/lib/tsconfig/rulesets/strict-family-options.d.ts +0 -4
  44. package/lib/tsconfig/rulesets/strict-family-options.js +0 -17
  45. package/lib/tsconfig/rulesets/strict-family-options.js.map +0 -1
  46. package/lib/tsconfig/rulesets/strict.public.d.ts +0 -4
  47. package/lib/tsconfig/rulesets/strict.public.js +0 -33
  48. package/lib/tsconfig/rulesets/strict.public.js.map +0 -1
  49. package/lib/tsconfig/tsconfig-validator.d.ts +0 -16
  50. package/lib/tsconfig/tsconfig-validator.js +0 -46
  51. package/lib/tsconfig/tsconfig-validator.js.map +0 -1
  52. package/lib/tsconfig/validator.d.ts +0 -155
  53. package/lib/tsconfig/validator.js +0 -301
  54. package/lib/tsconfig/validator.js.map +0 -1
package/lib/case.d.ts CHANGED
@@ -2,5 +2,4 @@ export declare const camel: (text: string) => string;
2
2
  export declare const constant: (text: string) => string;
3
3
  export declare const pascal: (text: string) => string;
4
4
  export declare const snake: (text: string) => string;
5
- export declare const kebab: (text: string) => string;
6
5
  //# sourceMappingURL=case.d.ts.map
package/lib/case.js CHANGED
@@ -1,13 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.kebab = exports.snake = exports.pascal = exports.constant = exports.camel = void 0;
3
+ exports.snake = exports.pascal = exports.constant = exports.camel = void 0;
4
4
  const Case = require("case");
5
5
  const withCache = (func) => (text) => Cache.fetch(text, func);
6
6
  exports.camel = withCache(Case.camel);
7
7
  exports.constant = withCache(Case.constant);
8
8
  exports.pascal = withCache(Case.pascal);
9
9
  exports.snake = withCache(Case.snake);
10
- exports.kebab = withCache(Case.kebab);
11
10
  class Cache {
12
11
  static fetch(text, func) {
13
12
  // Check whether we have a cache for this function...
package/lib/case.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"case.js","sourceRoot":"","sources":["../src/case.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAE7B,MAAM,SAAS,GACb,CAAC,IAA8B,EAA8B,EAAE,CAC/D,CAAC,IAAY,EAAE,EAAE,CACf,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AAEf,QAAA,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC9B,QAAA,QAAQ,GAAG,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACpC,QAAA,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAChC,QAAA,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC9B,QAAA,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAE3C,MAAM,KAAK;IACF,MAAM,CAAC,KAAK,CAAC,IAAY,EAAE,IAA8B;QAC9D,qDAAqD;QACrD,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACpC,IAAI,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACtC,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;YAClB,wBAAwB;YACxB,KAAK,GAAG,IAAI,GAAG,EAAkB,CAAC;YAClC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QACnC,CAAC;QAED,0DAA0D;QAC1D,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC/B,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;YACnB,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,yBAAyB;QACzB,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1B,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACxB,OAAO,MAAM,CAAC;IAChB,CAAC;IAKD,gBAAuB,CAAC;;AAHxB,uFAAuF;AAC/D,YAAM,GAAG,IAAI,OAAO,EAAiC,CAAC;AAKhF,MAAM,QAAQ;IACL,MAAM,CAAC,GAAG,CAAC,IAAS;QACzB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC;QAC5C,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;YAClB,OAAO,KAAK,CAAC;QACf,CAAC;QACD,MAAM,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;QAC9B,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;QAC1C,OAAO,MAAM,CAAC;IAChB,CAAC;IAKD,gBAAuB,CAAC;;AAHxB,iGAAiG;AACzE,cAAK,GAAG,IAAI,GAAG,EAA0B,CAAC","sourcesContent":["import * as Case from 'case';\n\nconst withCache =\n (func: (text: string) => string): ((text: string) => string) =>\n (text: string) =>\n Cache.fetch(text, func);\n\nexport const camel = withCache(Case.camel);\nexport const constant = withCache(Case.constant);\nexport const pascal = withCache(Case.pascal);\nexport const snake = withCache(Case.snake);\nexport const kebab = withCache(Case.kebab);\n\nclass Cache {\n public static fetch(text: string, func: (text: string) => string): string {\n // Check whether we have a cache for this function...\n const cacheKey = CacheKey.for(func);\n let cache = this.CACHES.get(cacheKey);\n if (cache == null) {\n // If not, create one...\n cache = new Map<string, string>();\n this.CACHES.set(cacheKey, cache);\n }\n\n // Check if the current cache has a value for this text...\n const cached = cache.get(text);\n if (cached != null) {\n return cached;\n }\n\n // If not, compute one...\n const result = func(text);\n cache.set(text, result);\n return result;\n }\n\n // Cache is indexed on a weak CacheKey so the cache can be purged under memory pressure\n private static readonly CACHES = new WeakMap<CacheKey, Map<string, string>>();\n\n private constructor() {}\n}\n\nclass CacheKey {\n public static for(data: any) {\n const entry = this.STORE.get(data)?.deref();\n if (entry != null) {\n return entry;\n }\n const newKey = new CacheKey();\n this.STORE.set(data, new WeakRef(newKey));\n return newKey;\n }\n\n // Storing cache keys as weak references to allow garbage collection if there is memory pressure.\n private static readonly STORE = new Map<any, WeakRef<CacheKey>>();\n\n private constructor() {}\n}\n"]}
1
+ {"version":3,"file":"case.js","sourceRoot":"","sources":["../src/case.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAE7B,MAAM,SAAS,GACb,CAAC,IAA8B,EAA8B,EAAE,CAC/D,CAAC,IAAY,EAAE,EAAE,CACf,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AAEf,QAAA,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC9B,QAAA,QAAQ,GAAG,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACpC,QAAA,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAChC,QAAA,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAE3C,MAAM,KAAK;IACF,MAAM,CAAC,KAAK,CAAC,IAAY,EAAE,IAA8B;QAC9D,qDAAqD;QACrD,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACpC,IAAI,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACtC,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;YAClB,wBAAwB;YACxB,KAAK,GAAG,IAAI,GAAG,EAAkB,CAAC;YAClC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QACnC,CAAC;QAED,0DAA0D;QAC1D,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC/B,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;YACnB,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,yBAAyB;QACzB,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1B,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACxB,OAAO,MAAM,CAAC;IAChB,CAAC;IAKD,gBAAuB,CAAC;;AAHxB,uFAAuF;AAC/D,YAAM,GAAG,IAAI,OAAO,EAAiC,CAAC;AAKhF,MAAM,QAAQ;IACL,MAAM,CAAC,GAAG,CAAC,IAAS;QACzB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC;QAC5C,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;YAClB,OAAO,KAAK,CAAC;QACf,CAAC;QACD,MAAM,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;QAC9B,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;QAC1C,OAAO,MAAM,CAAC;IAChB,CAAC;IAKD,gBAAuB,CAAC;;AAHxB,iGAAiG;AACzE,cAAK,GAAG,IAAI,GAAG,EAA0B,CAAC","sourcesContent":["import * as Case from 'case';\n\nconst withCache =\n (func: (text: string) => string): ((text: string) => string) =>\n (text: string) =>\n Cache.fetch(text, func);\n\nexport const camel = withCache(Case.camel);\nexport const constant = withCache(Case.constant);\nexport const pascal = withCache(Case.pascal);\nexport const snake = withCache(Case.snake);\n\nclass Cache {\n public static fetch(text: string, func: (text: string) => string): string {\n // Check whether we have a cache for this function...\n const cacheKey = CacheKey.for(func);\n let cache = this.CACHES.get(cacheKey);\n if (cache == null) {\n // If not, create one...\n cache = new Map<string, string>();\n this.CACHES.set(cacheKey, cache);\n }\n\n // Check if the current cache has a value for this text...\n const cached = cache.get(text);\n if (cached != null) {\n return cached;\n }\n\n // If not, compute one...\n const result = func(text);\n cache.set(text, result);\n return result;\n }\n\n // Cache is indexed on a weak CacheKey so the cache can be purged under memory pressure\n private static readonly CACHES = new WeakMap<CacheKey, Map<string, string>>();\n\n private constructor() {}\n}\n\nclass CacheKey {\n public static for(data: any) {\n const entry = this.STORE.get(data)?.deref();\n if (entry != null) {\n return entry;\n }\n const newKey = new CacheKey();\n this.STORE.set(data, new WeakRef(newKey));\n return newKey;\n }\n\n // Storing cache keys as weak references to allow garbage collection if there is memory pressure.\n private static readonly STORE = new Map<any, WeakRef<CacheKey>>();\n\n private constructor() {}\n}\n"]}
package/lib/compiler.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import * as ts from 'typescript';
2
2
  import { Emitter } from './emitter';
3
3
  import { ProjectInfo } from './project-info';
4
- import { TypeScriptConfigValidationRuleSet } from './tsconfig';
5
4
  export declare const DIAGNOSTICS = "diagnostics";
6
5
  export declare const JSII_DIAGNOSTICS_CODE = 9999;
7
6
  export interface CompilerOptions {
@@ -20,38 +19,30 @@ export interface CompilerOptions {
20
19
  /** Whether to add warnings for deprecated elements */
21
20
  addDeprecationWarnings?: boolean;
22
21
  /**
23
- * The name of the tsconfig file to generate.
24
- * Cannot be used at the same time as `typeScriptConfig`.
22
+ * The name of the tsconfig file to generate
25
23
  * @default "tsconfig.json"
26
24
  */
27
25
  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
26
  /**
41
27
  * Whether to compress the assembly
42
28
  * @default false
43
29
  */
44
30
  compressAssembly?: boolean;
45
31
  }
32
+ export interface TypescriptConfig {
33
+ compilerOptions: ts.CompilerOptions;
34
+ include?: string[];
35
+ exclude?: string[];
36
+ references?: ts.ProjectReference[];
37
+ }
46
38
  export declare class Compiler implements Emitter {
47
39
  private readonly options;
48
40
  private readonly system;
49
41
  private readonly compilerHost;
50
- private readonly userProvidedTypeScriptConfig;
51
- private readonly tsconfig;
42
+ private typescriptConfig?;
52
43
  private rootFiles;
53
44
  private readonly configPath;
54
- private readonly projectRoot;
45
+ private readonly projectReferences;
55
46
  constructor(options: CompilerOptions);
56
47
  /**
57
48
  * Compiles the configured program.
@@ -70,33 +61,18 @@ export declare class Compiler implements Emitter {
70
61
  *
71
62
  * @param files the files that were specified as input in the CLI invocation.
72
63
  */
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;
64
+ private _prepareForBuild;
84
65
  /**
85
66
  * Do a single build
86
67
  */
87
- private buildOnce;
88
- private consumeProgram;
68
+ private _buildOnce;
69
+ private _consumeProgram;
89
70
  /**
90
- * Build the TypeScript config object from jsii config
71
+ * Build the TypeScript config object
91
72
  *
92
- * This is the object that will be written to disk
93
- * unless an existing tsconfig was provided.
73
+ * This is the object that will be written to disk.
94
74
  */
95
75
  private buildTypeScriptConfig;
96
- /**
97
- * Load the TypeScript config object from a provided file
98
- */
99
- private readTypeScriptConfig;
100
76
  /**
101
77
  * Creates a `tsconfig.json` file to improve the IDE experience.
102
78
  *
package/lib/compiler.js CHANGED
@@ -7,15 +7,34 @@ const chalk = require("chalk");
7
7
  const log4js = require("log4js");
8
8
  const ts = require("typescript");
9
9
  const assembler_1 = require("./assembler");
10
+ const Case = require("./case");
10
11
  const find_utils_1 = require("./common/find-utils");
11
12
  const downlevel_dts_1 = require("./downlevel-dts");
12
13
  const jsii_diagnostic_1 = require("./jsii-diagnostic");
13
14
  const deprecation_warnings_1 = require("./transforms/deprecation-warnings");
14
- const tsconfig_1 = require("./tsconfig");
15
- const compiler_options_1 = require("./tsconfig/compiler-options");
16
- const tsconfig_validator_1 = require("./tsconfig/tsconfig-validator");
17
- const validator_1 = require("./tsconfig/validator");
18
15
  const utils = require("./utils");
16
+ const BASE_COMPILER_OPTIONS = {
17
+ alwaysStrict: true,
18
+ declaration: true,
19
+ experimentalDecorators: true,
20
+ incremental: true,
21
+ lib: ['lib.es2020.d.ts'],
22
+ module: ts.ModuleKind.CommonJS,
23
+ noEmitOnError: true,
24
+ noFallthroughCasesInSwitch: true,
25
+ noImplicitAny: true,
26
+ noImplicitReturns: true,
27
+ noImplicitThis: true,
28
+ noUnusedLocals: true,
29
+ noUnusedParameters: true,
30
+ resolveJsonModule: true,
31
+ skipLibCheck: true,
32
+ strict: true,
33
+ strictNullChecks: true,
34
+ strictPropertyInitialization: true,
35
+ stripInternal: false,
36
+ target: ts.ScriptTarget.ES2020,
37
+ };
19
38
  const LOG = log4js.getLogger('jsii/compiler');
20
39
  exports.DIAGNOSTICS = 'diagnostics';
21
40
  exports.JSII_DIAGNOSTICS_CODE = 9999;
@@ -23,27 +42,28 @@ class Compiler {
23
42
  constructor(options) {
24
43
  this.options = options;
25
44
  this.rootFiles = [];
26
- if (options.generateTypeScriptConfig != null && options.typeScriptConfig != null) {
27
- throw new Error('Cannot use `generateTypeScriptConfig` and `typeScriptConfig` together. Provide only one of them.');
28
- }
29
- this.projectRoot = this.options.projectInfo.projectRoot;
30
- const configFileName = options.typeScriptConfig ?? options.generateTypeScriptConfig ?? 'tsconfig.json';
31
- this.configPath = path.join(this.projectRoot, configFileName);
32
- this.userProvidedTypeScriptConfig = Boolean(options.typeScriptConfig);
33
- this.tsconfig = this.configureTypeScript();
45
+ const rootDir = this.options.projectInfo.projectRoot;
34
46
  this.system = {
35
47
  ...ts.sys,
36
- getCurrentDirectory: () => this.projectRoot,
37
- createDirectory: (pth) => ts.sys.createDirectory(path.resolve(this.projectRoot, pth)),
38
- deleteFile: ts.sys.deleteFile && ((pth) => ts.sys.deleteFile(path.join(this.projectRoot, pth))),
39
- fileExists: (pth) => ts.sys.fileExists(path.resolve(this.projectRoot, pth)),
40
- getFileSize: ts.sys.getFileSize && ((pth) => ts.sys.getFileSize(path.resolve(this.projectRoot, pth))),
41
- readFile: (pth, encoding) => ts.sys.readFile(path.resolve(this.projectRoot, pth), encoding),
48
+ getCurrentDirectory: () => rootDir,
49
+ createDirectory: (pth) => ts.sys.createDirectory(path.resolve(rootDir, pth)),
50
+ deleteFile: ts.sys.deleteFile && ((pth) => ts.sys.deleteFile(path.join(rootDir, pth))),
51
+ fileExists: (pth) => ts.sys.fileExists(path.resolve(rootDir, pth)),
52
+ getFileSize: ts.sys.getFileSize && ((pth) => ts.sys.getFileSize(path.resolve(rootDir, pth))),
53
+ readFile: (pth, encoding) => ts.sys.readFile(path.resolve(rootDir, pth), encoding),
42
54
  watchFile: ts.sys.watchFile &&
43
- ((pth, callback, pollingInterval, watchOptions) => ts.sys.watchFile(path.resolve(this.projectRoot, pth), callback, pollingInterval, watchOptions)),
44
- writeFile: (pth, data, writeByteOrderMark) => ts.sys.writeFile(path.resolve(this.projectRoot, pth), data, writeByteOrderMark),
55
+ ((pth, callback, pollingInterval, watchOptions) => ts.sys.watchFile(path.resolve(rootDir, pth), callback, pollingInterval, watchOptions)),
56
+ writeFile: (pth, data, writeByteOrderMark) => ts.sys.writeFile(path.resolve(rootDir, pth), data, writeByteOrderMark),
45
57
  };
46
- this.compilerHost = ts.createIncrementalCompilerHost(this.tsconfig.compilerOptions, this.system);
58
+ this.compilerHost = ts.createIncrementalCompilerHost(BASE_COMPILER_OPTIONS, this.system);
59
+ const configFileName = options.generateTypeScriptConfig ?? 'tsconfig.json';
60
+ this.configPath = path.join(this.options.projectInfo.projectRoot, configFileName);
61
+ this.projectReferences =
62
+ options.projectReferences !== undefined
63
+ ? options.projectReferences
64
+ : options.projectInfo.projectReferences !== undefined
65
+ ? options.projectInfo.projectReferences
66
+ : false;
47
67
  }
48
68
  /**
49
69
  * Compiles the configured program.
@@ -51,15 +71,18 @@ class Compiler {
51
71
  * @param files can be specified to override the standard source code location logic. Useful for example when testing "negatives".
52
72
  */
53
73
  emit(...files) {
54
- this.prepareForBuild(...files);
55
- return this.buildOnce();
74
+ this._prepareForBuild(...files);
75
+ return this._buildOnce();
56
76
  }
57
77
  async watch(opts) {
58
- this.prepareForBuild();
78
+ this._prepareForBuild();
79
+ const pi = this.options.projectInfo;
80
+ const projectRoot = pi.projectRoot;
59
81
  const host = ts.createWatchCompilerHost(this.configPath, {
60
- ...this.tsconfig.compilerOptions,
82
+ ...pi.tsc,
83
+ ...BASE_COMPILER_OPTIONS,
61
84
  noEmitOnError: false,
62
- }, this.system, ts.createEmitAndSemanticDiagnosticsBuilderProgram, opts?.reportDiagnostics, opts?.reportWatchStatus, this.tsconfig.watchOptions);
85
+ }, this.system, ts.createEmitAndSemanticDiagnosticsBuilderProgram, opts?.reportDiagnostics, opts?.reportWatchStatus);
63
86
  if (!host.getDefaultLibLocation) {
64
87
  throw new Error('No default library location was found on the TypeScript compiler host!');
65
88
  }
@@ -69,9 +92,9 @@ class Compiler {
69
92
  //
70
93
  // eslint-disable-next-line @typescript-eslint/no-misused-promises
71
94
  host.afterProgramCreate = (builderProgram) => {
72
- const emitResult = this.consumeProgram(builderProgram.getProgram(), host.getDefaultLibLocation());
95
+ const emitResult = this._consumeProgram(builderProgram.getProgram(), host.getDefaultLibLocation());
73
96
  for (const diag of emitResult.diagnostics.filter((d) => d.code === exports.JSII_DIAGNOSTICS_CODE)) {
74
- utils.logDiagnostic(diag, this.projectRoot);
97
+ utils.logDiagnostic(diag, projectRoot);
75
98
  }
76
99
  if (orig) {
77
100
  orig.call(host, builderProgram);
@@ -94,72 +117,35 @@ class Compiler {
94
117
  *
95
118
  * @param files the files that were specified as input in the CLI invocation.
96
119
  */
97
- configureTypeScript() {
98
- if (this.userProvidedTypeScriptConfig) {
99
- const config = this.readTypeScriptConfig();
100
- // emit a warning if validation is disabled
101
- const rules = this.options.validateTypeScriptConfig ?? tsconfig_1.TypeScriptConfigValidationRuleSet.NONE;
102
- if (rules === tsconfig_1.TypeScriptConfigValidationRuleSet.NONE) {
103
- utils.logDiagnostic(jsii_diagnostic_1.JsiiDiagnostic.JSII_4009_DISABLED_TSCONFIG_VALIDATION.create(undefined, this.configPath), this.projectRoot);
104
- }
105
- // validate the user provided config
106
- if (rules !== tsconfig_1.TypeScriptConfigValidationRuleSet.NONE) {
107
- const configName = path.relative(this.projectRoot, this.configPath);
108
- try {
109
- const validator = new tsconfig_validator_1.TypeScriptConfigValidator(rules);
110
- validator.validate({
111
- ...config,
112
- // convert the internal format to the user format which is what the validator operates on
113
- compilerOptions: (0, compiler_options_1.convertForJson)(config.compilerOptions),
114
- });
115
- }
116
- catch (error) {
117
- if (error instanceof validator_1.ValidationError) {
118
- utils.logDiagnostic(jsii_diagnostic_1.JsiiDiagnostic.JSII_4000_FAILED_TSCONFIG_VALIDATION.create(undefined, configName, rules, error.violations), this.projectRoot);
119
- }
120
- throw new Error(`Failed validation of tsconfig "compilerOptions" in "${configName}" against rule set "${rules}"!`);
121
- }
122
- }
123
- return config;
124
- }
125
- // generated config if none is provided by the user
126
- return this.buildTypeScriptConfig();
127
- }
128
- /**
129
- * Final preparations of the project for build.
130
- *
131
- * These are preparations that either
132
- * - must happen immediately before the build, or
133
- * - can be different for every build like assigning the relevant root file(s).
134
- *
135
- * @param files the files that were specified as input in the CLI invocation.
136
- */
137
- prepareForBuild(...files) {
138
- if (!this.userProvidedTypeScriptConfig) {
139
- this.writeTypeScriptConfig();
140
- }
120
+ _prepareForBuild(...files) {
121
+ this.buildTypeScriptConfig();
122
+ this.writeTypeScriptConfig();
141
123
  this.rootFiles = this.determineSources(files);
142
124
  }
143
125
  /**
144
126
  * Do a single build
145
127
  */
146
- buildOnce() {
128
+ _buildOnce() {
147
129
  if (!this.compilerHost.getDefaultLibLocation) {
148
130
  throw new Error('No default library location was found on the TypeScript compiler host!');
149
131
  }
150
- const tsconf = this.tsconfig;
132
+ const tsconf = this.typescriptConfig;
133
+ const pi = this.options.projectInfo;
151
134
  const prog = ts.createIncrementalProgram({
152
135
  rootNames: this.rootFiles.concat(_pathOfLibraries(this.compilerHost)),
153
- options: tsconf.compilerOptions,
136
+ options: {
137
+ ...pi.tsc,
138
+ ...(tsconf?.compilerOptions ?? BASE_COMPILER_OPTIONS),
139
+ },
154
140
  // Make the references absolute for the compiler
155
141
  projectReferences: tsconf.references?.map((ref) => ({
156
142
  path: path.resolve(path.dirname(this.configPath), ref.path),
157
143
  })),
158
144
  host: this.compilerHost,
159
145
  });
160
- return this.consumeProgram(prog.getProgram(), this.compilerHost.getDefaultLibLocation());
146
+ return this._consumeProgram(prog.getProgram(), this.compilerHost.getDefaultLibLocation());
161
147
  }
162
- consumeProgram(program, stdlib) {
148
+ _consumeProgram(program, stdlib) {
163
149
  const diagnostics = [...ts.getPreEmitDiagnostics(program)];
164
150
  let hasErrors = false;
165
151
  if (!hasErrors && this.diagsHaveAbortableErrors(diagnostics)) {
@@ -219,28 +205,22 @@ class Compiler {
219
205
  };
220
206
  }
221
207
  /**
222
- * Build the TypeScript config object from jsii config
208
+ * Build the TypeScript config object
223
209
  *
224
- * This is the object that will be written to disk
225
- * unless an existing tsconfig was provided.
210
+ * This is the object that will be written to disk.
226
211
  */
227
212
  buildTypeScriptConfig() {
228
213
  let references;
229
- const isComposite = this.options.projectReferences !== undefined
230
- ? this.options.projectReferences
231
- : this.options.projectInfo.projectReferences !== undefined
232
- ? this.options.projectInfo.projectReferences
233
- : false;
234
- if (isComposite) {
214
+ if (this.projectReferences) {
235
215
  references = this.findProjectReferences();
236
216
  }
237
217
  const pi = this.options.projectInfo;
238
- return {
218
+ this.typescriptConfig = {
239
219
  compilerOptions: {
240
220
  ...pi.tsc,
241
- ...compiler_options_1.BASE_COMPILER_OPTIONS,
221
+ ...BASE_COMPILER_OPTIONS,
242
222
  // Enable composite mode if project references are enabled
243
- composite: isComposite,
223
+ composite: this.projectReferences,
244
224
  // When incremental, configure a tsbuildinfo file
245
225
  tsBuildInfoFile: path.join(pi.tsc?.outDir ?? '.', 'tsconfig.tsbuildinfo'),
246
226
  },
@@ -261,25 +241,6 @@ class Compiler {
261
241
  references: references?.map((p) => ({ path: p })),
262
242
  };
263
243
  }
264
- /**
265
- * Load the TypeScript config object from a provided file
266
- */
267
- readTypeScriptConfig() {
268
- const projectRoot = this.options.projectInfo.projectRoot;
269
- const { config, error } = ts.readConfigFile(this.configPath, ts.sys.readFile);
270
- if (error) {
271
- utils.logDiagnostic(error, projectRoot);
272
- throw new Error(`Failed to load tsconfig at ${this.configPath}`);
273
- }
274
- const extended = ts.parseJsonConfigFileContent(config, ts.sys, projectRoot);
275
- // the tsconfig parser adds this in, but it is not an expected compilerOption
276
- delete extended.options.configFilePath;
277
- return {
278
- compilerOptions: extended.options,
279
- watchOptions: extended.watchOptions,
280
- include: extended.fileNames,
281
- };
282
- }
283
244
  /**
284
245
  * Creates a `tsconfig.json` file to improve the IDE experience.
285
246
  *
@@ -288,7 +249,7 @@ class Compiler {
288
249
  writeTypeScriptConfig() {
289
250
  const commentKey = '_generated_by_jsii_';
290
251
  const commentValue = 'Generated by jsii - safe to delete, and ideally should be in .gitignore';
291
- this.tsconfig[commentKey] = commentValue;
252
+ this.typescriptConfig[commentKey] = commentValue;
292
253
  if (fs.existsSync(this.configPath)) {
293
254
  const currentConfig = JSON.parse(fs.readFileSync(this.configPath, 'utf-8'));
294
255
  if (!(commentKey in currentConfig)) {
@@ -296,11 +257,43 @@ class Compiler {
296
257
  }
297
258
  }
298
259
  const outputConfig = {
299
- ...this.tsconfig,
300
- compilerOptions: (0, compiler_options_1.convertForJson)(this.tsconfig?.compilerOptions),
260
+ ...this.typescriptConfig,
261
+ compilerOptions: {
262
+ ...this.typescriptConfig?.compilerOptions,
263
+ lib: this.typescriptConfig?.compilerOptions?.lib?.map((lib) =>
264
+ // Drop the "lib." prefix and ".d.ts" suffix before writing up the tsconfig.json file
265
+ lib.slice(4, lib.length - 5)),
266
+ // Re-write the module, targets & jsx to be the JSON format instead of Programmatic API
267
+ module: (this.typescriptConfig?.compilerOptions?.module &&
268
+ ts.ModuleKind[this.typescriptConfig.compilerOptions.module]),
269
+ newLine: newLineForTsconfigJson(this.typescriptConfig?.compilerOptions.newLine),
270
+ target: (this.typescriptConfig?.compilerOptions?.target &&
271
+ ts.ScriptTarget[this.typescriptConfig.compilerOptions.target]),
272
+ jsx: (this.typescriptConfig?.compilerOptions?.jsx &&
273
+ Case.snake(ts.JsxEmit[this.typescriptConfig.compilerOptions.jsx])),
274
+ },
301
275
  };
302
276
  LOG.debug(`Creating or updating ${chalk.blue(this.configPath)}`);
303
277
  fs.writeFileSync(this.configPath, JSON.stringify(outputConfig, null, 2), 'utf8');
278
+ /**
279
+ * This is annoying - the values expected in the tsconfig.json file are not
280
+ * the same as the enum constant names, or their values. So we need this
281
+ * function to map the "compiler API version" to the "tsconfig.json version"
282
+ *
283
+ * @param newLine the compiler form of the new line configuration
284
+ *
285
+ * @return the requivalent value to put in tsconfig.json
286
+ */
287
+ function newLineForTsconfigJson(newLine) {
288
+ switch (newLine) {
289
+ case ts.NewLineKind.CarriageReturnLineFeed:
290
+ return 'crlf';
291
+ case ts.NewLineKind.LineFeed:
292
+ return 'lf';
293
+ default:
294
+ return undefined;
295
+ }
296
+ }
304
297
  }
305
298
  /**
306
299
  * Find all dependencies that look like TypeScript projects.
@@ -353,18 +346,16 @@ class Compiler {
353
346
  * This makes it so that running 'typescript' and running 'jsii' has the same behavior.
354
347
  */
355
348
  determineSources(files) {
356
- // explicitly requested files
349
+ const ret = new Array();
357
350
  if (files.length > 0) {
358
- return [...files];
351
+ ret.push(...files);
359
352
  }
360
- // for user provided config we already have parsed the full list of files
361
- if (this.userProvidedTypeScriptConfig) {
362
- return [...(this.tsconfig.include ?? [])];
353
+ else {
354
+ const parseConfigHost = parseConfigHostFromCompilerHost(this.compilerHost);
355
+ const parsed = ts.parseJsonConfigFileContent(this.typescriptConfig, parseConfigHost, this.options.projectInfo.projectRoot);
356
+ ret.push(...parsed.fileNames);
363
357
  }
364
- // finally get the file list for the generated config
365
- const parseConfigHost = parseConfigHostFromCompilerHost(this.compilerHost);
366
- const parsed = ts.parseJsonConfigFileContent(this.tsconfig, parseConfigHost, this.options.projectInfo.projectRoot);
367
- return [...parsed.fileNames];
358
+ return ret;
368
359
  }
369
360
  /**
370
361
  * Resolve the given dependency name from the current package, and find the associated tsconfig.json location
@@ -414,14 +405,14 @@ class Compiler {
414
405
  }
415
406
  exports.Compiler = Compiler;
416
407
  function _pathOfLibraries(host) {
417
- if (!compiler_options_1.BASE_COMPILER_OPTIONS.lib || compiler_options_1.BASE_COMPILER_OPTIONS.lib.length === 0) {
408
+ if (!BASE_COMPILER_OPTIONS.lib || BASE_COMPILER_OPTIONS.lib.length === 0) {
418
409
  return [];
419
410
  }
420
411
  const lib = host.getDefaultLibLocation?.();
421
412
  if (!lib) {
422
- throw new Error(`Compiler host doesn't have a default library directory available for ${compiler_options_1.BASE_COMPILER_OPTIONS.lib.join(', ')}`);
413
+ throw new Error(`Compiler host doesn't have a default library directory available for ${BASE_COMPILER_OPTIONS.lib.join(', ')}`);
423
414
  }
424
- return compiler_options_1.BASE_COMPILER_OPTIONS.lib.map((name) => path.join(lib, name));
415
+ return BASE_COMPILER_OPTIONS.lib.map((name) => path.join(lib, name));
425
416
  }
426
417
  function parseConfigHostFromCompilerHost(host) {
427
418
  // Copied from upstream