@atlaspack/diagnostic 2.14.2-typescript-1fd1095e8.0 → 2.14.2-typescript-e99c742e9.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.
Files changed (2) hide show
  1. package/lib/diagnostic.d.ts +162 -0
  2. package/package.json +7 -7
@@ -0,0 +1,162 @@
1
+ import { type Mapping } from '@mischnic/json-sourcemap';
2
+ /** These positions are 1-based (so <code>1</code> is the first line/column) */
3
+ export type DiagnosticHighlightLocation = {
4
+ readonly line: number;
5
+ readonly column: number;
6
+ };
7
+ export type DiagnosticSeverity = 'error' | 'warn' | 'info';
8
+ /**
9
+ * Note: A tab character is always counted as a single character
10
+ * This is to prevent any mismatch of highlighting across machines
11
+ */
12
+ export type DiagnosticCodeHighlight = {
13
+ /** Location of the first character that should get highlighted for this highlight. */
14
+ start: DiagnosticHighlightLocation;
15
+ /** Location of the last character that should get highlighted for this highlight. */
16
+ end: DiagnosticHighlightLocation;
17
+ /** A message that should be displayed at this location in the code (optional). */
18
+ message?: string;
19
+ };
20
+ /**
21
+ * Describes how to format a code frame.
22
+ * A code frame is a visualization of a piece of code with a certain amount of
23
+ * code highlights that point to certain chunk(s) inside the code.
24
+ */
25
+ export type DiagnosticCodeFrame = {
26
+ /**
27
+ * The contents of the source file.
28
+ *
29
+ * If no code is passed, it will be read in from filePath, remember that
30
+ * the asset's current code could be different from the input contents.
31
+ *
32
+ */
33
+ code?: string;
34
+ /** Path to the file this code frame is about (optional, absolute or relative to the project root) */
35
+ filePath?: string;
36
+ /** Language of the file this code frame is about (optional) */
37
+ language?: string;
38
+ codeHighlights: Array<DiagnosticCodeHighlight>;
39
+ };
40
+ /** A JSON object (as in "map") */
41
+ type JSONObject = {
42
+ [key: string]: any;
43
+ };
44
+ /**
45
+ * A style agnostic way of emitting errors, warnings and info.
46
+ * Reporters are responsible for rendering the message, codeframes, hints, ...
47
+ */
48
+ export type Diagnostic = {
49
+ /** This is the message you want to log. */
50
+ message: string;
51
+ /** Name of plugin or file that threw this error */
52
+ origin?: string;
53
+ /** A stacktrace of the error (optional) */
54
+ stack?: string;
55
+ /** Name of the error (optional) */
56
+ name?: string;
57
+ /** A code frame points to a certain location(s) in the file this diagnostic is linked to (optional) */
58
+ codeFrames?: Array<DiagnosticCodeFrame> | null | undefined;
59
+ /** An optional list of strings that suggest ways to resolve this issue */
60
+ hints?: Array<string>;
61
+ /** @private */
62
+ skipFormatting?: boolean;
63
+ /** A URL to documentation to learn more about the diagnostic. */
64
+ documentationURL?: string;
65
+ /** Diagnostic specific metadata (optional) */
66
+ meta?: JSONObject;
67
+ };
68
+ export interface PrintableError extends Error {
69
+ fileName?: string;
70
+ filePath?: string;
71
+ codeFrame?: string;
72
+ highlightedCodeFrame?: string;
73
+ loc?: {
74
+ column: number;
75
+ line: number;
76
+ } | null | undefined;
77
+ source?: string;
78
+ }
79
+ export type DiagnosticWithoutOrigin = Diagnostic & {
80
+ origin?: string;
81
+ };
82
+ /** Something that can be turned into a diagnostic. */
83
+ export type Diagnostifiable = Diagnostic | Array<Diagnostic> | ThrowableDiagnostic | PrintableError | Error | string;
84
+ /** Normalize the given value into a diagnostic. */
85
+ export declare function anyToDiagnostic(input: Diagnostifiable): Array<Diagnostic>;
86
+ /** Normalize the given error into a diagnostic. */
87
+ export declare function errorToDiagnostic(error: ThrowableDiagnostic | PrintableError | string, defaultValues?: {
88
+ origin?: string | null | undefined;
89
+ filePath?: string | null | undefined;
90
+ }): Array<Diagnostic>;
91
+ type ThrowableDiagnosticOpts = {
92
+ diagnostic: Diagnostic | Array<Diagnostic>;
93
+ };
94
+ /**
95
+ * An error wrapper around a diagnostic that can be <code>throw</code>n (e.g. to signal a
96
+ * build error).
97
+ */
98
+ export default class ThrowableDiagnostic extends Error {
99
+ diagnostics: Array<Diagnostic>;
100
+ constructor(opts: ThrowableDiagnosticOpts);
101
+ }
102
+ /**
103
+ * Turns a list of positions in a JSON5 file with messages into a list of diagnostics.
104
+ * Uses <a href="https://github.com/mischnic/json-sourcemap">@mischnic/json-sourcemap</a>.
105
+ *
106
+ * @param code the JSON code
107
+ * @param ids A list of JSON keypaths (<code>key: "/some/parent/child"</code>) with corresponding messages, \
108
+ * <code>type</code> signifies whether the key of the value in a JSON object should be highlighted.
109
+ */
110
+ export declare function generateJSONCodeHighlights(data: string | {
111
+ data: unknown;
112
+ pointers: {
113
+ [key: string]: Mapping;
114
+ };
115
+ }, ids: Array<{
116
+ key: string;
117
+ type?: 'key' | null | undefined | 'value';
118
+ message?: string;
119
+ }>): Array<DiagnosticCodeHighlight>;
120
+ /**
121
+ * Converts entries in <a href="https://github.com/mischnic/json-sourcemap">@mischnic/json-sourcemap</a>'s
122
+ * <code>result.pointers</code> array.
123
+ */
124
+ export declare function getJSONHighlightLocation(pos: Mapping, type?: 'key' | null | undefined | 'value'): {
125
+ start: DiagnosticHighlightLocation;
126
+ end: DiagnosticHighlightLocation;
127
+ };
128
+ /** Result is 1-based, but end is exclusive */
129
+ export declare function getJSONSourceLocation(pos: Mapping, type?: 'key' | null | undefined | 'value'): {
130
+ start: {
131
+ readonly line: number;
132
+ readonly column: number;
133
+ };
134
+ end: {
135
+ readonly line: number;
136
+ readonly column: number;
137
+ };
138
+ };
139
+ export declare function convertSourceLocationToHighlight<Location extends {
140
+ /** 1-based, inclusive */
141
+ readonly start: {
142
+ readonly line: number;
143
+ readonly column: number;
144
+ };
145
+ /** 1-based, exclusive */
146
+ readonly end: {
147
+ readonly line: number;
148
+ readonly column: number;
149
+ };
150
+ }>({ start, end }: Location, message?: string): DiagnosticCodeHighlight;
151
+ /** Sanitizes object keys before using them as <code>key</code> in generateJSONCodeHighlights */
152
+ export declare function encodeJSONKeyComponent(component: string): string;
153
+ export declare function escapeMarkdown(s: string): string;
154
+ type TemplateInput = any;
155
+ export declare function md(strings: Array<string>, ...params: Array<TemplateInput>): string;
156
+ export declare namespace md {
157
+ var bold: (s: TemplateInput) => TemplateInput;
158
+ var italic: (s: TemplateInput) => TemplateInput;
159
+ var underline: (s: TemplateInput) => TemplateInput;
160
+ var strikethrough: (s: TemplateInput) => TemplateInput;
161
+ }
162
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/diagnostic",
3
- "version": "2.14.2-typescript-1fd1095e8.0",
3
+ "version": "2.14.2-typescript-e99c742e9.0",
4
4
  "description": "Types and utilities for printing source-code located errors, warning and information messages.",
5
5
  "license": "(MIT OR Apache-2.0)",
6
6
  "publishConfig": {
@@ -10,19 +10,19 @@
10
10
  "type": "git",
11
11
  "url": "https://github.com/atlassian-labs/atlaspack.git"
12
12
  },
13
- "main": "lib/diagnostic.js",
14
- "source": "src/diagnostic.ts",
15
- "types": "src/diagnostic.ts",
13
+ "main": "./lib/diagnostic.js",
14
+ "source": "./src/diagnostic.ts",
15
+ "types": "./lib/diagnostic.d.ts",
16
16
  "engines": {
17
17
  "node": ">= 16.0.0"
18
18
  },
19
19
  "scripts": {
20
- "check-ts": "tsc --noEmit"
20
+ "check-ts": "tsc --emitDeclarationOnly --rootDir src"
21
21
  },
22
22
  "dependencies": {
23
23
  "@mischnic/json-sourcemap": "^0.1.0",
24
24
  "nullthrows": "^1.1.1"
25
25
  },
26
26
  "type": "commonjs",
27
- "gitHead": "1fd1095e86da1e50d6c7819c0f132ce09a2bf396"
28
- }
27
+ "gitHead": "e99c742e92175ac411d807daf2ba45d5bacebb58"
28
+ }