bajo 2.7.3 → 2.8.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/class/bajo.js CHANGED
@@ -853,6 +853,7 @@ class Bajo extends Plugin {
853
853
  */
854
854
  readConfig = async (file, { ns, pattern, globOptions = {}, ignoreError, defValue = {}, opts = {} } = {}) => {
855
855
  const { parseObject } = this.app.lib
856
+ opts.readFromFile = true
856
857
  if (!ns) ns = this.ns
857
858
  file = resolvePath(this.getPluginFile(file))
858
859
  let ext = path.extname(file)
@@ -862,7 +863,7 @@ class Bajo extends Plugin {
862
863
  const { readHandler } = find(this.app.configHandlers, { ext })
863
864
  return parseObject(await readHandler.call(this.app[ns], file, opts))
864
865
  }
865
- if (ext === '.json') return await this.fromJson(file, null)
866
+ if (ext === '.json') return await this.fromJson(file, opts)
866
867
  if (!['', '.*'].includes(ext)) {
867
868
  const item = find(this.app.configHandlers, { ext })
868
869
  if (!item) {
@@ -885,7 +886,7 @@ class Bajo extends Plugin {
885
886
  if (!ignoreError) throw this.error('cantParse%s', f, { code: 'BAJO_CONFIG_NO_PARSER' })
886
887
  continue
887
888
  }
888
- config = await item.readHandler.call(this.app[ns], f, undefined, opts)
889
+ config = await item.readHandler.call(this.app[ns], f, opts)
889
890
  if (!isEmpty(config)) break
890
891
  }
891
892
  return parseObject(config)
@@ -911,14 +912,18 @@ class Bajo extends Plugin {
911
912
  return parseObject(JSON.parse(resp))
912
913
  }
913
914
 
914
- fromJson (file, isContent) {
915
- const content = isContent ? file : fs.readFileSync(file, 'utf8')
915
+ fromJson (data, opts = {}) {
916
+ const content = opts.readFromFile ? fs.readFileSync(data, 'utf8') : data
916
917
  return JSON.parse(content)
917
918
  }
918
919
 
919
- toJson = (file, isContent, opts = 2) => {
920
- const content = isContent ? file : JSON.parse(fs.readFileSync(file, 'utf8'))
921
- return JSON.stringify(content, null, opts)
920
+ toJson = (data, opts = {}) => {
921
+ const content = JSON.stringify(data, null, omit(opts, ['writeToFile']))
922
+ if (opts.writeToFile) {
923
+ fs.writeFileSync(opts.saveAsFile, content, 'utf8')
924
+ return
925
+ }
926
+ return content
922
927
  }
923
928
 
924
929
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bajo",
3
- "version": "2.7.3",
3
+ "version": "2.8.0",
4
4
  "description": "The ultimate framework for whipping up massive apps in no time",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/wiki/CHANGES.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-03-22
4
+
5
+ - [2.8.0] Add ```options.readFromFile``` in ```readConfig()```
6
+ - [2.8.0] Bug fix in ```readConfig()``` while reading ```json``` file
7
+ - [2.8.0] Bug fix in ```fromJson()```
8
+ - [2.8.0] Bug fix in ```toJson()```
9
+
3
10
  ## 2026-03-15
4
11
 
5
12
  - [2.7.3] Bug fix in checking plugin dependency handler