@visulima/error 1.1.0 → 2.0.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 +25 -0
- package/README.md +1 -1
- package/dist/chunk-5DWOFJMB.js +10 -0
- package/dist/chunk-5DWOFJMB.js.map +1 -0
- package/dist/code-frame/index.d.ts +6 -0
- package/dist/code-frame/index.js +4 -0
- package/dist/code-frame/index.js.map +1 -0
- package/dist/error.d.ts +2 -2
- package/dist/index.d.ts +2 -11
- package/dist/index.js +1 -11
- package/dist/index.js.map +1 -1
- package/dist/stacktrace.d.ts +1 -1
- package/dist/{types-e15294e6.d.ts → types-4e2de6f5.d.ts} +18 -2
- package/package.json +10 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
+
## @visulima/error [2.0.0](https://github.com/visulima/visulima/compare/@visulima/error@1.1.1...@visulima/error@2.0.0) (2023-12-04)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### ⚠ BREAKING CHANGES
|
|
5
|
+
|
|
6
|
+
* removed positionAt, changed public interface of code-frame
|
|
7
|
+
Signed-off-by: prisis <d.bannert@anolilab.de>
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* changed public interface of code-frame, added multiline marker ([d9d60c0](https://github.com/visulima/visulima/commit/d9d60c06029f7564bc956a027d040331eddd0443))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
* fixed wrong export ([b3689cd](https://github.com/visulima/visulima/commit/b3689cd5f5479cf934d8d892ff7071feedd3b9ae))
|
|
17
|
+
|
|
18
|
+
## @visulima/error [1.1.1](https://github.com/visulima/visulima/compare/@visulima/error@1.1.0...@visulima/error@1.1.1) (2023-11-30)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Dependencies
|
|
23
|
+
|
|
24
|
+
* **@visulima/nextra-theme-docs:** upgraded to 4.0.10
|
|
25
|
+
|
|
1
26
|
## @visulima/error [1.1.0](https://github.com/visulima/visulima/compare/@visulima/error@1.0.2...@visulima/error@1.1.0) (2023-11-30)
|
|
2
27
|
|
|
3
28
|
|
package/README.md
CHANGED
|
@@ -74,7 +74,7 @@ import { codeFrame } from "@visulima/error";
|
|
|
74
74
|
const source = "const x = 10;\nconst error = x.y;\n";
|
|
75
75
|
const loc = { column: 16, line: 2 };
|
|
76
76
|
|
|
77
|
-
const frame = codeFrame(source, loc);
|
|
77
|
+
const frame = codeFrame(source, { start: loc });
|
|
78
78
|
|
|
79
79
|
console.log(frame);
|
|
80
80
|
// 1 | const x = 10;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
var A=s=>s.replaceAll(/\r\n|\r(?!\n)|\n/gu,`
|
|
2
|
+
`),x=A;var O=globalThis.process||Object.create(null),$={versions:{}},v=new Proxy(O,{get(s,r){if(r in s)return s[r];if(r in $)return $[r]}}),F=v;var S=(s,r,L,o)=>{let d={column:0,line:-1,...s.start},g={...d,...s.end},i=d.line,t=d.column,l=g.line,m=g.column,u=Math.max(i-(L+1),0),f=Math.min(r.length,l+o);i===-1&&(u=0),l===-1&&(f=r.length);let p=l-i,n={};if(p)for(let e=0;e<=p;e++){let a=e+i;if(!t)n[a]=!0;else if(e===0){let c=r[a-1]?.length;n[a]=[t,(c??0)-t+1];}else if(e===p)n[a]=[0,m];else {let c=r[a-e]?.length;n[a]=[0,c];}}else t===m?n[i]=t?[t,0]:!0:n[i]=[t,(m??0)-(t??0)];return {end:f,markerLines:n,start:u}},y=S;var j=F.platform==="win32"&&!F.env?.WT_SESSION?">":"\u276F",q=(s,r,L={})=>{let o={color:{gutter:e=>e,marker:e=>e,message:e=>e,...L.color},linesAbove:2,linesBelow:3,showGutter:!0,showLineNumbers:!0,...L},d=r.start&&typeof r.start.column=="number",g=x(s).split(`
|
|
3
|
+
`).map(e=>e.replaceAll(" "," ")),{end:i,markerLines:t,start:l}=y(r,g,o.linesAbove,o.linesBelow),m=String(i).length,{gutter:u,marker:f,message:p}=o.color,n=g.slice(l,i).map((e,a)=>{let c=l+1+a,h=t[c],z=` ${c}`.slice(-m),N=!t[c+1],b=` ${z}${o.showGutter?" |":""}`;if(h){let k="";if(Array.isArray(h)){let P=e.replaceAll(/[^\t]/g," ").slice(0,Math.max(h[0]-1,0)),w=h[1]||1;k=[`
|
|
4
|
+
`,u(b.replaceAll(/\d/g," "))," ",P,f("^").repeat(w)].join(""),N&&o.message&&(k+=` ${p(o.message)}`);}return [f(j),u(b),e.length>0?` ${e}`:"",k].join("")}return ` ${u(b)}${e.length>0?` ${e}`:""}`}).join(`
|
|
5
|
+
`);return o.message&&!d&&(n=`${" ".repeat(m+1)}${o.message}
|
|
6
|
+
${n}`),n};
|
|
7
|
+
|
|
8
|
+
export { q as a };
|
|
9
|
+
//# sourceMappingURL=out.js.map
|
|
10
|
+
//# sourceMappingURL=chunk-5DWOFJMB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/util/normalize-lf.ts","../src/util/process.ts","../src/code-frame/get-marker-lines.ts","../src/code-frame/index.ts"],"names":["normalizeLF","code","normalize_lf_default","_process","processShims","process","target","property","process_default","getMarkerLines","loc","source","linesAbove","linesBelow","startLoc","endLoc","startLine","startColumn","endLine","endColumn","start","end","lineDiff","markerLines","index","lineNumber","sourceLength","get_marker_lines_default","POINTER","codeFrame","options","config","value","hasColumns","lines","ln","numberMaxWidth","colorizeGutter","colorizeMarker","colorizeMessage","frame","line","number","hasMarker","paddedNumber","lastMarkerLine","gutter","markerLine","markerSpacing","numberOfMarkers"],"mappings":"AAAA,IAAMA,EAAeC,GAAyBA,EAAK,WAAW,qBAAsB;AAAA,CAAI,EAEjFC,EAAQF,ECGf,IAAMG,EAAY,WAAW,SAAW,OAAO,OAAO,IAAI,EAEpDC,EAAiC,CACnC,SAAU,CAAC,CACf,EAEMC,EAAU,IAAI,MAAeF,EAAU,CACzC,IAAIG,E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AU,CAAC,GAAK,EAExCI,EAAa,CAAC;AAAA,GAAOV,EAAeS,EAAO,WAAW,MAAO,GAAG,CAAC,EAAG,IAAKE,EAAeV,EAAe,GAAG,EAAE,OAAOW,CAAe,CAAC,EAAE,KACjI,EACJ,EAEIJ,GAAkBd,EAAO,UACzBgB,GAAc,IAAIR,EAAgBR,EAAO,OAAO,CAAC,GAEzD,CAEA,MAAO,CAACO,EAAeV,CAAO,EAAGS,EAAeS,CAAM,EAAGL,EAAK,OAAS,EAAI,IAAIA,CAAI,GAAK,GAAIM,CAAU,EAAE,KAAK,EAAE,CACnH,CAEA,MAAO,IAAIV,EAAeS,CAAM,CAAC,GAAGL,EAAK,OAAS,EAAI,IAAIA,CAAI,GAAK,EAAE,EACzE,CAAC,EACA,KAAK;AAAA,CAAI,EAEd,OAAIV,EAAO,SAAW,CAACE,IACnBO,EAAQ,GAAG,IAAI,OAAOJ,EAAiB,CAAC,CAAC,GAAGL,EAAO,OAAO;AAAA,EAAKS,CAAK,IAGjEA,CACX","sourcesContent":["const normalizeLF = (code: string): string => code.replaceAll(/\\r\\n|\\r(?!\\n)|\\n/gu, \"\\n\");\n\nexport default normalizeLF;\n","interface Process extends Partial<Omit<typeof globalThis.process, \"versions\">> {\n versions: Record<string, string>;\n}\n\n// eslint-disable-next-line @typescript-eslint/naming-convention,@typescript-eslint/no-unnecessary-condition,no-underscore-dangle\nconst _process = (globalThis.process || Object.create(null)) as unknown as Process;\n\nconst processShims: Partial<Process> = {\n versions: {},\n};\n\nconst process = new Proxy<Process>(_process, {\n get(target, property: keyof Process) {\n if (property in target) {\n // eslint-disable-next-line security/detect-object-injection\n return target[property];\n }\n\n if (property in processShims) {\n // eslint-disable-next-line security/detect-object-injection\n return processShims[property];\n }\n\n return undefined;\n },\n});\n\nexport default process;\n","// eslint-disable-next-line no-secrets/no-secrets\n/**\n * This is a copy of the codeFrame function from Babel\n * @see https://github.com/babel/babel/blob/85e649203b61b7c908eb04c05511a0d35f893e8e/packages/babel-code-frame/src/index.ts#L68-L143\n *\n * MIT License\n *\n * Copyright (c) 2014-present Sebastian McKenzie and other contributors\n */\n\n/**\n * Extract what lines should be marked and highlighted.\n */\nimport type { CodeFrameLocation, CodeFrameNodeLocation } from \"../types\";\n\ntype MarkerLines = Record<number, true | [number | undefined, number | undefined]>;\n\nconst getMarkerLines = (\n loc: CodeFrameNodeLocation,\n source: string[],\n linesAbove: number,\n linesBelow: number,\n): {\n end: number;\n markerLines: MarkerLines;\n start: number;\n // eslint-disable-next-line sonarjs/cognitive-complexity\n} => {\n const startLoc: CodeFrameLocation = {\n column: 0,\n // @ts-expect-error Can be overwritten\n line: -1,\n ...loc.start,\n };\n const endLoc: CodeFrameLocation = {\n ...startLoc,\n ...loc.end,\n };\n const startLine = startLoc.line;\n const startColumn = startLoc.column;\n const endLine = endLoc.line;\n const endColumn = endLoc.column;\n\n let start = Math.max(startLine - (linesAbove + 1), 0);\n let end = Math.min(source.length, endLine + linesBelow);\n\n if (startLine === -1) {\n start = 0;\n }\n\n if (endLine === -1) {\n end = source.length;\n }\n\n const lineDiff = endLine - startLine;\n const markerLines: MarkerLines = {};\n\n if (lineDiff) {\n // eslint-disable-next-line no-plusplus,no-loops/no-loops\n for (let index = 0; index <= lineDiff; index++) {\n const lineNumber = index + startLine;\n\n if (!startColumn) {\n // eslint-disable-next-line security/detect-object-injection\n markerLines[lineNumber] = true;\n } else if (index === 0) {\n const sourceLength = source[lineNumber - 1]?.length;\n\n // eslint-disable-next-line security/detect-object-injection\n markerLines[lineNumber] = [startColumn, (sourceLength ?? 0) - startColumn + 1];\n } else if (index === lineDiff) {\n // eslint-disable-next-line security/detect-object-injection\n markerLines[lineNumber] = [0, endColumn];\n } else {\n const sourceLength = source[lineNumber - index]?.length;\n\n // eslint-disable-next-line security/detect-object-injection\n markerLines[lineNumber] = [0, sourceLength];\n }\n }\n } else if (startColumn === endColumn) {\n // eslint-disable-next-line security/detect-object-injection\n markerLines[startLine] = startColumn ? [startColumn, 0] : true;\n } else {\n // eslint-disable-next-line security/detect-object-injection\n markerLines[startLine] = [startColumn, (endColumn ?? 0) - (startColumn ?? 0)];\n }\n\n return { end, markerLines, start };\n};\n\nexport default getMarkerLines;\n","// eslint-disable-next-line no-secrets/no-secrets\n/**\n * This is a modified copy of the codeFrameColumns function from Babel\n * @see https://github.com/babel/babel/blob/85e649203b61b7c908eb04c05511a0d35f893e8e/packages/babel-code-frame/src/index.ts#L145-L217\n *\n * MIT License\n *\n * Copyright (c) 2014-present Sebastian McKenzie and other contributors\n */\n\nimport type { CodeFrameNodeLocation, CodeFrameOptions, ColorizeMethod } from \"../types\";\nimport normalizeLF from \"../util/normalize-lf\";\nimport process from \"../util/process\";\nimport getMarkerLines from \"./get-marker-lines\";\n\nconst POINTER = process.platform === \"win32\" && !process.env?.[\"WT_SESSION\"] ? \">\" : \"❯\";\n\n/** Generate a code frame from string and an error location */\nexport const codeFrame = (\n source: string,\n loc: CodeFrameNodeLocation,\n options: Partial<CodeFrameOptions> = {},\n // eslint-disable-next-line sonarjs/cognitive-complexity\n): string => {\n // grab 2 lines before, and 3 lines after focused line\n const config = {\n color: {\n gutter: (value: string) => value,\n marker: (value: string) => value,\n message: (value: string) => value,\n ...options.color,\n },\n linesAbove: 2,\n linesBelow: 3,\n showGutter: true,\n showLineNumbers: true,\n ...options,\n };\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const hasColumns = loc.start && typeof loc.start.column === \"number\";\n\n const lines = normalizeLF(source)\n .split(\"\\n\")\n .map((ln) => ln.replaceAll(\"\\t\", \" \"));\n\n const { end, markerLines, start } = getMarkerLines(loc, lines, config.linesAbove, config.linesBelow);\n\n const numberMaxWidth = String(end).length;\n\n const {\n gutter: colorizeGutter,\n marker: colorizeMarker,\n message: colorizeMessage,\n } = config.color as {\n gutter: ColorizeMethod;\n marker: ColorizeMethod;\n message: ColorizeMethod;\n };\n\n let frame = lines\n .slice(start, end)\n .map((line, index) => {\n const number = start + 1 + index;\n // eslint-disable-next-line security/detect-object-injection\n const hasMarker = markerLines[number];\n const paddedNumber = ` ${number}`.slice(-numberMaxWidth);\n const lastMarkerLine = !markerLines[number + 1];\n\n const gutter = ` ${paddedNumber}${config.showGutter ? ` |` : \"\"}`;\n\n if (hasMarker) {\n let markerLine = \"\";\n\n if (Array.isArray(hasMarker)) {\n const markerSpacing = line.replaceAll(/[^\\t]/g, \" \").slice(0, Math.max((hasMarker[0] as number) - 1, 0));\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n const numberOfMarkers = hasMarker[1] || 1;\n\n markerLine = [\"\\n \", colorizeGutter(gutter.replaceAll(/\\d/g, \" \")), \" \", markerSpacing, colorizeMarker(\"^\").repeat(numberOfMarkers)].join(\n \"\",\n );\n\n if (lastMarkerLine && config.message) {\n markerLine += ` ${colorizeMessage(config.message)}`;\n }\n }\n\n return [colorizeMarker(POINTER), colorizeGutter(gutter), line.length > 0 ? ` ${line}` : \"\", markerLine].join(\"\");\n }\n\n return ` ${colorizeGutter(gutter)}${line.length > 0 ? ` ${line}` : \"\"}`;\n })\n .join(\"\\n\");\n\n if (config.message && !hasColumns) {\n frame = `${\" \".repeat(numberMaxWidth + 1)}${config.message}\\n${frame}`;\n }\n\n return frame;\n};\n\nexport type { CodeFrameNodeLocation, CodeFrameOptions, ColorizeMethod } from \"../types\";\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { C as CodeFrameNodeLocation, a as CodeFrameOptions } from '../types-4e2de6f5.js';
|
|
2
|
+
export { b as ColorizeMethod } from '../types-4e2de6f5.js';
|
|
3
|
+
|
|
4
|
+
declare const codeFrame: (source: string, loc: CodeFrameNodeLocation, options?: Partial<CodeFrameOptions>) => string;
|
|
5
|
+
|
|
6
|
+
export { CodeFrameNodeLocation, CodeFrameOptions, codeFrame };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
package/dist/error.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { E as ErrorLocation,
|
|
2
|
-
export {
|
|
1
|
+
import { E as ErrorLocation, c as ErrorProperties } from './types-4e2de6f5.js';
|
|
2
|
+
export { d as ErrorWithMetadata, T as Trace } from './types-4e2de6f5.js';
|
|
3
3
|
|
|
4
4
|
declare const isVisulimaError: (error: unknown) => error is VisulimaError;
|
|
5
5
|
declare class VisulimaError extends Error {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
export { a as
|
|
1
|
+
export { codeFrame } from './code-frame/index.js';
|
|
2
|
+
export { C as CodeFrameNodeLocation, a as CodeFrameOptions, b as ColorizeMethod, E as ErrorLocation, c as ErrorProperties, d as ErrorWithMetadata, T as Trace } from './types-4e2de6f5.js';
|
|
3
3
|
export { VisulimaError, isVisulimaError } from './error.js';
|
|
4
4
|
export { loadSourceMap } from './sourcemap.js';
|
|
5
5
|
export { TraceMap, generatedPositionFor, originalPositionFor, sourceContentFor, traceSegment } from '@jridgewell/trace-mapping';
|
|
6
6
|
export { parseStacktrace } from './stacktrace.js';
|
|
7
|
-
|
|
8
|
-
declare const codeFrame: (source: string, loc: ErrorLocation, options?: CodeFrameOptions) => string;
|
|
9
|
-
|
|
10
|
-
declare const positionAt: (offset: number, text: string) => {
|
|
11
|
-
column: number;
|
|
12
|
-
line: number;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export { CodeFrameOptions, ErrorLocation, codeFrame, positionAt };
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,7 @@
|
|
|
1
|
+
export { a as codeFrame } from './chunk-5DWOFJMB.js';
|
|
1
2
|
export { b as VisulimaError, a as isVisulimaError } from './chunk-X3TE67TZ.js';
|
|
2
3
|
export { a as parseStacktrace } from './chunk-26F4MLO2.js';
|
|
3
4
|
export { b as generatedPositionFor, a as loadSourceMap, c as originalPositionFor, d as sourceContentFor, e as traceSegment } from './chunk-F52HEHA7.js';
|
|
4
5
|
import './chunk-7Q3PPTBP.js';
|
|
5
|
-
import { platform, env } from 'process';
|
|
6
|
-
|
|
7
|
-
var O=r=>{let o=[],i=!0;for(let e=0;e<r.length;e++){i&&(o.push(e),i=!1);let t=r.charAt(e);i=t==="\r"||t===`
|
|
8
|
-
`,t==="\r"&&e+1<r.length&&r.charAt(e+1)===`
|
|
9
|
-
`&&e++;}return i&&r.length>0&&o.push(r.length),o},f=r=>r.replaceAll(/\r\n|\r(?!\n)|\n/gu,`
|
|
10
|
-
`),S=(r,o)=>{let i=O(o);r=Math.max(0,Math.min(o.length,r));let e=0,t=i.length;if(t===0)return {column:r,line:0};for(;e<=t;){let s=Math.floor((e+t)/2),m=i[s];if(m===r)return {column:0,line:s};r>m?e=s+1:t=s-1;}let a=e-1;return {column:r-i[a],line:a}};var h=platform==="win32"&&!env.WT_SESSION?">":"\u276F",y=(r,o,i)=>{if(o.line===void 0||o.column===void 0)return "";let e={focusLineColor:n=>n,linesAbove:2,linesBelow:3,...i},t=f(r).split(`
|
|
11
|
-
`).map(n=>n.replaceAll(" "," ")),a=[];for(let n=-(e.linesAbove+1);n<=e.linesBelow;n++)t[o.line+n]&&a.push(o.line+n);let s=0;a.forEach(n=>{let l=`${h} ${n}${n<9?" ":""}`;l.length>s&&(s=l.length);});let m="";return a.forEach(n=>{let l="",c=n===o.line-1;l+=c?`${h} `:" ",l+=`${n<9?" ":""}${n+1} | ${t[n]}
|
|
12
|
-
`,c&&(l+=`${Array.from({length:s}).join(" ")} | ${Array.from({length:o.column}).join(" ")}^`),m+=c?`${e.focusLineColor(l)}
|
|
13
|
-
`:l;}),m},C=y;
|
|
14
|
-
|
|
15
|
-
export { C as codeFrame, S as positionAt };
|
|
16
6
|
//# sourceMappingURL=out.js.map
|
|
17
7
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
package/dist/stacktrace.d.ts
CHANGED
|
@@ -29,10 +29,26 @@ interface ErrorWithMetadata<Type = NonNullable<unknown> & string> {
|
|
|
29
29
|
title?: string;
|
|
30
30
|
type?: Type | "VisulimaError";
|
|
31
31
|
}
|
|
32
|
+
type CodeFrameLocation = {
|
|
33
|
+
column?: number;
|
|
34
|
+
line: number;
|
|
35
|
+
};
|
|
36
|
+
type CodeFrameNodeLocation = {
|
|
37
|
+
end?: CodeFrameLocation;
|
|
38
|
+
start: CodeFrameLocation;
|
|
39
|
+
};
|
|
40
|
+
type ColorizeMethod = (value: string) => string;
|
|
32
41
|
type CodeFrameOptions = {
|
|
33
|
-
|
|
42
|
+
color?: Partial<{
|
|
43
|
+
gutter: ColorizeMethod;
|
|
44
|
+
marker: ColorizeMethod;
|
|
45
|
+
message: ColorizeMethod;
|
|
46
|
+
}>;
|
|
34
47
|
linesAbove?: number;
|
|
35
48
|
linesBelow?: number;
|
|
49
|
+
message?: string;
|
|
50
|
+
showGutter?: boolean;
|
|
51
|
+
showLineNumbers?: boolean;
|
|
36
52
|
};
|
|
37
53
|
type TraceType = "eval" | "internal" | "native" | undefined;
|
|
38
54
|
interface Trace {
|
|
@@ -45,4 +61,4 @@ interface Trace {
|
|
|
45
61
|
type?: TraceType | undefined;
|
|
46
62
|
}
|
|
47
63
|
|
|
48
|
-
export {
|
|
64
|
+
export { CodeFrameNodeLocation as C, ErrorLocation as E, Trace as T, CodeFrameOptions as a, ColorizeMethod as b, ErrorProperties as c, ErrorWithMetadata as d };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visulima/error",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Error with more than just a message, stacktrace parsing and sourcemap loading.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"visulima",
|
|
@@ -47,6 +47,12 @@
|
|
|
47
47
|
"default": "./dist/index.js"
|
|
48
48
|
}
|
|
49
49
|
},
|
|
50
|
+
"./code-frame": {
|
|
51
|
+
"import": {
|
|
52
|
+
"types": "./dist/code-frame/index.d.ts",
|
|
53
|
+
"default": "./dist/code-frame/index.js"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
50
56
|
"./error": {
|
|
51
57
|
"import": {
|
|
52
58
|
"types": "./dist/error.d.ts",
|
|
@@ -106,11 +112,10 @@
|
|
|
106
112
|
"@total-typescript/ts-reset": "^0.5.1",
|
|
107
113
|
"@types/command-line-args": "^5.2.3",
|
|
108
114
|
"@types/node": "18.18.5",
|
|
109
|
-
"@visulima/nextra-theme-docs": "4.0.
|
|
115
|
+
"@visulima/nextra-theme-docs": "4.0.10",
|
|
110
116
|
"@vitest/coverage-v8": "^0.34.6",
|
|
111
|
-
"chalk": "^5.3.0",
|
|
112
117
|
"cross-env": "^7.0.3",
|
|
113
|
-
"eslint": "^8.
|
|
118
|
+
"eslint": "^8.55.0",
|
|
114
119
|
"eslint-plugin-deprecation": "^2.0.0",
|
|
115
120
|
"eslint-plugin-import": "npm:eslint-plugin-i@^2.29.0",
|
|
116
121
|
"eslint-plugin-mdx": "^2.2.0",
|
|
@@ -146,6 +151,7 @@
|
|
|
146
151
|
},
|
|
147
152
|
"sources": [
|
|
148
153
|
"src/index.ts",
|
|
154
|
+
"src/code-frame/index.ts",
|
|
149
155
|
"src/error.ts",
|
|
150
156
|
"src/stacktrace.ts",
|
|
151
157
|
"src/sourcemap.ts"
|