@nera-static/plugin-utils 1.5.0 → 1.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/README.md +2 -0
- package/index.js +19 -2
- package/package.json +4 -4
package/README.md
CHANGED
package/index.js
CHANGED
|
@@ -1,11 +1,28 @@
|
|
|
1
1
|
import fs from 'fs'
|
|
2
2
|
import path from 'path'
|
|
3
|
-
|
|
3
|
+
// js-yaml 5 dropped the default export; `load` is a named export now.
|
|
4
|
+
import { load } from 'js-yaml'
|
|
5
|
+
|
|
6
|
+
// js-yaml 5 throws on a document with no content, where 4 returned undefined.
|
|
7
|
+
// A packaged config whose every key is commented out is the normal case here —
|
|
8
|
+
// that is how plugins ship their defaults — so it has to keep behaving like an
|
|
9
|
+
// absent config instead of crashing the build. Real syntax errors still throw.
|
|
10
|
+
function hasNoDocument(content) {
|
|
11
|
+
return content
|
|
12
|
+
.split('\n')
|
|
13
|
+
.every((line) => {
|
|
14
|
+
const trimmed = line.trim()
|
|
15
|
+
return trimmed === '' || trimmed.startsWith('#')
|
|
16
|
+
})
|
|
17
|
+
}
|
|
4
18
|
|
|
5
19
|
export function getConfig(filePath) {
|
|
6
20
|
if (fs.existsSync(filePath)) {
|
|
7
21
|
const content = fs.readFileSync(filePath, 'utf-8')
|
|
8
|
-
|
|
22
|
+
if (hasNoDocument(content)) {
|
|
23
|
+
return {}
|
|
24
|
+
}
|
|
25
|
+
return load(content) || {}
|
|
9
26
|
}
|
|
10
27
|
return {}
|
|
11
28
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nera-static/plugin-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "Shared utility functions for Nera plugins (config loading, template publishing)",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
"access": "public"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"js-yaml": "^
|
|
29
|
+
"js-yaml": "^5.2.2"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"eslint": "^
|
|
32
|
+
"eslint": "^10.8.0",
|
|
33
33
|
"husky": "^9.1.7",
|
|
34
|
-
"vitest": "^
|
|
34
|
+
"vitest": "^4.1.10"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"test": "vitest",
|