@atlaspack/codeframe 2.13.3-canary.206 → 2.13.3-canary.208
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.
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { DiagnosticCodeHighlight } from '@atlaspack/diagnostic';
|
|
2
|
+
type CodeFramePadding = {
|
|
3
|
+
before: number;
|
|
4
|
+
after: number;
|
|
5
|
+
};
|
|
6
|
+
type CodeFrameOptionsInput = Partial<CodeFrameOptions>;
|
|
7
|
+
type CodeFrameOptions = {
|
|
8
|
+
useColor: boolean;
|
|
9
|
+
syntaxHighlighting: boolean;
|
|
10
|
+
maxLines: number;
|
|
11
|
+
padding: CodeFramePadding;
|
|
12
|
+
terminalWidth: number;
|
|
13
|
+
language?: string;
|
|
14
|
+
};
|
|
15
|
+
export default function codeFrame(code: string, highlights: Array<DiagnosticCodeHighlight>, inputOpts?: CodeFrameOptionsInput): string;
|
|
16
|
+
export {};
|
package/lib/codeframe.js
CHANGED
|
@@ -33,6 +33,10 @@ function _sliceAnsi() {
|
|
|
33
33
|
return data;
|
|
34
34
|
}
|
|
35
35
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
36
|
+
// @ts-expect-error emphasize is not typed
|
|
37
|
+
|
|
38
|
+
// @ts-expect-error slice-ansi is not typed
|
|
39
|
+
|
|
36
40
|
const NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
|
|
37
41
|
const TAB_REPLACE_REGEX = /\t/g;
|
|
38
42
|
const TAB_REPLACEMENT = ' ';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/codeframe",
|
|
3
|
-
"version": "2.13.3-canary.
|
|
3
|
+
"version": "2.13.3-canary.208+43fdd2238",
|
|
4
4
|
"description": "Blazing fast, zero configuration web application bundler",
|
|
5
5
|
"license": "(MIT OR Apache-2.0)",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -11,8 +11,9 @@
|
|
|
11
11
|
"type": "git",
|
|
12
12
|
"url": "https://github.com/atlassian-labs/atlaspack.git"
|
|
13
13
|
},
|
|
14
|
-
"main": "lib/codeframe.js",
|
|
15
|
-
"source": "src/codeframe.
|
|
14
|
+
"main": "./lib/codeframe.js",
|
|
15
|
+
"source": "./src/codeframe.ts",
|
|
16
|
+
"types": "./lib/codeframe.d.ts",
|
|
16
17
|
"engines": {
|
|
17
18
|
"node": ">= 16.0.0"
|
|
18
19
|
},
|
|
@@ -29,5 +30,8 @@
|
|
|
29
30
|
"slice-ansi": "^4.0.0",
|
|
30
31
|
"string-width": "^4.2.0"
|
|
31
32
|
},
|
|
32
|
-
"
|
|
33
|
-
|
|
33
|
+
"scripts": {
|
|
34
|
+
"check-ts": "tsc --emitDeclarationOnly --rootDir src"
|
|
35
|
+
},
|
|
36
|
+
"gitHead": "43fdd223860fbc97af17d68c65419b97412cb888"
|
|
37
|
+
}
|
|
@@ -1,26 +1,27 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import type {DiagnosticCodeHighlight} from '@atlaspack/diagnostic';
|
|
3
2
|
|
|
4
3
|
import chalk from 'chalk';
|
|
4
|
+
// @ts-expect-error emphasize is not typed
|
|
5
5
|
import emphasize from 'emphasize';
|
|
6
6
|
import stringWidth from 'string-width';
|
|
7
|
+
// @ts-expect-error slice-ansi is not typed
|
|
7
8
|
import sliceAnsi from 'slice-ansi';
|
|
8
9
|
|
|
9
|
-
type CodeFramePadding = {
|
|
10
|
-
before: number
|
|
11
|
-
after: number
|
|
12
|
-
|
|
10
|
+
type CodeFramePadding = {
|
|
11
|
+
before: number;
|
|
12
|
+
after: number;
|
|
13
|
+
};
|
|
13
14
|
|
|
14
|
-
type CodeFrameOptionsInput =
|
|
15
|
+
type CodeFrameOptionsInput = Partial<CodeFrameOptions>;
|
|
15
16
|
|
|
16
|
-
type CodeFrameOptions = {
|
|
17
|
-
useColor: boolean
|
|
18
|
-
syntaxHighlighting: boolean
|
|
19
|
-
maxLines: number
|
|
20
|
-
padding: CodeFramePadding
|
|
21
|
-
terminalWidth: number
|
|
22
|
-
language?: string
|
|
23
|
-
|
|
17
|
+
type CodeFrameOptions = {
|
|
18
|
+
useColor: boolean;
|
|
19
|
+
syntaxHighlighting: boolean;
|
|
20
|
+
maxLines: number;
|
|
21
|
+
padding: CodeFramePadding;
|
|
22
|
+
terminalWidth: number;
|
|
23
|
+
language?: string;
|
|
24
|
+
};
|
|
24
25
|
|
|
25
26
|
const NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
|
|
26
27
|
const TAB_REPLACE_REGEX = /\t/g;
|
|
@@ -31,7 +32,7 @@ const highlightSyntax = (txt: string, lang?: string): string => {
|
|
|
31
32
|
if (lang) {
|
|
32
33
|
try {
|
|
33
34
|
return emphasize.highlight(lang, txt).value;
|
|
34
|
-
} catch (e) {
|
|
35
|
+
} catch (e: any) {
|
|
35
36
|
// fallback for unknown languages...
|
|
36
37
|
}
|
|
37
38
|
}
|
|
@@ -69,11 +70,11 @@ export default function codeFrame(
|
|
|
69
70
|
};
|
|
70
71
|
|
|
71
72
|
// Prefix lines with the line number
|
|
72
|
-
const lineNumberPrefixer = (params: {
|
|
73
|
-
lineNumber?: string
|
|
74
|
-
lineNumberLength: number
|
|
75
|
-
isHighlighted: boolean
|
|
76
|
-
|
|
73
|
+
const lineNumberPrefixer = (params: {
|
|
74
|
+
lineNumber?: string;
|
|
75
|
+
lineNumberLength: number;
|
|
76
|
+
isHighlighted: boolean;
|
|
77
|
+
}) => {
|
|
77
78
|
let {lineNumber, lineNumberLength, isHighlighted} = params;
|
|
78
79
|
|
|
79
80
|
return `${isHighlighted ? highlighter('>') : ' '} ${
|
|
@@ -136,7 +137,7 @@ export default function codeFrame(
|
|
|
136
137
|
.split(NEWLINE);
|
|
137
138
|
|
|
138
139
|
// Loop over all lines and create codeframe
|
|
139
|
-
let resultLines = [];
|
|
140
|
+
let resultLines: Array<string> = [];
|
|
140
141
|
for (
|
|
141
142
|
let currentLineIndex = startLine;
|
|
142
143
|
currentLineIndex < syntaxHighlightedLines.length;
|
package/tsconfig.json
ADDED