@cspell/cspell-json-reporter 6.28.0 → 6.29.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.
@@ -1,4 +1,4 @@
1
1
  import type { CSpellReporter, ReporterConfiguration } from '@cspell/cspell-types';
2
- import type { CSpellJSONReporterSettings } from './CSpellJSONReporterSettings';
2
+ import type { CSpellJSONReporterSettings } from './CSpellJSONReporterSettings.js';
3
3
  export declare function getReporter(settings: unknown | CSpellJSONReporterSettings, cliOptions?: ReporterConfiguration): Required<CSpellReporter>;
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -27,8 +27,8 @@ exports.getReporter = void 0;
27
27
  const cspell_types_1 = require("@cspell/cspell-types");
28
28
  const fs_1 = require("fs");
29
29
  const path = __importStar(require("path"));
30
- const setToJSONReplacer_1 = require("./utils/setToJSONReplacer");
31
- const validateSettings_1 = require("./utils/validateSettings");
30
+ const setToJSONReplacer_js_1 = require("./utils/setToJSONReplacer.js");
31
+ const validateSettings_js_1 = require("./utils/validateSettings.js");
32
32
  function mkdirp(p) {
33
33
  return fs_1.promises.mkdir(p, { recursive: true });
34
34
  }
@@ -70,7 +70,7 @@ function getReporter(settings, cliOptions) {
70
70
  ...reportData,
71
71
  result,
72
72
  };
73
- const jsonData = JSON.stringify(output, setToJSONReplacer_1.setToJSONReplacer, 4);
73
+ const jsonData = JSON.stringify(output, setToJSONReplacer_js_1.setToJSONReplacer, 4);
74
74
  if (outFile === STDOUT) {
75
75
  console.log(jsonData);
76
76
  return;
@@ -89,7 +89,7 @@ exports.getReporter = getReporter;
89
89
  function normalizeSettings(settings) {
90
90
  if (settings === undefined)
91
91
  return { outFile: STDOUT };
92
- (0, validateSettings_1.validateSettings)(settings);
92
+ (0, validateSettings_js_1.validateSettings)(settings);
93
93
  return settings;
94
94
  }
95
95
  function push(src, value) {
@@ -1,4 +1,4 @@
1
- import type { CSpellJSONReporterSettings } from '../CSpellJSONReporterSettings';
1
+ import type { CSpellJSONReporterSettings } from '../CSpellJSONReporterSettings.js';
2
2
  /**
3
3
  * Throws an error if passed cspell-json-reporter settings are invalid
4
4
  */
@@ -0,0 +1,36 @@
1
+ import type { ErrorLike, Issue, MessageType, ProgressFileComplete, ProgressItem, RunResult } from '@cspell/cspell-types';
2
+ export type CSpellJSONReporterOutput = {
3
+ /**
4
+ * Found spelling issues
5
+ */
6
+ issues: Array<Issue>;
7
+ /**
8
+ * CSpell execution logs
9
+ */
10
+ info?: Array<{
11
+ message: string;
12
+ msgType: MessageType;
13
+ }>;
14
+ /**
15
+ * CSpell debug logs
16
+ */
17
+ debug?: Array<{
18
+ message: string;
19
+ }>;
20
+ /**
21
+ * CSpell error logs
22
+ */
23
+ error?: Array<{
24
+ message: string;
25
+ error: ErrorLike;
26
+ }>;
27
+ /**
28
+ * CSpell file progress logs
29
+ */
30
+ progress?: Array<ProgressItem | ProgressFileComplete>;
31
+ /**
32
+ * Execution result
33
+ */
34
+ result: RunResult;
35
+ };
36
+ //# sourceMappingURL=CSpellJSONReporterOutput.d.mts.map
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,33 @@
1
+ /**
2
+ * CSpell-json-reporter settings type definition
3
+ */
4
+ export type CSpellJSONReporterSettings = {
5
+ /**
6
+ * Path to the output file.
7
+ *
8
+ * Relative paths are relative to the current working directory.
9
+ *
10
+ * Special values:
11
+ * - `stdout` - write the JSON to `stdout`.
12
+ * - `stderr` - write the JSON to `stderr`.
13
+ *
14
+ * @default stdout
15
+ */
16
+ outFile?: string;
17
+ /**
18
+ * Add more information about the files being checked and the configuration
19
+ * @default false
20
+ */
21
+ verbose?: boolean;
22
+ /**
23
+ * Add information useful for debugging cspell.json files
24
+ * @default false
25
+ */
26
+ debug?: boolean;
27
+ /**
28
+ * Add progress messages
29
+ * @default false
30
+ */
31
+ progress?: boolean;
32
+ };
33
+ //# sourceMappingURL=CSpellJSONReporterSettings.d.mts.map
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ import type { CSpellReporter, ReporterConfiguration } from '@cspell/cspell-types';
2
+ import type { CSpellJSONReporterSettings } from './CSpellJSONReporterSettings.mjs';
3
+ export declare function getReporter(settings: unknown | CSpellJSONReporterSettings, cliOptions?: ReporterConfiguration): Required<CSpellReporter>;
4
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1,74 @@
1
+ import { MessageTypes } from '@cspell/cspell-types';
2
+ import { promises as fs } from 'fs';
3
+ import * as path from 'path';
4
+ import { setToJSONReplacer } from './utils/setToJSONReplacer.mjs';
5
+ import { validateSettings } from './utils/validateSettings.mjs';
6
+ function mkdirp(p) {
7
+ return fs.mkdir(p, { recursive: true });
8
+ }
9
+ const noopReporter = () => undefined;
10
+ const STDOUT = 'stdout';
11
+ const STDERR = 'stderr';
12
+ export function getReporter(settings, cliOptions) {
13
+ const useSettings = normalizeSettings(settings);
14
+ const reportData = { issues: [], info: [], debug: [], error: [], progress: [] };
15
+ return {
16
+ issue: (issue) => {
17
+ reportData.issues.push(issue);
18
+ },
19
+ info: (message, msgType) => {
20
+ if (msgType === MessageTypes.Debug && !useSettings.debug) {
21
+ return;
22
+ }
23
+ if (msgType === MessageTypes.Info && !useSettings.verbose) {
24
+ return;
25
+ }
26
+ reportData.info = push(reportData.info, { message, msgType });
27
+ },
28
+ debug: useSettings.debug
29
+ ? (message) => {
30
+ reportData.debug = push(reportData.debug, { message });
31
+ }
32
+ : noopReporter,
33
+ error: (message, error) => {
34
+ reportData.error = push(reportData.error, { message, error });
35
+ },
36
+ progress: useSettings.progress
37
+ ? (item) => {
38
+ reportData.progress = push(reportData.progress, item);
39
+ }
40
+ : noopReporter,
41
+ result: async (result) => {
42
+ const outFile = useSettings.outFile || STDOUT;
43
+ const output = {
44
+ ...reportData,
45
+ result,
46
+ };
47
+ const jsonData = JSON.stringify(output, setToJSONReplacer, 4);
48
+ if (outFile === STDOUT) {
49
+ console.log(jsonData);
50
+ return;
51
+ }
52
+ if (outFile === STDERR) {
53
+ console.error(jsonData);
54
+ return;
55
+ }
56
+ const outFilePath = path.join(cliOptions?.root ?? process.cwd(), outFile);
57
+ await mkdirp(path.dirname(outFilePath));
58
+ return fs.writeFile(outFilePath, jsonData);
59
+ },
60
+ };
61
+ }
62
+ function normalizeSettings(settings) {
63
+ if (settings === undefined)
64
+ return { outFile: STDOUT };
65
+ validateSettings(settings);
66
+ return settings;
67
+ }
68
+ function push(src, value) {
69
+ if (src) {
70
+ src.push(value);
71
+ return src;
72
+ }
73
+ return [value];
74
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * JSON.stringify replacer which converts Set to Array to allow serialization
3
+ */
4
+ export declare function setToJSONReplacer(_: string, value: unknown): unknown;
5
+ //# sourceMappingURL=setToJSONReplacer.d.mts.map
@@ -0,0 +1,9 @@
1
+ /**
2
+ * JSON.stringify replacer which converts Set to Array to allow serialization
3
+ */
4
+ export function setToJSONReplacer(_, value) {
5
+ if (typeof value === 'object' && value instanceof Set) {
6
+ return [...value];
7
+ }
8
+ return value;
9
+ }
@@ -0,0 +1,6 @@
1
+ import type { CSpellJSONReporterSettings } from '../CSpellJSONReporterSettings.mjs';
2
+ /**
3
+ * Throws an error if passed cspell-json-reporter settings are invalid
4
+ */
5
+ export declare function validateSettings(settings: unknown): asserts settings is CSpellJSONReporterSettings;
6
+ //# sourceMappingURL=validateSettings.d.mts.map
@@ -0,0 +1,33 @@
1
+ import { AssertionError } from 'assert';
2
+ function assertBooleanOrUndefined(key, value) {
3
+ if (typeof value !== 'boolean' && value !== undefined) {
4
+ throw new AssertionError({
5
+ message: `cspell-json-reporter settings.${key} must be a boolean`,
6
+ actual: typeof value,
7
+ expected: 'boolean',
8
+ });
9
+ }
10
+ }
11
+ /**
12
+ * Throws an error if passed cspell-json-reporter settings are invalid
13
+ */
14
+ export function validateSettings(settings) {
15
+ if (!settings || typeof settings !== 'object' || Array.isArray(settings)) {
16
+ throw new AssertionError({
17
+ message: 'cspell-json-reporter settings must be an object',
18
+ actual: typeof settings,
19
+ expected: 'object',
20
+ });
21
+ }
22
+ const { outFile = 'stdout', debug, verbose, progress } = settings;
23
+ if (typeof outFile !== 'string') {
24
+ throw new AssertionError({
25
+ message: 'cspell-json-reporter settings.outFile must be a string',
26
+ actual: typeof outFile,
27
+ expected: 'string',
28
+ });
29
+ }
30
+ assertBooleanOrUndefined('verbose', verbose);
31
+ assertBooleanOrUndefined('debug', debug);
32
+ assertBooleanOrUndefined('progress', progress);
33
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cspell/cspell-json-reporter",
3
- "version": "6.28.0",
3
+ "version": "6.29.0",
4
4
  "description": "JSON reporter for CSpell",
5
5
  "author": "Jason Dent",
6
6
  "license": "MIT",
@@ -8,12 +8,23 @@
8
8
  "url": "https://github.com/streetsidesoftware/cspell/labels/cspell-json-reporter"
9
9
  },
10
10
  "homepage": "https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell-json-reporter#readme",
11
- "main": "dist/index.js",
12
- "typings": "dist/index.d.ts",
11
+ "type": "commonjs",
12
+ "main": "dist/cjs/index.js",
13
+ "types": "dist/cjs/index.d.ts",
14
+ "module": "dist/esm/index.mjs",
15
+ "exports": {
16
+ ".": {
17
+ "import": "./dist/esm/index.mjs",
18
+ "require": "./dist/cjs/index.js"
19
+ }
20
+ },
13
21
  "files": [
14
22
  "dist",
23
+ "!dist/esm/**/*.js",
24
+ "!dist/esm/**/*.ts",
15
25
  "!**/*.tsbuildInfo",
16
26
  "!**/__mocks__",
27
+ "!**/test/**",
17
28
  "!**/*.test.*",
18
29
  "!**/*.spec.*",
19
30
  "!**/*.map"
@@ -26,22 +37,22 @@
26
37
  "url": "git+https://github.com/streetsidesoftware/cspell.git"
27
38
  },
28
39
  "scripts": {
29
- "clean": "shx rm -rf dist temp coverage .tsbuildinfo",
30
- "build": "pnpm run compile",
40
+ "clean": "shx rm -rf dist coverage .tsbuildinfo",
41
+ "build": "tsc -b . && ts2mjs dist/esm",
42
+ "build:esm": "tsc -p tsconfig.esm.json",
31
43
  "clean-build": "pnpm run clean && pnpm run build",
32
- "compile": "tsc -p .",
33
- "watch": "tsc --watch -p .",
34
- "coverage": "jest --coverage",
35
- "test-watch": "jest --watch",
36
- "prepublishOnly": "pnpm run clean-build",
37
- "test": "jest",
38
- "update-snapshot": "jest --updateSnapshot"
44
+ "coverage": "pnpm coverage:vitest && pnpm coverage:fix",
45
+ "coverage:vitest": "vitest run --coverage",
46
+ "coverage:fix": "nyc report --temp-dir \"$(pwd)/coverage\" --reporter lcov --report-dir \"$(pwd)/coverage\" --cwd ../..",
47
+ "test:watch": "vitest",
48
+ "test": "vitest run",
49
+ "watch": "tsc -b . -w"
39
50
  },
40
51
  "dependencies": {
41
- "@cspell/cspell-types": "6.28.0"
52
+ "@cspell/cspell-types": "6.29.0"
42
53
  },
43
54
  "engines": {
44
55
  "node": ">=14"
45
56
  },
46
- "gitHead": "1c314413e76908e5fbf61fd2555726112b177c0e"
57
+ "gitHead": "2eabb1c47c12c2a42eb95d30329be6f544ee2ffc"
47
58
  }
File without changes
File without changes