v8r 4.3.0 → 4.4.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 CHANGED
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## 📦 [4.4.0](https://www.npmjs.com/package/v8r/v/4.4.0) - 2025-04-26
4
+
5
+ Version 4.4.0 is a deprecation release. This release adds deprecation warnings for
6
+ upcoming breaking changes that will be made in version 5.0
7
+
8
+ * This release adds the `--output-format` CLI argument and `outputFormat` config file key.
9
+ In v8r 4.4.0 `--format` and `format` can still be used as aliases.
10
+ In version 5 `--format` and `format` will be removed.
11
+ It is recommended to switch to using `--output-format` and `outputFormat` now.
12
+ * Starting from v8r version 5, v8r will ignore patterns in `.gitignore` by default.
13
+ * In v8r version 5 the `fileLocation` argument of `getSingleResultLogMessage` will be removed.
14
+ The signature will become `getSingleResultLogMessage(result, format)`.
15
+ Plugins implementing the `getSingleResultLogMessage` plugin hook will need to to update
16
+ the signature to be compatible with version 5.
17
+ If you are using `fileLocation` in the `getSingleResultLogMessage` function body,
18
+ switch to using `result.fileLocation`.
19
+ * Starting from v8r version 5 file paths will no longer be passed to plugins in dot-relative notation.
20
+ Plugins implementing the `getSingleResultLogMessage`, `getAllResultsLogMessage` and `parseInputFile`
21
+ plugin hooks may need to be updated.
22
+
3
23
  ## 📦 [4.3.0](https://www.npmjs.com/package/v8r/v/4.3.0) - 2025-04-21
4
24
 
5
25
  * Add ignore patern files. v8r now looks for ignore patterns in `.v8rignore` by default.
@@ -3,6 +3,13 @@
3
3
  "$schema": "https://json-schema.org/draft/2019-09/schema",
4
4
  "type": "object",
5
5
  "additionalProperties": false,
6
+ "allOf": [
7
+ {
8
+ "not": {
9
+ "required": ["format", "outputFormat"]
10
+ }
11
+ }
12
+ ],
6
13
  "properties": {
7
14
  "cacheTtl": {
8
15
  "description": "Remove cached HTTP responses older than cacheTtl seconds old. Specifying 0 clears and disables cache completely",
@@ -57,10 +64,15 @@
57
64
  }
58
65
  }
59
66
  },
60
- "format": {
67
+ "outputFormat": {
61
68
  "description": "Output format for validation results. 'text' and 'json' are always valid. Plugins may define additional values which are valid here.",
62
69
  "type": "string"
63
70
  },
71
+ "format": {
72
+ "description": "Output format for validation results. 'text' and 'json' are always valid. Plugins may define additional values which are valid here.",
73
+ "type": "string",
74
+ "deprecated": true
75
+ },
64
76
  "ignoreErrors": {
65
77
  "description": "Exit with code 0 even if an error was encountered. True means a non-zero exit code is only issued if validation could be completed successfully and one or more files were invalid",
66
78
  "type": "boolean"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "v8r",
3
- "version": "4.3.0",
3
+ "version": "4.4.0",
4
4
  "description": "A command-line JSON, YAML and TOML validator that's on your wavelength",
5
5
  "scripts": {
6
6
  "test": "V8R_CACHE_NAME=v8r-test c8 --reporter=text mocha \"src/**/*.spec.js\"",
package/src/bootstrap.js CHANGED
@@ -53,6 +53,8 @@ function mergeConfigs(args, config) {
53
53
  if (config.filepath) {
54
54
  mergedConfig.configFileRelativePath = getRelativeFilePath(config);
55
55
  }
56
+ // https://github.com/chris48s/v8r/issues/494
57
+ delete mergedConfig.format;
56
58
  return mergedConfig;
57
59
  }
58
60
 
@@ -120,6 +122,13 @@ function parseArgs(argv, config, documentFormats, outputFormats) {
120
122
  if (args.ignore === undefined) {
121
123
  args.ignore = true;
122
124
  }
125
+
126
+ // https://github.com/chris48s/v8r/issues/494
127
+ if (process.argv.includes("--format")) {
128
+ logger.warning(
129
+ "In v8r version 5 the --format argument will be removed. Switch to using --output-format",
130
+ );
131
+ }
123
132
  },
124
133
  )
125
134
  .version(
@@ -177,11 +186,14 @@ function parseArgs(argv, config, documentFormats, outputFormats) {
177
186
  "Remove cached HTTP responses older than <cache-ttl> seconds old. " +
178
187
  "Passing 0 clears and disables cache completely",
179
188
  })
180
- .option("format", {
189
+ .option("output-format", {
181
190
  type: "string",
182
191
  choices: outputFormats,
183
192
  default: "text",
184
- describe: "Output format for validation results",
193
+ // https://github.com/chris48s/v8r/issues/494
194
+ describe:
195
+ "Output format for validation results. The '--format' alias is deprecated.",
196
+ alias: "format",
185
197
  })
186
198
  .example([
187
199
  ["$0 file.json", "Validate a single file"],
@@ -193,7 +205,7 @@ function parseArgs(argv, config, documentFormats, outputFormats) {
193
205
  ]);
194
206
 
195
207
  for (const [key, value] of Object.entries(config.config)) {
196
- if (["cacheTtl", "format", "ignoreErrors", "verbose"].includes(key)) {
208
+ if (["cacheTtl", "outputFormat", "ignoreErrors", "verbose"].includes(key)) {
197
209
  parser.default(
198
210
  decamelize(key, { separator: "-" }),
199
211
  value,
@@ -239,6 +251,14 @@ async function bootstrap(argv, config, cosmiconfigOptions = {}) {
239
251
  const configFile = await getCosmiConfig(cosmiconfigOptions);
240
252
  validateConfigAgainstSchema(configFile);
241
253
 
254
+ // https://github.com/chris48s/v8r/issues/494
255
+ if (configFile.config.format) {
256
+ logger.warning(
257
+ "In v8r version 5 the 'format' config file key will be removed. Switch to using 'outputFormat'",
258
+ );
259
+ configFile.config.outputFormat = configFile.config.format;
260
+ }
261
+
242
262
  // load both core and user plugins
243
263
  let plugins = resolveUserPlugins(configFile.config.plugins || []);
244
264
  const { allLoadedPlugins, loadedCorePlugins, loadedUserPlugins } =
@@ -254,6 +274,11 @@ async function bootstrap(argv, config, cosmiconfigOptions = {}) {
254
274
  // parse command line arguments
255
275
  const args = parseArgs(argv, configFile, documentFormats, outputFormats);
256
276
 
277
+ // https://github.com/chris48s/v8r/issues/599
278
+ logger.warning(
279
+ "Starting from v8r version 5, v8r will ignore patterns in .gitignore by default.",
280
+ );
281
+
257
282
  return {
258
283
  config: mergeConfigs(args, configFile),
259
284
  allLoadedPlugins,
package/src/cli.js CHANGED
@@ -145,7 +145,7 @@ async function validateFile(filename, config, plugins, cache) {
145
145
  const message = plugin.getSingleResultLogMessage(
146
146
  result,
147
147
  filename,
148
- config.format,
148
+ config.outputFormat,
149
149
  );
150
150
  if (message != null) {
151
151
  logger.log(message);
@@ -191,7 +191,10 @@ function Validator() {
191
191
  }
192
192
 
193
193
  for (const plugin of plugins) {
194
- const message = plugin.getAllResultsLogMessage(results, config.format);
194
+ const message = plugin.getAllResultsLogMessage(
195
+ results,
196
+ config.outputFormat,
197
+ );
195
198
  if (message != null) {
196
199
  logger.log(message);
197
200
  break;
package/src/logger.js CHANGED
@@ -47,6 +47,12 @@ class Logger {
47
47
  this.writeErr(formatedMessage);
48
48
  }
49
49
 
50
+ warning(message) {
51
+ const formatedMessage = chalk.yellow.bold("▲ ") + message;
52
+ this.stderr.push(formatedMessage);
53
+ this.writeErr(formatedMessage);
54
+ }
55
+
50
56
  error(message) {
51
57
  const formatedMessage = chalk.red.bold("✖ ") + message;
52
58
  this.stderr.push(formatedMessage);
package/src/plugins.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import path from "node:path";
2
+ import logger from "./logger.js";
2
3
 
3
4
  /**
4
5
  * Base class for all v8r plugins.
@@ -53,8 +54,8 @@ class BasePlugin {
53
54
  /**
54
55
  * Use the `registerOutputFormats` hook to tell v8r about additional output
55
56
  * formats that can be generated. Any formats registered with this hook become
56
- * valid values for the `format` property in the config file and the
57
- * `--format` command line argument.
57
+ * valid values for the `outputFormat` property in the config file and the
58
+ * `--output-format` command line argument.
58
59
  *
59
60
  * @returns {string[]} Output formats to register
60
61
  */
@@ -80,7 +81,7 @@ class BasePlugin {
80
81
  * paths in the current directory will be prefixed with `./` (or `.\` on
81
82
  * Windows) even if this was not present in the input filename or pattern.
82
83
  * @param {string} format - The user's requested output format as specified in
83
- * the config file or via the `--format` command line argument.
84
+ * the config file or via the `--output-format` command line argument.
84
85
  * @returns {string | undefined} Log message
85
86
  */
86
87
  // eslint-disable-next-line no-unused-vars
@@ -102,7 +103,7 @@ class BasePlugin {
102
103
  * @param {ValidationResult[]} results - Results of attempting to validate
103
104
  * these documents.
104
105
  * @param {string} format - The user's requested output format as specified in
105
- * the config file or via the `--format` command line argument.
106
+ * the config file or via the `--output-format` command line argument.
106
107
  * @returns {string | undefined} Log message
107
108
  */
108
109
  // eslint-disable-next-line no-unused-vars
@@ -123,7 +124,11 @@ class Document {
123
124
  }
124
125
  }
125
126
 
126
- function validatePlugin(plugin) {
127
+ function hasProperty(plugin, prop) {
128
+ return Object.prototype.hasOwnProperty.call(plugin.prototype, prop);
129
+ }
130
+
131
+ function validatePlugin(plugin, warnings) {
127
132
  if (
128
133
  typeof plugin.name !== "string" ||
129
134
  !plugin.name.startsWith("v8r-plugin-")
@@ -150,6 +155,29 @@ function validatePlugin(plugin) {
150
155
  );
151
156
  }
152
157
  }
158
+
159
+ if (warnings === true) {
160
+ // https://github.com/chris48s/v8r/issues/500
161
+ if (hasProperty(plugin, "getSingleResultLogMessage")) {
162
+ logger.warning(
163
+ "In v8r version 5 the fileLocation argument of getSingleResultLogMessage will be removed.\n" +
164
+ " The signature will become getSingleResultLogMessage(result, format).\n" +
165
+ ` ${plugin.name} will need to be updated`,
166
+ );
167
+ }
168
+
169
+ // https://github.com/chris48s/v8r/issues/600
170
+ if (
171
+ hasProperty(plugin, "getSingleResultLogMessage") ||
172
+ hasProperty(plugin, "getAllResultsLogMessage") ||
173
+ hasProperty(plugin, "parseInputFile")
174
+ ) {
175
+ logger.warning(
176
+ "Starting from v8r version 5 file paths will no longer be passed to plugins in dot-relative notation.\n" +
177
+ ` ${plugin.name} may need to be updated`,
178
+ );
179
+ }
180
+ }
153
181
  }
154
182
 
155
183
  function resolveUserPlugins(userPlugins) {
@@ -165,19 +193,19 @@ function resolveUserPlugins(userPlugins) {
165
193
  return plugins;
166
194
  }
167
195
 
168
- async function loadPlugins(plugins) {
196
+ async function loadPlugins(plugins, warnings) {
169
197
  let loadedPlugins = [];
170
198
  for (const plugin of plugins) {
171
199
  loadedPlugins.push(await import(plugin));
172
200
  }
173
201
  loadedPlugins = loadedPlugins.map((plugin) => plugin.default);
174
- loadedPlugins.forEach((plugin) => validatePlugin(plugin));
202
+ loadedPlugins.forEach((plugin) => validatePlugin(plugin, warnings));
175
203
  loadedPlugins = loadedPlugins.map((plugin) => new plugin());
176
204
  return loadedPlugins;
177
205
  }
178
206
 
179
207
  async function loadAllPlugins(userPlugins) {
180
- const loadedUserPlugins = await loadPlugins(userPlugins);
208
+ const loadedUserPlugins = await loadPlugins(userPlugins, true);
181
209
 
182
210
  const corePlugins = [
183
211
  "./plugins/parser-json.js",
@@ -187,7 +215,7 @@ async function loadAllPlugins(userPlugins) {
187
215
  "./plugins/output-text.js",
188
216
  "./plugins/output-json.js",
189
217
  ];
190
- const loadedCorePlugins = await loadPlugins(corePlugins);
218
+ const loadedCorePlugins = await loadPlugins(corePlugins, false);
191
219
 
192
220
  return {
193
221
  allLoadedPlugins: loadedUserPlugins.concat(loadedCorePlugins),