diff --git a/src/assembler.ts b/src/assembler.ts index 6402d91d..ed48a78e 100644 --- a/src/assembler.ts +++ b/src/assembler.ts @@ -23,6 +23,7 @@ import { DeprecatedRemover } from './transforms/deprecated-remover'; import { DeprecationWarningsInjector } from './transforms/deprecation-warnings'; import { RuntimeTypeInfoInjector } from './transforms/runtime-info'; import { combinedTransformers } from './transforms/utils'; +import { JsiiError } from './utils'; import { Validator } from './validator'; import { SHORT_VERSION, VERSION } from './version'; import { enabledWarnings } from './warnings'; @@ -82,7 +83,7 @@ export class Assembler implements Emitter { let allowlistedDeprecations: Set | undefined; if (options.stripDeprecatedAllowListFile) { if (!fs.existsSync(options.stripDeprecatedAllowListFile)) { - throw new Error(`--strip-deprecated file not found: ${options.stripDeprecatedAllowListFile}`); + throw new JsiiError(`--strip-deprecated file not found: ${options.stripDeprecatedAllowListFile}`); } allowlistedDeprecations = new Set( fs.readFileSync(options.stripDeprecatedAllowListFile, 'utf8').split('\n'), @@ -1348,7 +1349,7 @@ export class Assembler implements Emitter { private _getTypeFromTypeNode(t: ts.TypeNode) { const type = this._typeChecker.getTypeFromTypeNode(t); if (isErrorType(type)) { - throw new Error( + throw new JsiiError( `Unable to resolve type: ${t.getFullText()}. This typically happens if something is wrong with your dependency closure.`, ); } @@ -1484,7 +1485,7 @@ export class Assembler implements Emitter { symbol = getSymbolFromDeclaration(decl, this._typeChecker); } if (!decl || !symbol || !ts.isEnumDeclaration(decl)) { - throw new Error(`Unable to resolve enum declaration for ${type.symbol.name}!`); + throw new JsiiError(`Unable to resolve enum declaration for ${type.symbol.name}!`); } if (_hasInternalJsDocTag(symbol)) { diff --git a/src/common/find-utils.ts b/src/common/find-utils.ts index 87a9b79c..8d17e734 100644 --- a/src/common/find-utils.ts +++ b/src/common/find-utils.ts @@ -1,5 +1,6 @@ import * as fs from 'node:fs'; import * as path from 'node:path'; +import { JsiiError } from '../utils'; /** * Find a directory up the tree from a starting directory matching a condition @@ -55,7 +56,7 @@ export function findDependencyDirectory(dependencyName: string, searchStart: str const depPkgJsonPath = findPackageJsonUp(dependencyName, path.dirname(entryPoint)); if (!depPkgJsonPath) { - throw new Error(`Could not find dependency '${dependencyName}' from '${searchStart}'`); + throw new JsiiError(`Could not find dependency '${dependencyName}' from '${searchStart}'`); } return depPkgJsonPath; diff --git a/src/compiler.ts b/src/compiler.ts index 38a7d529..9e592ecc 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -73,7 +73,7 @@ export class Compiler implements Emitter { public constructor(private readonly options: CompilerOptions) { if (options.generateTypeScriptConfig != null && options.typeScriptConfig != null) { - throw new Error( + throw new utils.JsiiError( 'Cannot use `generateTypeScriptConfig` and `typeScriptConfig` together. Provide only one of them.', ); } @@ -214,7 +214,7 @@ export class Compiler implements Emitter { ); } - throw new Error( + throw new utils.JsiiError( `Failed validation of tsconfig "compilerOptions" in "${configName}" against rule set "${rules}"!`, ); } @@ -404,7 +404,7 @@ export class Compiler implements Emitter { const { config, error } = ts.readConfigFile(this.configPath, ts.sys.readFile); if (error) { utils.logDiagnostic(error, projectRoot); - throw new Error(`Failed to load tsconfig at ${this.configPath}`); + throw new utils.JsiiError(`Failed to load tsconfig at ${this.configPath}`); } const extended = ts.parseJsonConfigFileContent(config, ts.sys, projectRoot); // the tsconfig parser adds this in, but it is not an expected compilerOption @@ -431,7 +431,7 @@ export class Compiler implements Emitter { if (fs.existsSync(this.configPath)) { const currentConfig = JSON.parse(fs.readFileSync(this.configPath, 'utf-8')); if (!(commentKey in currentConfig)) { - throw new Error( + throw new utils.JsiiError( `A '${this.configPath}' file that was not generated by jsii is in ${this.options.projectInfo.projectRoot}. Aborting instead of overwriting.`, ); } diff --git a/src/helpers.ts b/src/helpers.ts index 84ebf226..fb08c2d4 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -15,7 +15,7 @@ import { DiagnosticCategory } from 'typescript'; import { Compiler, CompilerOptions } from './compiler'; import { loadProjectInfo, ProjectInfo } from './project-info'; -import { formatDiagnostic } from './utils'; +import { formatDiagnostic, JsiiError } from './utils'; /** * A set of source files for `sourceToAssemblyHelper`, at least containing 'index.ts' @@ -113,7 +113,7 @@ export function compileJsiiForTest( // logDiagnostic() doesn't work out of the box, so console.error() it is. } if (errors.length > 0 || emitResult.emitSkipped) { - throw new Error('There were compiler errors'); + throw new JsiiError('There were compiler errors'); } const assembly = loadAssemblyFromPath(process.cwd(), false); const files: Record = {}; @@ -280,7 +280,7 @@ export class TestWorkspace { */ public addDependency(dependencyAssembly: HelperCompilationResult) { if (this.installed.has(dependencyAssembly.assembly.name)) { - throw new Error( + throw new JsiiError( `A dependency with name '${dependencyAssembly.assembly.name}' was already installed. Give one a different name.`, ); } @@ -314,7 +314,7 @@ export class TestWorkspace { public dependencyDir(name: string) { if (!this.installed.has(name)) { - throw new Error(`No dependency with name '${name}' has been installed`); + throw new JsiiError(`No dependency with name '${name}' has been installed`); } return path.join(this.rootDirectory, 'node_modules', name); } diff --git a/src/main.ts b/src/main.ts index ce1526df..7e39768c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -138,55 +138,74 @@ const ruleSets: { global: true, }), async (argv) => { - _configureLog4js(argv.verbose); + try { + _configureLog4js(argv.verbose); - if (argv['generate-tsconfig'] != null && argv.tsconfig != null) { - throw new Error('Options --generate-tsconfig and --tsconfig are mutually exclusive'); - } + if (argv['generate-tsconfig'] != null && argv.tsconfig != null) { + throw new utils.JsiiError('Options --generate-tsconfig and --tsconfig are mutually exclusive', true); + } + + const projectRoot = path.normalize(path.resolve(process.cwd(), argv.PROJECT_ROOT)); - const projectRoot = path.normalize(path.resolve(process.cwd(), argv.PROJECT_ROOT)); + const { projectInfo, diagnostics: projectInfoDiagnostics } = loadProjectInfo(projectRoot); - const { projectInfo, diagnostics: projectInfoDiagnostics } = loadProjectInfo(projectRoot); + // disable all silenced warnings + for (const key of argv['silence-warnings']) { + if (!(key in enabledWarnings)) { + throw new utils.JsiiError( + `Unknown warning type ${key as any}. Must be one of: ${warningTypes.join(', ')}`, + ); + } - // disable all silenced warnings - for (const key of argv['silence-warnings']) { - if (!(key in enabledWarnings)) { - throw new Error(`Unknown warning type ${key as any}. Must be one of: ${warningTypes.join(', ')}`); + enabledWarnings[key] = false; } - enabledWarnings[key] = false; - } + configureCategories(projectInfo.diagnostics ?? {}); - configureCategories(projectInfo.diagnostics ?? {}); - - const typeScriptConfig = argv.tsconfig ?? projectInfo.packageJson.jsii?.tsconfig; - const validateTypeScriptConfig = - (argv['validate-tsconfig'] as TypeScriptConfigValidationRuleSet) ?? - projectInfo.packageJson.jsii?.validateTsconfig ?? - TypeScriptConfigValidationRuleSet.STRICT; - - const compiler = new Compiler({ - projectInfo, - projectReferences: argv['project-references'], - failOnWarnings: argv['fail-on-warnings'], - stripDeprecated: argv['strip-deprecated'] != null, - stripDeprecatedAllowListFile: argv['strip-deprecated'], - addDeprecationWarnings: argv['add-deprecation-warnings'], - generateTypeScriptConfig: argv['generate-tsconfig'], - typeScriptConfig, - validateTypeScriptConfig, - compressAssembly: argv['compress-assembly'], - }); - - const emitResult = argv.watch ? await compiler.watch() : compiler.emit(); - - const allDiagnostics = [...projectInfoDiagnostics, ...emitResult.diagnostics]; - - for (const diagnostic of allDiagnostics) { - utils.logDiagnostic(diagnostic, projectRoot); - } - if (emitResult.emitSkipped) { - process.exitCode = 1; + const typeScriptConfig = argv.tsconfig ?? projectInfo.packageJson.jsii?.tsconfig; + const validateTypeScriptConfig = + (argv['validate-tsconfig'] as TypeScriptConfigValidationRuleSet) ?? + projectInfo.packageJson.jsii?.validateTsconfig ?? + TypeScriptConfigValidationRuleSet.STRICT; + + const compiler = new Compiler({ + projectInfo, + projectReferences: argv['project-references'], + failOnWarnings: argv['fail-on-warnings'], + stripDeprecated: argv['strip-deprecated'] != null, + stripDeprecatedAllowListFile: argv['strip-deprecated'], + addDeprecationWarnings: argv['add-deprecation-warnings'], + generateTypeScriptConfig: argv['generate-tsconfig'], + typeScriptConfig, + validateTypeScriptConfig, + compressAssembly: argv['compress-assembly'], + }); + + const emitResult = argv.watch ? await compiler.watch() : compiler.emit(); + + const allDiagnostics = [...projectInfoDiagnostics, ...emitResult.diagnostics]; + + for (const diagnostic of allDiagnostics) { + utils.logDiagnostic(diagnostic, projectRoot); + } + if (emitResult.emitSkipped) { + process.exitCode = 1; + } + } catch (e: unknown) { + if (e instanceof utils.JsiiError) { + if (e.showHelp) { + console.log(); + yargs.showHelp(); + console.log(); + } + + const LOG = log4js.getLogger(utils.CLI_LOGGER); + LOG.error(e.message); + + process.exitCode = -1; + } else { + throw e; + } } }, ) @@ -212,18 +231,30 @@ function _configureLog4js(verbosity: number) { type: 'stderr', layout: { type: stderrColor ? 'colored' : 'basic' }, }, + [utils.DIAGNOSTICS]: { type: 'stdout', layout: { type: stdoutColor ? 'messagePassThrough' : ('passThroughNoColor' as any), }, }, + [utils.CLI_LOGGER]: { + type: 'stderr', + layout: { + type: 'pattern', + pattern: stdoutColor ? '%[[%p]%] %m' : '[%p] %m', + }, + }, }, categories: { default: { appenders: ['console'], level: _logLevel() }, + [utils.CLI_LOGGER]: { + appenders: [utils.CLI_LOGGER], + level: _logLevel(), + }, // The diagnostics logger must be set to INFO or more verbose, or watch won't show important messages [utils.DIAGNOSTICS]: { - appenders: ['diagnostics'], + appenders: [utils.DIAGNOSTICS], level: _logLevel(Math.max(verbosity, 1)), }, }, diff --git a/src/project-info.ts b/src/project-info.ts index d6ac5584..376d44f0 100644 --- a/src/project-info.ts +++ b/src/project-info.ts @@ -9,7 +9,7 @@ import * as ts from 'typescript'; import { findDependencyDirectory } from './common/find-utils'; import { JsiiDiagnostic } from './jsii-diagnostic'; import { TypeScriptConfigValidationRuleSet } from './tsconfig'; -import { parsePerson, parseRepository } from './utils'; +import { JsiiError, parsePerson, parseRepository } from './utils'; // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports const spdx: Set = require('spdx-license-list/simple'); @@ -154,13 +154,15 @@ export function loadProjectInfo(projectRoot: string): ProjectInfoResult { for (const name of pkg.bundleDependencies ?? pkg.bundledDependencies ?? []) { const version = pkg.dependencies?.[name]; if (!version) { - throw new Error( + throw new JsiiError( `The "package.json" file has "${name}" in "bundleDependencies", but it is not declared in "dependencies"`, ); } if (pkg.peerDependencies && name in pkg.peerDependencies) { - throw new Error(`The "package.json" file has "${name}" in "bundleDependencies", and also in "peerDependencies"`); + throw new JsiiError( + `The "package.json" file has "${name}" in "bundleDependencies", and also in "peerDependencies"`, + ); } bundleDependencies = bundleDependencies ?? {}; @@ -283,7 +285,9 @@ function _guessRepositoryType(url: string): string { if (parts?.[1] !== 'http' && parts?.[1] !== 'https') { return parts![1]; } - throw new Error(`The "package.json" file must specify the "repository.type" attribute (could not guess from ${url})`); + throw new JsiiError( + `The "package.json" file must specify the "repository.type" attribute (could not guess from ${url})`, + ); } function _sourceMapPreferences({ declarationMap, inlineSourceMap, inlineSources, sourceMap }: TSCompilerOptions = {}) { @@ -335,7 +339,7 @@ class DependencyResolver { const actualVersion = resolved.dependencyInfo.assembly.version; if (!semver.satisfies(actualVersion, declaration)) { - throw new Error( + throw new JsiiError( `Declared dependency on version ${declaration} of ${name}, but version ${actualVersion} was found`, ); } @@ -371,7 +375,7 @@ class DependencyResolver { const { version: versionString, localPackage } = _resolveVersion(declaration, root); const version = new semver.Range(versionString); if (!version) { - throw new Error(`Invalid semver expression for ${name}: ${versionString}`); + throw new JsiiError(`Invalid semver expression for ${name}: ${versionString}`); } const jsiiFile = _tryResolveAssembly(name, localPackage, root); LOG.debug(`Resolved dependency ${name} to ${jsiiFile}`); @@ -406,7 +410,7 @@ class DependencyResolver { function _required(value: T | undefined, message: string): T { if (value == null) { - throw new Error(message); + throw new JsiiError(message); } return value; } @@ -443,7 +447,7 @@ function _tryResolveAssembly(mod: string, localPackage: string | undefined, sear if (localPackage) { const result = findAssemblyFile(localPackage); if (!fs.existsSync(result)) { - throw new Error(`Assembly does not exist: ${result}`); + throw new JsiiError(`Assembly does not exist: ${result}`); } return result; } @@ -451,7 +455,7 @@ function _tryResolveAssembly(mod: string, localPackage: string | undefined, sear const dependencyDir = findDependencyDirectory(mod, searchPath); return findAssemblyFile(dependencyDir); } catch (e: any) { - throw new Error( + throw new JsiiError( `Unable to locate jsii assembly for "${mod}". If this module is not jsii-enabled, it must also be declared under bundledDependencies: ${e}`, ); } @@ -459,7 +463,7 @@ function _tryResolveAssembly(mod: string, localPackage: string | undefined, sear function _validateLicense(id: string | undefined): string { if (id == null) { - throw new Error( + throw new JsiiError( 'No "license" was specified in "package.json", see valid license identifiers at https://spdx.org/licenses/', ); } @@ -467,14 +471,16 @@ function _validateLicense(id: string | undefined): string { return id; } if (!spdx.has(id)) { - throw new Error(`Invalid license identifier "${id}", see valid license identifiers at https://spdx.org/licenses/`); + throw new JsiiError( + `Invalid license identifier "${id}", see valid license identifiers at https://spdx.org/licenses/`, + ); } return id; } function _validateVersionFormat(format: string): 'short' | 'full' { if (format !== 'short' && format !== 'full') { - throw new Error(`Invalid jsii.versionFormat "${format}", it must be either "short" or "full" (the default)`); + throw new JsiiError(`Invalid jsii.versionFormat "${format}", it must be either "short" or "full" (the default)`); } return format; } @@ -491,7 +497,9 @@ function _validateStability(stability: string | undefined, deprecated: string | return undefined; } if (!Object.values(spec.Stability).includes(stability as any)) { - throw new Error(`Invalid stability "${stability}", it must be one of ${Object.values(spec.Stability).join(', ')}`); + throw new JsiiError( + `Invalid stability "${stability}", it must be one of ${Object.values(spec.Stability).join(', ')}`, + ); } return stability as spec.Stability; } @@ -501,7 +509,7 @@ function _validateTsconfigRuleSet(ruleSet: string): TypeScriptConfigValidationRu return undefined; } if (!Object.values(TypeScriptConfigValidationRuleSet).includes(ruleSet as any)) { - throw new Error( + throw new JsiiError( `Invalid validateTsconfig "${ruleSet}", it must be one of ${Object.values(TypeScriptConfigValidationRuleSet).join( ', ', )}`, @@ -593,7 +601,7 @@ function _loadDiagnostics(entries?: { [key: string]: string }): category = ts.DiagnosticCategory.Message; break; default: - throw new Error(`Invalid category '${entries[code]}' for code '${code}'`); + throw new JsiiError(`Invalid category '${entries[code]}' for code '${code}'`); } result[code] = category; } diff --git a/src/transforms/deprecated-remover.js b/src/transforms/deprecated-remover.js deleted file mode 100644 index 61f1bf07..00000000 --- a/src/transforms/deprecated-remover.js +++ /dev/null @@ -1,510 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.DeprecatedRemover = void 0; -const spec_1 = require("@jsii/spec"); -const path_1 = require("path"); -const ts = require("typescript"); -const jsii_diagnostic_1 = require("../jsii-diagnostic"); -const bindings = require("../node-bindings"); -class DeprecatedRemover { - constructor(typeChecker, allowlistedDeprecations) { - this.typeChecker = typeChecker; - this.allowlistedDeprecations = allowlistedDeprecations; - this.transformations = new Array(); - this.nodesToRemove = new Set(); - } - /** - * Obtains the configuration for the TypeScript transform(s) that will remove - * `@deprecated` members from the generated declarations (`.d.ts`) files. It - * will leverage information accumulated during `#removeFrom(Assembly)` in - * order to apply corrections to inheritance chains, ensuring a valid output - * is produced. - */ - get customTransformers() { - return { - afterDeclarations: [ - (context) => { - const transformer = new DeprecationRemovalTransformer(this.typeChecker, context, this.transformations, this.nodesToRemove); - return transformer.transform.bind(transformer); - }, - ], - }; - } - /** - * Removes all `@deprecated` API elements from the provided assembly, and - * records the operations needed in order to fix the inheritance chains that - * mix `@deprecated` and non-`@deprecated` types. - * - * @param assembly the assembly to be modified. - * - * @returns diagnostic messages produced when validating no remaining API - * makes use of a `@deprecated` type that was removed. - */ - removeFrom(assembly) { - if (assembly.types == null) { - return []; - } - const strippedFqns = new Set(); - const replaceWithClass = new Map(); - const replaceWithInterfaces = new Map(); - // Find all types that will be stripped out - for (const [fqn, typeInfo] of Object.entries(assembly.types)) { - if (typeInfo.docs?.stability === spec_1.Stability.Deprecated) { - if (!this.shouldFqnBeStripped(fqn)) { - continue; - } - strippedFqns.add(fqn); - if ((0, spec_1.isClassType)(typeInfo) && typeInfo.base != null) { - replaceWithClass.set(fqn, typeInfo.base); - } - if ((0, spec_1.isClassOrInterfaceType)(typeInfo) && typeInfo.interfaces != null) { - replaceWithInterfaces.set(fqn, typeInfo.interfaces); - } - this.nodesToRemove.add(bindings.getRelatedNode(typeInfo)); - } - } - for (const [fqn, typeInfo] of Object.entries(assembly.types)) { - // Ignore `@deprecated` types - if (strippedFqns.has(fqn)) { - continue; - } - // Enums cannot have references to `@deprecated` types, but can have deprecated members - if ((0, spec_1.isEnumType)(typeInfo)) { - const enumNode = bindings.getEnumRelatedNode(typeInfo); - const members = []; - typeInfo.members.forEach((mem) => { - if (mem.docs?.stability === spec_1.Stability.Deprecated && - this.shouldFqnBeStripped(`${fqn}#${mem.name}`)) { - const matchingMemberNode = enumNode.members.find((enumMem) => enumMem.name.getText() === mem.name); - if (matchingMemberNode) { - this.nodesToRemove.add(matchingMemberNode); - } - } - else { - members.push(mem); - } - }); - typeInfo.members = members; - continue; - } - // For classes, we erase `@deprecated` base classes, replacing as needed - const additionalInterfaces = new Set(); - if ((0, spec_1.isClassType)(typeInfo) && - typeInfo.base != null && - strippedFqns.has(typeInfo.base)) { - while (typeInfo.base != null && strippedFqns.has(typeInfo.base)) { - const oldBase = assembly.types[typeInfo.base]; - oldBase.interfaces?.forEach((fqn) => additionalInterfaces.add(fqn)); - typeInfo.base = replaceWithClass.get(typeInfo.base); - } - this.transformations.push(typeInfo.base != null - ? Transformation.replaceBaseClass(this.typeChecker, bindings.getClassRelatedNode(typeInfo), typeInfo.base in assembly.types - ? bindings.getClassRelatedNode(assembly.types[typeInfo.base]) ?? typeInfo.base - : typeInfo.base) - : Transformation.removeBaseClass(this.typeChecker, bindings.getClassRelatedNode(typeInfo))); - } - // Be defensive in case we add other kinds in the future - if (!(0, spec_1.isClassOrInterfaceType)(typeInfo)) { - throw new Error(`Unhandled type encountered! ${JSON.stringify(typeInfo, null, 2)}`); - } - // Strip all `@deprecated` interfaces from the inheritance tree, replacing as needed - if (typeInfo.interfaces?.some((fqn) => strippedFqns.has(fqn)) || - additionalInterfaces.size > 0) { - const originalSet = new Set(typeInfo.interfaces ?? []); - const newSet = new Set(); - const candidates = Array.from(new Set([...originalSet, ...additionalInterfaces])); - while (candidates.length > 0) { - const fqn = candidates.pop(); - if (!strippedFqns.has(fqn)) { - newSet.add(fqn); - if (!originalSet.has(fqn)) { - this.transformations.push(Transformation.addInterface(this.typeChecker, bindings.getClassOrInterfaceRelatedNode(typeInfo), fqn in assembly.types - ? bindings.getInterfaceRelatedNode(assembly.types[fqn]) ?? fqn - : fqn)); - } - continue; - } - if (originalSet.has(fqn)) { - this.transformations.push(Transformation.removeInterface(this.typeChecker, bindings.getClassOrInterfaceRelatedNode(typeInfo), bindings.getInterfaceRelatedNode(assembly.types[fqn]))); - } - const replacement = replaceWithInterfaces.get(fqn); - if (replacement != null) { - candidates.push(...replacement); - } - } - typeInfo.interfaces = - newSet.size > 0 ? Array.from(newSet).sort() : undefined; - } - // Drop all `@deprecated` members, and remove "overrides" from stripped types - const methods = []; - const properties = []; - typeInfo.methods?.forEach((meth) => { - if (meth.docs?.stability === spec_1.Stability.Deprecated && - this.shouldFqnBeStripped(`${fqn}#${meth.name}`)) { - this.nodesToRemove.add(bindings.getMethodRelatedNode(meth)); - } - else { - methods.push(meth.overrides != null && strippedFqns.has(meth.overrides) - ? { ...meth, overrides: undefined } - : meth); - } - }); - typeInfo.methods = typeInfo.methods ? methods : undefined; - typeInfo.properties?.forEach((prop) => { - if (prop.docs?.stability === spec_1.Stability.Deprecated && - this.shouldFqnBeStripped(`${fqn}#${prop.name}`)) { - this.nodesToRemove.add(bindings.getParameterRelatedNode(prop)); - } - else { - properties.push(prop.overrides != null && strippedFqns.has(prop.overrides) - ? { ...prop, overrides: undefined } - : prop); - } - }); - typeInfo.properties = typeInfo.properties ? properties : undefined; - } - const diagnostics = this.findLeftoverUseOfDeprecatedAPIs(assembly, strippedFqns); - // Remove all `@deprecated` types, after we did everything, so we could - // still access the related nodes from the assembly object. - for (const fqn of strippedFqns) { - if (this.shouldFqnBeStripped(fqn)) { - delete assembly.types[fqn]; - } - } - return diagnostics; - } - findLeftoverUseOfDeprecatedAPIs(assembly, strippedFqns) { - if (assembly.types == null) { - return []; - } - const result = new Array(); - for (const type of Object.values(assembly.types)) { - if ((0, spec_1.isEnumType)(type) || strippedFqns.has(type.fqn)) { - continue; - } - if ((0, spec_1.isClassType)(type) && type.initializer) { - result.push(...this.verifyCallable(assembly, strippedFqns, type.initializer)); - } - type.methods?.forEach((method) => result.push(...this.verifyCallable(assembly, strippedFqns, method))); - type.properties?.forEach((property) => result.push(...this.verifyProperty(assembly, strippedFqns, property))); - } - return result; - } - verifyCallable(assembly, strippedFqns, method) { - const diagnostics = new Array(); - const deprecatedReturnFqn = (0, spec_1.isMethod)(method) && - method.returns && - this.tryFindReference(method.returns.type, strippedFqns); - if (deprecatedReturnFqn) { - diagnostics.push(this.makeDiagnostic(deprecatedReturnFqn, 'Method', method, assembly)); - } - if (method.parameters) { - for (const parameter of method.parameters) { - const deprecatedTypeFqn = this.tryFindReference(parameter.type, strippedFqns); - if (deprecatedTypeFqn) { - diagnostics.push(this.makeDiagnostic(deprecatedTypeFqn, 'Parameter', parameter, assembly)); - } - } - } - return diagnostics; - } - verifyProperty(assembly, strippedFqns, property) { - const deprecatedTypeFqn = this.tryFindReference(property.type, strippedFqns); - if (deprecatedTypeFqn) { - return [ - this.makeDiagnostic(deprecatedTypeFqn, 'Property', property, assembly), - ]; - } - return []; - } - /** - * Determines whether a `TypeReference` contains an FQN within a given set. - * - * @param ref the tested `TypeReference`. - * @param fqns the set of FQNs that are being searched for. - * - * @returns the first FQN that was identified. - */ - tryFindReference(ref, fqns) { - if ((0, spec_1.isNamedTypeReference)(ref)) { - return fqns.has(ref.fqn) ? ref.fqn : undefined; - } - if ((0, spec_1.isPrimitiveTypeReference)(ref)) { - return undefined; - } - if ((0, spec_1.isCollectionTypeReference)(ref)) { - return this.tryFindReference(ref.collection.elementtype, fqns); - } - return ref.union.types - .map((type) => this.tryFindReference(type, fqns)) - .find((ref) => ref != null); - } - shouldFqnBeStripped(fqn) { - return this.allowlistedDeprecations?.has(fqn) ?? true; - } - makeDiagnostic(fqn, messagePrefix, context, assembly) { - const node = bindings.getRelatedNode(context); - const diagnostic = jsii_diagnostic_1.JsiiDiagnostic.JSII_3999_INCOHERENT_TYPE_MODEL.create(node?.type ?? node, `${messagePrefix} has @deprecated type ${fqn}, and it is erased by --strip-deprecated.`); - const typeInfo = assembly.types?.[fqn]; - const typeNode = typeInfo && bindings.getTypeRelatedNode(typeInfo); - if (typeNode == null) { - return diagnostic; - } - return diagnostic.addRelatedInformation(ts.getNameOfDeclaration(typeNode) ?? typeNode, `The @deprecated type is declared here`); - } -} -exports.DeprecatedRemover = DeprecatedRemover; -class Transformation { - constructor(typeChecker, node, apply) { - this.typeChecker = typeChecker; - this.apply = apply; - this.nodeName = Transformation.fullyQualifiedName(typeChecker, node); - } - static addInterface(typeChecker, node, iface) { - return new Transformation(typeChecker, node, (declaration) => { - if (!ts.isClassDeclaration(declaration) && - !ts.isInterfaceDeclaration(declaration)) { - throw new Error(`Expected a ClassDeclaration or InterfaceDeclaration, found a ${ts.SyntaxKind[declaration.kind]}`); - } - const { typeExpression: newInterface, syntheticImport } = Transformation.typeReference(iface, declaration, typeChecker); - if (ts.isClassDeclaration(declaration)) { - return { - node: ts.updateClassDeclaration(declaration, declaration.decorators, declaration.modifiers, declaration.name, declaration.typeParameters, addInterfaceTo(ts.SyntaxKind.ImplementsKeyword, declaration.heritageClauses), declaration.members), - syntheticImport, - }; - } - return { - node: ts.updateInterfaceDeclaration(declaration, declaration.decorators, declaration.modifiers, declaration.name, declaration.typeParameters, addInterfaceTo(ts.SyntaxKind.ExtendsKeyword, declaration.heritageClauses), declaration.members), - syntheticImport, - }; - function addInterfaceTo(token, clauses = []) { - const existingClause = clauses.find((clause) => clause.token === token); - if (existingClause == null) { - return [...clauses, ts.createHeritageClause(token, [newInterface])]; - } - return [ - ...clauses.filter((clause) => clause !== existingClause), - ts.updateHeritageClause(existingClause, [ - ...existingClause.types, - newInterface, - ]), - ]; - } - }); - } - static replaceBaseClass(typeChecker, node, baseClass) { - return new Transformation(typeChecker, node, (declaration) => { - if (!ts.isClassDeclaration(declaration)) { - throw new Error(`Expected a ClassDeclaration, found a ${ts.SyntaxKind[declaration.kind]}`); - } - const { typeExpression: newBaseClass, syntheticImport } = Transformation.typeReference(baseClass, declaration, typeChecker); - const existingClause = declaration.heritageClauses?.find((clause) => clause.token === ts.SyntaxKind.ExtendsKeyword); - return { - node: ts.updateClassDeclaration(declaration, declaration.decorators, declaration.modifiers, declaration.name, declaration.typeParameters, [ - ...(declaration.heritageClauses ?? []).filter((clause) => clause !== existingClause), - existingClause - ? ts.updateHeritageClause(existingClause, [newBaseClass]) - : ts.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [ - newBaseClass, - ]), - ], declaration.members), - syntheticImports: syntheticImport && [syntheticImport], - }; - }); - } - static removeBaseClass(typeChecker, node) { - return new Transformation(typeChecker, node, (declaration) => { - if (!ts.isClassDeclaration(declaration)) { - throw new Error(`Expected a ClassDeclaration, found a ${ts.SyntaxKind[declaration.kind]}`); - } - return { - node: ts.updateClassDeclaration(declaration, declaration.decorators, declaration.modifiers, declaration.name, declaration.typeParameters, declaration.heritageClauses?.filter((clause) => clause.token !== ts.SyntaxKind.ExtendsKeyword), declaration.members), - }; - }); - } - static removeInterface(typeChecker, node, iface) { - const ifaceName = Transformation.fullyQualifiedName(typeChecker, iface); - return new Transformation(typeChecker, node, (declaration) => { - if (ts.isClassDeclaration(declaration)) { - return { - node: ts.updateClassDeclaration(declaration, declaration.decorators, declaration.modifiers, declaration.name, declaration.typeParameters, removeInterfaceHeritage(declaration.heritageClauses), declaration.members), - }; - } - else if (ts.isInterfaceDeclaration(declaration)) { - return { - node: ts.updateInterfaceDeclaration(declaration, declaration.decorators, declaration.modifiers, declaration.name, declaration.typeParameters, removeInterfaceHeritage(declaration.heritageClauses), declaration.members), - }; - } - throw new Error(`Expected a ClassDeclaration or InterfaceDeclaration, found a ${ts.SyntaxKind[declaration.kind]}`); - }); - function removeInterfaceHeritage(clauses) { - if (clauses == null) { - return clauses; - } - return clauses - .map((clause) => { - const types = clause.types.filter((type) => Transformation.fullyQualifiedName(typeChecker, type.expression) !== ifaceName); - if (types.length === clause.types.length) { - // Means the interface was only transitively present... - return clause; - } - if (types.length === 0) { - return undefined; - } - return ts.updateHeritageClause(clause, types); - }) - .filter((clause) => clause != null); - } - } - static fullyQualifiedName(typeChecker, node) { - const symbol = typeChecker.getSymbolAtLocation(ts.getNameOfDeclaration(node) ?? node); - // This symbol ☝️ does not contain enough information in some cases - when - // an imported type is part of a heritage clause - to produce the fqn. - // Round tripping this to its type and back to a symbol seems to fix this. - const type = symbol && typeChecker.getDeclaredTypeOfSymbol(symbol); - return type?.symbol && typeChecker.getFullyQualifiedName(type.symbol); - } - static typeReference(type, context, typeChecker) { - context = ts.getOriginalNode(context); - const [, contextSource] = /^"([^"]+)"\..*$/.exec(typeChecker.getFullyQualifiedName(typeChecker.getSymbolAtLocation(ts.getNameOfDeclaration(context)))); - let expression; - let syntheticImport; - if (typeof type === 'string') { - const [root, ...tail] = type.split('.'); - const syntheticImportName = ts.createUniqueName(root); - syntheticImport = ts.createImportDeclaration(undefined /* decorators */, undefined /* modifiers */, ts.createImportClause(undefined, ts.createNamespaceImport(syntheticImportName)), ts.createStringLiteral(root)); - expression = tail.reduce((curr, elt) => ts.createPropertyAccess(curr, elt), syntheticImportName); - } - else { - const [, typeSource, qualifiedName] = /^"([^"]+)"\.(.*)$/.exec(typeChecker.getFullyQualifiedName(typeChecker.getSymbolAtLocation(ts.getNameOfDeclaration(type)))); - if (typeSource === contextSource) { - const [root, ...tail] = qualifiedName.split('.'); - expression = tail.reduce((curr, elt) => ts.createPropertyAccess(curr, elt), ts.createIdentifier(root)); - } - else { - const syntheticImportName = ts.createUniqueName((0, path_1.basename)(typeSource)); - syntheticImport = ts.createImportDeclaration(undefined /* decorators */, undefined /* modifiers */, ts.createImportClause(undefined, ts.createNamespaceImport(syntheticImportName)), ts.createStringLiteral(`./${(0, path_1.relative)((0, path_1.dirname)(contextSource), typeSource)}`)); - expression = qualifiedName - .split('.') - .reduce((curr, elt) => ts.createPropertyAccess(curr, elt), syntheticImportName); - } - } - return { - typeExpression: ts.createExpressionWithTypeArguments(undefined, expression), - syntheticImport, - }; - } - targets(node) { - return (this.nodeName === - Transformation.fullyQualifiedName(this.typeChecker, node)); - } -} -class DeprecationRemovalTransformer { - constructor(typeChecker, context, transformations, nodesToRemove) { - this.typeChecker = typeChecker; - this.context = context; - this.transformations = transformations; - this.nodesToRemove = nodesToRemove; - this.syntheticImports = new Array(); - } - transform(node) { - let result = this.visitEachChild(node); - // If there are any synthetic imports, add them to the source file - if (ts.isSourceFile(result) && this.syntheticImports.length > 0) { - result = ts.updateSourceFileNode(result, [...this.syntheticImports, ...result.statements], result.isDeclarationFile, result.referencedFiles, result.typeReferenceDirectives, result.hasNoDefaultLib, result.libReferenceDirectives); - this.syntheticImports = new Array(); - } - return result; - } - visitEachChild(node) { - return ts.visitEachChild(node, this.visitor.bind(this), this.context); - } - visitor(node) { - if (this.isDeprecated(node)) { - // Removing deprecated members by substituting "nothing" to them - return undefined; - } - if (ts.isClassDeclaration(node) || ts.isInterfaceDeclaration(node)) { - for (const transformation of this.transformations) { - // 👇 as any because the assignment below confuses type checker - if (transformation.targets(node)) { - const { node: transformedNode, syntheticImport } = transformation.apply(node); - node = transformedNode; - if (syntheticImport) { - this.syntheticImports.push(syntheticImport); - } - } - } - } - // Remove named imports of `@deprecated` members from the source... - if (ts.isImportDeclaration(node) && - node.importClause && - node.importClause.namedBindings && - ts.isNamedImports(node.importClause.namedBindings)) { - const filteredElements = node.importClause.namedBindings.elements.filter((element) => { - // This symbol is local (it's declaration points back to the named import) - const symbol = this.typeChecker.getSymbolAtLocation(element.name); - const exportedSymbol = - // This "resolves" the imported type, so we can get to it's declaration(s) - symbol && this.typeChecker.getDeclaredTypeOfSymbol(symbol)?.symbol; - return !exportedSymbol?.declarations.some((decl) => this.isDeprecated(decl)); - }); - if (filteredElements.length !== - node.importClause.namedBindings.elements.length) { - return ts.updateImportDeclaration(node, node.decorators, node.modifiers, node.importClause.name != null || filteredElements.length > 0 - ? ts.updateImportClause(node.importClause, node.importClause.name, ts.updateNamedImports(node.importClause.namedBindings, filteredElements), node.importClause.isTypeOnly) - : undefined, node.moduleSpecifier); - } - return node; - } - // Replace "export ... from ..." places that no longer export anything - // with an "import from ...", so side effects are preserved. - if (ts.isExportDeclaration(node) && node.moduleSpecifier) { - const symbol = this.typeChecker.getSymbolAtLocation(node.moduleSpecifier); - const moduleExports = symbol && - this.typeChecker - .getExportsOfModule(symbol) - ?.filter((sym) => !sym.declarations.some((decl) => this.isDeprecated(decl))); - if ((node.exportClause == null || - ts.isNamespaceExport(node.exportClause)) && - moduleExports?.length === 0) { - return ts.createImportDeclaration(undefined /* decorators */, undefined /* modifiers */, undefined /* importClause */, node.moduleSpecifier); - } - if (node.exportClause != null && moduleExports) { - const bindings = node.exportClause; - const exportedNames = new Set(moduleExports.map((sym) => sym.name)); - const filteredElements = bindings.elements?.filter((elt) => exportedNames.has(elt.name.text)); - if (filteredElements?.length !== bindings.elements?.length) { - return ts.updateExportDeclaration(node, node.decorators, node.modifiers, ts.updateNamedExports(bindings, filteredElements), node.moduleSpecifier, node.isTypeOnly); - } - } - } - return DeprecationRemovalTransformer.IGNORE_CHILDREN.has(node.kind) - ? node - : this.visitEachChild(node); - } - isDeprecated(node) { - const original = ts.getOriginalNode(node); - return (this.nodesToRemove.has(original) && - ts.getJSDocTags(original).some((tag) => tag.tagName.text === 'deprecated')); - } -} -/** - * A list of SyntaxKinds for which it is not necessary to evaluate children, - * since they are never of interest to this transform. This opens up a wee - * optimization, which is particularly useful when trying to troubleshoot the - * transform in a debugger (saves a TON of time stepping into useless nodes - * then). - */ -DeprecationRemovalTransformer.IGNORE_CHILDREN = new Set([ - ts.SyntaxKind.Constructor, - ts.SyntaxKind.FunctionDeclaration, - ts.SyntaxKind.GetAccessor, - ts.SyntaxKind.MethodDeclaration, - ts.SyntaxKind.MethodSignature, - ts.SyntaxKind.PropertySignature, - ts.SyntaxKind.PropertyDeclaration, - ts.SyntaxKind.SetAccessor, - ts.SyntaxKind.VariableDeclaration, -]); -//# sourceMappingURL=deprecated-remover.js.map \ No newline at end of file diff --git a/src/transforms/deprecated-remover.js.map b/src/transforms/deprecated-remover.js.map deleted file mode 100644 index eb3ab4f8..00000000 --- a/src/transforms/deprecated-remover.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"deprecated-remover.js","sourceRoot":"","sources":["deprecated-remover.ts"],"names":[],"mappings":";;;AAAA,qCAkBoB;AACpB,+BAAmD;AACnD,iCAAiC;AAEjC,wDAAoD;AACpD,6CAA6C;AAE7C,MAAa,iBAAiB;IAI5B,YACmB,WAA2B,EAC3B,uBAAgD;QADhD,gBAAW,GAAX,WAAW,CAAgB;QAC3B,4BAAuB,GAAvB,uBAAuB,CAAyB;QALlD,oBAAe,GAAG,IAAI,KAAK,EAAkB,CAAC;QAC9C,kBAAa,GAAG,IAAI,GAAG,EAAW,CAAC;IAKjD,CAAC;IAEJ;;;;;;OAMG;IACH,IAAW,kBAAkB;QAC3B,OAAO;YACL,iBAAiB,EAAE;gBACjB,CAAC,OAAO,EAAE,EAAE;oBACV,MAAM,WAAW,GAAG,IAAI,6BAA6B,CACnD,IAAI,CAAC,WAAW,EAChB,OAAO,EACP,IAAI,CAAC,eAAe,EACpB,IAAI,CAAC,aAAa,CACnB,CAAC;oBACF,OAAO,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;gBACjD,CAAC;aACF;SACF,CAAC;IACJ,CAAC;IAED;;;;;;;;;OASG;IACI,UAAU,CAAC,QAAkB;QAClC,IAAI,QAAQ,CAAC,KAAK,IAAI,IAAI,EAAE;YAC1B,OAAO,EAAE,CAAC;SACX;QAED,MAAM,YAAY,GAAG,IAAI,GAAG,EAAU,CAAC;QACvC,MAAM,gBAAgB,GAAG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,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,KAAK,YAAY,CAAC,CAC3E,CAAC;IACJ,CAAC;;AA7KD;;;;;;GAMG;AACqB,6CAAe,GAA+B,IAAI,GAAG,CAC3E;IACE,EAAE,CAAC,UAAU,CAAC,WAAW;IACzB,EAAE,CAAC,UAAU,CAAC,mBAAmB;IACjC,EAAE,CAAC,UAAU,CAAC,WAAW;IACzB,EAAE,CAAC,UAAU,CAAC,iBAAiB;IAC/B,EAAE,CAAC,UAAU,CAAC,eAAe;IAC7B,EAAE,CAAC,UAAU,CAAC,iBAAiB;IAC/B,EAAE,CAAC,UAAU,CAAC,mBAAmB;IACjC,EAAE,CAAC,UAAU,CAAC,WAAW;IACzB,EAAE,CAAC,UAAU,CAAC,mBAAmB;CAClC,CACF,CAAC"} \ No newline at end of file diff --git a/src/transforms/deprecated-remover.ts b/src/transforms/deprecated-remover.ts index 35ce2326..7a6a4dff 100644 --- a/src/transforms/deprecated-remover.ts +++ b/src/transforms/deprecated-remover.ts @@ -22,6 +22,7 @@ import * as ts from 'typescript'; import { JsiiDiagnostic } from '../jsii-diagnostic'; import * as bindings from '../node-bindings'; +import { JsiiError } from '../utils'; export class DeprecatedRemover { private readonly transformations = new Array(); @@ -361,7 +362,7 @@ class Transformation { ) { return new Transformation(typeChecker, node, (declaration) => { if (!ts.isClassDeclaration(declaration) && !ts.isInterfaceDeclaration(declaration)) { - throw new Error( + throw new JsiiError( `Expected a ClassDeclaration or InterfaceDeclaration, found a ${ts.SyntaxKind[declaration.kind]}`, ); } @@ -419,7 +420,7 @@ class Transformation { ) { return new Transformation(typeChecker, node, (declaration) => { if (!ts.isClassDeclaration(declaration)) { - throw new Error(`Expected a ClassDeclaration, found a ${ts.SyntaxKind[declaration.kind]}`); + throw new JsiiError(`Expected a ClassDeclaration, found a ${ts.SyntaxKind[declaration.kind]}`); } const { typeExpression: newBaseClass, syntheticImport } = Transformation.typeReference( baseClass, @@ -451,7 +452,7 @@ class Transformation { public static removeBaseClass(typeChecker: ts.TypeChecker, node: ts.ClassDeclaration) { return new Transformation(typeChecker, node, (declaration) => { if (!ts.isClassDeclaration(declaration)) { - throw new Error(`Expected a ClassDeclaration, found a ${ts.SyntaxKind[declaration.kind]}`); + throw new JsiiError(`Expected a ClassDeclaration, found a ${ts.SyntaxKind[declaration.kind]}`); } return { node: ts.factory.updateClassDeclaration( @@ -497,7 +498,7 @@ class Transformation { ), }; } - throw new Error( + throw new JsiiError( `Expected a ClassDeclaration or InterfaceDeclaration, found a ${ts.SyntaxKind[declaration.kind]}`, ); }); diff --git a/src/transforms/deprecation-warnings.js b/src/transforms/deprecation-warnings.js deleted file mode 100644 index 244d2fc5..00000000 --- a/src/transforms/deprecation-warnings.js +++ /dev/null @@ -1,479 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.DeprecationWarningsInjector = exports.WARNINGSCODE_FILE_NAME = void 0; -const spec = require("@jsii/spec"); -const fs = require("fs"); -const path = require("path"); -const ts = require("typescript"); -const symbol_id_1 = require("../symbol-id"); -exports.WARNINGSCODE_FILE_NAME = '.warnings.jsii.js'; -const WARNING_FUNCTION_NAME = 'print'; -const PARAMETER_NAME = 'p'; -const FOR_LOOP_ITEM_NAME = 'o'; -const NAMESPACE = 'jsiiDeprecationWarnings'; -const LOCAL_ENUM_NAMESPACE = 'ns'; -const VISITED_OBJECTS_SET_NAME = 'visitedObjects'; -const DEPRECATION_ERROR = 'DeprecationError'; -const GET_PROPERTY_DESCRIPTOR = 'getPropertyDescriptor'; -class DeprecationWarningsInjector { - constructor(typeChecker) { - this.typeChecker = typeChecker; - this.transformers = { - before: [], - }; - } - process(assembly, projectInfo) { - const projectRoot = projectInfo.projectRoot; - const functionDeclarations = []; - const types = assembly.types ?? {}; - for (const type of Object.values(types)) { - const statements = []; - let isEmpty = true; - // This will add the parameter to the set of visited objects, to prevent infinite recursion - statements.push(ts.createExpressionStatement(ts.createCall(ts.createPropertyAccess(ts.createIdentifier(VISITED_OBJECTS_SET_NAME), 'add'), undefined, [ts.createIdentifier(PARAMETER_NAME)]))); - const tryStatements = []; - if (spec.isDeprecated(type) && spec.isEnumType(type)) { - // The type is deprecated - tryStatements.push(createWarningFunctionCall(type.fqn, type.docs?.deprecated)); - isEmpty = false; - } - if (spec.isEnumType(type) && type.locationInModule?.filename) { - tryStatements.push(createEnumRequireStatement(type.locationInModule?.filename)); - tryStatements.push(createDuplicateEnumValuesCheck(type)); - for (const member of Object.values(type.members ?? [])) { - if (spec.isDeprecated(member)) { - // The enum member is deprecated - const condition = ts.createBinary(ts.createIdentifier(PARAMETER_NAME), ts.SyntaxKind.EqualsEqualsEqualsToken, ts.createPropertyAccess(ts.createPropertyAccess(ts.createIdentifier(LOCAL_ENUM_NAMESPACE), type.name), member.name)); - tryStatements.push(createWarningFunctionCall(`${type.fqn}#${member.name}`, member.docs?.deprecated, condition)); - isEmpty = false; - } - } - } - else if (spec.isInterfaceType(type) && type.datatype) { - const { statementsByProp, excludedProps } = processInterfaceType(type, types, assembly, projectInfo, undefined, undefined); - for (const [name, statement] of statementsByProp.entries()) { - if (!excludedProps.has(name)) { - tryStatements.push(statement); - isEmpty = false; - } - } - } - statements.push(ts.createTry(ts.createBlock(tryStatements), undefined, ts.createBlock([ - ts.createExpressionStatement(ts.createCall(ts.createPropertyAccess(ts.createIdentifier(VISITED_OBJECTS_SET_NAME), 'delete'), undefined, [ts.createIdentifier(PARAMETER_NAME)])), - ]))); - const paramValue = ts.createParameter(undefined, undefined, undefined, PARAMETER_NAME); - const functionName = fnName(type.fqn); - const functionDeclaration = ts.createFunctionDeclaration(undefined, undefined, undefined, functionName, undefined, [paramValue], undefined, createFunctionBlock(isEmpty ? [] : statements)); - functionDeclarations.push(functionDeclaration); - } - this.transformers = { - before: [ - (context) => { - const transformer = new Transformer(this.typeChecker, context, projectRoot, this.buildTypeIndex(assembly), assembly); - return transformer.transform.bind(transformer); - }, - ], - }; - generateWarningsFile(projectRoot, functionDeclarations); - } - get customTransformers() { - return this.transformers; - } - buildTypeIndex(assembly) { - const result = new Map(); - for (const type of Object.values(assembly.types ?? {})) { - const symbolId = type.symbolId; - if (symbolId) { - result.set(symbolId, type); - } - } - return result; - } -} -exports.DeprecationWarningsInjector = DeprecationWarningsInjector; -function processInterfaceType(type, types, assembly, projectInfo, statementsByProp = new Map(), excludedProps = new Set()) { - for (const prop of Object.values(type.properties ?? {})) { - const fqn = `${type.fqn}#${prop.name}`; - if (spec.isDeprecated(prop) || spec.isDeprecated(type)) { - // If the property individually is deprecated, or the entire type is deprecated - const deprecatedDocs = prop.docs?.deprecated ?? type.docs?.deprecated; - const statement = createWarningFunctionCall(fqn, deprecatedDocs, ts.createBinary(ts.createStringLiteral(prop.name), ts.SyntaxKind.InKeyword, ts.createIdentifier(PARAMETER_NAME)), undefined); - statementsByProp.set(prop.name, statement); - } - else { - /* If a prop is not deprecated, we don't want to generate a warning for it, - even if another property with the same name is deprecated in another - super-interface. */ - excludedProps.add(prop.name); - } - if (spec.isNamedTypeReference(prop.type) && - Object.keys(types).includes(prop.type.fqn)) { - const functionName = importedFunctionName(prop.type.fqn, assembly, projectInfo); - if (functionName) { - const statement = createTypeHandlerCall(functionName, `${PARAMETER_NAME}.${prop.name}`); - statementsByProp.set(`${prop.name}_`, statement); - } - } - else if (spec.isCollectionTypeReference(prop.type) && - spec.isNamedTypeReference(prop.type.collection.elementtype)) { - const functionName = importedFunctionName(prop.type.collection.elementtype.fqn, assembly, projectInfo); - if (functionName) { - const statement = createTypeHandlerCall(functionName, `${PARAMETER_NAME}.${prop.name}`, prop.type.collection.kind); - statementsByProp.set(`${prop.name}_`, statement); - } - } - else if (spec.isUnionTypeReference(prop.type) && - spec.isNamedTypeReference(prop.type.union.types[0]) && - Object.keys(types).includes(prop.type.union.types[0].fqn)) { - const functionName = importedFunctionName(prop.type.union.types[0].fqn, assembly, projectInfo); - if (functionName) { - const statement = createTypeHandlerCall(functionName, `${PARAMETER_NAME}.${prop.name}`); - statementsByProp.set(`${prop.name}_`, statement); - } - } - } - // We also generate calls to all the supertypes - for (const interfaceName of type.interfaces ?? []) { - const assemblies = projectInfo.dependencyClosure.concat(assembly); - const superType = findType(interfaceName, assemblies); - if (superType.type) { - processInterfaceType(superType.type, types, assembly, projectInfo, statementsByProp, excludedProps); - } - } - return { statementsByProp, excludedProps }; -} -function fnName(fqn) { - return fqn.replace(/[^\w\d]/g, '_'); -} -function createFunctionBlock(statements) { - if (statements.length > 0) { - const validation = ts.createIf(ts.createBinary(ts.createIdentifier(PARAMETER_NAME), ts.SyntaxKind.EqualsEqualsToken, ts.createNull()), ts.createReturn()); - return ts.createBlock([validation, ...statements], true); - } - return ts.createBlock([], true); -} -function createWarningFunctionCall(fqn, message = '', condition, includeNamespace = false) { - const functionName = includeNamespace - ? `${NAMESPACE}.${WARNING_FUNCTION_NAME}` - : WARNING_FUNCTION_NAME; - const mainStatement = ts.createExpressionStatement(ts.createCall(ts.createIdentifier(functionName), undefined, [ - ts.createLiteral(fqn), - ts.createLiteral(message), - ])); - return condition ? ts.createIf(condition, mainStatement) : mainStatement; -} -function generateWarningsFile(projectRoot, functionDeclarations) { - const names = [...functionDeclarations] - .map((d) => d.name?.text) - .filter(Boolean); - const exportedSymbols = [ - WARNING_FUNCTION_NAME, - GET_PROPERTY_DESCRIPTOR, - DEPRECATION_ERROR, - ...names, - ].join(','); - const functionText = `function ${WARNING_FUNCTION_NAME}(name, deprecationMessage) { - const deprecated = process.env.JSII_DEPRECATED; - const deprecationMode = ['warn', 'fail', 'quiet'].includes(deprecated) ? deprecated : 'warn'; - const message = \`\${name} is deprecated.\\n \${deprecationMessage.trim()}\\n This API will be removed in the next major release.\`; - switch (deprecationMode) { - case "fail": - throw new ${DEPRECATION_ERROR}(message); - case "warn": - console.warn("[WARNING]", message); - break; - } -} - -function ${GET_PROPERTY_DESCRIPTOR}(obj, prop) { - const descriptor = Object.getOwnPropertyDescriptor(obj, prop); - if (descriptor) { - return descriptor; - } - const proto = Object.getPrototypeOf(obj); - const prototypeDescriptor = proto && getPropertyDescriptor(proto, prop); - if (prototypeDescriptor) { - return prototypeDescriptor; - } - return {}; -} - -const ${VISITED_OBJECTS_SET_NAME} = new Set(); - -class ${DEPRECATION_ERROR} extends Error { - constructor(...args) { - super(...args); - Object.defineProperty(this, 'name', { - configurable: false, - enumerable: true, - value: '${DEPRECATION_ERROR}', - writable: false, - }); - } -} - -module.exports = {${exportedSymbols}} -`; - const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed }); - const resultFile = ts.createSourceFile(path.join(projectRoot, exports.WARNINGSCODE_FILE_NAME), functionText, ts.ScriptTarget.Latest, false, ts.ScriptKind.JS); - const declarations = functionDeclarations.map((declaration) => printer.printNode(ts.EmitHint.Unspecified, declaration, resultFile)); - const content = declarations.concat(printer.printFile(resultFile)).join('\n'); - fs.writeFileSync(path.join(projectRoot, exports.WARNINGSCODE_FILE_NAME), content); -} -class Transformer { - constructor(typeChecker, context, projectRoot, typeIndex, assembly) { - this.typeChecker = typeChecker; - this.context = context; - this.projectRoot = projectRoot; - this.typeIndex = typeIndex; - this.assembly = assembly; - this.warningCallsWereInjected = false; - } - transform(node) { - this.warningCallsWereInjected = false; - const result = this.visitEachChild(node); - if (ts.isSourceFile(result) && this.warningCallsWereInjected) { - const importDir = path.relative(path.dirname(result.fileName), this.projectRoot); - const importPath = importDir.startsWith('..') - ? unixPath(path.join(importDir, exports.WARNINGSCODE_FILE_NAME)) - : `./${exports.WARNINGSCODE_FILE_NAME}`; - return ts.updateSourceFileNode(result, [ - createRequireStatement(NAMESPACE, importPath), - ...result.statements, - ]); - } - return result; - } - visitEachChild(node) { - return ts.visitEachChild(node, this.visitor.bind(this), this.context); - } - visitor(node) { - if (ts.isMethodDeclaration(node) && node.body != null) { - const statements = this.getStatementsForDeclaration(node); - this.warningCallsWereInjected = - this.warningCallsWereInjected || statements.length > 0; - return ts.updateMethod(node, node.decorators, node.modifiers, node.asteriskToken, node.name, node.questionToken, node.typeParameters, node.parameters, node.type, ts.updateBlock(node.body, [ - ...wrapWithRethrow(statements, ts.createPropertyAccess(ts.createThis(), node.name.getText(node.getSourceFile()))), - ...node.body.statements, - ])); - } - else if (ts.isGetAccessorDeclaration(node) && node.body != null) { - const statements = this.getStatementsForDeclaration(node); - this.warningCallsWereInjected = - this.warningCallsWereInjected || statements.length > 0; - return ts.updateGetAccessor(node, node.decorators, node.modifiers, node.name, node.parameters, node.type, ts.updateBlock(node.body, [ - ...wrapWithRethrow(statements, ts.createPropertyAccess(ts.createCall(ts.createPropertyAccess(ts.createIdentifier(NAMESPACE), GET_PROPERTY_DESCRIPTOR), undefined, [ - ts.createThis(), - ts.createLiteral(node.name.getText(node.getSourceFile())), - ]), 'get')), - ...node.body.statements, - ])); - } - else if (ts.isSetAccessorDeclaration(node) && node.body != null) { - const statements = this.getStatementsForDeclaration(node); - this.warningCallsWereInjected = - this.warningCallsWereInjected || statements.length > 0; - return ts.updateSetAccessor(node, node.decorators, node.modifiers, node.name, node.parameters, ts.updateBlock(node.body, [ - ...wrapWithRethrow(statements, ts.createPropertyAccess(ts.createCall(ts.createPropertyAccess(ts.createIdentifier(NAMESPACE), GET_PROPERTY_DESCRIPTOR), undefined, [ - ts.createThis(), - ts.createLiteral(node.name.getText(node.getSourceFile())), - ]), 'set')), - ...node.body.statements, - ])); - } - else if (ts.isConstructorDeclaration(node) && node.body != null) { - const statements = this.getStatementsForDeclaration(node); - this.warningCallsWereInjected = - this.warningCallsWereInjected || statements.length > 0; - return ts.updateConstructor(node, node.decorators, node.modifiers, node.parameters, ts.updateBlock(node.body, insertStatements(node.body, wrapWithRethrow(statements, node.parent.name)))); - } - return this.visitEachChild(node); - } - /** - * @param getOrSet for property accessors, determines which of the getter or - * setter should be used to get the caller function value. - */ - getStatementsForDeclaration(node) { - const klass = node.parent; - const classSymbolId = (0, symbol_id_1.symbolIdentifier)(this.typeChecker, this.typeChecker.getTypeAtLocation(klass).symbol); - if (classSymbolId && this.typeIndex.has(classSymbolId)) { - const classType = this.typeIndex.get(classSymbolId); - if (ts.isConstructorDeclaration(node)) { - const initializer = classType?.initializer; - if (initializer) { - return this.getStatements(classType, initializer); - } - } - const methods = classType?.methods ?? []; - const method = methods.find((method) => method.name === node.name?.getText()); - if (method) { - return this.getStatements(classType, method); - } - const properties = classType?.properties ?? []; - const property = properties.find((property) => property.name === node.name?.getText()); - if (property) { - return createWarningStatementForElement(property, classType); - } - } - return []; - } - getStatements(classType, method) { - const statements = createWarningStatementForElement(method, classType); - for (const parameter of Object.values(method.parameters ?? {})) { - const parameterType = this.assembly.types && spec.isNamedTypeReference(parameter.type) - ? this.assembly.types[parameter.type.fqn] - : undefined; - if (parameterType) { - const functionName = `${NAMESPACE}.${fnName(parameterType.fqn)}`; - statements.push(ts.createExpressionStatement(ts.createCall(ts.createIdentifier(functionName), undefined, [ - ts.createIdentifier(parameter.name), - ]))); - } - } - return statements; - } -} -function createWarningStatementForElement(element, classType) { - if (spec.isDeprecated(element)) { - const elementName = element.name; - const fqn = elementName ? `${classType.fqn}#${elementName}` : classType.fqn; - const message = element.docs?.deprecated ?? classType.docs?.deprecated; - return [createWarningFunctionCall(fqn, message, undefined, true)]; - } - return []; -} -/** - * Inserts a list of statements in the correct position inside a block of statements. - * If there is a `super` call, It inserts the statements just after it. Otherwise, - * insert the statements right at the beginning of the block. - */ -function insertStatements(block, newStatements) { - function splicePoint(statement) { - if (statement == null) { - return 0; - } - let isSuper = false; - statement.forEachChild((node) => { - if (ts.isCallExpression(node) && - node.expression.kind === ts.SyntaxKind.SuperKeyword) { - isSuper = true; - } - }); - return isSuper ? 1 : 0; - } - const result = [...block.statements]; - result.splice(splicePoint(block.statements[0]), 0, ...newStatements); - return ts.createNodeArray(result); -} -function createEnumRequireStatement(typeLocation) { - const { ext } = path.parse(typeLocation); - const jsFileName = typeLocation.replace(ext, '.js'); - return createRequireStatement(LOCAL_ENUM_NAMESPACE, `./${jsFileName}`); -} -function createRequireStatement(name, importPath) { - return ts.createVariableStatement(undefined, ts.createVariableDeclarationList([ - ts.createVariableDeclaration(name, undefined, ts.createCall(ts.createIdentifier('require'), undefined, [ - ts.createLiteral(importPath), - ])), - ], ts.NodeFlags.Const)); -} -/** - * Returns a ready-to-used function name (including a `require`, if necessary) - */ -function importedFunctionName(typeName, assembly, projectInfo) { - const assemblies = projectInfo.dependencyClosure.concat(assembly); - const { type, moduleName } = findType(typeName, assemblies); - if (type) { - return moduleName !== assembly.name - ? `require("${moduleName}/${exports.WARNINGSCODE_FILE_NAME}").${fnName(type.fqn)}` - : fnName(type.fqn); - } - return undefined; -} -/** - * Find the type and module name in an array of assemblies - * matching a given type name - */ -function findType(typeName, assemblies) { - for (const asm of assemblies) { - if (asm.metadata?.jsii?.compiledWithDeprecationWarnings) { - const types = asm.types ?? {}; - for (const name of Object.keys(types)) { - if (typeName === name) { - return { type: types[name], moduleName: asm.name }; - } - } - } - } - return {}; -} -function createTypeHandlerCall(functionName, parameter, collectionKind) { - switch (collectionKind) { - case spec.CollectionKind.Array: - return ts.createIf(ts.createBinary(ts.createIdentifier(parameter), ts.SyntaxKind.ExclamationEqualsToken, ts.createNull()), ts.createForOf(undefined, ts.createVariableDeclarationList([ts.createVariableDeclaration(FOR_LOOP_ITEM_NAME)], ts.NodeFlags.Const), ts.createIdentifier(parameter), createTypeHandlerCall(functionName, FOR_LOOP_ITEM_NAME))); - case spec.CollectionKind.Map: - return ts.createIf(ts.createBinary(ts.createIdentifier(parameter), ts.SyntaxKind.ExclamationEqualsToken, ts.createNull()), ts.createForOf(undefined, ts.createVariableDeclarationList([ts.createVariableDeclaration(FOR_LOOP_ITEM_NAME)], ts.NodeFlags.Const), ts.createCall(ts.createPropertyAccess(ts.createIdentifier('Object'), 'values'), undefined, [ts.createIdentifier(parameter)]), createTypeHandlerCall(functionName, FOR_LOOP_ITEM_NAME))); - case undefined: - return ts.createIf(ts.createPrefix(ts.SyntaxKind.ExclamationToken, ts.createCall(ts.createPropertyAccess(ts.createIdentifier(VISITED_OBJECTS_SET_NAME), ts.createIdentifier('has')), undefined, [ts.createIdentifier(parameter)])), ts.createExpressionStatement(ts.createCall(ts.createIdentifier(functionName), undefined, [ - ts.createIdentifier(parameter), - ]))); - } -} -/** - * There is a chance an enum contains duplicates values with distinct keys, - * with one of those keys being deprecated. This is a potential pattern to "rename" an enum. - * In this case, we can't concretely determine if the deprecated member was used or not, - * so in those cases we skip the warnings altogether, rather than erroneously warning for valid usage. - * This create a statement to check if the enum value is a duplicate: - * - * if (Object.values(Foo).filter(x => x === p).length > 1) { return; } - * - * Note that we can't just check the assembly for these duplicates, due to: - * https://github.com/aws/jsii/issues/2782 - */ -function createDuplicateEnumValuesCheck(type) { - return ts.createIf(ts.createBinary(ts.createPropertyAccess(ts.createCall(ts.createPropertyAccess(ts.createCall(ts.createPropertyAccess(ts.createIdentifier('Object'), 'values'), undefined, [ - ts.createPropertyAccess(ts.createIdentifier(LOCAL_ENUM_NAMESPACE), type.name), - ]), ts.createIdentifier('filter')), undefined, [ - ts.createArrowFunction(undefined, undefined, [ts.createParameter(undefined, undefined, undefined, 'x')], undefined, ts.createToken(ts.SyntaxKind.EqualsGreaterThanToken), ts.createBinary(ts.createIdentifier('x'), ts.createToken(ts.SyntaxKind.EqualsEqualsEqualsToken), ts.createIdentifier(PARAMETER_NAME))), - ]), ts.createIdentifier('length')), ts.createToken(ts.SyntaxKind.GreaterThanToken), ts.createNumericLiteral('1')), ts.createReturn()); -} -// We try-then-rethrow exceptions to avoid runtimes displaying an uncanny wall of text if the place -// where the error was thrown is webpacked. For example, jest somehow manages to capture the throw -// location and renders the source line (which may be the whole file) when bundled. -function wrapWithRethrow(statements, caller) { - if (statements.length === 0) { - return statements; - } - return [ - ts.createTry(ts.createBlock(statements), ts.createCatchClause(ts.createVariableDeclaration('error'), ts.createBlock([ - // If this is a DeprecationError, trim its stack trace to surface level before re-throwing, - // so we don't carry out possibly confusing frames from injected code. That can be toggled - // off by setting JSII_DEBUG=1, so we can also diagnose in-injected code faults. - ts.createIf(ts.createBinary(ts.createBinary(ts.createPropertyAccess(ts.createPropertyAccess(ts.createIdentifier('process'), 'env'), 'JSII_DEBUG'), ts.SyntaxKind.ExclamationEqualsEqualsToken, ts.createLiteral('1')), ts.SyntaxKind.AmpersandAmpersandToken, ts.createBinary(ts.createPropertyAccess(ts.createIdentifier('error'), 'name'), ts.SyntaxKind.EqualsEqualsEqualsToken, ts.createLiteral(DEPRECATION_ERROR))), ts.createBlock([ - ts.createExpressionStatement(ts.createCall(ts.createPropertyAccess(ts.createIdentifier('Error'), 'captureStackTrace'), undefined, [ts.createIdentifier('error'), caller])), - ])), - ts.createThrow(ts.createIdentifier('error')), - ])), undefined), - ]; -} -/** - * Force a path to be UNIXy (use `/` as a separator) - * - * `path.join()` etc. will use the system-dependent path separator (either `/` or `\` - * depending on your platform). - * - * However, if we actually emit the path-dependent separator to the `.js` files, then - * files compiled with jsii on Windows cannot be used on any other platform. That seems - * like an unnecessary restriction, especially since a `/` will work fine on Windows, - * so make sure to always emit `/`. - * - * TSC itself always strictly emits `/` (or at least, emits the same what you put in). - */ -function unixPath(filePath) { - if (path.sep === '\\') { - return filePath.replace(/\\/g, '/'); - } - return filePath; -} -//# sourceMappingURL=deprecation-warnings.js.map \ No newline at end of file diff --git a/src/transforms/deprecation-warnings.js.map b/src/transforms/deprecation-warnings.js.map deleted file mode 100644 index 89b8d578..00000000 --- a/src/transforms/deprecation-warnings.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"deprecation-warnings.js","sourceRoot":"","sources":["deprecation-warnings.ts"],"names":[],"mappings":";;;AAAA,mCAAmC;AAEnC,yBAAyB;AACzB,6BAA6B;AAC7B,iCAAiC;AAGjC,4CAAgD;AAEnC,QAAA,sBAAsB,GAAG,mBAAmB,CAAC;AAC1D,MAAM,qBAAqB,GAAG,OAAO,CAAC;AACtC,MAAM,cAAc,GAAG,GAAG,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AAC,gBAAgB,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,CACvC,CACF;aACF,CAAC,CACH;YACD,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;SAC7C,CAAC,CACH,EACD,SAAS,CACV;KACF,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAS,QAAQ,CAAC,QAAgB;IAChC,IAAI,IAAI,CAAC,GAAG,KAAK,IAAI,EAAE;QACrB,OAAO,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;KACrC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"} \ No newline at end of file diff --git a/src/transforms/runtime-info.js b/src/transforms/runtime-info.js deleted file mode 100644 index 08beaa42..00000000 --- a/src/transforms/runtime-info.js +++ /dev/null @@ -1,91 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.RuntimeTypeInfoInjector = void 0; -const ts = require("typescript"); -/** - * Provides a TransformerFactory to annotate classes with runtime information - * (e.g., fully-qualified name, version). - * - * It does this by first inserting this definition at the top of each source file: - * ``` - * var JSII_RTTI_SYMBOL_1 = Symbol.for("jsii.rtti"); - * ``` - * - * Then, for each class that has registered runtime information during assembly, - * insert a static member to the class with its fqn and version: - * ``` - * private static readonly [JSII_RTTI_SYMBOL_1] = { fqn: "ModuleName.ClassName", version: "1.2.3" } - * ``` - */ -class RuntimeTypeInfoInjector { - constructor(version) { - this.version = version; - this.fqnsByClass = new Map(); - } - /** - * Register the fully-qualified name (fqn) of a class with its ClassDeclaration. - * Only ClassDeclarations with registered fqns will be annotated. - */ - registerClassFqn(clazz, fqn) { - this.fqnsByClass.set(clazz, fqn); - } - /** - * Return the set of Transformers to be used in TSC's program.emit() - */ - makeTransformers() { - return { - before: [this.runtimeTypeTransformer()], - }; - } - runtimeTypeTransformer() { - return (context) => { - return (sourceFile) => { - const rttiSymbolIdentifier = ts.createUniqueName('JSII_RTTI_SYMBOL'); - let classesAnnotated = false; - const visitor = (node) => { - if (ts.isClassDeclaration(node)) { - const fqn = this.getClassFqn(node); - if (fqn) { - classesAnnotated = true; - return this.addRuntimeInfoToClass(node, fqn, rttiSymbolIdentifier); - } - } - return ts.visitEachChild(node, visitor, context); - }; - // Visit the source file, annotating the classes. - let annotatedSourceFile = ts.visitNode(sourceFile, visitor); - // Only add the symbol definition if it's actually used. - if (classesAnnotated) { - const rttiSymbol = ts.createCall(ts.createPropertyAccess(ts.createIdentifier('Symbol'), ts.createIdentifier('for')), undefined, [ts.createStringLiteral('jsii.rtti')]); - const rttiSymbolDeclaration = ts.createVariableDeclaration(rttiSymbolIdentifier, undefined, rttiSymbol); - const variableDeclaration = ts.createVariableStatement([], ts.createVariableDeclarationList([rttiSymbolDeclaration], ts.NodeFlags.Const)); - annotatedSourceFile = ts.updateSourceFileNode(annotatedSourceFile, [ - variableDeclaration, - ...annotatedSourceFile.statements, - ]); - } - return annotatedSourceFile; - }; - }; - } - /** Used instead of direct access to the map to faciliate testing. */ - getClassFqn(clazz) { - return this.fqnsByClass.get(clazz); - } - /** - * If the ClassDeclaration has an associated fully-qualified name registered, - * will append a static property to the class with the fqn and version. - */ - addRuntimeInfoToClass(node, fqn, rttiSymbol) { - const runtimeInfo = ts.createObjectLiteral([ - ts.createPropertyAssignment(ts.createIdentifier('fqn'), ts.createStringLiteral(fqn)), - ts.createPropertyAssignment(ts.createIdentifier('version'), ts.createStringLiteral(this.version)), - ]); - const runtimeProperty = ts.createProperty(undefined, ts.createModifiersFromModifierFlags(ts.ModifierFlags.Private | - ts.ModifierFlags.Static | - ts.ModifierFlags.Readonly), ts.createComputedPropertyName(rttiSymbol), undefined, undefined, runtimeInfo); - return ts.updateClassDeclaration(node, node.decorators, node.modifiers, node.name, node.typeParameters, node.heritageClauses, [runtimeProperty, ...node.members]); - } -} -exports.RuntimeTypeInfoInjector = RuntimeTypeInfoInjector; -//# sourceMappingURL=runtime-info.js.map \ No newline at end of file diff --git a/src/transforms/runtime-info.js.map b/src/transforms/runtime-info.js.map deleted file mode 100644 index 8a2abb49..00000000 --- a/src/transforms/runtime-info.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"runtime-info.js","sourceRoot":"","sources":["runtime-info.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AAEjC;;;;;;;;;;;;;;GAcG;AACH,MAAa,uBAAuB;IAGlC,YAAoC,OAAe;QAAf,YAAO,GAAP,OAAO,CAAQ;QAFlC,gBAAW,GAAG,IAAI,GAAG,EAA+B,CAAC;IAEhB,CAAC;IAEvD;;;OAGG;IACI,gBAAgB,CAAC,KAA0B,EAAE,GAAW;QAC7D,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACnC,CAAC;IAED;;OAEG;IACI,gBAAgB;QACrB,OAAO;YACL,MAAM,EAAE,CAAC,IAAI,CAAC,sBAAsB,EAAE,CAAC;SACxC,CAAC;IACJ,CAAC;IAEM,sBAAsB;QAC3B,OAAO,CAAC,OAAO,EAAE,EAAE;YACjB,OAAO,CAAC,UAAU,EAAE,EAAE;gBACpB,MAAM,oBAAoB,GAAG,EAAE,CAAC,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;gBAErE,IAAI,gBAAgB,GAAG,KAAK,CAAC;gBAC7B,MAAM,OAAO,GAAG,CAAC,IAAa,EAAW,EAAE;oBACzC,IAAI,EAAE,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAAE;wBAC/B,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;wBACnC,IAAI,GAAG,EAAE;4BACP,gBAAgB,GAAG,IAAI,CAAC;4BACxB,OAAO,IAAI,CAAC,qBAAqB,CAC/B,IAAI,EACJ,GAAG,EACH,oBAAoB,CACrB,CAAC;yBACH;qBACF;oBACD,OAAO,EAAE,CAAC,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;g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C,CAC5B;YACD,EAAE,CAAC,wBAAwB,CACzB,EAAE,CAAC,gBAAgB,CAAC,SAAS,CAAC,EAC9B,EAAE,CAAC,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,CACrC;SACF,CAAC,CAAC;QACH,MAAM,eAAe,GAAG,EAAE,CAAC,cAAc,CACvC,SAAS,EACT,EAAE,CAAC,gCAAgC,CACjC,EAAE,CAAC,aAAa,CAAC,OAAO;YACtB,EAAE,CAAC,aAAa,CAAC,MAAM;YACvB,EAAE,CAAC,aAAa,CAAC,QAAQ,CAC5B,EACD,EAAE,CAAC,0BAA0B,CAAC,UAAU,CAAC,EACzC,SAAS,EACT,SAAS,EACT,WAAW,CACZ,CAAC;QACF,OAAO,EAAE,CAAC,sBAAsB,CAC9B,IAAI,EACJ,IAAI,CAAC,UAAU,EACf,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,cAAc,EACnB,IAAI,CAAC,eAAe,EACpB,CAAC,eAAe,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,CACnC,CAAC;IACJ,CAAC;CACF;AA9HD,0DA8HC"} \ No newline at end of file diff --git a/src/transforms/utils.js b/src/transforms/utils.js deleted file mode 100644 index 9abf2a04..00000000 --- a/src/transforms/utils.js +++ /dev/null @@ -1,32 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.combinedTransformers = void 0; -/** - * Combines a collection of `CustomTransformers` configurations into a single - * one, preserving the order of arguments. - * - * @param transformers the list of transformers to combine. - * - * @returns the combined transformer. - */ -function combinedTransformers(...transformers) { - // Note the ! below are just to stop the type checker from seeing undefined as - // a value for the whole map-filter-reduce chain, as this would require heavy - // syntax that is not desirable. The filter step removes the `undefined`. - return { - before: transformers - .map((transformer) => transformer.before) - .filter((transform) => transform != null) - .reduce((acc, elt) => (acc ? [...acc, ...elt] : elt), undefined), - after: transformers - .map((transformer) => transformer.after) - .filter((transform) => transform != null) - .reduce((acc, elt) => (acc ? [...acc, ...elt] : elt), undefined), - afterDeclarations: transformers - .map((transformer) => transformer.afterDeclarations) - .filter((transform) => transform != null) - .reduce((acc, elt) => (acc ? [...acc, ...elt] : elt), undefined), - }; -} -exports.combinedTransformers = combinedTransformers; -//# sourceMappingURL=utils.js.map \ No newline at end of file diff --git a/src/transforms/utils.js.map b/src/transforms/utils.js.map deleted file mode 100644 index a8944e81..00000000 --- a/src/transforms/utils.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"utils.js","sourceRoot":"","sources":["utils.ts"],"names":[],"mappings":";;;AAEA;;;;;;;GAOG;AACH,SAAgB,oBAAoB,CAClC,GAAG,YAA2C;IAE9C,8EAA8E;IAC9E,6EAA6E;IAC7E,yEAAyE;IACzE,OAAO;QACL,MAAM,EAAE,YAAY;aACjB,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,MAAO,CAAC;aACzC,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,IAAI,IAAI,CAAC;aACxC,MAAM,CACL,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAC5C,SAAyC,CAC1C;QACH,KAAK,EAAE,YAAY;aAChB,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,KAAM,CAAC;aACxC,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,IAAI,IAAI,CAAC;aACxC,MAAM,CACL,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAC5C,SAAwC,CACzC;QACH,iBAAiB,EAAE,YAAY;aAC5B,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,iBAAkB,CAAC;aACpD,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,IAAI,IAAI,CAAC;aACxC,MAAM,CACL,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAC5C,SAAoD,CACrD;KACJ,CAAC;AACJ,CAAC;AA7BD,oDA6BC"} \ No newline at end of file diff --git a/src/utils.ts b/src/utils.ts index 767b030f..ca98b0e7 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -3,6 +3,10 @@ import * as ts from 'typescript'; import { JsiiDiagnostic } from './jsii-diagnostic'; +/** + * Name of the logger for cli errors + */ +export const CLI_LOGGER = 'jsii/cli'; /** * Name of the logger for diagnostics information */ @@ -115,7 +119,7 @@ const PERSON_REGEX = /^\s*(.+?)(?:\s*<([^>]+)>)?(?:\s*\(([^)]+)\))?\s*$/; export function parsePerson(value: string) { const match = PERSON_REGEX.exec(value); if (!match) { - throw new Error(`Invalid stringified "person" value: ${value}`); + throw new JsiiError(`Invalid stringified "person" value: ${value}`); } const [, name, email, url] = match; const result: { name: string; email?: string; url?: string } = { @@ -147,7 +151,7 @@ export function parseRepository(value: string): { url: string } { case 'gitlab': return { url: `https://gitlab.com/${slug}.git` }; default: - throw new Error(`Unknown host service: ${host}`); + throw new JsiiError(`Unknown repository hosting service: ${host}`); } } @@ -163,3 +167,20 @@ export function stripAnsi(x: string): string { * Maps the provided type to stip all `readonly` modifiers from its properties. */ export type Mutable = { -readonly [K in keyof T]: Mutable }; + +/** + * Throws an error that is intended as CLI output. + */ +export class JsiiError extends Error { + /** + * An expected error that can be nicely formatted where needed (e.g. in CLI output) + * This should only be used for errors that a user can fix themselves. + * + * @param message The error message to be printed to the user. + * @param showHelp Print the help before the error. + */ + constructor(public override readonly message: string, public readonly showHelp = false) { + super(message); + Object.setPrototypeOf(this, JsiiError.prototype); + } +}