bajo 2.19.0 → 2.20.1

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.
@@ -0,0 +1,37 @@
1
+ name: Bajo Tests
2
+
3
+ # Trigger the workflow on pushes or pull requests to the main branch
4
+ on:
5
+ push:
6
+ branches: [ main ]
7
+ pull_request:
8
+ branches: [ main ]
9
+
10
+ jobs:
11
+ test-package:
12
+ runs-on: ubuntu-latest
13
+
14
+ strategy:
15
+ # Test your package across multiple Node.js versions
16
+ matrix:
17
+ node-version: [22.x, 24.x]
18
+
19
+ steps:
20
+ # Step 1: Download the repository code onto the runner machine
21
+ - name: Checkout repository
22
+ uses: actions/checkout@v6
23
+
24
+ # Step 2: Set up the specific Node.js version from the matrix
25
+ - name: Use Node.js ${{ matrix.node-version }}
26
+ uses: actions/setup-node@v6
27
+ with:
28
+ node-version: ${{ matrix.node-version }}
29
+ cache: 'npm' # Speeds up subsequent runs by caching node_modules
30
+
31
+ # Step 3: Perform a clean install of your exact dependencies
32
+ - name: Install dependencies
33
+ run: npm ci
34
+
35
+ # Step 4: Execute the test command defined in package.json
36
+ - name: Run package tests
37
+ run: npm test
package/class/_helper.js CHANGED
@@ -264,6 +264,7 @@ export async function collectConfigHandlers () {
264
264
  if (!mod) continue
265
265
  if (isFunction(mod)) mod = await mod.call(this.app[camelCase(pkg)])
266
266
  if (isPlainObject(mod)) mod = [mod]
267
+ mod.forEach(m => set(m, 'ns', camelCase(pkg)))
267
268
  this.app.configHandlers = this.app.configHandlers.concat(mod)
268
269
  }
269
270
  }
package/class/app.js CHANGED
@@ -562,10 +562,13 @@ class App {
562
562
  /**
563
563
  * Helper method to list all supported config formats.
564
564
  *
565
+ * @method
566
+ * @param {boolean} [noDot] - If ```true```, it will return the list without dot prefix.
565
567
  * @returns {string[]}
566
568
  */
567
- getConfigFormats = () => {
568
- return map(this.configHandlers, 'ext')
569
+ getConfigFormats = (noDot) => {
570
+ const formats = map(this.configHandlers, 'ext')
571
+ return noDot ? formats.map(f => f.slice(1)) : formats
569
572
  }
570
573
 
571
574
  /**
package/class/bajo.js CHANGED
@@ -77,8 +77,8 @@ class Bajo extends Plugin {
77
77
 
78
78
  // by defaualt, only these config formats below are supported.
79
79
  app.configHandlers = [
80
- { ext: '.js', readHandler: this.fromJs },
81
- { ext: '.json', readHandler: this.fromJson, writeHandler: this.toJson }
80
+ { ns: 'bajo', ext: '.js', readHandler: this.fromJs },
81
+ { ns: 'bajo', ext: '.json', readHandler: this.fromJson, writeHandler: this.toJson }
82
82
  ]
83
83
 
84
84
  this.hooks = []
@@ -843,20 +843,20 @@ class Bajo extends Plugin {
843
843
  let ext = path.extname(file)
844
844
  const fname = path.dirname(file) + '/' + path.basename(file, ext)
845
845
  ext = ext.toLowerCase()
846
- if (ext === '.js') {
847
- const { readHandler } = find(this.app.configHandlers, { ext })
848
- return await output(await readHandler.call(this.app[ns], file, parserOpts))
846
+ if (['.js', '.json'].includes(ext)) {
847
+ const item = find(this.app.configHandlers, { ext })
848
+ return await output(await item.readHandler.call(this.app[ns], file, parserOpts))
849
849
  }
850
- if (ext === '.json') return await output(await this.fromJson(file, parserOpts))
851
850
  if (!['', '.*'].includes(ext)) {
852
851
  const item = find(this.app.configHandlers, { ext })
853
852
  if (!item) {
854
853
  if (!ignoreError) throw this.error('cantParse%s', file, { code: 'BAJO_CONFIG_NO_PARSER' })
855
854
  return await output(defValue)
856
855
  }
857
- return await output(await item.readHandler.call(this.app[ns], file, parserOpts))
856
+ return await output(await item.readHandler.call(this.app[item.ns], file, parserOpts))
858
857
  }
859
- const item = pattern ?? `${fname}.{${map(map(this.app.configHandlers, 'ext'), k => k.slice(1)).join(',')}}`
858
+ const formats = this.app.getConfigFormats(true)
859
+ const item = pattern ?? `${fname}.{${formats.join(',')}}`
860
860
  const files = await fastGlob(item, globOpts ?? {})
861
861
  if (files.length === 0) {
862
862
  if (!ignoreError) throw this.error('noConfigFileFound', { code: 'BAJO_CONFIG_FILE_NOT_FOUND' })
@@ -870,7 +870,8 @@ class Bajo extends Plugin {
870
870
  if (!ignoreError) throw this.error('cantParse%s', f, { code: 'BAJO_CONFIG_NO_PARSER' })
871
871
  continue
872
872
  }
873
- config = await item.readHandler.call(this.app[ns], f, parserOpts)
873
+ const _ns = ['.js', '.json'].includes(ext) ? ns : item.ns
874
+ config = await item.readHandler.call(this.app[_ns], f, parserOpts)
874
875
  if (!isEmpty(config)) break
875
876
  }
876
877
  return await output(config)
@@ -1023,6 +1024,29 @@ class Bajo extends Plugin {
1023
1024
  if (printSaved) print.succeed('savedAs%s', path.resolve(fname), { skipSilence: true })
1024
1025
  return fname
1025
1026
  }
1027
+
1028
+ /**
1029
+ * Read config using all registered config handlers. The first handler that returns a
1030
+ * valid object or array will be used.
1031
+ *
1032
+ * @param {string} input - The input string to be processed by the config handlers.
1033
+ * @param {string[]} [exts] - Optional array of extensions to filter the config handlers. If provided, only handlers with matching extensions will be used.
1034
+ * @param {object} [options={}] - Options to be passed to the config handlers.
1035
+ * @returns {Object|Array|null} The result from the first successful config handler, or null if none succeed.
1036
+ */
1037
+ readAsConfig = async (input, exts, options = {}) => {
1038
+ let result
1039
+ const handlers = exts ? this.app.configHandlers.filter(h => exts.includes(h.ext)) : this.app.configHandlers
1040
+ for (const handler of handlers) {
1041
+ if (result) break
1042
+ try {
1043
+ const resp = await handler.readHandler.call(this.app[handler.ns], input, options)
1044
+ if (isPlainObject(resp) || isArray(resp)) result = resp
1045
+ } catch (err) {
1046
+ }
1047
+ }
1048
+ return result
1049
+ }
1026
1050
  }
1027
1051
 
1028
1052
  export default Bajo
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bajo",
3
- "version": "2.19.0",
3
+ "version": "2.20.1",
4
4
  "description": "The ultimate framework for whipping up massive apps in no time",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -44,6 +44,7 @@
44
44
  "devDependencies": {
45
45
  "chai": "^6.2.1",
46
46
  "clean-jsdoc-theme": "^4.3.0",
47
- "docdash": "^2.0.2"
47
+ "docdash": "^2.0.2",
48
+ "mocha": "^11.7.6"
48
49
  }
49
50
  }
package/wiki/CHANGES.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-06-28
4
+
5
+ - [2.20.1] Bug fix in ```readConfig()```
6
+
7
+ ## 2026-06-26
8
+
9
+ - [2.20.0] Add source ```ns``` to the config handlers
10
+ - [2.20.0] Bug fix in ```bajo.readConfig()```
11
+ - [2.20.0] Add ```bajo.readAsConfig()```
12
+ - [2.20.0] Add ```params.noDot``` to the ```app.getConfigFormats()```
13
+
3
14
  ## 2026-06-26
4
15
 
5
16
  - [2.19.0] Documentation overhaul