@parcel/utils 2.4.0 → 2.6.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcel/utils",
3
- "version": "2.4.0",
3
+ "version": "2.6.0",
4
4
  "description": "Blazing fast, zero configuration web application bundler",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -33,16 +33,15 @@
33
33
  }
34
34
  },
35
35
  "dependencies": {
36
- "@parcel/codeframe": "2.4.0",
37
- "@parcel/diagnostic": "2.4.0",
38
- "@parcel/hash": "2.4.0",
39
- "@parcel/logger": "2.4.0",
40
- "@parcel/markdown-ansi": "2.4.0",
36
+ "@parcel/codeframe": "2.6.0",
37
+ "@parcel/diagnostic": "2.6.0",
38
+ "@parcel/hash": "2.6.0",
39
+ "@parcel/logger": "2.6.0",
40
+ "@parcel/markdown-ansi": "2.6.0",
41
41
  "@parcel/source-map": "^2.0.0",
42
42
  "chalk": "^4.1.0"
43
43
  },
44
44
  "devDependencies": {
45
- "@babel/plugin-transform-flow-strip-types": "^7.2.0",
46
45
  "@iarna/toml": "^2.2.0",
47
46
  "ansi-html-community": "0.0.8",
48
47
  "clone": "^2.1.1",
@@ -64,5 +63,5 @@
64
63
  "./src/http-server.js": false,
65
64
  "./src/openInBrowser.js": false
66
65
  },
67
- "gitHead": "b1bbfdab2e902d33c0b6ff75bfba2d22283a8de6"
66
+ "gitHead": "f2d0a3a27d6e493b23ddc2edbc8a4c0053ff34ab"
68
67
  }
@@ -10,10 +10,18 @@ import nullthrows from 'nullthrows';
10
10
  // $FlowFixMe
11
11
  import terminalLink from 'terminal-link';
12
12
 
13
+ export type FormattedCodeFrame = {|
14
+ location: string,
15
+ code: string,
16
+ |};
17
+
13
18
  export type AnsiDiagnosticResult = {|
14
19
  message: string,
15
20
  stack: string,
21
+ /** A formatted string containing all code frames, including their file locations. */
16
22
  codeframe: string,
23
+ /** A list of code frames with highlighted code and file locations separately. */
24
+ frames: Array<FormattedCodeFrame>,
17
25
  hints: Array<string>,
18
26
  documentation: string,
19
27
  |};
@@ -39,6 +47,7 @@ export default async function prettyDiagnostic(
39
47
  (skipFormatting ? message : mdAnsi(message)),
40
48
  stack: '',
41
49
  codeframe: '',
50
+ frames: [],
42
51
  hints: [],
43
52
  documentation: '',
44
53
  };
@@ -69,16 +78,20 @@ export default async function prettyDiagnostic(
69
78
  });
70
79
  }
71
80
 
72
- result.codeframe +=
81
+ let location =
73
82
  typeof filePath !== 'string'
74
83
  ? ''
75
- : chalk.gray.underline(
76
- `${filePath}:${highlights[0].start.line}:${highlights[0].start.column}\n`,
77
- );
84
+ : `${filePath}:${highlights[0].start.line}:${highlights[0].start.column}`;
85
+ result.codeframe += location ? chalk.gray.underline(location) + '\n' : '';
78
86
  result.codeframe += formattedCodeFrame;
79
87
  if (codeFrame !== codeFrames[codeFrames.length - 1]) {
80
88
  result.codeframe += '\n\n';
81
89
  }
90
+
91
+ result.frames.push({
92
+ location,
93
+ code: formattedCodeFrame,
94
+ });
82
95
  }
83
96
  }
84
97
 
package/src/schema.js CHANGED
@@ -4,7 +4,7 @@ import ThrowableDiagnostic, {
4
4
  escapeMarkdown,
5
5
  encodeJSONKeyComponent,
6
6
  } from '@parcel/diagnostic';
7
- import type {Mapping} from 'json-source-map';
7
+ import type {Mapping} from '@mischnic/json-sourcemap';
8
8
  import nullthrows from 'nullthrows';
9
9
  // flowlint-next-line untyped-import:off
10
10
  import levenshtein from 'fastest-levenshtein';
@@ -406,7 +406,7 @@ validateSchema.diagnostic = function (
406
406
  !data
407
407
  ) {
408
408
  throw new Error(
409
- 'At least one of data.source and data.source must be defined!',
409
+ 'At least one of data.source and data.data must be defined!',
410
410
  );
411
411
  }
412
412
  let object = data.map