@atlaspack/diagnostic 2.13.2-dev.3689 → 2.14.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.
- package/CHANGELOG.md +10 -0
- package/package.json +2 -2
- package/LICENSE +0 -201
- package/lib/diagnostic.d.ts +0 -158
- package/lib/diagnostic.js +0 -285
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @atlaspack/diagnostic
|
|
2
2
|
|
|
3
|
+
## 2.14.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#339](https://github.com/atlassian-labs/atlaspack/pull/339) [`bfe81e5`](https://github.com/atlassian-labs/atlaspack/commit/bfe81e551c4e4bb2cac7fc4745222e66962c1728) Thanks [@yamadapc](https://github.com/yamadapc)! - Update cache invalidation metrics with build type
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- [#414](https://github.com/atlassian-labs/atlaspack/pull/414) [`eff9809`](https://github.com/atlassian-labs/atlaspack/commit/eff98093703b9999a511b87a19562f5aaccfcb53) Thanks [@alshdavid](https://github.com/alshdavid)! - Added type:commonjs to package.json files
|
|
12
|
+
|
|
3
13
|
## 2.13.1
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/diagnostic",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.14.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": {
|
|
@@ -24,5 +24,5 @@
|
|
|
24
24
|
"@mischnic/json-sourcemap": "^0.1.0",
|
|
25
25
|
"nullthrows": "^1.1.1"
|
|
26
26
|
},
|
|
27
|
-
"
|
|
27
|
+
"type": "commonjs"
|
|
28
28
|
}
|
package/LICENSE
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|
|
177
|
-
|
|
178
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
-
|
|
180
|
-
To apply the Apache License to your work, attach the following
|
|
181
|
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
-
replaced with your own identifying information. (Don't include
|
|
183
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
-
comment syntax for the file format. We also recommend that a
|
|
185
|
-
file or class name and description of purpose be included on the
|
|
186
|
-
same "printed page" as the copyright notice for easier
|
|
187
|
-
identification within third-party archives.
|
|
188
|
-
|
|
189
|
-
Copyright (c) 2024 Atlassian US., Inc.
|
|
190
|
-
|
|
191
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
-
you may not use this file except in compliance with the License.
|
|
193
|
-
You may obtain a copy of the License at
|
|
194
|
-
|
|
195
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
-
|
|
197
|
-
Unless required by applicable law or agreed to in writing, software
|
|
198
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
-
See the License for the specific language governing permissions and
|
|
201
|
-
limitations under the License.
|
package/lib/diagnostic.d.ts
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
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 = Record<string, any>;
|
|
42
|
-
/**
|
|
43
|
-
* A style agnostic way of emitting errors, warnings and info.
|
|
44
|
-
* Reporters are responsible for rendering the message, codeframes, hints, ...
|
|
45
|
-
*/
|
|
46
|
-
export type Diagnostic = {
|
|
47
|
-
/** This is the message you want to log. */
|
|
48
|
-
message: string;
|
|
49
|
-
/** Name of plugin or file that threw this error */
|
|
50
|
-
origin?: string;
|
|
51
|
-
/** A stacktrace of the error (optional) */
|
|
52
|
-
stack?: string;
|
|
53
|
-
/** Name of the error (optional) */
|
|
54
|
-
name?: string;
|
|
55
|
-
/** A code frame points to a certain location(s) in the file this diagnostic is linked to (optional) */
|
|
56
|
-
codeFrames?: Array<DiagnosticCodeFrame> | null | undefined;
|
|
57
|
-
/** An optional list of strings that suggest ways to resolve this issue */
|
|
58
|
-
hints?: Array<string>;
|
|
59
|
-
/** @private */
|
|
60
|
-
skipFormatting?: boolean;
|
|
61
|
-
/** A URL to documentation to learn more about the diagnostic. */
|
|
62
|
-
documentationURL?: string;
|
|
63
|
-
/** Diagnostic specific metadata (optional) */
|
|
64
|
-
meta?: JSONObject;
|
|
65
|
-
};
|
|
66
|
-
export interface PrintableError extends Error {
|
|
67
|
-
fileName?: string;
|
|
68
|
-
filePath?: string;
|
|
69
|
-
codeFrame?: string;
|
|
70
|
-
highlightedCodeFrame?: string;
|
|
71
|
-
loc?: {
|
|
72
|
-
column: number;
|
|
73
|
-
line: number;
|
|
74
|
-
} | null | undefined;
|
|
75
|
-
source?: string;
|
|
76
|
-
}
|
|
77
|
-
export type DiagnosticWithoutOrigin = Diagnostic & {
|
|
78
|
-
origin?: string;
|
|
79
|
-
};
|
|
80
|
-
/** Something that can be turned into a diagnostic. */
|
|
81
|
-
export type Diagnostifiable = Diagnostic | Array<Diagnostic> | ThrowableDiagnostic | PrintableError | Error | string;
|
|
82
|
-
/** Normalize the given value into a diagnostic. */
|
|
83
|
-
export declare function anyToDiagnostic(input: Diagnostifiable): Array<Diagnostic>;
|
|
84
|
-
/** Normalize the given error into a diagnostic. */
|
|
85
|
-
export declare function errorToDiagnostic(error: ThrowableDiagnostic | PrintableError | string, defaultValues?: {
|
|
86
|
-
origin?: string | null | undefined;
|
|
87
|
-
filePath?: string | null | undefined;
|
|
88
|
-
}): Array<Diagnostic>;
|
|
89
|
-
type ThrowableDiagnosticOpts = {
|
|
90
|
-
diagnostic: Diagnostic | Array<Diagnostic>;
|
|
91
|
-
};
|
|
92
|
-
/**
|
|
93
|
-
* An error wrapper around a diagnostic that can be <code>throw</code>n (e.g. to signal a
|
|
94
|
-
* build error).
|
|
95
|
-
*/
|
|
96
|
-
export default class ThrowableDiagnostic extends Error {
|
|
97
|
-
diagnostics: Array<Diagnostic>;
|
|
98
|
-
constructor(opts: ThrowableDiagnosticOpts);
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Turns a list of positions in a JSON5 file with messages into a list of diagnostics.
|
|
102
|
-
* Uses <a href="https://github.com/mischnic/json-sourcemap">@mischnic/json-sourcemap</a>.
|
|
103
|
-
*
|
|
104
|
-
* @param code the JSON code
|
|
105
|
-
* @param ids A list of JSON keypaths (<code>key: "/some/parent/child"</code>) with corresponding messages, \
|
|
106
|
-
* <code>type</code> signifies whether the key of the value in a JSON object should be highlighted.
|
|
107
|
-
*/
|
|
108
|
-
export declare function generateJSONCodeHighlights(data: string | {
|
|
109
|
-
data: unknown;
|
|
110
|
-
pointers: Record<string, Mapping>;
|
|
111
|
-
}, ids: Array<{
|
|
112
|
-
key: string;
|
|
113
|
-
type?: ("key" | null | undefined) | "value";
|
|
114
|
-
message?: string;
|
|
115
|
-
}>): Array<DiagnosticCodeHighlight>;
|
|
116
|
-
/**
|
|
117
|
-
* Converts entries in <a href="https://github.com/mischnic/json-sourcemap">@mischnic/json-sourcemap</a>'s
|
|
118
|
-
* <code>result.pointers</code> array.
|
|
119
|
-
*/
|
|
120
|
-
export declare function getJSONHighlightLocation(pos: Mapping, type?: ("key" | null | undefined) | "value"): {
|
|
121
|
-
start: DiagnosticHighlightLocation;
|
|
122
|
-
end: DiagnosticHighlightLocation;
|
|
123
|
-
};
|
|
124
|
-
/** Result is 1-based, but end is exclusive */
|
|
125
|
-
export declare function getJSONSourceLocation(pos: Mapping, type?: ("key" | null | undefined) | "value"): {
|
|
126
|
-
start: {
|
|
127
|
-
readonly line: number;
|
|
128
|
-
readonly column: number;
|
|
129
|
-
};
|
|
130
|
-
end: {
|
|
131
|
-
readonly line: number;
|
|
132
|
-
readonly column: number;
|
|
133
|
-
};
|
|
134
|
-
};
|
|
135
|
-
export declare function convertSourceLocationToHighlight<Location extends {
|
|
136
|
-
/** 1-based, inclusive */
|
|
137
|
-
readonly start: {
|
|
138
|
-
readonly line: number;
|
|
139
|
-
readonly column: number;
|
|
140
|
-
};
|
|
141
|
-
/** 1-based, exclusive */
|
|
142
|
-
readonly end: {
|
|
143
|
-
readonly line: number;
|
|
144
|
-
readonly column: number;
|
|
145
|
-
};
|
|
146
|
-
}>({ start, end }: Location, message?: string): DiagnosticCodeHighlight;
|
|
147
|
-
/** Sanitizes object keys before using them as <code>key</code> in generateJSONCodeHighlights */
|
|
148
|
-
export declare function encodeJSONKeyComponent(component: string): string;
|
|
149
|
-
export declare function escapeMarkdown(s: string): string;
|
|
150
|
-
type TemplateInput = any;
|
|
151
|
-
export declare function md(strings: Array<string>, ...params: Array<TemplateInput>): string;
|
|
152
|
-
export declare namespace md {
|
|
153
|
-
var bold: (s: TemplateInput) => TemplateInput;
|
|
154
|
-
var italic: (s: TemplateInput) => TemplateInput;
|
|
155
|
-
var underline: (s: TemplateInput) => TemplateInput;
|
|
156
|
-
var strikethrough: (s: TemplateInput) => TemplateInput;
|
|
157
|
-
}
|
|
158
|
-
export {};
|
package/lib/diagnostic.js
DELETED
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.anyToDiagnostic = anyToDiagnostic;
|
|
7
|
-
exports.convertSourceLocationToHighlight = convertSourceLocationToHighlight;
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
exports.encodeJSONKeyComponent = encodeJSONKeyComponent;
|
|
10
|
-
exports.errorToDiagnostic = errorToDiagnostic;
|
|
11
|
-
exports.escapeMarkdown = escapeMarkdown;
|
|
12
|
-
exports.generateJSONCodeHighlights = generateJSONCodeHighlights;
|
|
13
|
-
exports.getJSONHighlightLocation = getJSONHighlightLocation;
|
|
14
|
-
exports.getJSONSourceLocation = getJSONSourceLocation;
|
|
15
|
-
exports.md = md;
|
|
16
|
-
function _assert() {
|
|
17
|
-
const data = _interopRequireDefault(require("assert"));
|
|
18
|
-
_assert = function () {
|
|
19
|
-
return data;
|
|
20
|
-
};
|
|
21
|
-
return data;
|
|
22
|
-
}
|
|
23
|
-
function _nullthrows() {
|
|
24
|
-
const data = _interopRequireDefault(require("nullthrows"));
|
|
25
|
-
_nullthrows = function () {
|
|
26
|
-
return data;
|
|
27
|
-
};
|
|
28
|
-
return data;
|
|
29
|
-
}
|
|
30
|
-
function _jsonSourcemap() {
|
|
31
|
-
const data = require("@mischnic/json-sourcemap");
|
|
32
|
-
_jsonSourcemap = function () {
|
|
33
|
-
return data;
|
|
34
|
-
};
|
|
35
|
-
return data;
|
|
36
|
-
}
|
|
37
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
38
|
-
/** These positions are 1-based (so <code>1</code> is the first line/column) */
|
|
39
|
-
/**
|
|
40
|
-
* Note: A tab character is always counted as a single character
|
|
41
|
-
* This is to prevent any mismatch of highlighting across machines
|
|
42
|
-
*/
|
|
43
|
-
/**
|
|
44
|
-
* Describes how to format a code frame.
|
|
45
|
-
* A code frame is a visualization of a piece of code with a certain amount of
|
|
46
|
-
* code highlights that point to certain chunk(s) inside the code.
|
|
47
|
-
*/
|
|
48
|
-
/** A JSON object (as in "map") */
|
|
49
|
-
/**
|
|
50
|
-
* A style agnostic way of emitting errors, warnings and info.
|
|
51
|
-
* Reporters are responsible for rendering the message, codeframes, hints, ...
|
|
52
|
-
*/
|
|
53
|
-
// This type should represent all error formats Atlaspack can encounter...
|
|
54
|
-
/** Something that can be turned into a diagnostic. */
|
|
55
|
-
/** Normalize the given value into a diagnostic. */
|
|
56
|
-
function anyToDiagnostic(input) {
|
|
57
|
-
if (Array.isArray(input)) {
|
|
58
|
-
return input.flatMap(e => anyToDiagnostic(e));
|
|
59
|
-
} else if (input instanceof ThrowableDiagnostic) {
|
|
60
|
-
return input.diagnostics;
|
|
61
|
-
} else if (input instanceof Error) {
|
|
62
|
-
return errorToDiagnostic(input);
|
|
63
|
-
} else if (typeof input === 'string') {
|
|
64
|
-
return [{
|
|
65
|
-
message: input
|
|
66
|
-
}];
|
|
67
|
-
} else if (typeof input === 'object') {
|
|
68
|
-
return [input];
|
|
69
|
-
} else {
|
|
70
|
-
return errorToDiagnostic(input);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/** Normalize the given error into a diagnostic. */
|
|
75
|
-
function errorToDiagnostic(error, defaultValues) {
|
|
76
|
-
let codeFrames = undefined;
|
|
77
|
-
if (typeof error === 'string') {
|
|
78
|
-
return [{
|
|
79
|
-
origin: (defaultValues === null || defaultValues === void 0 ? void 0 : defaultValues.origin) ?? 'Error',
|
|
80
|
-
message: escapeMarkdown(error)
|
|
81
|
-
}];
|
|
82
|
-
}
|
|
83
|
-
if (error instanceof ThrowableDiagnostic) {
|
|
84
|
-
return error.diagnostics.map(d => {
|
|
85
|
-
return {
|
|
86
|
-
...d,
|
|
87
|
-
origin: d.origin ?? (defaultValues === null || defaultValues === void 0 ? void 0 : defaultValues.origin) ?? 'unknown'
|
|
88
|
-
};
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
if (error.loc && error.source != null) {
|
|
92
|
-
codeFrames = [{
|
|
93
|
-
filePath: error.filePath ?? error.fileName ?? (defaultValues === null || defaultValues === void 0 ? void 0 : defaultValues.filePath) ?? undefined,
|
|
94
|
-
code: error.source,
|
|
95
|
-
codeHighlights: [{
|
|
96
|
-
start: {
|
|
97
|
-
line: error.loc.line,
|
|
98
|
-
column: error.loc.column
|
|
99
|
-
},
|
|
100
|
-
end: {
|
|
101
|
-
line: error.loc.line,
|
|
102
|
-
column: error.loc.column
|
|
103
|
-
}
|
|
104
|
-
}]
|
|
105
|
-
}];
|
|
106
|
-
}
|
|
107
|
-
return [{
|
|
108
|
-
origin: (defaultValues === null || defaultValues === void 0 ? void 0 : defaultValues.origin) ?? 'Error',
|
|
109
|
-
message: escapeMarkdown(error.message),
|
|
110
|
-
name: error.name,
|
|
111
|
-
stack: codeFrames == null ? error.highlightedCodeFrame ?? error.codeFrame ?? error.stack : undefined,
|
|
112
|
-
codeFrames
|
|
113
|
-
}];
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* An error wrapper around a diagnostic that can be <code>throw</code>n (e.g. to signal a
|
|
117
|
-
* build error).
|
|
118
|
-
*/
|
|
119
|
-
class ThrowableDiagnostic extends Error {
|
|
120
|
-
constructor(opts) {
|
|
121
|
-
let diagnostics = Array.isArray(opts.diagnostic) ? opts.diagnostic : [opts.diagnostic];
|
|
122
|
-
|
|
123
|
-
// Construct error from diagnostics
|
|
124
|
-
super(diagnostics[0].message);
|
|
125
|
-
// @ts-ignore
|
|
126
|
-
this.stack = diagnostics[0].stack ?? super.stack;
|
|
127
|
-
// @ts-ignore
|
|
128
|
-
this.name = diagnostics[0].name ?? super.name;
|
|
129
|
-
this.diagnostics = diagnostics;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Turns a list of positions in a JSON5 file with messages into a list of diagnostics.
|
|
135
|
-
* Uses <a href="https://github.com/mischnic/json-sourcemap">@mischnic/json-sourcemap</a>.
|
|
136
|
-
*
|
|
137
|
-
* @param code the JSON code
|
|
138
|
-
* @param ids A list of JSON keypaths (<code>key: "/some/parent/child"</code>) with corresponding messages, \
|
|
139
|
-
* <code>type</code> signifies whether the key of the value in a JSON object should be highlighted.
|
|
140
|
-
*/
|
|
141
|
-
exports.default = ThrowableDiagnostic;
|
|
142
|
-
function generateJSONCodeHighlights(data, ids) {
|
|
143
|
-
let map = typeof data == 'string' ? (0, _jsonSourcemap().parse)(data, undefined, {
|
|
144
|
-
dialect: 'JSON5',
|
|
145
|
-
tabWidth: 1
|
|
146
|
-
}) : data;
|
|
147
|
-
return ids.map(({
|
|
148
|
-
key,
|
|
149
|
-
type,
|
|
150
|
-
message
|
|
151
|
-
}) => {
|
|
152
|
-
let pos = (0, _nullthrows().default)(map.pointers[key]);
|
|
153
|
-
return {
|
|
154
|
-
...getJSONHighlightLocation(pos, type),
|
|
155
|
-
message
|
|
156
|
-
};
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Converts entries in <a href="https://github.com/mischnic/json-sourcemap">@mischnic/json-sourcemap</a>'s
|
|
162
|
-
* <code>result.pointers</code> array.
|
|
163
|
-
*/
|
|
164
|
-
function getJSONHighlightLocation(pos, type) {
|
|
165
|
-
let key = 'key' in pos ? pos.key : undefined;
|
|
166
|
-
let keyEnd = 'keyEnd' in pos ? pos.keyEnd : undefined;
|
|
167
|
-
if (!type && key && pos.value) {
|
|
168
|
-
// key and value
|
|
169
|
-
return {
|
|
170
|
-
start: {
|
|
171
|
-
line: key.line + 1,
|
|
172
|
-
column: key.column + 1
|
|
173
|
-
},
|
|
174
|
-
end: {
|
|
175
|
-
line: pos.valueEnd.line + 1,
|
|
176
|
-
column: pos.valueEnd.column
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
} else if (type == 'key' || !pos.value) {
|
|
180
|
-
(0, _assert().default)(key && keyEnd);
|
|
181
|
-
return {
|
|
182
|
-
start: {
|
|
183
|
-
line: key.line + 1,
|
|
184
|
-
column: key.column + 1
|
|
185
|
-
},
|
|
186
|
-
end: {
|
|
187
|
-
line: keyEnd.line + 1,
|
|
188
|
-
column: keyEnd.column
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
} else {
|
|
192
|
-
return {
|
|
193
|
-
start: {
|
|
194
|
-
line: pos.value.line + 1,
|
|
195
|
-
column: pos.value.column + 1
|
|
196
|
-
},
|
|
197
|
-
end: {
|
|
198
|
-
line: pos.valueEnd.line + 1,
|
|
199
|
-
column: pos.valueEnd.column
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/** Result is 1-based, but end is exclusive */
|
|
206
|
-
function getJSONSourceLocation(pos, type) {
|
|
207
|
-
let v = getJSONHighlightLocation(pos, type);
|
|
208
|
-
return {
|
|
209
|
-
start: v.start,
|
|
210
|
-
end: {
|
|
211
|
-
line: v.end.line,
|
|
212
|
-
column: v.end.column + 1
|
|
213
|
-
}
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
function convertSourceLocationToHighlight({
|
|
217
|
-
start,
|
|
218
|
-
end
|
|
219
|
-
}, message) {
|
|
220
|
-
return {
|
|
221
|
-
message,
|
|
222
|
-
start,
|
|
223
|
-
end: {
|
|
224
|
-
line: end.line,
|
|
225
|
-
column: end.column - 1
|
|
226
|
-
}
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/** Sanitizes object keys before using them as <code>key</code> in generateJSONCodeHighlights */
|
|
231
|
-
function encodeJSONKeyComponent(component) {
|
|
232
|
-
return component.replace(/~/g, '~0').replace(/\//g, '~1');
|
|
233
|
-
}
|
|
234
|
-
const escapeCharacters = ['\\', '*', '_', '~'];
|
|
235
|
-
function escapeMarkdown(s) {
|
|
236
|
-
let result = s;
|
|
237
|
-
for (const char of escapeCharacters) {
|
|
238
|
-
result = result.replace(new RegExp(`\\${char}`, 'g'), `\\${char}`);
|
|
239
|
-
}
|
|
240
|
-
return result;
|
|
241
|
-
}
|
|
242
|
-
const mdVerbatim = Symbol();
|
|
243
|
-
function md(strings, ...params) {
|
|
244
|
-
let result = [];
|
|
245
|
-
for (let i = 0; i < params.length; i++) {
|
|
246
|
-
result.push(strings[i]);
|
|
247
|
-
let param = params[i];
|
|
248
|
-
if (Array.isArray(param)) {
|
|
249
|
-
for (let j = 0; j < param.length; j++) {
|
|
250
|
-
var _param$j;
|
|
251
|
-
result.push(((_param$j = param[j]) === null || _param$j === void 0 ? void 0 : _param$j[mdVerbatim]) ?? escapeMarkdown(`${param[j]}`));
|
|
252
|
-
if (j < param.length - 1) {
|
|
253
|
-
result.push(', ');
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
} else {
|
|
257
|
-
result.push((param === null || param === void 0 ? void 0 : param[mdVerbatim]) ?? escapeMarkdown(`${param}`));
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
return result.join('') + strings[strings.length - 1];
|
|
261
|
-
}
|
|
262
|
-
md.bold = function (s) {
|
|
263
|
-
// $FlowFixMe[invalid-computed-prop]
|
|
264
|
-
return {
|
|
265
|
-
[mdVerbatim]: '**' + escapeMarkdown(`${s}`) + '**'
|
|
266
|
-
};
|
|
267
|
-
};
|
|
268
|
-
md.italic = function (s) {
|
|
269
|
-
// $FlowFixMe[invalid-computed-prop]
|
|
270
|
-
return {
|
|
271
|
-
[mdVerbatim]: '_' + escapeMarkdown(`${s}`) + '_'
|
|
272
|
-
};
|
|
273
|
-
};
|
|
274
|
-
md.underline = function (s) {
|
|
275
|
-
// $FlowFixMe[invalid-computed-prop]
|
|
276
|
-
return {
|
|
277
|
-
[mdVerbatim]: '__' + escapeMarkdown(`${s}`) + '__'
|
|
278
|
-
};
|
|
279
|
-
};
|
|
280
|
-
md.strikethrough = function (s) {
|
|
281
|
-
// $FlowFixMe[invalid-computed-prop]
|
|
282
|
-
return {
|
|
283
|
-
[mdVerbatim]: '~~' + escapeMarkdown(`${s}`) + '~~'
|
|
284
|
-
};
|
|
285
|
-
};
|