doc-detective-common 3.0.8 → 3.0.9

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": "doc-detective-common",
3
- "version": "3.0.8",
3
+ "version": "3.0.9",
4
4
  "description": "Shared components for Doc Detective projects.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -25,7 +25,7 @@
25
25
  "sinon": "^20.0.0"
26
26
  },
27
27
  "dependencies": {
28
- "@apidevtools/json-schema-ref-parser": "^12.0.2",
28
+ "@apidevtools/json-schema-ref-parser": "^13.0.1",
29
29
  "ajv": "^8.17.1",
30
30
  "ajv-errors": "^3.0.0",
31
31
  "ajv-formats": "^3.0.1",
package/src/files.js CHANGED
@@ -59,18 +59,25 @@ async function readFile({ fileURLOrPath }) {
59
59
  }
60
60
  }
61
61
 
62
- // Parse based on file content, and return either object or string
63
- try {
64
- // Try to parse as JSON
65
- return JSON.parse(content);
66
- } catch (error) {
62
+ // Parse based on file extension
63
+ const ext = fileURLOrPath.split('.').pop().toLowerCase();
64
+
65
+ if (ext === "json") {
66
+ try {
67
+ return JSON.parse(content);
68
+ } catch (error) {
69
+ console.warn(`Failed to parse JSON: ${error.message}`);
70
+ return content;
71
+ }
72
+ } else if (ext === "yaml" || ext === "yml") {
67
73
  try {
68
- // Try to parse as YAML
69
74
  return YAML.parse(content);
70
75
  } catch (error) {
71
- // Return raw content if not JSON or YAML
76
+ console.warn(`Failed to parse YAML: ${error.message}`);
72
77
  return content;
73
78
  }
79
+ } else {
80
+ return content;
74
81
  }
75
82
  }
76
83
 
package/src/validate.js CHANGED
@@ -126,7 +126,7 @@ function validate({ schemaKey, object, addDefaults = true }) {
126
126
  if (check(validationObject)) return key;
127
127
  });
128
128
  if (!matchedSchemaKey) {
129
- result.errors = `Invalid object`;
129
+ result.errors = `Invalid object: ${check.errors}.`;
130
130
  result.object = object;
131
131
  result.valid = false;
132
132
  return result;