jsii-rosetta 1.76.0 → 1.77.0

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.
@@ -426,7 +426,7 @@ function handleDiagnostics(diagnostics, fail, snippetCount = 1) {
426
426
  if (fail !== false) {
427
427
  // Fail on any diagnostic
428
428
  if (diagnostics.length > 0) {
429
- (0, util_1.printDiagnostics)(diagnostics, process.stderr);
429
+ (0, util_1.printDiagnostics)(diagnostics, process.stderr, process.stderr.isTTY);
430
430
  logging.error([
431
431
  `${diagnostics.length} diagnostics encountered in ${snippetCount} snippets`,
432
432
  ...(fail === true ? ["(running with '--fail')"] : []),
@@ -439,7 +439,7 @@ function handleDiagnostics(diagnostics, fail, snippetCount = 1) {
439
439
  // (so it's very clear what is failing the build), otherwise print everything.
440
440
  const strictDiagnostics = diagnostics.filter((diag) => diag.isFromStrictAssembly);
441
441
  if (strictDiagnostics.length > 0) {
442
- (0, util_1.printDiagnostics)(strictDiagnostics, process.stderr);
442
+ (0, util_1.printDiagnostics)(strictDiagnostics, process.stderr, process.stderr.isTTY);
443
443
  const remaining = diagnostics.length - strictDiagnostics.length;
444
444
  logging.warn([
445
445
  `${strictDiagnostics.length} diagnostics from assemblies with 'strict' mode on`,
@@ -449,7 +449,7 @@ function handleDiagnostics(diagnostics, fail, snippetCount = 1) {
449
449
  return;
450
450
  }
451
451
  if (diagnostics.length > 0) {
452
- (0, util_1.printDiagnostics)(diagnostics, process.stderr);
452
+ (0, util_1.printDiagnostics)(diagnostics, process.stderr, process.stderr.isTTY);
453
453
  logging.warn(`${diagnostics.length} diagnostics encountered in ${snippetCount} snippets`);
454
454
  }
455
455
  }
@@ -68,7 +68,7 @@ async function transliterateAssembly(assemblyLocations, targetLanguages, options
68
68
  (0, logging_1.debug)(`Done transliterating ${result.name}@${result.version} to ${language} after ${then - now} milliseconds`);
69
69
  }
70
70
  }
71
- rosetta.printDiagnostics(process.stderr);
71
+ rosetta.printDiagnostics(process.stderr, process.stderr.isTTY);
72
72
  if (rosetta.hasErrors && options.strict) {
73
73
  throw new Error('Strict mode is enabled and some examples failed compilation!');
74
74
  }
@@ -323,12 +323,13 @@ class GoVisitor extends default_1.DefaultVisitor {
323
323
  ts.isClassDeclaration(expressionType.symbol.valueDeclaration) &&
324
324
  (ts.isPropertyDeclaration(valueSymbol.valueDeclaration) || ts.isAccessor(valueSymbol.valueDeclaration));
325
325
  const isClassStaticMethodAccess = isStaticMember && !isClassStaticPropertyAccess && ts.isMethodDeclaration(valueSymbol.valueDeclaration);
326
- // When the expression has an unknown type (unresolved symbol), and has an upper-case first
327
- // letter, we assume it's a type name... In such cases, what comes after can be considered a
328
- // static member access. Note that the expression might be further qualified, so we check using
329
- // a regex that checks for the last "."-delimited segment if there's dots in there...
326
+ // When the expression has an unknown type (unresolved symbol), has an upper-case first letter,
327
+ // and doesn't end in a call expression (as hinted by the presence of parentheses), we assume
328
+ // it's a type name... In such cases, what comes after can be considered a static member access.
329
+ // Note that the expression might be further qualified, so we check using a regex that checks
330
+ // for the last "." - delimited segment if there's dots in there...
330
331
  const expressionLooksLikeTypeReference = expressionType.symbol == null &&
331
- /(?:\.|^)[A-Z][^.]*$/.exec(node.expression.getText(node.expression.getSourceFile())) != null;
332
+ /(?:\.|^)[A-Z][^.)]*$/.exec(node.expression.getText(node.expression.getSourceFile())) != null;
332
333
  // Whether the node is an enum member reference.
333
334
  const isEnumMember = expressionType?.symbol?.valueDeclaration != null && ts.isEnumDeclaration(expressionType.symbol.valueDeclaration);
334
335
  const jsiiSymbol = (0, jsii_utils_1.lookupJsiiSymbolFromNode)(renderer.typeChecker, node.name);
@@ -139,7 +139,7 @@ export declare class RosettaTabletReader {
139
139
  * method for documentation.
140
140
  */
141
141
  translateSnippetsInMarkdown(apiLocation: ApiLocation, markdown: string, targetLang: TargetLanguage, strict: boolean, translationToCodeBlock?: (x: Translation) => CodeBlock, compileDirectory?: string): string;
142
- printDiagnostics(stream: NodeJS.WritableStream): void;
142
+ printDiagnostics(stream: NodeJS.WritableStream, colors?: boolean): void;
143
143
  get hasErrors(): boolean;
144
144
  private get allTablets();
145
145
  /**
@@ -198,8 +198,8 @@ class RosettaTabletReader {
198
198
  return translationToCodeBlock(translated);
199
199
  }));
200
200
  }
201
- printDiagnostics(stream) {
202
- (0, util_1.printDiagnostics)(this.diagnostics, stream);
201
+ printDiagnostics(stream, colors = true) {
202
+ (0, util_1.printDiagnostics)(this.diagnostics, stream, colors);
203
203
  }
204
204
  get hasErrors() {
205
205
  return this.diagnostics.some((d) => d.isError);
package/lib/util.d.ts CHANGED
@@ -6,7 +6,7 @@ export interface File {
6
6
  readonly contents: string;
7
7
  readonly fileName: string;
8
8
  }
9
- export declare function printDiagnostics(diags: readonly RosettaDiagnostic[], stream: NodeJS.WritableStream): void;
9
+ export declare function printDiagnostics(diags: readonly RosettaDiagnostic[], stream: NodeJS.WritableStream, colors: boolean): void;
10
10
  export declare function formatList(xs: string[], n?: number): string;
11
11
  export declare const StrictBrand = "jsii.strict";
12
12
  /**
package/lib/util.js CHANGED
@@ -6,11 +6,11 @@ function startsWithUppercase(x) {
6
6
  return /^[A-Z]/.exec(x) != null;
7
7
  }
8
8
  exports.startsWithUppercase = startsWithUppercase;
9
- function printDiagnostics(diags, stream) {
9
+ function printDiagnostics(diags, stream, colors) {
10
10
  // Don't print too much, at some point it just clogs up the log
11
11
  const maxDiags = 50;
12
12
  for (const diag of diags.slice(0, maxDiags)) {
13
- stream.write(diag.formattedMessage);
13
+ stream.write(colors ? diag.formattedMessage : stripColorCodes(diag.formattedMessage));
14
14
  }
15
15
  if (diags.length > maxDiags) {
16
16
  stream.write(`(...and ${diags.length - maxDiags} more diagnostics not shown)`);
@@ -198,4 +198,12 @@ async function pathExists(path) {
198
198
  }
199
199
  }
200
200
  exports.pathExists = pathExists;
201
+ // Copy/pasted from the 'ansi-regex' package to avoid taking a dependency for this one line that will never change
202
+ const ANSI_PATTERN = new RegExp([
203
+ '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
204
+ '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))',
205
+ ].join('|'), 'g');
206
+ function stripColorCodes(x) {
207
+ return x.replace(ANSI_PATTERN, '');
208
+ }
201
209
  //# sourceMappingURL=util.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsii-rosetta",
3
- "version": "1.76.0",
3
+ "version": "1.77.0",
4
4
  "description": "Translate TypeScript code snippets to other languages",
5
5
  "main": "lib/index.js",
6
6
  "bin": {
@@ -20,23 +20,23 @@
20
20
  "@types/mock-fs": "^4.13.1",
21
21
  "@types/workerpool": "^6.1.1",
22
22
  "@types/semver": "^7.3.13",
23
- "jsii-build-tools": "1.76.0",
23
+ "jsii-build-tools": "1.77.0",
24
24
  "jsii-calc": "3.20.120",
25
25
  "memory-streams": "^0.1.3",
26
26
  "mock-fs": "^5.2.0"
27
27
  },
28
28
  "dependencies": {
29
- "@jsii/check-node": "1.76.0",
30
- "@jsii/spec": "1.76.0",
29
+ "@jsii/check-node": "1.77.0",
30
+ "@jsii/spec": "1.77.0",
31
31
  "commonmark": "^0.30.0",
32
32
  "typescript": "~3.9.10",
33
33
  "@xmldom/xmldom": "^0.8.6",
34
- "workerpool": "^6.3.1",
34
+ "workerpool": "^6.4.0",
35
35
  "yargs": "^16.2.0",
36
36
  "semver": "^7.3.8",
37
37
  "semver-intersect": "^1.4.0",
38
38
  "fast-glob": "^3.2.12",
39
- "jsii": "1.76.0"
39
+ "jsii": "1.77.0"
40
40
  },
41
41
  "license": "Apache-2.0",
42
42
  "author": {