jsii 6.0.21 → 7.1.0-dev.1

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 (107) hide show
  1. package/lib/assembler.d.ts +254 -196
  2. package/lib/assembler.js +2105 -2327
  3. package/lib/assembler.js.map +1 -1
  4. package/lib/case.js.map +1 -1
  5. package/lib/common/find-utils.js.map +1 -1
  6. package/lib/common/index.d.ts +1 -1
  7. package/lib/common/index.js +2 -1
  8. package/lib/common/index.js.map +1 -1
  9. package/lib/common/symbol-id.d.ts +23 -4
  10. package/lib/common/symbol-id.js +13 -9
  11. package/lib/common/symbol-id.js.map +1 -1
  12. package/lib/compiler-host.d.ts +60 -0
  13. package/lib/compiler-host.js +201 -0
  14. package/lib/compiler-host.js.map +1 -0
  15. package/lib/compiler.d.ts +74 -62
  16. package/lib/compiler.js +332 -254
  17. package/lib/compiler.js.map +1 -1
  18. package/lib/diagnostic.d.ts +34 -0
  19. package/lib/diagnostic.js +141 -0
  20. package/lib/diagnostic.js.map +1 -0
  21. package/lib/emitter.d.ts +40 -10
  22. package/lib/emitter.js +188 -0
  23. package/lib/emitter.js.map +1 -1
  24. package/lib/helpers.d.ts +1 -1
  25. package/lib/helpers.js +2 -2
  26. package/lib/helpers.js.map +1 -1
  27. package/lib/index.js.map +1 -1
  28. package/lib/jsii-diagnostic.d.ts +27 -22
  29. package/lib/jsii-diagnostic.js +22 -38
  30. package/lib/jsii-diagnostic.js.map +1 -1
  31. package/lib/literate.js.map +1 -1
  32. package/lib/main.js +3 -2
  33. package/lib/main.js.map +1 -1
  34. package/lib/project-info.d.ts +23 -4
  35. package/lib/project-info.js +5 -5
  36. package/lib/project-info.js.map +1 -1
  37. package/lib/support-types.d.ts +2 -0
  38. package/lib/support-types.js +3 -0
  39. package/lib/support-types.js.map +1 -0
  40. package/lib/support.js.map +1 -1
  41. package/lib/tsconfig/compiler-options.d.ts +12 -46
  42. package/lib/tsconfig/compiler-options.js +45 -87
  43. package/lib/tsconfig/compiler-options.js.map +1 -1
  44. package/lib/tsconfig/index.d.ts +24 -5
  45. package/lib/tsconfig/index.js.map +1 -1
  46. package/lib/tsconfig/read.d.ts +15 -0
  47. package/lib/tsconfig/read.js +196 -0
  48. package/lib/tsconfig/read.js.map +1 -0
  49. package/lib/tsconfig/rule-set-format.js.map +1 -1
  50. package/lib/tsconfig/rulesets/configurable-options.js.map +1 -1
  51. package/lib/tsconfig/rulesets/deprecated-options.js.map +1 -1
  52. package/lib/tsconfig/rulesets/generated.public.js.map +1 -1
  53. package/lib/tsconfig/rulesets/incompatible-options.js.map +1 -1
  54. package/lib/tsconfig/rulesets/jsii-configured-options.js.map +1 -1
  55. package/lib/tsconfig/rulesets/minimal.public.js.map +1 -1
  56. package/lib/tsconfig/rulesets/strict-family-options.js.map +1 -1
  57. package/lib/tsconfig/rulesets/strict.public.js.map +1 -1
  58. package/lib/tsconfig/tsconfig-validator.js +2 -50
  59. package/lib/tsconfig/tsconfig-validator.js.map +1 -1
  60. package/lib/tsconfig/validator.js.map +1 -1
  61. package/lib/type-analysis.js.map +1 -1
  62. package/lib/type-reference.js.map +1 -1
  63. package/lib/type-visitor.js.map +1 -1
  64. package/lib/utils.d.ts +6 -6
  65. package/lib/utils.js +8 -13
  66. package/lib/utils.js.map +1 -1
  67. package/lib/version.d.ts +3 -3
  68. package/lib/version.js +4 -4
  69. package/lib/version.js.map +1 -1
  70. package/lib/warnings.d.ts +2 -2
  71. package/lib/warnings.js +3 -77
  72. package/lib/warnings.js.map +1 -1
  73. package/package.json +15 -10
  74. package/scripts/ts7-compare-jsii.mjs +101 -0
  75. package/lib/directives.d.ts +0 -24
  76. package/lib/directives.js +0 -139
  77. package/lib/directives.js.map +0 -1
  78. package/lib/docs.d.ts +0 -64
  79. package/lib/docs.js +0 -293
  80. package/lib/docs.js.map +0 -1
  81. package/lib/node-bindings.d.ts +0 -19
  82. package/lib/node-bindings.js +0 -49
  83. package/lib/node-bindings.js.map +0 -1
  84. package/lib/reserved-words.d.ts +0 -6
  85. package/lib/reserved-words.js +0 -258
  86. package/lib/reserved-words.js.map +0 -1
  87. package/lib/sets.d.ts +0 -16
  88. package/lib/sets.js +0 -41
  89. package/lib/sets.js.map +0 -1
  90. package/lib/transforms/deprecated-remover.d.ts +0 -44
  91. package/lib/transforms/deprecated-remover.js +0 -545
  92. package/lib/transforms/deprecated-remover.js.map +0 -1
  93. package/lib/transforms/deprecation-warnings.d.ts +0 -37
  94. package/lib/transforms/deprecation-warnings.js +0 -616
  95. package/lib/transforms/deprecation-warnings.js.map +0 -1
  96. package/lib/transforms/runtime-info.d.ts +0 -39
  97. package/lib/transforms/runtime-info.js +0 -128
  98. package/lib/transforms/runtime-info.js.map +0 -1
  99. package/lib/transforms/utils.d.ts +0 -11
  100. package/lib/transforms/utils.js +0 -31
  101. package/lib/transforms/utils.js.map +0 -1
  102. package/lib/type-tracker.d.ts +0 -13
  103. package/lib/type-tracker.js +0 -67
  104. package/lib/type-tracker.js.map +0 -1
  105. package/lib/validator.d.ts +0 -19
  106. package/lib/validator.js +0 -602
  107. package/lib/validator.js.map +0 -1
package/lib/case.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"case.js","sourceRoot":"","sources":["../src/case.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AAExB,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,cAAI,CAAC,KAAK,CAAC,CAAC;AAC9B,QAAA,QAAQ,GAAG,SAAS,CAAC,cAAI,CAAC,QAAQ,CAAC,CAAC;AACpC,QAAA,MAAM,GAAG,SAAS,CAAC,cAAI,CAAC,MAAM,CAAC,CAAC;AAChC,QAAA,KAAK,GAAG,SAAS,CAAC,cAAI,CAAC,KAAK,CAAC,CAAC;AAC9B,QAAA,KA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AAC,MAAM,CAAC,CAAC,CAAC;QAC1C,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,iGAAiG;IACzF,MAAM,CAAU,KAAK,GAAG,IAAI,GAAG,EAA0B,CAAC;IAElE,gBAAuB,CAAC","sourcesContent":["import 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","sources":["../src/case.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AAExB,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,cAAI,CA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AAG,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;IAED,iGAAiG;IACzF,MAAM,CAAU,KAAK,GAAG,IAAI,GAAG,EAA0B,CAAC;IAElE,gBAAuB,CAAC;CACzB","sourcesContent":["import 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 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6E;IAC7E,MAAM,cAAc,GAAG,iBAAiB,CAAC,cAAc,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;IAEnF,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,MAAM,IAAI,iBAAS,CAAC,8BAA8B,cAAc,WAAW,WAAW,GAAG,CAAC,CAAC;IAC7F,CAAC;IAED,OAAO,cAAc,CAAC;AACxB,CAAC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { JsiiError } from '../utils';\n\n/**\n * Find a directory up the tree from a starting directory matching a condition\n *\n * Will return `undefined` if no directory matches\n *\n * (This code is duplicated among jsii/jsii-pacmak/jsii-reflect. Changes should be done in all\n * 3 locations, and we should unify these at some point: https://github.com/aws/jsii/issues/3236)\n */\nexport function findUp(directory: string, pred: (dir: string) => boolean): string | undefined {\n const result = pred(directory);\n\n if (result) {\n return directory;\n }\n\n const parent = path.dirname(directory);\n if (parent === directory) {\n return undefined;\n }\n\n return findUp(parent, pred);\n}\n\n/**\n * Find the package.json for a given package upwards from the given directory\n *\n * (This code is duplicated among jsii/jsii-pacmak/jsii-reflect. Changes should be done in all\n * 3 locations, and we should unify these at some point: https://github.com/aws/jsii/issues/3236)\n */\nexport function findPackageJsonUp(packageName: string, directory: string) {\n return findUp(directory, (dir) => {\n const pjFile = path.join(dir, 'package.json');\n return fs.existsSync(pjFile) && JSON.parse(fs.readFileSync(pjFile, 'utf-8')).name === packageName;\n });\n}\n\n/**\n * Find the directory that contains a given dependency, identified by its 'package.json', from a starting search directory\n *\n * (This code is duplicated among jsii/jsii-pacmak/jsii-reflect. Changes should be done in all\n * 3 locations, and we should unify these at some point: https://github.com/aws/jsii/issues/3236)\n */\nexport function findDependencyDirectory(dependencyName: string, searchStart: string) {\n // Explicitly do not use 'require(\"dep/package.json\")' because that will fail if the\n // package does not export that particular file.\n const entryPoint = require.resolve(dependencyName, {\n paths: [searchStart],\n });\n\n // Search up from the given directory, looking for a package.json that matches\n // the dependency name (so we don't accidentally find stray 'package.jsons').\n const depPkgJsonPath = findPackageJsonUp(dependencyName, path.dirname(entryPoint));\n\n if (!depPkgJsonPath) {\n throw new JsiiError(`Could not find dependency '${dependencyName}' from '${searchStart}'`);\n }\n\n return depPkgJsonPath;\n}\n"]}
1
+ {"version":3,"file":"find-utils.js","sources":["../../src/common/find-utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAY,EAAE,oCAAgB;AAC9B,MAAY,IAAI,sCAAkB;AAClC,oCAAqC;AAErC;;;;;;;GAOG;AACH,gBAAuB,SAAiB,EAAE,IAA8B;IACtE,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC;IAE/B,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACvC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAC9B,CAAC;AAED;;;;;GAKG;AACH,2BAAkC,WAAmB,EAAE,SAAiB;IACtE,OAAO,MAAM,CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,EAAE;QAC/B,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;QAC9C,OAAO,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC;IACpG,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,iCAAwC,cAAsB,EAAE,WAAmB;IACjF,oFAAoF;IACpF,gDAAgD;IAChD,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,cAAc,EAAE;QACjD,KAAK,EAAE,CAAC,WAAW,CAAC;KACrB,CAAC,CAAC;IAEH,8EAA8E;IAC9E,6EAA6E;IAC7E,MAAM,cAAc,GAAG,iBAAiB,CAAC,cAAc,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;IAEnF,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,MAAM,IAAI,iBAAS,CAAC,8BAA8B,cAAc,WAAW,WAAW,GAAG,CAAC,CAAC;IAC7F,CAAC;IAED,OAAO,cAAc,CAAC;AACxB,CAAC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { JsiiError } from '../utils';\n\n/**\n * Find a directory up the tree from a starting directory matching a condition\n *\n * Will return `undefined` if no directory matches\n *\n * (This code is duplicated among jsii/jsii-pacmak/jsii-reflect. Changes should be done in all\n * 3 locations, and we should unify these at some point: https://github.com/aws/jsii/issues/3236)\n */\nexport function findUp(directory: string, pred: (dir: string) => boolean): string | undefined {\n const result = pred(directory);\n\n if (result) {\n return directory;\n }\n\n const parent = path.dirname(directory);\n if (parent === directory) {\n return undefined;\n }\n\n return findUp(parent, pred);\n}\n\n/**\n * Find the package.json for a given package upwards from the given directory\n *\n * (This code is duplicated among jsii/jsii-pacmak/jsii-reflect. Changes should be done in all\n * 3 locations, and we should unify these at some point: https://github.com/aws/jsii/issues/3236)\n */\nexport function findPackageJsonUp(packageName: string, directory: string) {\n return findUp(directory, (dir) => {\n const pjFile = path.join(dir, 'package.json');\n return fs.existsSync(pjFile) && JSON.parse(fs.readFileSync(pjFile, 'utf-8')).name === packageName;\n });\n}\n\n/**\n * Find the directory that contains a given dependency, identified by its 'package.json', from a starting search directory\n *\n * (This code is duplicated among jsii/jsii-pacmak/jsii-reflect. Changes should be done in all\n * 3 locations, and we should unify these at some point: https://github.com/aws/jsii/issues/3236)\n */\nexport function findDependencyDirectory(dependencyName: string, searchStart: string) {\n // Explicitly do not use 'require(\"dep/package.json\")' because that will fail if the\n // package does not export that particular file.\n const entryPoint = require.resolve(dependencyName, {\n paths: [searchStart],\n });\n\n // Search up from the given directory, looking for a package.json that matches\n // the dependency name (so we don't accidentally find stray 'package.jsons').\n const depPkgJsonPath = findPackageJsonUp(dependencyName, path.dirname(entryPoint));\n\n if (!depPkgJsonPath) {\n throw new JsiiError(`Could not find dependency '${dependencyName}' from '${searchStart}'`);\n }\n\n return depPkgJsonPath;\n}\n"]}
@@ -1,2 +1,2 @@
1
- export { symbolIdentifier } from './symbol-id';
1
+ export { normalizePath, symbolIdentifier, type SymbolIdChecker, type SymbolIdOptions, type SymbolIdSymbol, } from './symbol-id';
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.symbolIdentifier = void 0;
3
+ exports.symbolIdentifier = exports.normalizePath = void 0;
4
4
  var symbol_id_1 = require("./symbol-id");
5
+ Object.defineProperty(exports, "normalizePath", { enumerable: true, get: function () { return symbol_id_1.normalizePath; } });
5
6
  Object.defineProperty(exports, "symbolIdentifier", { enumerable: true, get: function () { return symbol_id_1.symbolIdentifier; } });
6
7
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":";;;AAAA,yCAA+C;AAAtC,6GAAA,gBAAgB,OAAA","sourcesContent":["export { symbolIdentifier } from './symbol-id';\n"]}
1
+ {"version":3,"file":"index.js","sources":["../../src/common/index.ts"],"names":[],"mappings":";;;AAAA,yCAMqB;AALnB,0GAAA,aAAa,OAAA;AACb,6GAAA,gBAAgB,OAAA","sourcesContent":["export {\n normalizePath,\n symbolIdentifier,\n type SymbolIdChecker,\n type SymbolIdOptions,\n type SymbolIdSymbol,\n} from './symbol-id';\n"]}
@@ -1,9 +1,8 @@
1
1
  import type { Assembly } from '@jsii/spec';
2
- import * as ts from 'typescript';
3
2
  /**
4
3
  * Additional options that may be provided to the symbolIdentifier.
5
4
  */
6
- interface SymbolIdOptions {
5
+ export interface SymbolIdOptions {
7
6
  /**
8
7
  * The assembly that the symbol is found in.
9
8
  * This is used to provide the correct root directory
@@ -13,6 +12,27 @@ interface SymbolIdOptions {
13
12
  */
14
13
  readonly assembly?: Assembly;
15
14
  }
15
+ /**
16
+ * The part of a TypeScript symbol `symbolIdentifier` needs.
17
+ *
18
+ * This is a structural type so that both the classic in-process `ts.Symbol`
19
+ * (as used by jsii-rosetta) and the symbol handles of the TypeScript 7
20
+ * programmatic API satisfy it.
21
+ */
22
+ export interface SymbolIdSymbol {
23
+ /** The `SymbolFlags` bit set of the symbol. */
24
+ readonly flags: number;
25
+ }
26
+ /**
27
+ * The part of a TypeScript type checker `symbolIdentifier` needs.
28
+ *
29
+ * Structurally satisfied by the classic `ts.TypeChecker` and by the TypeScript 7
30
+ * `Checker`, so callers can keep passing whichever checker they drive.
31
+ */
32
+ export interface SymbolIdChecker<S extends SymbolIdSymbol = SymbolIdSymbol> {
33
+ getAliasedSymbol(symbol: S): S;
34
+ getFullyQualifiedName(symbol: S): string;
35
+ }
16
36
  /**
17
37
  * Return a symbol identifier for the given symbol
18
38
  *
@@ -41,7 +61,7 @@ interface SymbolIdOptions {
41
61
  * Whoops ^_^ (this historical accident is why the format is similar to but
42
62
  * different from what the TS checker returns).
43
63
  */
44
- export declare function symbolIdentifier(typeChecker: ts.TypeChecker, sym: ts.Symbol | undefined, options?: SymbolIdOptions): string | undefined;
64
+ export declare function symbolIdentifier<S extends SymbolIdSymbol>(typeChecker: SymbolIdChecker<S>, sym: S | undefined, options?: SymbolIdOptions): string | undefined;
45
65
  /**
46
66
  * Ensures that the sourcePath is pointing to the source code
47
67
  * and not compiled code. This can happen if the root directory
@@ -50,5 +70,4 @@ export declare function symbolIdentifier(typeChecker: ts.TypeChecker, sym: ts.Sy
50
70
  * we replace it with the root directory.
51
71
  */
52
72
  export declare function normalizePath(sourcePath: string, rootDir?: string, outDir?: string): string;
53
- export {};
54
73
  //# sourceMappingURL=symbol-id.d.ts.map
@@ -37,8 +37,18 @@ exports.symbolIdentifier = symbolIdentifier;
37
37
  exports.normalizePath = normalizePath;
38
38
  const fs = __importStar(require("node:fs"));
39
39
  const path = __importStar(require("node:path"));
40
- const ts = __importStar(require("typescript"));
41
40
  const find_utils_1 = require("./find-utils");
41
+ /**
42
+ * The `SymbolFlags` values `symbolIdentifier` tests for. They are identical in
43
+ * the classic compiler and in the TypeScript 7 `typescript/ast` module, which
44
+ * lets this function stay independent from either package.
45
+ */
46
+ const SYMBOL_FLAGS = {
47
+ Property: 4,
48
+ EnumMember: 8,
49
+ Method: 8192,
50
+ Alias: 2097152,
51
+ };
42
52
  /**
43
53
  * Return a symbol identifier for the given symbol
44
54
  *
@@ -73,18 +83,12 @@ function symbolIdentifier(typeChecker, sym, options = {}) {
73
83
  }
74
84
  // If this symbol happens to be an alias, resolve it first
75
85
  // eslint-disable-next-line no-bitwise
76
- while ((sym.flags & ts.SymbolFlags.Alias) !== 0) {
86
+ while ((sym.flags & SYMBOL_FLAGS.Alias) !== 0) {
77
87
  sym = typeChecker.getAliasedSymbol(sym);
78
88
  }
79
89
  const isMember =
80
90
  // eslint-disable-next-line no-bitwise
81
- (sym.flags &
82
- // eslint-disable-next-line no-bitwise
83
- (ts.SymbolFlags.Method |
84
- // eslint-disable-next-line no-bitwise
85
- ts.SymbolFlags.Property |
86
- ts.SymbolFlags.EnumMember)) !==
87
- 0;
91
+ (sym.flags & (SYMBOL_FLAGS.Method | SYMBOL_FLAGS.Property | SYMBOL_FLAGS.EnumMember)) !== 0;
88
92
  const tsName = typeChecker.getFullyQualifiedName(sym);
89
93
  // TypeScript fqn looks like "/path/to/file"[.name.in.file]
90
94
  const groups = /^"([^"]+)"(?:\.(.*))?$/.exec(tsName);
@@ -1 +1 @@
1
- {"version":3,"file":"symbol-id.js","sourceRoot":"","sources":["../../src/common/symbol-id.ts"],"names":[],"mappings":";;;;;;;;;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AI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAE5D,IAAI,MAAM,KAAK,OAAO,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;QACzC,wDAAwD;QACxD,qCAAqC;QACrC,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;YACnB,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;QACpC,CAAC;QACD,UAAU,GAAG,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IACnF,CAAC;IACD,OAAO,OAAO,CAAC,UAAU,CAAC,CAAC;IAE3B,SAAS,cAAc,CAAC,QAAgB;QACtC,OAAO,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;IACzF,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,OAAO,CAAC,CAAS;IACxB,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAC/B,CAAC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport type { Assembly } from '@jsii/spec';\nimport * as ts from 'typescript';\n\nimport { findUp } from './find-utils';\n\n/**\n * Additional options that may be provided to the symbolIdentifier.\n */\ninterface SymbolIdOptions {\n /**\n * The assembly that the symbol is found in.\n * This is used to provide the correct root directory\n * as specified in the assembly metadata. In turn,\n * the root directory is used to ensure that the\n * symbolId comes from source code and not compiled code.\n */\n readonly assembly?: Assembly;\n}\n\n/**\n * Return a symbol identifier for the given symbol\n *\n * The symbol identifier identifies a TypeScript symbol in a source file inside\n * a package. We can use this to map between jsii entries in the manifest, and\n * entities in the TypeScript source code.\n *\n * Going via symbol id is the only way to identify symbols in submodules. Otherwise,\n * all the TypeScript compiler sees is:\n *\n * ```\n * /my/package/lib/source/directory/dist.js <containing> MyClass\n * ```\n *\n * And there's no way to figure out what submodule name\n * `lib/source/directory/dist` is exported as.\n *\n * The format of a symbol id is:\n *\n * ```\n * relative/source/file:Name.space.Class[#member]\n * ```\n *\n * We used to build this identifier ourselves. Turns out there was a built-in\n * way to get pretty much the same, by calling `typeChecker.getFullyQualifiedName()`.\n * Whoops ^_^ (this historical accident is why the format is similar to but\n * different from what the TS checker returns).\n */\nexport function symbolIdentifier(\n typeChecker: ts.TypeChecker,\n sym: ts.Symbol | undefined,\n options: SymbolIdOptions = {},\n): string | undefined {\n if (!sym) {\n return undefined;\n }\n\n // If this symbol happens to be an alias, resolve it first\n // eslint-disable-next-line no-bitwise\n while ((sym.flags & ts.SymbolFlags.Alias) !== 0) {\n sym = typeChecker.getAliasedSymbol(sym);\n }\n\n const isMember =\n // eslint-disable-next-line no-bitwise\n (sym.flags &\n // eslint-disable-next-line no-bitwise\n (ts.SymbolFlags.Method |\n // eslint-disable-next-line no-bitwise\n ts.SymbolFlags.Property |\n ts.SymbolFlags.EnumMember)) !==\n 0;\n\n const tsName = typeChecker.getFullyQualifiedName(sym);\n\n // TypeScript fqn looks like \"/path/to/file\"[.name.in.file]\n const groups = /^\"([^\"]+)\"(?:\\.(.*))?$/.exec(tsName);\n if (!groups) {\n return undefined;\n }\n\n const [, fileName, inFileName] = groups; // inFileName may be absent\n\n const relFile = Helper.for(typeChecker).assemblyRelativeSourceFile(fileName, options?.assembly);\n if (!relFile) {\n return undefined;\n }\n\n // If this is a member symbol, replace the final '.' with a '#'\n const typeSymbol = isMember ? (inFileName ?? '').replace(/\\.([^.]+)$/, '#$1') : inFileName ?? '';\n\n return `${relFile}:${typeSymbol}`;\n}\n\nclass Helper {\n public static for(typeChecker: ts.TypeChecker) {\n const cached = this.INSTANCES.get(typeChecker);\n if (cached != null) {\n return cached;\n }\n const helper = new Helper();\n this.INSTANCES.set(typeChecker, helper);\n return helper;\n }\n\n private static readonly INSTANCES = new WeakMap<ts.TypeChecker, Helper>();\n\n private readonly packageInfo = new Map<string, PackageInfo | undefined>();\n\n private constructor() {}\n\n public assemblyRelativeSourceFile(sourceFileName: string, asm?: Assembly) {\n const packageInfo = this.findPackageInfo(path.dirname(sourceFileName));\n if (!packageInfo) {\n return undefined;\n }\n\n let sourcePath = removePrefix(packageInfo.outdir ?? '', path.relative(packageInfo.packageJsonDir, sourceFileName));\n\n // Modify the namespace if we send in the assembly.\n if (asm) {\n const tscRootDir = packageInfo.tscRootDir ?? asm.metadata?.tscRootDir;\n const tscOutDir = packageInfo.tscOutDir ?? asm.metadata?.tscOutDir;\n sourcePath = normalizePath(sourcePath, tscRootDir, tscOutDir);\n }\n\n return sourcePath.replace(/(\\.d)?\\.ts$/, '');\n\n function removePrefix(prefix: string, filePath: string) {\n const prefixParts = prefix.split(/[/\\\\]/g);\n const pathParts = filePath.split(/[/\\\\]/g);\n let i = 0;\n while (prefixParts[i] === pathParts[i]) {\n i++;\n }\n return pathParts.slice(i).join('/');\n }\n }\n\n private findPackageInfo(from: string): PackageInfo | undefined {\n if (this.packageInfo.has(from)) {\n return this.packageInfo.get(from);\n }\n\n const packageJsonDir = findUp(from, (dir) => fs.existsSync(path.join(dir, 'package.json')));\n\n if (!packageJsonDir) {\n this.packageInfo.set(from, undefined);\n return undefined;\n }\n\n if (this.packageInfo.has(packageJsonDir)) {\n return this.packageInfo.get(packageJsonDir);\n }\n\n const { jsii } = JSON.parse(fs.readFileSync(path.join(packageJsonDir, 'package.json'), 'utf-8'));\n\n const result = {\n packageJsonDir,\n outdir: jsii?.outdir,\n tscRootDir: jsii?.tsc?.rootDir,\n tscOutDir: jsii?.tsc?.outDir,\n };\n this.packageInfo.set(from, result);\n this.packageInfo.set(packageJsonDir, result);\n return result;\n }\n}\n\ninterface PackageInfo {\n readonly packageJsonDir: string;\n readonly outdir: string | undefined;\n readonly tscRootDir: string | undefined;\n readonly tscOutDir: string | undefined;\n}\n\n/**\n * Ensures that the sourcePath is pointing to the source code\n * and not compiled code. This can happen if the root directory\n * and/or out directory is set for the project. We check to see\n * if the out directory is present in the sourcePath, and if so,\n * we replace it with the root directory.\n */\nexport function normalizePath(sourcePath: string, rootDir?: string, outDir?: string): string {\n if (rootDir === undefined || outDir === undefined) {\n return sourcePath;\n }\n\n outDir = removeEndSlash(path.normalize(outDir));\n const outDirLength = outDir.split(path.sep).length;\n rootDir = removeEndSlash(path.normalize(rootDir));\n\n let paths = path.normalize(sourcePath).split(path.sep);\n const pathDir = paths.slice(0, outDirLength).join(path.sep);\n\n if (outDir === pathDir || outDir === '.') {\n // outDir === '.' is a special case where we do not want\n // to remove any paths from the list.\n if (outDir !== '.') {\n paths = paths.slice(outDirLength);\n }\n sourcePath = rootDir === '.' ? paths.join('/') : `${rootDir}/${paths.join('/')}`;\n }\n return unixize(sourcePath);\n\n function removeEndSlash(filePath: string) {\n return filePath.endsWith(path.sep) ? filePath.slice(0, filePath.length - 1) : filePath;\n }\n}\n\n/**\n * Turn backslashes in a path into forward slashes\n */\nfunction unixize(p: string) {\n return p.replace(/\\\\/g, '/');\n}\n"]}
1
+ {"version":3,"file":"symbol-id.js","sources":["../../src/common/symbol-id.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAY,EAAE,oCAAgB;AAC9B,MAAY,IAAI,sCAAkB;AAGlC,6CAAsC;AAuCtC;;;;GAIG;AACH,MAAM,YAAY,GAAG;IACnB,QAAQ,EAAE,CAAC;IACX,UAAU,EAAE,CAAC;IACb,MAAM,EAAE,IAAI;IACZ,KAAK,EAAE,OAAO;CACN,CAAC;AAEX;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,0BACE,WAA+B,EAC/B,GAAkB,EAClB,OAAO,GAAoB,EAAE;IAE7B,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,O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,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IACnF,CAAC;IACD,OAAO,OAAO,CAAC,UAAU,CAAC,CAAC;IAE3B,SAAS,cAAc,CAAC,QAAgB;QACtC,OAAO,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;IACzF,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,OAAO,CAAC,CAAS;IACxB,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAC/B,CAAC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport type { Assembly } from '@jsii/spec';\n\nimport { findUp } from './find-utils';\n\n/**\n * Additional options that may be provided to the symbolIdentifier.\n */\nexport interface SymbolIdOptions {\n /**\n * The assembly that the symbol is found in.\n * This is used to provide the correct root directory\n * as specified in the assembly metadata. In turn,\n * the root directory is used to ensure that the\n * symbolId comes from source code and not compiled code.\n */\n readonly assembly?: Assembly;\n}\n\n/**\n * The part of a TypeScript symbol `symbolIdentifier` needs.\n *\n * This is a structural type so that both the classic in-process `ts.Symbol`\n * (as used by jsii-rosetta) and the symbol handles of the TypeScript 7\n * programmatic API satisfy it.\n */\nexport interface SymbolIdSymbol {\n /** The `SymbolFlags` bit set of the symbol. */\n readonly flags: number;\n}\n\n/**\n * The part of a TypeScript type checker `symbolIdentifier` needs.\n *\n * Structurally satisfied by the classic `ts.TypeChecker` and by the TypeScript 7\n * `Checker`, so callers can keep passing whichever checker they drive.\n */\nexport interface SymbolIdChecker<S extends SymbolIdSymbol = SymbolIdSymbol> {\n getAliasedSymbol(symbol: S): S;\n getFullyQualifiedName(symbol: S): string;\n}\n\n/**\n * The `SymbolFlags` values `symbolIdentifier` tests for. They are identical in\n * the classic compiler and in the TypeScript 7 `typescript/ast` module, which\n * lets this function stay independent from either package.\n */\nconst SYMBOL_FLAGS = {\n Property: 4,\n EnumMember: 8,\n Method: 8192,\n Alias: 2097152,\n} as const;\n\n/**\n * Return a symbol identifier for the given symbol\n *\n * The symbol identifier identifies a TypeScript symbol in a source file inside\n * a package. We can use this to map between jsii entries in the manifest, and\n * entities in the TypeScript source code.\n *\n * Going via symbol id is the only way to identify symbols in submodules. Otherwise,\n * all the TypeScript compiler sees is:\n *\n * ```\n * /my/package/lib/source/directory/dist.js <containing> MyClass\n * ```\n *\n * And there's no way to figure out what submodule name\n * `lib/source/directory/dist` is exported as.\n *\n * The format of a symbol id is:\n *\n * ```\n * relative/source/file:Name.space.Class[#member]\n * ```\n *\n * We used to build this identifier ourselves. Turns out there was a built-in\n * way to get pretty much the same, by calling `typeChecker.getFullyQualifiedName()`.\n * Whoops ^_^ (this historical accident is why the format is similar to but\n * different from what the TS checker returns).\n */\nexport function symbolIdentifier<S extends SymbolIdSymbol>(\n typeChecker: SymbolIdChecker<S>,\n sym: S | undefined,\n options: SymbolIdOptions = {},\n): string | undefined {\n if (!sym) {\n return undefined;\n }\n\n // If this symbol happens to be an alias, resolve it first\n // eslint-disable-next-line no-bitwise\n while ((sym.flags & SYMBOL_FLAGS.Alias) !== 0) {\n sym = typeChecker.getAliasedSymbol(sym);\n }\n\n const isMember =\n // eslint-disable-next-line no-bitwise\n (sym.flags & (SYMBOL_FLAGS.Method | SYMBOL_FLAGS.Property | SYMBOL_FLAGS.EnumMember)) !== 0;\n\n const tsName = typeChecker.getFullyQualifiedName(sym);\n\n // TypeScript fqn looks like \"/path/to/file\"[.name.in.file]\n const groups = /^\"([^\"]+)\"(?:\\.(.*))?$/.exec(tsName);\n if (!groups) {\n return undefined;\n }\n\n const [, fileName, inFileName] = groups; // inFileName may be absent\n\n const relFile = Helper.for(typeChecker).assemblyRelativeSourceFile(fileName, options?.assembly);\n if (!relFile) {\n return undefined;\n }\n\n // If this is a member symbol, replace the final '.' with a '#'\n const typeSymbol = isMember ? (inFileName ?? '').replace(/\\.([^.]+)$/, '#$1') : inFileName ?? '';\n\n return `${relFile}:${typeSymbol}`;\n}\n\nclass Helper {\n public static for(typeChecker: object) {\n const cached = this.INSTANCES.get(typeChecker);\n if (cached != null) {\n return cached;\n }\n const helper = new Helper();\n this.INSTANCES.set(typeChecker, helper);\n return helper;\n }\n\n private static readonly INSTANCES = new WeakMap<object, Helper>();\n\n private readonly packageInfo = new Map<string, PackageInfo | undefined>();\n\n private constructor() {}\n\n public assemblyRelativeSourceFile(sourceFileName: string, asm?: Assembly) {\n const packageInfo = this.findPackageInfo(path.dirname(sourceFileName));\n if (!packageInfo) {\n return undefined;\n }\n\n let sourcePath = removePrefix(packageInfo.outdir ?? '', path.relative(packageInfo.packageJsonDir, sourceFileName));\n\n // Modify the namespace if we send in the assembly.\n if (asm) {\n const tscRootDir = packageInfo.tscRootDir ?? asm.metadata?.tscRootDir;\n const tscOutDir = packageInfo.tscOutDir ?? asm.metadata?.tscOutDir;\n sourcePath = normalizePath(sourcePath, tscRootDir, tscOutDir);\n }\n\n return sourcePath.replace(/(\\.d)?\\.ts$/, '');\n\n function removePrefix(prefix: string, filePath: string) {\n const prefixParts = prefix.split(/[/\\\\]/g);\n const pathParts = filePath.split(/[/\\\\]/g);\n let i = 0;\n while (prefixParts[i] === pathParts[i]) {\n i++;\n }\n return pathParts.slice(i).join('/');\n }\n }\n\n private findPackageInfo(from: string): PackageInfo | undefined {\n if (this.packageInfo.has(from)) {\n return this.packageInfo.get(from);\n }\n\n const packageJsonDir = findUp(from, (dir) => fs.existsSync(path.join(dir, 'package.json')));\n\n if (!packageJsonDir) {\n this.packageInfo.set(from, undefined);\n return undefined;\n }\n\n if (this.packageInfo.has(packageJsonDir)) {\n return this.packageInfo.get(packageJsonDir);\n }\n\n const { jsii } = JSON.parse(fs.readFileSync(path.join(packageJsonDir, 'package.json'), 'utf-8'));\n\n const result = {\n packageJsonDir,\n outdir: jsii?.outdir,\n tscRootDir: jsii?.tsc?.rootDir,\n tscOutDir: jsii?.tsc?.outDir,\n };\n this.packageInfo.set(from, result);\n this.packageInfo.set(packageJsonDir, result);\n return result;\n }\n}\n\ninterface PackageInfo {\n readonly packageJsonDir: string;\n readonly outdir: string | undefined;\n readonly tscRootDir: string | undefined;\n readonly tscOutDir: string | undefined;\n}\n\n/**\n * Ensures that the sourcePath is pointing to the source code\n * and not compiled code. This can happen if the root directory\n * and/or out directory is set for the project. We check to see\n * if the out directory is present in the sourcePath, and if so,\n * we replace it with the root directory.\n */\nexport function normalizePath(sourcePath: string, rootDir?: string, outDir?: string): string {\n if (rootDir === undefined || outDir === undefined) {\n return sourcePath;\n }\n\n outDir = removeEndSlash(path.normalize(outDir));\n const outDirLength = outDir.split(path.sep).length;\n rootDir = removeEndSlash(path.normalize(rootDir));\n\n let paths = path.normalize(sourcePath).split(path.sep);\n const pathDir = paths.slice(0, outDirLength).join(path.sep);\n\n if (outDir === pathDir || outDir === '.') {\n // outDir === '.' is a special case where we do not want\n // to remove any paths from the list.\n if (outDir !== '.') {\n paths = paths.slice(outDirLength);\n }\n sourcePath = rootDir === '.' ? paths.join('/') : `${rootDir}/${paths.join('/')}`;\n }\n return unixize(sourcePath);\n\n function removeEndSlash(filePath: string) {\n return filePath.endsWith(path.sep) ? filePath.slice(0, filePath.length - 1) : filePath;\n }\n}\n\n/**\n * Turn backslashes in a path into forward slashes\n */\nfunction unixize(p: string) {\n return p.replace(/\\\\/g, '/');\n}\n"]}
@@ -0,0 +1,60 @@
1
+ /** Minimum TypeScript version that ships the `sync` programmatic API. */
2
+ export declare const TS7_MIN_VERSION = "7.1.0-0";
3
+ /**
4
+ * A very small, intentionally loose view of the pieces of the TypeScript 7 API
5
+ * surface that the compiler consumes. This favours a working `.jsii` over
6
+ * precise typings (see the file header of `assembler.ts`).
7
+ */
8
+ export interface TypeScriptApi {
9
+ readonly API: any;
10
+ readonly SymbolFlags: any;
11
+ readonly TypeFlags: any;
12
+ readonly SyntaxKind: any;
13
+ /** Combines request generators so `api.batch(all(...))` issues them in one round-trip. */
14
+ readonly all: (...generators: any[]) => any;
15
+ /** Directory of the TypeScript package the API was loaded from. */
16
+ readonly packageDir: string;
17
+ /** Version of that package. */
18
+ readonly version: string;
19
+ }
20
+ /**
21
+ * The directory of the TypeScript 7 package (`#typescript`), after checking
22
+ * that it is new enough to expose the `sync` API. Exported for unit tests.
23
+ */
24
+ export declare function resolveTypeScript7PackageDir(): string;
25
+ /**
26
+ * Load the TypeScript 7 `sync` API and the AST enums.
27
+ */
28
+ export declare function loadTypeScriptApi(): TypeScriptApi;
29
+ export interface TypeScriptProject {
30
+ /** The raw `Program` handle. */
31
+ readonly program: any;
32
+ /** The raw `TypeChecker` handle. */
33
+ readonly checker: any;
34
+ /** The owning `API` session (exposes `batch()` for multi-request round-trips). */
35
+ readonly api: any;
36
+ /** The root files of the configuration (`parsedCommandLine.fileNames`). */
37
+ readonly rootFileNames: readonly string[];
38
+ }
39
+ /**
40
+ * Owns a single API session and the snapshot opened for a project.
41
+ */
42
+ export declare class CompilerHost {
43
+ readonly ts: TypeScriptApi;
44
+ private readonly api;
45
+ private readonly snapshot;
46
+ readonly tsconfigPath: string;
47
+ /**
48
+ * Open an API session against `projectRoot`/`tsconfig.json` and return a host
49
+ * bound to the resulting program + checker.
50
+ */
51
+ static open(projectRoot: string, tsconfigFileName?: string): CompilerHost;
52
+ private constructor();
53
+ /** RPC timing info (requestCount/bytes) when JSII_TS7_TIMING is enabled. */
54
+ getTimingInfo(): any;
55
+ /** The program + checker for the opened project. */
56
+ getProject(): TypeScriptProject;
57
+ /** Dispose the snapshot and close the API session / native process. */
58
+ close(): void;
59
+ }
60
+ //# sourceMappingURL=compiler-host.d.ts.map
@@ -0,0 +1,201 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.CompilerHost = exports.TS7_MIN_VERSION = void 0;
37
+ exports.resolveTypeScript7PackageDir = resolveTypeScript7PackageDir;
38
+ exports.loadTypeScriptApi = loadTypeScriptApi;
39
+ /*
40
+ * ---------------------------------------------------------------------------
41
+ * Access to the TypeScript 7 programmatic API: loading the `sync` client and
42
+ * the AST enums of the TypeScript package (`#typescript`), and the
43
+ * `CompilerHost` that owns an API session and the project snapshot opened for
44
+ * a tsconfig (program + checker). The assembler reads the raw handles the
45
+ * session returns; nothing here imitates the in-process `ts.Program` /
46
+ * `ts.TypeChecker` of TypeScript 6.
47
+ *
48
+ * The TypeScript package is installed under the `@typescript/native` alias and
49
+ * imported as `#typescript` (see the `imports` field of package.json); the
50
+ * plain `typescript` dev dependency is TypeScript 6, for the development tools
51
+ * that still need the in-process compiler API.
52
+ *
53
+ * The API is loaded with Node's own `require` rather than a static `import`:
54
+ * the package is ESM, and a test runner's module loader (jest) cannot load ES
55
+ * modules through `require()`, while Node >= 22.12 can.
56
+ * ---------------------------------------------------------------------------
57
+ */
58
+ const nodeModule = __importStar(require("node:module"));
59
+ const path = __importStar(require("node:path"));
60
+ const semver = __importStar(require("semver"));
61
+ /** Minimum TypeScript version that ships the `sync` programmatic API. */
62
+ exports.TS7_MIN_VERSION = '7.1.0-0';
63
+ /**
64
+ * The directory of the TypeScript 7 package (`#typescript`), after checking
65
+ * that it is new enough to expose the `sync` API. Exported for unit tests.
66
+ */
67
+ function resolveTypeScript7PackageDir() {
68
+ const dir = path.dirname(nodeCreateRequire(__filename).resolve('#typescript/package.json'));
69
+ const version = readPackageVersion(dir);
70
+ if (!isNewEnough(version)) {
71
+ throw new Error(`The TypeScript package at ${dir} is typescript ${version ?? '<unknown>'}; ` +
72
+ `jsii needs typescript >= 7.1 (${exports.TS7_MIN_VERSION}) for its programmatic API.`);
73
+ }
74
+ return dir;
75
+ }
76
+ function readPackageVersion(dir) {
77
+ try {
78
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
79
+ const pkg = require(path.join(dir, 'package.json'));
80
+ return typeof pkg.version === 'string' ? pkg.version : undefined;
81
+ }
82
+ catch {
83
+ return undefined;
84
+ }
85
+ }
86
+ function isNewEnough(version) {
87
+ return version != null && semver.valid(version) != null && semver.gte(version, exports.TS7_MIN_VERSION);
88
+ }
89
+ /**
90
+ * `createRequire` from Node's own `Module`, even when a test runner (jest) hands
91
+ * out a sandboxed subclass whose loader cannot load ES modules: the real class is
92
+ * the deepest one on the prototype chain that still provides `createRequire`.
93
+ */
94
+ function nodeCreateRequire(filename) {
95
+ let real = nodeModule.Module ?? nodeModule;
96
+ while (typeof Object.getPrototypeOf(real)?.createRequire === 'function') {
97
+ real = Object.getPrototypeOf(real);
98
+ }
99
+ return real.createRequire(filename);
100
+ }
101
+ let cached;
102
+ /**
103
+ * Load the TypeScript 7 `sync` API and the AST enums.
104
+ */
105
+ function loadTypeScriptApi() {
106
+ if (cached) {
107
+ return cached;
108
+ }
109
+ const packageDir = resolveTypeScript7PackageDir();
110
+ const version = readPackageVersion(packageDir) ?? '<unknown>';
111
+ const nativeRequire = nodeCreateRequire(__filename);
112
+ let apiModule;
113
+ let astModule;
114
+ try {
115
+ apiModule = nativeRequire('#typescript/sync');
116
+ astModule = nativeRequire('#typescript/ast');
117
+ }
118
+ catch (err) {
119
+ throw new Error(`Failed to load the TypeScript 7 programmatic API from "${packageDir}" (typescript ${version}): ${err.message}`);
120
+ }
121
+ cached = {
122
+ API: apiModule.API,
123
+ SymbolFlags: apiModule.SymbolFlags,
124
+ TypeFlags: apiModule.TypeFlags,
125
+ SyntaxKind: astModule.SyntaxKind,
126
+ all: apiModule.all,
127
+ packageDir,
128
+ version,
129
+ };
130
+ return cached;
131
+ }
132
+ /**
133
+ * Owns a single API session and the snapshot opened for a project.
134
+ */
135
+ class CompilerHost {
136
+ ts;
137
+ api;
138
+ snapshot;
139
+ tsconfigPath;
140
+ /**
141
+ * Open an API session against `projectRoot`/`tsconfig.json` and return a host
142
+ * bound to the resulting program + checker.
143
+ */
144
+ static open(projectRoot, tsconfigFileName = 'tsconfig.json') {
145
+ const ts = loadTypeScriptApi();
146
+ const tsconfigPath = path.join(projectRoot, tsconfigFileName);
147
+ // collectTiming lets us report RPC request counts / bytes for perf work
148
+ // (opt-in via JSII_TS7_TIMING; negligible overhead but off by default).
149
+ const collectTiming = !!process.env.JSII_TS7_TIMING;
150
+ const api = new ts.API({ cwd: projectRoot, collectTiming });
151
+ const snapshot = api.createSnapshot({ openProjects: [tsconfigPath] });
152
+ return new CompilerHost(ts, api, snapshot, tsconfigPath);
153
+ }
154
+ constructor(ts, api, snapshot, tsconfigPath) {
155
+ this.ts = ts;
156
+ this.api = api;
157
+ this.snapshot = snapshot;
158
+ this.tsconfigPath = tsconfigPath;
159
+ }
160
+ /** RPC timing info (requestCount/bytes) when JSII_TS7_TIMING is enabled. */
161
+ getTimingInfo() {
162
+ try {
163
+ return this.api.getTimingInfo();
164
+ }
165
+ catch {
166
+ return undefined;
167
+ }
168
+ }
169
+ /** The program + checker for the opened project. */
170
+ getProject() {
171
+ const project = this.snapshot.getConfiguredProject(this.tsconfigPath);
172
+ if (!project) {
173
+ throw new Error(`TypeScript project not found for ${this.tsconfigPath}`);
174
+ }
175
+ return {
176
+ program: project.program,
177
+ checker: project.checker,
178
+ api: this.api,
179
+ rootFileNames: project.parsedCommandLine.fileNames,
180
+ };
181
+ }
182
+ /** Dispose the snapshot and close the API session / native process. */
183
+ close() {
184
+ // Tolerate a channel that is already gone (e.g. the server process exited):
185
+ // dispose/close can throw EPIPE, which must not mask the real result.
186
+ try {
187
+ this.snapshot.dispose();
188
+ }
189
+ catch {
190
+ /* ignore */
191
+ }
192
+ try {
193
+ this.api.close();
194
+ }
195
+ catch {
196
+ /* ignore */
197
+ }
198
+ }
199
+ }
200
+ exports.CompilerHost = CompilerHost;
201
+ //# sourceMappingURL=compiler-host.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compiler-host.js","sources":["../src/compiler-host.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAY,UAAU,wCAAoB;AAC1C,MAAY,IAAI,sCAAkB;AAClC,MAAY,MAAM,mCAAe;AAEjC,yEAAyE;AAC5D,QAAA,eAAe,GAAG,SAAS,CAAC;AAsBzC;;;GAGG;AACH;IACE,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,0BAA0B,CAAC,CAAC,CAAC;IAC5F,MAAM,OAAO,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC;IACxC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK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CAAC,CAAC;QAEtE,OAAO,IAAI,YAAY,CAAC,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC;IAC3D,CAAC;IAED,YACkB,EAAiB,EAChB,GAAQ,EACR,QAAa,EACd,YAAoB;kBAHpB,EAAE;mBACD,GAAG;wBACH,QAAQ;4BACT,YAAY;IAC3B,CAAC;IAEJ,4EAA4E;IACrE,aAAa;QAClB,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC;QAClC,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;IAED,oDAAoD;IAC7C,UAAU;QACf,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,oBAAoB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACtE,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,oCAAoC,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC;QAC3E,CAAC;QACD,OAAO;YACL,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,aAAa,EAAE,OAAO,CAAC,iBAAiB,CAAC,SAAS;SACnD,CAAC;IACJ,CAAC;IAED,uEAAuE;IAChE,KAAK;QACV,4EAA4E;QAC5E,sEAAsE;QACtE,IAAI,CAAC;YACH,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;QAC1B,CAAC;QAAC,MAAM,CAAC;YACP,YAAY;QACd,CAAC;QACD,IAAI,CAAC;YACH,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;QACnB,CAAC;QAAC,MAAM,CAAC;YACP,YAAY;QACd,CAAC;IACH,CAAC;CACF","sourcesContent":["/*\n * ---------------------------------------------------------------------------\n * Access to the TypeScript 7 programmatic API: loading the `sync` client and\n * the AST enums of the TypeScript package (`#typescript`), and the\n * `CompilerHost` that owns an API session and the project snapshot opened for\n * a tsconfig (program + checker). The assembler reads the raw handles the\n * session returns; nothing here imitates the in-process `ts.Program` /\n * `ts.TypeChecker` of TypeScript 6.\n *\n * The TypeScript package is installed under the `@typescript/native` alias and\n * imported as `#typescript` (see the `imports` field of package.json); the\n * plain `typescript` dev dependency is TypeScript 6, for the development tools\n * that still need the in-process compiler API.\n *\n * The API is loaded with Node's own `require` rather than a static `import`:\n * the package is ESM, and a test runner's module loader (jest) cannot load ES\n * modules through `require()`, while Node >= 22.12 can.\n * ---------------------------------------------------------------------------\n */\nimport * as nodeModule from 'node:module';\nimport * as path from 'node:path';\nimport * as semver from 'semver';\n\n/** Minimum TypeScript version that ships the `sync` programmatic API. */\nexport const TS7_MIN_VERSION = '7.1.0-0';\n\n/**\n * A very small, intentionally loose view of the pieces of the TypeScript 7 API\n * surface that the compiler consumes. This favours a working `.jsii` over\n * precise typings (see the file header of `assembler.ts`).\n */\nexport interface TypeScriptApi {\n /* eslint-disable @typescript-eslint/naming-convention */\n readonly API: any;\n readonly SymbolFlags: any;\n readonly TypeFlags: any;\n readonly SyntaxKind: any;\n /* eslint-enable @typescript-eslint/naming-convention */\n /** Combines request generators so `api.batch(all(...))` issues them in one round-trip. */\n readonly all: (...generators: any[]) => any;\n /** Directory of the TypeScript package the API was loaded from. */\n readonly packageDir: string;\n /** Version of that package. */\n readonly version: string;\n}\n\n/**\n * The directory of the TypeScript 7 package (`#typescript`), after checking\n * that it is new enough to expose the `sync` API. Exported for unit tests.\n */\nexport function resolveTypeScript7PackageDir(): string {\n const dir = path.dirname(nodeCreateRequire(__filename).resolve('#typescript/package.json'));\n const version = readPackageVersion(dir);\n if (!isNewEnough(version)) {\n throw new Error(\n `The TypeScript package at ${dir} is typescript ${version ?? '<unknown>'}; ` +\n `jsii needs typescript >= 7.1 (${TS7_MIN_VERSION}) for its programmatic API.`,\n );\n }\n return dir;\n}\n\nfunction readPackageVersion(dir: string): string | undefined {\n try {\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n const pkg = require(path.join(dir, 'package.json'));\n return typeof pkg.version === 'string' ? pkg.version : undefined;\n } catch {\n return undefined;\n }\n}\n\nfunction isNewEnough(version: string | undefined): boolean {\n return version != null && semver.valid(version) != null && semver.gte(version, TS7_MIN_VERSION);\n}\n\n/**\n * `createRequire` from Node's own `Module`, even when a test runner (jest) hands\n * out a sandboxed subclass whose loader cannot load ES modules: the real class is\n * the deepest one on the prototype chain that still provides `createRequire`.\n */\nfunction nodeCreateRequire(filename: string): NodeJS.Require {\n let real: any = (nodeModule as any).Module ?? nodeModule;\n while (typeof Object.getPrototypeOf(real)?.createRequire === 'function') {\n real = Object.getPrototypeOf(real);\n }\n return real.createRequire(filename);\n}\n\nlet cached: TypeScriptApi | undefined;\n\n/**\n * Load the TypeScript 7 `sync` API and the AST enums.\n */\nexport function loadTypeScriptApi(): TypeScriptApi {\n if (cached) {\n return cached;\n }\n const packageDir = resolveTypeScript7PackageDir();\n const version = readPackageVersion(packageDir) ?? '<unknown>';\n\n const nativeRequire = nodeCreateRequire(__filename);\n let apiModule: any;\n let astModule: any;\n try {\n apiModule = nativeRequire('#typescript/sync');\n astModule = nativeRequire('#typescript/ast');\n } catch (err) {\n throw new Error(\n `Failed to load the TypeScript 7 programmatic API from \"${packageDir}\" (typescript ${version}): ${\n (err as Error).message\n }`,\n );\n }\n\n cached = {\n API: apiModule.API,\n SymbolFlags: apiModule.SymbolFlags,\n TypeFlags: apiModule.TypeFlags,\n SyntaxKind: astModule.SyntaxKind,\n all: apiModule.all,\n packageDir,\n version,\n };\n return cached;\n}\n\nexport interface TypeScriptProject {\n /** The raw `Program` handle. */\n readonly program: any;\n /** The raw `TypeChecker` handle. */\n readonly checker: any;\n /** The owning `API` session (exposes `batch()` for multi-request round-trips). */\n readonly api: any;\n /** The root files of the configuration (`parsedCommandLine.fileNames`). */\n readonly rootFileNames: readonly string[];\n}\n\n/**\n * Owns a single API session and the snapshot opened for a project.\n */\nexport class CompilerHost {\n /**\n * Open an API session against `projectRoot`/`tsconfig.json` and return a host\n * bound to the resulting program + checker.\n */\n public static open(projectRoot: string, tsconfigFileName = 'tsconfig.json'): CompilerHost {\n const ts = loadTypeScriptApi();\n const tsconfigPath = path.join(projectRoot, tsconfigFileName);\n\n // collectTiming lets us report RPC request counts / bytes for perf work\n // (opt-in via JSII_TS7_TIMING; negligible overhead but off by default).\n const collectTiming = !!process.env.JSII_TS7_TIMING;\n const api = new ts.API({ cwd: projectRoot, collectTiming });\n const snapshot = api.createSnapshot({ openProjects: [tsconfigPath] });\n\n return new CompilerHost(ts, api, snapshot, tsconfigPath);\n }\n\n private constructor(\n public readonly ts: TypeScriptApi,\n private readonly api: any,\n private readonly snapshot: any,\n public readonly tsconfigPath: string,\n ) {}\n\n /** RPC timing info (requestCount/bytes) when JSII_TS7_TIMING is enabled. */\n public getTimingInfo(): any {\n try {\n return this.api.getTimingInfo();\n } catch {\n return undefined;\n }\n }\n\n /** The program + checker for the opened project. */\n public getProject(): TypeScriptProject {\n const project = this.snapshot.getConfiguredProject(this.tsconfigPath);\n if (!project) {\n throw new Error(`TypeScript project not found for ${this.tsconfigPath}`);\n }\n return {\n program: project.program,\n checker: project.checker,\n api: this.api,\n rootFileNames: project.parsedCommandLine.fileNames,\n };\n }\n\n /** Dispose the snapshot and close the API session / native process. */\n public close(): void {\n // Tolerate a channel that is already gone (e.g. the server process exited):\n // dispose/close can throw EPIPE, which must not mask the real result.\n try {\n this.snapshot.dispose();\n } catch {\n /* ignore */\n }\n try {\n this.api.close();\n } catch {\n /* ignore */\n }\n }\n}\n"]}