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.
- package/lib/assembler.d.ts +254 -196
- package/lib/assembler.js +2105 -2327
- package/lib/assembler.js.map +1 -1
- package/lib/case.js.map +1 -1
- package/lib/common/find-utils.js.map +1 -1
- package/lib/common/index.d.ts +1 -1
- package/lib/common/index.js +2 -1
- package/lib/common/index.js.map +1 -1
- package/lib/common/symbol-id.d.ts +23 -4
- package/lib/common/symbol-id.js +13 -9
- package/lib/common/symbol-id.js.map +1 -1
- package/lib/compiler-host.d.ts +60 -0
- package/lib/compiler-host.js +201 -0
- package/lib/compiler-host.js.map +1 -0
- package/lib/compiler.d.ts +74 -62
- package/lib/compiler.js +332 -254
- package/lib/compiler.js.map +1 -1
- package/lib/diagnostic.d.ts +34 -0
- package/lib/diagnostic.js +141 -0
- package/lib/diagnostic.js.map +1 -0
- package/lib/emitter.d.ts +40 -10
- package/lib/emitter.js +188 -0
- package/lib/emitter.js.map +1 -1
- package/lib/helpers.d.ts +1 -1
- package/lib/helpers.js +2 -2
- package/lib/helpers.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/jsii-diagnostic.d.ts +27 -22
- package/lib/jsii-diagnostic.js +22 -38
- package/lib/jsii-diagnostic.js.map +1 -1
- package/lib/literate.js.map +1 -1
- package/lib/main.js +3 -2
- package/lib/main.js.map +1 -1
- package/lib/project-info.d.ts +23 -4
- package/lib/project-info.js +5 -5
- package/lib/project-info.js.map +1 -1
- package/lib/support-types.d.ts +2 -0
- package/lib/support-types.js +3 -0
- package/lib/support-types.js.map +1 -0
- package/lib/support.js.map +1 -1
- package/lib/tsconfig/compiler-options.d.ts +12 -46
- package/lib/tsconfig/compiler-options.js +45 -87
- package/lib/tsconfig/compiler-options.js.map +1 -1
- package/lib/tsconfig/index.d.ts +24 -5
- package/lib/tsconfig/index.js.map +1 -1
- package/lib/tsconfig/read.d.ts +15 -0
- package/lib/tsconfig/read.js +196 -0
- package/lib/tsconfig/read.js.map +1 -0
- package/lib/tsconfig/rule-set-format.js.map +1 -1
- package/lib/tsconfig/rulesets/configurable-options.js.map +1 -1
- package/lib/tsconfig/rulesets/deprecated-options.js.map +1 -1
- package/lib/tsconfig/rulesets/generated.public.js.map +1 -1
- package/lib/tsconfig/rulesets/incompatible-options.js.map +1 -1
- package/lib/tsconfig/rulesets/jsii-configured-options.js.map +1 -1
- package/lib/tsconfig/rulesets/minimal.public.js.map +1 -1
- package/lib/tsconfig/rulesets/strict-family-options.js.map +1 -1
- package/lib/tsconfig/rulesets/strict.public.js.map +1 -1
- package/lib/tsconfig/tsconfig-validator.js +2 -50
- package/lib/tsconfig/tsconfig-validator.js.map +1 -1
- package/lib/tsconfig/validator.js.map +1 -1
- package/lib/type-analysis.js.map +1 -1
- package/lib/type-reference.js.map +1 -1
- package/lib/type-visitor.js.map +1 -1
- package/lib/utils.d.ts +6 -6
- package/lib/utils.js +8 -13
- package/lib/utils.js.map +1 -1
- package/lib/version.d.ts +3 -3
- package/lib/version.js +4 -4
- package/lib/version.js.map +1 -1
- package/lib/warnings.d.ts +2 -2
- package/lib/warnings.js +3 -77
- package/lib/warnings.js.map +1 -1
- package/package.json +15 -10
- package/scripts/ts7-compare-jsii.mjs +101 -0
- package/lib/directives.d.ts +0 -24
- package/lib/directives.js +0 -139
- package/lib/directives.js.map +0 -1
- package/lib/docs.d.ts +0 -64
- package/lib/docs.js +0 -293
- package/lib/docs.js.map +0 -1
- package/lib/node-bindings.d.ts +0 -19
- package/lib/node-bindings.js +0 -49
- package/lib/node-bindings.js.map +0 -1
- package/lib/reserved-words.d.ts +0 -6
- package/lib/reserved-words.js +0 -258
- package/lib/reserved-words.js.map +0 -1
- package/lib/sets.d.ts +0 -16
- package/lib/sets.js +0 -41
- package/lib/sets.js.map +0 -1
- package/lib/transforms/deprecated-remover.d.ts +0 -44
- package/lib/transforms/deprecated-remover.js +0 -545
- package/lib/transforms/deprecated-remover.js.map +0 -1
- package/lib/transforms/deprecation-warnings.d.ts +0 -37
- package/lib/transforms/deprecation-warnings.js +0 -616
- package/lib/transforms/deprecation-warnings.js.map +0 -1
- package/lib/transforms/runtime-info.d.ts +0 -39
- package/lib/transforms/runtime-info.js +0 -128
- package/lib/transforms/runtime-info.js.map +0 -1
- package/lib/transforms/utils.d.ts +0 -11
- package/lib/transforms/utils.js +0 -31
- package/lib/transforms/utils.js.map +0 -1
- package/lib/type-tracker.d.ts +0 -13
- package/lib/type-tracker.js +0 -67
- package/lib/type-tracker.js.map +0 -1
- package/lib/validator.d.ts +0 -19
- package/lib/validator.js +0 -602
- package/lib/validator.js.map +0 -1
package/lib/emitter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emitter.js","sourceRoot":"","sources":["../src/emitter.ts"],"names":[],"mappings":"","sourcesContent":["import * as ts from 'typescript';\n\n/**\n * An object that is capable of emitting stuff.\n */\nexport interface Emitter {\n /**\n * Attempts to emit stuff.\n *\n * @return the result of attempting to emit stuff.\n */\n emit(): ts.EmitResult;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"emitter.js","sources":["../src/emitter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;GASG;AACH,uNAAuN;AACvN,MAAY,EAAE,oCAAgB;AAC9B,MAAY,IAAI,sCAAkB;AAClC,MAAY,IAAI,uCAAmB;AACnC,MAAY,MAAM,mCAAe;AAIjC,MAAM,GAAG,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;AAe7C,wEAAwE;AACxE,MAAM,WAAW,GAAG,WAAW,CAAC;AAEhC;;;;;;;;;;;GAWG;AACH,qBAA4B,OAA0B,EAAE,OAA2B;IACjF,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAC5B,MAAM,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC;IACjC,MAAM,QAAQ,GA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O,CAAC;AACjB,CAAC","sourcesContent":["/*\n * ---------------------------------------------------------------------------\n * Emit: produce the JS / d.ts artifacts via the TypeScript 7 `program.emit()`,\n * then inject the jsii runtime type information (the `Symbol.for(\"jsii.rtti\")`\n * marker on each exported class) into the emitted `.js`. The previous\n * implementation did the injection with a `CustomTransformer` during emit; the\n * TypeScript 7 API has no transformer hook, so this is a post-emit text pass\n * (the injected code is the same).\n * ---------------------------------------------------------------------------\n */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-return */\nimport * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport * as spec from '@jsii/spec';\nimport * as log4js from 'log4js';\n\nimport { TypeScriptProject } from './compiler-host';\n\nconst LOG = log4js.getLogger('jsii/emitter');\n\nexport interface EmitProjectOptions {\n readonly projectRoot: string;\n readonly assembly: spec.Assembly;\n /** tsc `outDir` from the jsii config (for mapping source -> emitted js path). */\n readonly outDir?: string;\n /** tsc `rootDir` from the jsii config. */\n readonly rootDir?: string;\n}\n\nexport interface EmitProjectResult {\n readonly emittedFiles: string[];\n}\n\n/** The jsii runtime-type-information symbol key (see @jsii/runtime). */\nconst RTTI_SYMBOL = 'jsii.rtti';\n\n/**\n * Emit JS/d.ts for the whole project in a SINGLE `program.emit()` call. The\n * server writes every output file directly to disk and returns only file names,\n * so the ~345MB emit payload (aws-cdk-lib) never crosses the RPC channel; jsii\n * then reads back only the class-bearing `.js` files to append the jsii rtti\n * marker.\n *\n * NOTE (perf/stability): emitting per source file would issue one round-trip\n * per file and, at aws-cdk-lib scale (~thousands of files), was observed to\n * destabilize the out-of-process session (EPIPE / process exit). The\n * whole-project emit collapses this to one request.\n */\nexport function emitProject(project: TypeScriptProject, options: EmitProjectOptions): EmitProjectResult {\n const { program } = project;\n const root = options.projectRoot;\n const assembly = options.assembly;\n\n // Map the emitted `.js` path (relative to root, normalized) -> classes to stamp\n // with rtti. Derive the emitted path from each class's source `locationInModule`\n // via the tsc outDir/rootDir transform, so it is robust to duplicate basenames\n // across modules (common at aws-cdk-lib scale). We also index by basename as a\n // fallback for simple layouts.\n const classesByJsRel = new Map<string, Array<{ name: string; fqn: string }>>();\n // Basename fallback index: basename -> the set of jsRel paths that share it.\n // The fallback is only safe when a basename is unambiguous (single jsRel).\n const jsRelsByBasename = new Map<string, Set<string>>();\n for (const [fqn, type] of Object.entries(assembly.types ?? {})) {\n if ((type as any).kind !== spec.TypeKind.Class) {\n continue;\n }\n const relSrc: string | undefined = (type as any).locationInModule?.filename;\n if (!relSrc) {\n continue;\n }\n const entry = { name: (type as any).name, fqn };\n const jsRel = sourceRelToJsRel(relSrc, options.outDir, options.rootDir);\n if (!classesByJsRel.has(jsRel)) {\n classesByJsRel.set(jsRel, []);\n }\n classesByJsRel.get(jsRel)!.push(entry);\n const base = path.basename(jsRel);\n if (!jsRelsByBasename.has(base)) {\n jsRelsByBasename.set(base, new Set());\n }\n jsRelsByBasename.get(base)!.add(jsRel);\n }\n\n const emittedFiles: string[] = [];\n\n // Whole-project emit (see the function docblock for why this is one RPC).\n // `program.emit()` writes to the host filesystem and returns\n // { emitSkipped, diagnostics, emittedFiles } with absolute file names.\n const result = program.emit();\n if (result?.emitSkipped) {\n const reasons = (result.diagnostics ?? []).map((d: any) => d.text ?? d.messageText ?? String(d)).slice(0, 5);\n throw new Error(`TypeScript emit was skipped${reasons.length ? `: ${reasons.join('; ')}` : ''}`);\n }\n let outputNames: string[] | undefined = result?.emittedFiles;\n if (outputNames === undefined) {\n // emittedFiles may be omitted by the server; fall back to the class-bearing\n // JS files we can derive locally (sufficient for rtti injection).\n outputNames = [...classesByJsRel.keys()];\n }\n\n for (const name of outputNames) {\n const outPath = path.resolve(root, name);\n emittedFiles.push(outPath);\n\n if (!/\\.js$/.test(name)) {\n continue; // non-JS (d.ts / maps): already written by the server, nothing to do\n }\n const jsRel = normalizeRel(path.relative(root, outPath));\n let classesHere = classesByJsRel.get(jsRel);\n if (!classesHere) {\n // Fall back to basename matching ONLY when it is unambiguous (a single\n // source file maps to this basename); otherwise skip and say so.\n const candidates = jsRelsByBasename.get(path.basename(name));\n if (candidates?.size === 1) {\n classesHere = classesByJsRel.get([...candidates][0]);\n } else if (candidates && candidates.size > 1) {\n LOG.warn(\n `ts backend: skipping rtti injection for ${jsRel} (ambiguous basename across ${candidates.size} files)`,\n );\n }\n }\n if (!classesHere || !classesHere.length) {\n continue; // JS without exported classes: no rtti to inject, leave as written\n }\n // Read the server-written JS, inject the rtti snippet, write it back. Only a\n // small fraction of files (those declaring exported classes) are touched.\n const onDisk = fs.readFileSync(outPath, 'utf8');\n fs.writeFileSync(outPath, injectRtti(onDisk, rttiSnippet(classesHere, assembly.version)), { encoding: 'utf8' });\n }\n\n return { emittedFiles };\n}\n\n/** Normalize a relative path for use as a map key (posix separators). */\nfunction normalizeRel(p: string): string {\n return p.split(path.sep).join('/');\n}\n\n/**\n * Transform a source path (relative to root, e.g. `src/foo.ts`) into the emitted\n * JS path (relative to root, e.g. `lib/foo.js`) using the tsc outDir/rootDir.\n */\nfunction sourceRelToJsRel(relSrc: string, outDir?: string, rootDir?: string): string {\n let p = relSrc.replace(/\\.tsx?$/, '.js');\n if (rootDir != null && outDir != null) {\n const rootRel = normalizeRel(path.relative(rootDir, p));\n if (!rootRel.startsWith('..')) {\n p = path.join(outDir, rootRel);\n }\n }\n return normalizeRel(p);\n}\n\n/**\n * Insert the rtti snippet into emitted JS. When the file ends with a\n * `//# sourceMappingURL=` comment, the snippet is inserted BEFORE it so the\n * marker comment stays the last line of the file (tooling convention).\n * Exported for unit tests.\n */\nexport function injectRtti(source: string, snippet: string): string {\n const m = /\\n\\/\\/# sourceMappingURL=[^\\n]*\\s*$/.exec(source);\n if (m) {\n return source.slice(0, m.index) + snippet.replace(/\\n$/, '') + source.slice(m.index);\n }\n return source + snippet;\n}\n\n/**\n * Build the post-emit rtti injection snippet for a set of classes, matching the\n * shape the classic runtime-info transformer produces at runtime.\n * Exported for unit tests.\n */\nexport function rttiSnippet(classes: Array<{ name: string; fqn: string }>, version: string): string {\n let snippet = '\\n// jsii runtime type information (injected after emit)\\n';\n for (const c of classes) {\n snippet +=\n `try { Object.defineProperty(exports.${c.name}, Symbol.for(\"${RTTI_SYMBOL}\"), ` +\n `{ value: { fqn: ${JSON.stringify(c.fqn)}, version: ${JSON.stringify(\n version,\n )} }, configurable: true }); } catch (e) { }\\n`;\n }\n return snippet;\n}\n"]}
|
package/lib/helpers.d.ts
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { PackageJson } from '@jsii/spec';
|
|
9
9
|
import * as spec from '@jsii/spec';
|
|
10
|
-
import { Diagnostic } from 'typescript';
|
|
11
10
|
import { CompilerOptions } from './compiler';
|
|
11
|
+
import { Diagnostic } from './diagnostic';
|
|
12
12
|
/**
|
|
13
13
|
* A set of source files for `sourceToAssemblyHelper`, at least containing 'index.ts'
|
|
14
14
|
*/
|
package/lib/helpers.js
CHANGED
|
@@ -48,8 +48,8 @@ const fs = __importStar(require("node:fs"));
|
|
|
48
48
|
const os = __importStar(require("node:os"));
|
|
49
49
|
const path = __importStar(require("node:path"));
|
|
50
50
|
const spec_1 = require("@jsii/spec");
|
|
51
|
-
const typescript_1 = require("typescript");
|
|
52
51
|
const compiler_1 = require("./compiler");
|
|
52
|
+
const diagnostic_1 = require("./diagnostic");
|
|
53
53
|
const project_info_1 = require("./project-info");
|
|
54
54
|
const utils_1 = require("./utils");
|
|
55
55
|
/**
|
|
@@ -105,7 +105,7 @@ function compileJsiiForTest(source, options, compilerOptions) {
|
|
|
105
105
|
...compilerOptions,
|
|
106
106
|
});
|
|
107
107
|
const emitResult = compiler.emit();
|
|
108
|
-
const errors = emitResult.diagnostics.filter((d) => d.category ===
|
|
108
|
+
const errors = emitResult.diagnostics.filter((d) => d.category === diagnostic_1.DiagnosticCategory.Error);
|
|
109
109
|
if (typeof options !== 'object' || !options?.captureDiagnostics) {
|
|
110
110
|
for (const error of errors) {
|
|
111
111
|
console.error((0, utils_1.formatDiagnostic)(error, projectInfo.projectRoot));
|
package/lib/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCH,wDASC;AA4DD,gDAsFC;AA2MD,kDAKC;AA7YD,4CAA8B;AAC9B,4CAA8B;AAC9B,gDAAkC;AAClC,qCAA8E;AAE9E,2CAA4D;AAE5D,yCAAuD;AACvD,iDAA8D;AAC9D,mCAAsD;AAUtD;;GAEG;AACU,QAAA,2BAA2B,GAAuB,CAAC,oBAAoB,EAAE,2BAA2B,CAAC,CAAC;AAEnH;;;;;;;;;GASG;AACH,SAAgB,sBAAsB,CACpC,MAAoC,EACpC,OAA+D;IAE/D,MAAM,MAAM,GAAG,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnD,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;IACxC,CAAC;IACD,OAAO,MAAM,CAAC,QAAQ,CAAC;AACzB,CAAC;AAkDD;;;;;;;;;GASG;AACH,SAAgB,kBAAkB,CAChC,MAA+D,EAC/D,OAA0C,EAC1C,eAAgE;IAEhE,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,MAAM,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC;IAClC,CAAC;IAED,MAAM,cAAc,GAClB,eAAe,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAElH,oFAAoF;IACpF,+EAA+E;IAC/E,O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,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAClE,CAAC;CACF;AA/ED,sCA+EC;AAKD;;;;;;;GAOG;AACH,SAAgB,mBAAmB,CAAC,IAAY,EAAE,eAAwB;IACxE,IAAI,eAAe,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;QACjE,OAAO,eAAe,CAAC;IACzB,CAAC;IACD,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;AAC9C,CAAC","sourcesContent":["/**\n * Helper routines for use with the jsii compiler\n *\n * These are mostly used for testing, but all projects that need to exercise\n * the JSII compiler to test something need to share this code, so might as\n * well put it in one reusable place.\n */\n\nimport * as fs from 'node:fs';\nimport * as os from 'node:os';\nimport * as path from 'node:path';\nimport { PackageJson, loadAssemblyFromPath, writeAssembly } from '@jsii/spec';\nimport * as spec from '@jsii/spec';\nimport { Diagnostic, DiagnosticCategory } from 'typescript';\n\nimport { Compiler, CompilerOptions } from './compiler';\nimport { loadProjectInfo, ProjectInfo } from './project-info';\nimport { formatDiagnostic, JsiiError } from './utils';\n\n/**\n * A set of source files for `sourceToAssemblyHelper`, at least containing 'index.ts'\n */\nexport type MultipleSourceFiles = {\n 'index.ts': string;\n [name: string]: string;\n};\n\n/**\n * Assembly features supported by this compiler\n */\nexport const ASSEMBLY_FEATURES_SUPPORTED: spec.JsiiFeature[] = ['intersection-types', 'class-covariant-overrides'];\n\n/**\n * Compile a piece of source and return the JSII assembly for it\n *\n * Only usable for trivial cases and tests.\n *\n * @param source can either be a single `string` (the content of `index.ts`), or\n * a map of fileName to content, which *must* include `index.ts`.\n * @param options accepts a callback for historical reasons but really expects to\n * take an options object.\n */\nexport function sourceToAssemblyHelper(\n source: string | MultipleSourceFiles,\n options?: TestCompilationOptions | ((obj: PackageJson) => void),\n): spec.Assembly {\n const result = compileJsiiForTest(source, options);\n if (result.type !== 'success') {\n throw new Error('Compilation failed');\n }\n return result.assembly;\n}\n\nexport type HelperCompilationOut = HelperCompilationResult | HelperCompilationFailure;\n\n/**\n * Successful output of a compilation command (for testing)\n *\n * A better name would have been `HelperCompilationSuccess`, but the name is part of\n * the public API surface, so we keep it like this.\n */\nexport interface HelperCompilationResult {\n readonly type: 'success';\n\n /**\n * The generated assembly\n */\n readonly assembly: spec.Assembly;\n\n /**\n * Generated .js/.d.ts file(s)\n */\n readonly files: Record<string, string>;\n\n /**\n * The packageInfo used\n */\n readonly packageJson: PackageJson;\n\n /**\n * Whether to compress the assembly file\n */\n readonly compressAssembly: boolean;\n\n /**\n * Diagnostics that occurred during compilation\n */\n readonly diagnostics: readonly Diagnostic[];\n}\n\nexport interface HelperCompilationFailure {\n readonly type: 'failure';\n\n /**\n * Diagnostics that occurred during compilation\n *\n * Contains at least one error.\n */\n readonly diagnostics: readonly Diagnostic[];\n}\n\n/**\n * Compile a piece of source and return the assembly and compiled sources for it\n *\n * Only usable for trivial cases and tests.\n *\n * @param source can either be a single `string` (the content of `index.ts`), or\n * a map of fileName to content, which *must* include `index.ts`.\n * @param options accepts a callback for historical reasons but really expects to\n * take an options object.\n */\nexport function compileJsiiForTest<O extends TestCompilationOptions>(\n source: string | { 'index.ts': string; [name: string]: string },\n options?: O | ((obj: PackageJson) => void),\n compilerOptions?: Omit<CompilerOptions, 'projectInfo' | 'watch'>,\n): ResultOrSuccess<O> {\n if (typeof source === 'string') {\n source = { 'index.ts': source };\n }\n\n const inSomeLocation =\n isOptionsObject(options) && options.compilationDirectory ? inOtherDir(options.compilationDirectory) : inTempDir;\n\n // Easiest way to get the source into the compiler is to write it to disk somewhere.\n // I guess we could make an in-memory compiler host but that seems like work...\n return inSomeLocation(() => {\n for (const [fileName, content] of Object.entries(source)) {\n fs.mkdirSync(path.dirname(fileName), { recursive: true });\n fs.writeFileSync(fileName, content, { encoding: 'utf-8' });\n }\n const { projectInfo, packageJson } = makeProjectInfo(\n 'index.ts',\n typeof options === 'function'\n ? options\n : (pi) => {\n Object.assign(pi, options?.packageJson ?? options?.projectInfo ?? {});\n },\n );\n const compiler = new Compiler({\n projectInfo,\n ...compilerOptions,\n });\n const emitResult = compiler.emit();\n\n const errors = emitResult.diagnostics.filter((d) => d.category === DiagnosticCategory.Error);\n\n if (typeof options !== 'object' || !options?.captureDiagnostics) {\n for (const error of errors) {\n console.error(formatDiagnostic(error, projectInfo.projectRoot));\n // logDiagnostic() doesn't work out of the box, so console.error() it is.\n }\n }\n\n if (errors.length > 0 || emitResult.emitSkipped) {\n if (typeof options === 'object' && options?.captureDiagnostics) {\n return {\n type: 'failure',\n diagnostics: emitResult.diagnostics,\n } satisfies HelperCompilationFailure;\n }\n throw new JsiiError('There were compiler errors');\n }\n\n const assembly = loadAssemblyFromPath(process.cwd(), false, ASSEMBLY_FEATURES_SUPPORTED);\n const files: Record<string, string> = {};\n\n for (const filename of Object.keys(source)) {\n let jsFile = filename.replace(/\\.ts$/, '.js');\n let dtsFile = filename.replace(/\\.ts$/, '.d.ts');\n if (projectInfo.tsc?.outDir && filename !== 'README.md') {\n jsFile = path.join(projectInfo.tsc.outDir, jsFile);\n dtsFile = path.join(projectInfo.tsc.outDir, dtsFile);\n }\n\n // eslint-disable-next-line no-await-in-loop\n files[jsFile] = fs.readFileSync(jsFile, { encoding: 'utf-8' });\n // eslint-disable-next-line no-await-in-loop\n files[dtsFile] = fs.readFileSync(dtsFile, { encoding: 'utf-8' });\n\n const warningsFileName = '.warnings.jsii.js';\n if (fs.existsSync(warningsFileName)) {\n // eslint-disable-next-line no-await-in-loop\n files[warningsFileName] = fs.readFileSync(warningsFileName, {\n encoding: 'utf-8',\n });\n }\n }\n\n return {\n type: 'success',\n assembly,\n files,\n packageJson,\n compressAssembly: isOptionsObject(options) && options.compressAssembly ? true : false,\n diagnostics: emitResult.diagnostics,\n } satisfies HelperCompilationResult;\n }) as ResultOrSuccess<O>;\n}\n\ntype ResultOrSuccess<O extends TestCompilationOptions> = O['captureDiagnostics'] extends true\n ? HelperCompilationOut\n : HelperCompilationResult;\n\nfunction inTempDir<T>(block: () => T): T {\n const origDir = process.cwd();\n const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'jsii'));\n process.chdir(tmpDir);\n const ret = block();\n process.chdir(origDir);\n fs.rmSync(tmpDir, { force: true, recursive: true });\n return ret;\n}\n\nfunction inOtherDir(dir: string) {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint\n return <T extends unknown>(block: () => T): T => {\n const origDir = process.cwd();\n process.chdir(dir);\n try {\n return block();\n } finally {\n process.chdir(origDir);\n }\n };\n}\n\n/**\n * Obtain project info so we can call the compiler\n *\n * Creating this directly in-memory leads to slightly different behavior from calling\n * jsii from the command-line, and I don't want to figure out right now.\n *\n * Most consistent behavior seems to be to write a package.json to disk and\n * then calling the same functions as the CLI would.\n */\nfunction makeProjectInfo(\n types: string,\n cb?: (obj: PackageJson) => void,\n): { projectInfo: ProjectInfo; packageJson: PackageJson } {\n const packageJson: PackageJson = {\n types,\n main: types.replace(/(?:\\.d)?\\.ts(x?)/, '.js$1'),\n name: 'testpkg', // That's what package.json would tell if we look up...\n version: '0.0.1',\n license: 'Apache-2.0',\n author: { name: 'John Doe' },\n repository: { type: 'git', url: 'https://github.com/aws/jsii.git' },\n jsii: {},\n };\n\n if (cb) {\n cb(packageJson);\n }\n\n fs.writeFileSync(\n 'package.json',\n JSON.stringify(packageJson, (_: string, v: any) => v, 2),\n 'utf-8',\n );\n\n const { projectInfo } = loadProjectInfo(path.resolve(process.cwd(), '.'));\n return { projectInfo, packageJson };\n}\n\nexport interface TestCompilationOptions {\n /**\n * The directory in which we write and compile the files\n */\n readonly compilationDirectory?: string;\n\n /**\n * Parts of projectInfo to override (package name etc)\n *\n * @deprecated Prefer using `packageJson` instead.\n */\n readonly projectInfo?: Partial<PackageJson>;\n\n /**\n * Parts of projectInfo to override (package name etc)\n *\n * @default - Use some default values\n */\n readonly packageJson?: Partial<PackageJson>;\n\n /**\n * Whether to compress the assembly file.\n *\n * @default false\n */\n readonly compressAssembly?: boolean;\n\n /**\n * Whether or not to print the diagnostics\n *\n * @default false\n */\n readonly captureDiagnostics?: boolean;\n}\n\nfunction isOptionsObject(\n x: TestCompilationOptions | ((obj: PackageJson) => void) | undefined,\n): x is TestCompilationOptions {\n return x ? typeof x === 'object' : false;\n}\n\n/**\n * An NPM-ready workspace where we can install test-compile dependencies and compile new assemblies\n */\nexport class TestWorkspace {\n /**\n * Create a new workspace.\n *\n * Creates a temporary directory, don't forget to call cleanUp\n */\n public static create(): TestWorkspace {\n const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'jsii-testworkspace'));\n fs.mkdirSync(tmpDir, { recursive: true });\n return new TestWorkspace(tmpDir);\n }\n\n /**\n * Execute a block with a temporary workspace\n */\n public static withWorkspace<A>(block: (ws: TestWorkspace) => A): A {\n const ws = TestWorkspace.create();\n try {\n return block(ws);\n } finally {\n ws.cleanup();\n }\n }\n\n private readonly installed = new Set<string>();\n\n private constructor(public readonly rootDirectory: string) {}\n\n /**\n * Add a test-compiled jsii assembly as a dependency\n */\n public addDependency(dependencyAssembly: HelperCompilationOut) {\n if (dependencyAssembly.type !== 'success') {\n throw new JsiiError('Cannot add dependency: assembly compilation failed');\n }\n\n if (this.installed.has(dependencyAssembly.assembly.name)) {\n throw new JsiiError(\n `A dependency with name '${dependencyAssembly.assembly.name}' was already installed. Give one a different name.`,\n );\n }\n this.installed.add(dependencyAssembly.assembly.name);\n\n // The following is silly, however: the helper has compiled the given source to\n // an assembly, and output files, and then removed their traces from disk.\n // We need those files back on disk, so write them back out again.\n //\n // We will drop them in 'node_modules/<name>' so they can be imported\n // as if they were installed.\n const modDir = path.join(this.rootDirectory, 'node_modules', dependencyAssembly.assembly.name);\n fs.mkdirSync(modDir, { recursive: true });\n\n writeAssembly(modDir, dependencyAssembly.assembly, {\n compress: dependencyAssembly.compressAssembly,\n });\n fs.writeFileSync(\n path.join(modDir, 'package.json'),\n JSON.stringify(dependencyAssembly.packageJson, null, 2),\n 'utf-8',\n );\n\n for (const [fileName, fileContents] of Object.entries(dependencyAssembly.files)) {\n fs.mkdirSync(path.dirname(path.join(modDir, fileName)), {\n recursive: true,\n });\n fs.writeFileSync(path.join(modDir, fileName), fileContents);\n }\n }\n\n public dependencyDir(name: string) {\n if (!this.installed.has(name)) {\n throw new JsiiError(`No dependency with name '${name}' has been installed`);\n }\n return path.join(this.rootDirectory, 'node_modules', name);\n }\n\n public cleanup() {\n fs.rmSync(this.rootDirectory, { force: true, recursive: true });\n }\n}\n\n// Alias for backwards compatibility\nexport type PackageInfo = PackageJson;\n\n/**\n * TSConfig paths can either be relative to the project or absolute.\n * This function normalizes paths to be relative to the provided root.\n * After normalization, code using these paths can be much simpler.\n *\n * @param root the project root\n * @param pathToNormalize the path to normalize, might be empty\n */\nexport function normalizeConfigPath(root: string, pathToNormalize?: string): string | undefined {\n if (pathToNormalize == null || !path.isAbsolute(pathToNormalize)) {\n return pathToNormalize;\n }\n return path.relative(root, pathToNormalize);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"helpers.js","sources":["../src/helpers.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,MAAY,EAAE,oCAAgB;AAC9B,MAAY,EAAE,oCAAgB;AAC9B,MAAY,IAAI,sCAAkB;AAClC,qCAA8E;AAE9E,yCAAuD;AACvD,6CAA8D;AAE9D,iDAA8D;AAC9D,mCAAsD;AAUtD;;GAEG;AACU,QAAA,2BAA2B,GAAuB,CAAC,oBAAoB,EAAE,2BAA2B,CAAC,CAAC;AAEnH;;;;;;;;;GASG;AACH,gCACE,MAAoC,EACpC,OAA+D;IAE/D,MAAM,MAAM,GAAG,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnD,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;IACxC,CAAC;IACD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AAC;QAC9D,CAAC;IACH,CAAC;IAEM,aAAa,CAAC,IAAY;QAC/B,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YAC9B,MAAM,IAAI,iBAAS,CAAC,4BAA4B,IAAI,sBAAsB,CAAC,CAAC;QAC9E,CAAC;QACD,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,cAAc,EAAE,IAAI,CAAC,CAAC;IAC7D,CAAC;IAEM,OAAO;QACZ,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAClE,CAAC;CACF;;AAKD;;;;;;;GAOG;AACH,6BAAoC,IAAY,EAAE,eAAwB;IACxE,IAAI,eAAe,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;QACjE,OAAO,eAAe,CAAC;IACzB,CAAC;IACD,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;AAC9C,CAAC","sourcesContent":["/**\n * Helper routines for use with the jsii compiler\n *\n * These are mostly used for testing, but all projects that need to exercise\n * the JSII compiler to test something need to share this code, so might as\n * well put it in one reusable place.\n */\n\nimport * as fs from 'node:fs';\nimport * as os from 'node:os';\nimport * as path from 'node:path';\nimport { PackageJson, loadAssemblyFromPath, writeAssembly } from '@jsii/spec';\nimport * as spec from '@jsii/spec';\nimport { Compiler, CompilerOptions } from './compiler';\nimport { Diagnostic, DiagnosticCategory } from './diagnostic';\n\nimport { loadProjectInfo, ProjectInfo } from './project-info';\nimport { formatDiagnostic, JsiiError } from './utils';\n\n/**\n * A set of source files for `sourceToAssemblyHelper`, at least containing 'index.ts'\n */\nexport type MultipleSourceFiles = {\n 'index.ts': string;\n [name: string]: string;\n};\n\n/**\n * Assembly features supported by this compiler\n */\nexport const ASSEMBLY_FEATURES_SUPPORTED: spec.JsiiFeature[] = ['intersection-types', 'class-covariant-overrides'];\n\n/**\n * Compile a piece of source and return the JSII assembly for it\n *\n * Only usable for trivial cases and tests.\n *\n * @param source can either be a single `string` (the content of `index.ts`), or\n * a map of fileName to content, which *must* include `index.ts`.\n * @param options accepts a callback for historical reasons but really expects to\n * take an options object.\n */\nexport function sourceToAssemblyHelper(\n source: string | MultipleSourceFiles,\n options?: TestCompilationOptions | ((obj: PackageJson) => void),\n): spec.Assembly {\n const result = compileJsiiForTest(source, options);\n if (result.type !== 'success') {\n throw new Error('Compilation failed');\n }\n return result.assembly;\n}\n\nexport type HelperCompilationOut = HelperCompilationResult | HelperCompilationFailure;\n\n/**\n * Successful output of a compilation command (for testing)\n *\n * A better name would have been `HelperCompilationSuccess`, but the name is part of\n * the public API surface, so we keep it like this.\n */\nexport interface HelperCompilationResult {\n readonly type: 'success';\n\n /**\n * The generated assembly\n */\n readonly assembly: spec.Assembly;\n\n /**\n * Generated .js/.d.ts file(s)\n */\n readonly files: Record<string, string>;\n\n /**\n * The packageInfo used\n */\n readonly packageJson: PackageJson;\n\n /**\n * Whether to compress the assembly file\n */\n readonly compressAssembly: boolean;\n\n /**\n * Diagnostics that occurred during compilation\n */\n readonly diagnostics: readonly Diagnostic[];\n}\n\nexport interface HelperCompilationFailure {\n readonly type: 'failure';\n\n /**\n * Diagnostics that occurred during compilation\n *\n * Contains at least one error.\n */\n readonly diagnostics: readonly Diagnostic[];\n}\n\n/**\n * Compile a piece of source and return the assembly and compiled sources for it\n *\n * Only usable for trivial cases and tests.\n *\n * @param source can either be a single `string` (the content of `index.ts`), or\n * a map of fileName to content, which *must* include `index.ts`.\n * @param options accepts a callback for historical reasons but really expects to\n * take an options object.\n */\nexport function compileJsiiForTest<O extends TestCompilationOptions>(\n source: string | { 'index.ts': string; [name: string]: string },\n options?: O | ((obj: PackageJson) => void),\n compilerOptions?: Omit<CompilerOptions, 'projectInfo' | 'watch'>,\n): ResultOrSuccess<O> {\n if (typeof source === 'string') {\n source = { 'index.ts': source };\n }\n\n const inSomeLocation =\n isOptionsObject(options) && options.compilationDirectory ? inOtherDir(options.compilationDirectory) : inTempDir;\n\n // Easiest way to get the source into the compiler is to write it to disk somewhere.\n // I guess we could make an in-memory compiler host but that seems like work...\n return inSomeLocation(() => {\n for (const [fileName, content] of Object.entries(source)) {\n fs.mkdirSync(path.dirname(fileName), { recursive: true });\n fs.writeFileSync(fileName, content, { encoding: 'utf-8' });\n }\n const { projectInfo, packageJson } = makeProjectInfo(\n 'index.ts',\n typeof options === 'function'\n ? options\n : (pi) => {\n Object.assign(pi, options?.packageJson ?? options?.projectInfo ?? {});\n },\n );\n const compiler = new Compiler({\n projectInfo,\n ...compilerOptions,\n });\n const emitResult = compiler.emit();\n\n const errors = emitResult.diagnostics.filter((d) => d.category === DiagnosticCategory.Error);\n\n if (typeof options !== 'object' || !options?.captureDiagnostics) {\n for (const error of errors) {\n console.error(formatDiagnostic(error, projectInfo.projectRoot));\n // logDiagnostic() doesn't work out of the box, so console.error() it is.\n }\n }\n\n if (errors.length > 0 || emitResult.emitSkipped) {\n if (typeof options === 'object' && options?.captureDiagnostics) {\n return {\n type: 'failure',\n diagnostics: emitResult.diagnostics,\n } satisfies HelperCompilationFailure;\n }\n throw new JsiiError('There were compiler errors');\n }\n\n const assembly = loadAssemblyFromPath(process.cwd(), false, ASSEMBLY_FEATURES_SUPPORTED);\n const files: Record<string, string> = {};\n\n for (const filename of Object.keys(source)) {\n let jsFile = filename.replace(/\\.ts$/, '.js');\n let dtsFile = filename.replace(/\\.ts$/, '.d.ts');\n if (projectInfo.tsc?.outDir && filename !== 'README.md') {\n jsFile = path.join(projectInfo.tsc.outDir, jsFile);\n dtsFile = path.join(projectInfo.tsc.outDir, dtsFile);\n }\n\n // eslint-disable-next-line no-await-in-loop\n files[jsFile] = fs.readFileSync(jsFile, { encoding: 'utf-8' });\n // eslint-disable-next-line no-await-in-loop\n files[dtsFile] = fs.readFileSync(dtsFile, { encoding: 'utf-8' });\n\n const warningsFileName = '.warnings.jsii.js';\n if (fs.existsSync(warningsFileName)) {\n // eslint-disable-next-line no-await-in-loop\n files[warningsFileName] = fs.readFileSync(warningsFileName, {\n encoding: 'utf-8',\n });\n }\n }\n\n return {\n type: 'success',\n assembly,\n files,\n packageJson,\n compressAssembly: isOptionsObject(options) && options.compressAssembly ? true : false,\n diagnostics: emitResult.diagnostics,\n } satisfies HelperCompilationResult;\n }) as ResultOrSuccess<O>;\n}\n\ntype ResultOrSuccess<O extends TestCompilationOptions> = O['captureDiagnostics'] extends true\n ? HelperCompilationOut\n : HelperCompilationResult;\n\nfunction inTempDir<T>(block: () => T): T {\n const origDir = process.cwd();\n const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'jsii'));\n process.chdir(tmpDir);\n const ret = block();\n process.chdir(origDir);\n fs.rmSync(tmpDir, { force: true, recursive: true });\n return ret;\n}\n\nfunction inOtherDir(dir: string) {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint\n return <T extends unknown>(block: () => T): T => {\n const origDir = process.cwd();\n process.chdir(dir);\n try {\n return block();\n } finally {\n process.chdir(origDir);\n }\n };\n}\n\n/**\n * Obtain project info so we can call the compiler\n *\n * Creating this directly in-memory leads to slightly different behavior from calling\n * jsii from the command-line, and I don't want to figure out right now.\n *\n * Most consistent behavior seems to be to write a package.json to disk and\n * then calling the same functions as the CLI would.\n */\nfunction makeProjectInfo(\n types: string,\n cb?: (obj: PackageJson) => void,\n): { projectInfo: ProjectInfo; packageJson: PackageJson } {\n const packageJson: PackageJson = {\n types,\n main: types.replace(/(?:\\.d)?\\.ts(x?)/, '.js$1'),\n name: 'testpkg', // That's what package.json would tell if we look up...\n version: '0.0.1',\n license: 'Apache-2.0',\n author: { name: 'John Doe' },\n repository: { type: 'git', url: 'https://github.com/aws/jsii.git' },\n jsii: {},\n };\n\n if (cb) {\n cb(packageJson);\n }\n\n fs.writeFileSync(\n 'package.json',\n JSON.stringify(packageJson, (_: string, v: any) => v, 2),\n 'utf-8',\n );\n\n const { projectInfo } = loadProjectInfo(path.resolve(process.cwd(), '.'));\n return { projectInfo, packageJson };\n}\n\nexport interface TestCompilationOptions {\n /**\n * The directory in which we write and compile the files\n */\n readonly compilationDirectory?: string;\n\n /**\n * Parts of projectInfo to override (package name etc)\n *\n * @deprecated Prefer using `packageJson` instead.\n */\n readonly projectInfo?: Partial<PackageJson>;\n\n /**\n * Parts of projectInfo to override (package name etc)\n *\n * @default - Use some default values\n */\n readonly packageJson?: Partial<PackageJson>;\n\n /**\n * Whether to compress the assembly file.\n *\n * @default false\n */\n readonly compressAssembly?: boolean;\n\n /**\n * Whether or not to print the diagnostics\n *\n * @default false\n */\n readonly captureDiagnostics?: boolean;\n}\n\nfunction isOptionsObject(\n x: TestCompilationOptions | ((obj: PackageJson) => void) | undefined,\n): x is TestCompilationOptions {\n return x ? typeof x === 'object' : false;\n}\n\n/**\n * An NPM-ready workspace where we can install test-compile dependencies and compile new assemblies\n */\nexport class TestWorkspace {\n /**\n * Create a new workspace.\n *\n * Creates a temporary directory, don't forget to call cleanUp\n */\n public static create(): TestWorkspace {\n const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'jsii-testworkspace'));\n fs.mkdirSync(tmpDir, { recursive: true });\n return new TestWorkspace(tmpDir);\n }\n\n /**\n * Execute a block with a temporary workspace\n */\n public static withWorkspace<A>(block: (ws: TestWorkspace) => A): A {\n const ws = TestWorkspace.create();\n try {\n return block(ws);\n } finally {\n ws.cleanup();\n }\n }\n\n private readonly installed = new Set<string>();\n\n private constructor(public readonly rootDirectory: string) {}\n\n /**\n * Add a test-compiled jsii assembly as a dependency\n */\n public addDependency(dependencyAssembly: HelperCompilationOut) {\n if (dependencyAssembly.type !== 'success') {\n throw new JsiiError('Cannot add dependency: assembly compilation failed');\n }\n\n if (this.installed.has(dependencyAssembly.assembly.name)) {\n throw new JsiiError(\n `A dependency with name '${dependencyAssembly.assembly.name}' was already installed. Give one a different name.`,\n );\n }\n this.installed.add(dependencyAssembly.assembly.name);\n\n // The following is silly, however: the helper has compiled the given source to\n // an assembly, and output files, and then removed their traces from disk.\n // We need those files back on disk, so write them back out again.\n //\n // We will drop them in 'node_modules/<name>' so they can be imported\n // as if they were installed.\n const modDir = path.join(this.rootDirectory, 'node_modules', dependencyAssembly.assembly.name);\n fs.mkdirSync(modDir, { recursive: true });\n\n writeAssembly(modDir, dependencyAssembly.assembly, {\n compress: dependencyAssembly.compressAssembly,\n });\n fs.writeFileSync(\n path.join(modDir, 'package.json'),\n JSON.stringify(dependencyAssembly.packageJson, null, 2),\n 'utf-8',\n );\n\n for (const [fileName, fileContents] of Object.entries(dependencyAssembly.files)) {\n fs.mkdirSync(path.dirname(path.join(modDir, fileName)), {\n recursive: true,\n });\n fs.writeFileSync(path.join(modDir, fileName), fileContents);\n }\n }\n\n public dependencyDir(name: string) {\n if (!this.installed.has(name)) {\n throw new JsiiError(`No dependency with name '${name}' has been installed`);\n }\n return path.join(this.rootDirectory, 'node_modules', name);\n }\n\n public cleanup() {\n fs.rmSync(this.rootDirectory, { force: true, recursive: true });\n }\n}\n\n// Alias for backwards compatibility\nexport type PackageInfo = PackageJson;\n\n/**\n * TSConfig paths can either be relative to the project or absolute.\n * This function normalizes paths to be relative to the provided root.\n * After normalization, code using these paths can be much simpler.\n *\n * @param root the project root\n * @param pathToNormalize the path to normalize, might be empty\n */\nexport function normalizeConfigPath(root: string, pathToNormalize?: string): string | undefined {\n if (pathToNormalize == null || !path.isAbsolute(pathToNormalize)) {\n return pathToNormalize;\n }\n return path.relative(root, pathToNormalize);\n}\n"]}
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,qDAAmC;AACnC,4CAA0B","sourcesContent":["export * from './jsii-diagnostic';\nexport * from './common/symbol-id';\nexport * from './helpers';\n"]}
|
package/lib/jsii-diagnostic.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as spec from '@jsii/spec';
|
|
2
|
-
import
|
|
3
|
-
import { TypeSystemHints } from './docs';
|
|
2
|
+
import { Diagnostic, DiagnosticCategory, DiagnosticSourceFile } from './diagnostic';
|
|
4
3
|
import { Violation } from './tsconfig/validator';
|
|
5
4
|
/**
|
|
6
5
|
* Descriptors for all valid jsii diagnostic codes.
|
|
@@ -51,15 +50,15 @@ export declare class Code<T extends DiagnosticMessageFormatter = DiagnosticMessa
|
|
|
51
50
|
/**
|
|
52
51
|
* The diagnostic category this particular code is filed as.
|
|
53
52
|
*/
|
|
54
|
-
get category():
|
|
53
|
+
get category(): DiagnosticCategory;
|
|
55
54
|
/**
|
|
56
55
|
* Update the diagnostic category for this particular code. If `isError` is
|
|
57
|
-
* `true`, attempting to set anything other than `
|
|
56
|
+
* `true`, attempting to set anything other than `DiagnosticCategory.Error`
|
|
58
57
|
* will result in an error being throw.
|
|
59
58
|
*
|
|
60
59
|
* @param newValue the new diagnostic category to be used.
|
|
61
60
|
*/
|
|
62
|
-
set category(newValue:
|
|
61
|
+
set category(newValue: DiagnosticCategory);
|
|
63
62
|
/**
|
|
64
63
|
* Creates a new `JsiiDiagnostic` message without any source code location
|
|
65
64
|
* data.
|
|
@@ -78,12 +77,18 @@ export declare class Code<T extends DiagnosticMessageFormatter = DiagnosticMessa
|
|
|
78
77
|
* @param location the source code location attachment of the message.
|
|
79
78
|
* @param args the arguments to the message formatter.
|
|
80
79
|
*/
|
|
81
|
-
create(location:
|
|
80
|
+
create(location: DiagnosticLocation | undefined, ...args: Parameters<T>): JsiiDiagnostic;
|
|
82
81
|
}
|
|
83
82
|
/**
|
|
84
83
|
* A jsii-specific diagnostic entry.
|
|
85
84
|
*/
|
|
86
|
-
|
|
85
|
+
/** A source range a diagnostic points at. */
|
|
86
|
+
export interface DiagnosticLocation {
|
|
87
|
+
readonly file: DiagnosticSourceFile;
|
|
88
|
+
readonly start: number;
|
|
89
|
+
readonly length: number;
|
|
90
|
+
}
|
|
91
|
+
export declare class JsiiDiagnostic implements Diagnostic {
|
|
87
92
|
#private;
|
|
88
93
|
static readonly JSII_0001_PKG_MISSING_DESCRIPTION: Code<() => string>;
|
|
89
94
|
static readonly JSII_0002_PKG_MISSING_HOMEPAGE: Code<() => string>;
|
|
@@ -114,12 +119,12 @@ export declare class JsiiDiagnostic implements ts.Diagnostic {
|
|
|
114
119
|
static readonly JSII_2100_STRUCT_ON_NON_INTERFACE: Code<() => string>;
|
|
115
120
|
static readonly JSII_2999_UNKNOWN_DIRECTIVE: Code<(text: string) => string>;
|
|
116
121
|
static readonly JSII_3000_EXPORTED_API_USES_HIDDEN_TYPE: Code<(badFqn: any) => string>;
|
|
117
|
-
static readonly JSII_3001_EXPOSED_INTERNAL_TYPE: Code<(
|
|
122
|
+
static readonly JSII_3001_EXPOSED_INTERNAL_TYPE: Code<(symbolName: string, isThisType: boolean, typeUse: string) => string>;
|
|
118
123
|
static readonly JSII_3002_USE_OF_UNEXPORTED_FOREIGN_TYPE: Code<(fqn: string, typeUse: string, pkg: {
|
|
119
124
|
readonly name: string;
|
|
120
125
|
}) => string>;
|
|
121
126
|
static readonly JSII_3003_SYMBOL_IS_EXPORTED_TWICE: Code<(ns1: string, ns2: string) => string>;
|
|
122
|
-
static readonly JSII_3004_INVALID_SUPERTYPE: Code<(
|
|
127
|
+
static readonly JSII_3004_INVALID_SUPERTYPE: Code<(clauseType: string, badDeclarationKind: string) => string>;
|
|
123
128
|
static readonly JSII_3005_TYPE_USED_AS_INTERFACE: Code<(badType: spec.TypeReference) => string>;
|
|
124
129
|
static readonly JSII_3006_TYPE_USED_AS_CLASS: Code<(badType: spec.TypeReference) => string>;
|
|
125
130
|
static readonly JSII_3007_ILLEGAL_STRUCT_EXTENSION: Code<(offender: spec.Type, struct: spec.InterfaceType) => string>;
|
|
@@ -131,7 +136,7 @@ export declare class JsiiDiagnostic implements ts.Diagnostic {
|
|
|
131
136
|
static readonly JSII_4010_SUBMODULE_NAMESPACE_CONFLICT: Code<(language: string, namespace: string, modules: string[]) => string>;
|
|
132
137
|
static readonly JSII_5000_JAVA_GETTERS: Code<(badName: string, typeName: string) => string>;
|
|
133
138
|
static readonly JSII_5001_JAVA_SETTERS: Code<(badName: string, typeName: string) => string>;
|
|
134
|
-
static readonly JSII_5002_OVERRIDE_CHANGES_VISIBILITY: Code<(newElement: string, action: string, newValue:
|
|
139
|
+
static readonly JSII_5002_OVERRIDE_CHANGES_VISIBILITY: Code<(newElement: string, action: string, newValue: 'protected' | 'public', oldValue: 'protected' | 'public') => string>;
|
|
135
140
|
static readonly JSII_5003_OVERRIDE_CHANGES_RETURN_TYPE: Code<(newElement: string, action: string, newValue: string, oldValue: string) => string>;
|
|
136
141
|
static readonly JSII_5004_OVERRIDE_CHANGES_PROP_TYPE: Code<(newElement: string, action: string, newType: spec.TypeReference, oldType: spec.TypeReference) => string>;
|
|
137
142
|
static readonly JSII_5005_OVERRIDE_CHANGES_PARAM_COUNT: Code<(newElement: string, action: string, newCount: number, oldCount: number) => string>;
|
|
@@ -148,11 +153,11 @@ export declare class JsiiDiagnostic implements ts.Diagnostic {
|
|
|
148
153
|
static readonly JSII_5016_PROHIBITED_MEMBER_NAME: Code<(badName: string) => string>;
|
|
149
154
|
static readonly JSII_5017_POSITIONAL_KEYWORD_CONFLICT: Code<(badName: string) => string>;
|
|
150
155
|
static readonly JSII_5018_RESERVED_WORD: Code<(badName: string, languages: readonly string[]) => string>;
|
|
151
|
-
static readonly JSII_5019_MEMBER_TYPE_NAME_CONFLICT: Code<(memberKind:
|
|
156
|
+
static readonly JSII_5019_MEMBER_TYPE_NAME_CONFLICT: Code<(memberKind: 'method' | 'property', memberName: string, declaringType: spec.Type) => string>;
|
|
152
157
|
static readonly JSII_5020_STATIC_MEMBER_CONFLICTS_WITH_NESTED_TYPE: Code<(nestingType: spec.Type, staticMember: spec.Property | spec.Method | spec.EnumMember, nestedType: spec.Type) => string>;
|
|
153
158
|
static readonly JSII_5021_ABSTRACT_CLASS_MISSING_PROP_IMPL: Code<(intf: spec.InterfaceType, cls: spec.ClassType, prop: string) => string>;
|
|
154
159
|
static readonly JSII_7000_NON_EXISTENT_PARAMETER: Code<(method: spec.Method, param: string) => string>;
|
|
155
|
-
static readonly JSII_7001_ILLEGAL_HINT: Code<(hint:
|
|
160
|
+
static readonly JSII_7001_ILLEGAL_HINT: Code<(hint: string, ...valid: readonly string[]) => string>;
|
|
156
161
|
static readonly JSII_7999_DOCUMENTATION_ERROR: Code<(messageText: any) => any>;
|
|
157
162
|
static readonly JSII_8000_PASCAL_CASED_TYPE_NAMES: Code<(badName: string, expectedName?: string) => string>;
|
|
158
163
|
static readonly JSII_8001_ALL_CAPS_ENUM_MEMBERS: Code<(badName: string, typeName: string) => string>;
|
|
@@ -169,27 +174,27 @@ export declare class JsiiDiagnostic implements ts.Diagnostic {
|
|
|
169
174
|
static readonly JSII_9004_UNABLE_TO_COMPUTE_SIGNATURE: Code<(methodName: string, type: spec.Type) => string>;
|
|
170
175
|
static readonly JSII_9996_UNNECESSARY_TOKEN: Code<() => string>;
|
|
171
176
|
static readonly JSII_9997_UNKNOWN_ERROR: Code<(error: Error) => string>;
|
|
172
|
-
static readonly JSII_9998_UNSUPPORTED_NODE: Code<(kindOrMessage:
|
|
177
|
+
static readonly JSII_9998_UNSUPPORTED_NODE: Code<(kindOrMessage: string) => string>;
|
|
173
178
|
/**
|
|
174
179
|
* Determines whether a `Diagnostic` instance is a `JsiiDiagnostic` or not.
|
|
175
180
|
* @param diag
|
|
176
181
|
*/
|
|
177
|
-
static isJsiiDiagnostic(diag:
|
|
182
|
+
static isJsiiDiagnostic(diag: Diagnostic): diag is JsiiDiagnostic;
|
|
178
183
|
private static readonly JSII_9999_RELATED_INFO;
|
|
179
184
|
/**
|
|
180
185
|
* This symbol unequivocally identifies the `JsiiDiagnostic` domain.
|
|
181
186
|
*/
|
|
182
187
|
private static readonly DOMAIN;
|
|
183
188
|
private readonly domain;
|
|
184
|
-
readonly category:
|
|
189
|
+
readonly category: DiagnosticCategory;
|
|
185
190
|
readonly code: number;
|
|
186
191
|
readonly jsiiCode: number;
|
|
187
|
-
readonly messageText: string
|
|
188
|
-
readonly file:
|
|
192
|
+
readonly messageText: string;
|
|
193
|
+
readonly file: DiagnosticSourceFile | undefined;
|
|
189
194
|
readonly start: number | undefined;
|
|
190
195
|
readonly length: number | undefined;
|
|
191
|
-
readonly relatedInformation:
|
|
192
|
-
addRelatedInformation(
|
|
196
|
+
readonly relatedInformation: JsiiDiagnostic[];
|
|
197
|
+
addRelatedInformation(location: DiagnosticLocation, message: JsiiDiagnostic['messageText']): this;
|
|
193
198
|
/**
|
|
194
199
|
* Links the provided `node` with the specified `message` as related to the
|
|
195
200
|
* current diagnostic, unless `node` is undefined.
|
|
@@ -199,7 +204,7 @@ export declare class JsiiDiagnostic implements ts.Diagnostic {
|
|
|
199
204
|
*
|
|
200
205
|
* @returns `this`
|
|
201
206
|
*/
|
|
202
|
-
addRelatedInformationIf(node:
|
|
207
|
+
addRelatedInformationIf(node: DiagnosticLocation | undefined, message: JsiiDiagnostic['messageText']): this;
|
|
203
208
|
/**
|
|
204
209
|
* Adds related information to this `JsiiDiagnostic` instance if the provided
|
|
205
210
|
* `node` is defined.
|
|
@@ -209,7 +214,7 @@ export declare class JsiiDiagnostic implements ts.Diagnostic {
|
|
|
209
214
|
*
|
|
210
215
|
* @returns `this`
|
|
211
216
|
*/
|
|
212
|
-
maybeAddRelatedInformation(node:
|
|
217
|
+
maybeAddRelatedInformation(node: DiagnosticLocation | undefined, message: JsiiDiagnostic['messageText']): this;
|
|
213
218
|
/**
|
|
214
219
|
* Formats this diagnostic with color and context if possible, and returns it.
|
|
215
220
|
* The formatted diagnostic is cached, so that it can be re-used. This is
|
|
@@ -221,6 +226,6 @@ export declare class JsiiDiagnostic implements ts.Diagnostic {
|
|
|
221
226
|
}
|
|
222
227
|
export type DiagnosticMessageFormatter = (...args: any[]) => JsiiDiagnostic['messageText'];
|
|
223
228
|
export declare function configureCategories(records: {
|
|
224
|
-
[code: string]:
|
|
229
|
+
[code: string]: DiagnosticCategory;
|
|
225
230
|
}): void;
|
|
226
231
|
//# sourceMappingURL=jsii-diagnostic.d.ts.map
|
package/lib/jsii-diagnostic.js
CHANGED
|
@@ -37,8 +37,7 @@ exports.JsiiDiagnostic = exports.Code = void 0;
|
|
|
37
37
|
exports.configureCategories = configureCategories;
|
|
38
38
|
const spec = __importStar(require("@jsii/spec"));
|
|
39
39
|
const case_1 = require("case");
|
|
40
|
-
const
|
|
41
|
-
const deprecation_warnings_1 = require("./transforms/deprecation-warnings");
|
|
40
|
+
const diagnostic_1 = require("./diagnostic");
|
|
42
41
|
const utils_1 = require("./utils");
|
|
43
42
|
/**
|
|
44
43
|
* Descriptors for all valid jsii diagnostic codes.
|
|
@@ -53,25 +52,25 @@ class Code {
|
|
|
53
52
|
* @internal
|
|
54
53
|
*/
|
|
55
54
|
static message({ code, name, formatter, }) {
|
|
56
|
-
return new Code(code, name,
|
|
55
|
+
return new Code(code, name, diagnostic_1.DiagnosticCategory.Message, formatter);
|
|
57
56
|
}
|
|
58
57
|
/**
|
|
59
58
|
* @internal
|
|
60
59
|
*/
|
|
61
60
|
static suggestion({ code, name, formatter, }) {
|
|
62
|
-
return new Code(code, name,
|
|
61
|
+
return new Code(code, name, diagnostic_1.DiagnosticCategory.Suggestion, formatter);
|
|
63
62
|
}
|
|
64
63
|
/**
|
|
65
64
|
* @internal
|
|
66
65
|
*/
|
|
67
66
|
static warning({ code, name, formatter, }) {
|
|
68
|
-
return new Code(code, name,
|
|
67
|
+
return new Code(code, name, diagnostic_1.DiagnosticCategory.Warning, formatter);
|
|
69
68
|
}
|
|
70
69
|
/**
|
|
71
70
|
* @internal
|
|
72
71
|
*/
|
|
73
72
|
static error({ code, name, formatter, }) {
|
|
74
|
-
return new Code(code, name,
|
|
73
|
+
return new Code(code, name, diagnostic_1.DiagnosticCategory.Error, formatter);
|
|
75
74
|
}
|
|
76
75
|
/**
|
|
77
76
|
* Get a diagnostic code by code or name.
|
|
@@ -142,7 +141,7 @@ class Code {
|
|
|
142
141
|
* category.
|
|
143
142
|
*/
|
|
144
143
|
get isError() {
|
|
145
|
-
return this.#defaultCategory ===
|
|
144
|
+
return this.#defaultCategory === diagnostic_1.DiagnosticCategory.Error;
|
|
146
145
|
}
|
|
147
146
|
/**
|
|
148
147
|
* The diagnostic category this particular code is filed as.
|
|
@@ -152,14 +151,14 @@ class Code {
|
|
|
152
151
|
}
|
|
153
152
|
/**
|
|
154
153
|
* Update the diagnostic category for this particular code. If `isError` is
|
|
155
|
-
* `true`, attempting to set anything other than `
|
|
154
|
+
* `true`, attempting to set anything other than `DiagnosticCategory.Error`
|
|
156
155
|
* will result in an error being throw.
|
|
157
156
|
*
|
|
158
157
|
* @param newValue the new diagnostic category to be used.
|
|
159
158
|
*/
|
|
160
159
|
set category(newValue) {
|
|
161
|
-
if (this.isError && newValue !==
|
|
162
|
-
throw new Error(`Illegal attempt to override category of error ${this.code} to ${
|
|
160
|
+
if (this.isError && newValue !== diagnostic_1.DiagnosticCategory.Error) {
|
|
161
|
+
throw new Error(`Illegal attempt to override category of error ${this.code} to ${diagnostic_1.DiagnosticCategory[newValue]}`);
|
|
163
162
|
}
|
|
164
163
|
this.#category = newValue;
|
|
165
164
|
}
|
|
@@ -188,9 +187,6 @@ class Code {
|
|
|
188
187
|
}
|
|
189
188
|
}
|
|
190
189
|
exports.Code = Code;
|
|
191
|
-
/**
|
|
192
|
-
* A jsii-specific diagnostic entry.
|
|
193
|
-
*/
|
|
194
190
|
class JsiiDiagnostic {
|
|
195
191
|
//////////////////////////////////////////////////////////////////////////////
|
|
196
192
|
// 0001 => 0999 -- PACKAGE METADATA PROBLEMS
|
|
@@ -233,7 +229,7 @@ class JsiiDiagnostic {
|
|
|
233
229
|
static JSII_0007_MISSING_WARNINGS_EXPORT = Code.error({
|
|
234
230
|
code: 7,
|
|
235
231
|
formatter: () => 'If you are compiling with --add-deprecation-warnings and your package.json ' +
|
|
236
|
-
`declares subpath exports, you must include { "
|
|
232
|
+
`declares subpath exports, you must include { "./.warnings.jsii.js": "./.warnings.jsii.js" } ` +
|
|
237
233
|
'in the set of exports.',
|
|
238
234
|
name: 'metadata/missing-warnings-export',
|
|
239
235
|
});
|
|
@@ -337,7 +333,7 @@ class JsiiDiagnostic {
|
|
|
337
333
|
});
|
|
338
334
|
static JSII_3001_EXPOSED_INTERNAL_TYPE = Code.error({
|
|
339
335
|
code: 3001,
|
|
340
|
-
formatter: (
|
|
336
|
+
formatter: (symbolName, isThisType, typeUse) => `Type ${isThisType ? `"this" (aka: "${symbolName}")` : `"${symbolName}"`} cannot be used as the ${typeUse} because it is private or @internal`,
|
|
341
337
|
name: 'type-model/use-of-internal-type',
|
|
342
338
|
});
|
|
343
339
|
static JSII_3002_USE_OF_UNEXPORTED_FOREIGN_TYPE = Code.error({
|
|
@@ -352,19 +348,7 @@ class JsiiDiagnostic {
|
|
|
352
348
|
});
|
|
353
349
|
static JSII_3004_INVALID_SUPERTYPE = Code.error({
|
|
354
350
|
code: 3004,
|
|
355
|
-
formatter: (
|
|
356
|
-
return `Illegal ${clauseType(clause.token)} clause for an exported API: ${ts.SyntaxKind[badDeclaration.kind]}`;
|
|
357
|
-
function clauseType(token) {
|
|
358
|
-
switch (token) {
|
|
359
|
-
case ts.SyntaxKind.ExtendsKeyword:
|
|
360
|
-
return 'extends';
|
|
361
|
-
case ts.SyntaxKind.ImplementsKeyword:
|
|
362
|
-
return 'implements';
|
|
363
|
-
default:
|
|
364
|
-
return ts.SyntaxKind[token];
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
},
|
|
351
|
+
formatter: (clauseType, badDeclarationKind) => `Illegal ${clauseType} clause for an exported API: ${badDeclarationKind}`,
|
|
368
352
|
name: 'type-model/invalid-supertype',
|
|
369
353
|
});
|
|
370
354
|
static JSII_3005_TYPE_USED_AS_INTERFACE = Code.error({
|
|
@@ -519,7 +503,7 @@ class JsiiDiagnostic {
|
|
|
519
503
|
});
|
|
520
504
|
static JSII_5019_MEMBER_TYPE_NAME_CONFLICT = Code.warning({
|
|
521
505
|
code: 5019,
|
|
522
|
-
formatter: (memberKind,
|
|
506
|
+
formatter: (memberKind, memberName, declaringType) => `The ${memberKind} name "${memberName}" conflicts with the declaring ${declaringType.kind} "${declaringType.name}". This will result in renaming the ${declaringType.kind} to "_${declaringType.name}" in C#. Consider renaming "${memberName}".`,
|
|
523
507
|
name: 'language-compatibility/member-name-conflicts-with-type-name',
|
|
524
508
|
});
|
|
525
509
|
static JSII_5020_STATIC_MEMBER_CONFLICTS_WITH_NESTED_TYPE = Code.error({
|
|
@@ -632,9 +616,9 @@ class JsiiDiagnostic {
|
|
|
632
616
|
});
|
|
633
617
|
static JSII_9998_UNSUPPORTED_NODE = Code.message({
|
|
634
618
|
code: 9998,
|
|
635
|
-
formatter: (kindOrMessage) =>
|
|
636
|
-
? kindOrMessage
|
|
637
|
-
:
|
|
619
|
+
formatter: (kindOrMessage) => /^[A-Z]\w*$/.test(kindOrMessage)
|
|
620
|
+
? `Unsupported ${kindOrMessage} node. This declaration will not be accessible from other languages.`
|
|
621
|
+
: kindOrMessage,
|
|
638
622
|
name: 'miscellaneous/unsupported-node',
|
|
639
623
|
});
|
|
640
624
|
//////////////////////////////////////////////////////////////////////////////
|
|
@@ -677,15 +661,15 @@ class JsiiDiagnostic {
|
|
|
677
661
|
this.jsiiCode = code.code;
|
|
678
662
|
this.messageText = messageText;
|
|
679
663
|
if (location != null) {
|
|
680
|
-
this.file = location.
|
|
681
|
-
this.start = location.
|
|
682
|
-
this.length = location.
|
|
664
|
+
this.file = location.file;
|
|
665
|
+
this.start = location.start;
|
|
666
|
+
this.length = location.length;
|
|
683
667
|
}
|
|
684
668
|
}
|
|
685
|
-
addRelatedInformation(
|
|
669
|
+
addRelatedInformation(location, message) {
|
|
686
670
|
// Don't relate info into the TypeScript standard library
|
|
687
|
-
if (!/[\\/]typescript[\\/]lib[\\/]lib\..+\.d\.ts$/.test(
|
|
688
|
-
this.relatedInformation.push(JsiiDiagnostic.JSII_9999_RELATED_INFO.create(
|
|
671
|
+
if (!/[\\/]typescript[\\/]lib[\\/]lib\..+\.d\.ts$/.test(location.file.fileName)) {
|
|
672
|
+
this.relatedInformation.push(JsiiDiagnostic.JSII_9999_RELATED_INFO.create(location, message));
|
|
689
673
|
}
|
|
690
674
|
// Clearing out #formatted, as this would no longer be the correct string.
|
|
691
675
|
this.#formatted = undefined;
|