@atlaspack/codeframe 2.13.3-canary.21 → 2.13.3-canary.211
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 +15 -0
- package/lib/codeframe.d.ts +16 -0
- package/lib/codeframe.js +227 -36037
- package/package.json +10 -8
- package/src/{codeframe.js → codeframe.ts} +22 -21
- package/test/{codeframe.test.js → codeframe.test.ts} +0 -1
- package/tsconfig.json +4 -0
- package/lib/codeframe.js.map +0 -1
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.211+12bee0e23",
|
|
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
|
},
|
|
@@ -24,12 +25,13 @@
|
|
|
24
25
|
}
|
|
25
26
|
},
|
|
26
27
|
"dependencies": {
|
|
27
|
-
"chalk": "^4.1.0"
|
|
28
|
-
},
|
|
29
|
-
"devDependencies": {
|
|
28
|
+
"chalk": "^4.1.0",
|
|
30
29
|
"emphasize": "^4.2.0",
|
|
31
30
|
"slice-ansi": "^4.0.0",
|
|
32
31
|
"string-width": "^4.2.0"
|
|
33
32
|
},
|
|
34
|
-
"
|
|
35
|
-
|
|
33
|
+
"scripts": {
|
|
34
|
+
"check-ts": "tsc --emitDeclarationOnly --rootDir src"
|
|
35
|
+
},
|
|
36
|
+
"gitHead": "12bee0e23f0464d7f6bd3e24fbe0d19c126d587d"
|
|
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