read-bsconfig
Advanced tools
Comparing version 1.0.1 to 1.0.2
26
index.js
@@ -5,4 +5,8 @@ const { readFile, readFileSync } = require('fs') | ||
function readBsConfig(cwd = process.cwd()) { | ||
return new Promise((resolve, reject) => { | ||
let asyncConfigCache = {} | ||
function readBsConfig(cwd = process.cwd(), enableCache = true) { | ||
if (asyncConfigCache[cwd] && enableCache) return asyncConfigCache[cwd] | ||
asyncConfigCache[cwd] = new Promise((resolve, reject) => { | ||
readFile(path.join(cwd, 'bsconfig.json'), (err, res) => { | ||
@@ -14,10 +18,22 @@ if (err) return reject(err) | ||
}) | ||
return asyncConfigCache[cwd] | ||
} | ||
function readBsConfigSync(cwd = process.cwd()) { | ||
let syncConfigCache = {} | ||
function readBsConfigSync(cwd = process.cwd(), enableCache = true) { | ||
if (syncConfigCache[cwd] && enableCache) return syncConfigCache[cwd] | ||
const content = readFileSync(path.join(cwd, 'bsconfig.json')) | ||
syncConfigCache[cwd] = JSON5.parse(content.toString()) | ||
return JSON5.parse(content.toString()) | ||
return syncConfigCache[cwd] | ||
} | ||
module.exports = { readBsConfig, readBsConfigSync } | ||
function clearCache() { | ||
asyncConfigCache = {} | ||
syncConfigCache = {} | ||
} | ||
module.exports = { readBsConfig, readBsConfigSync, clearCache } |
{ | ||
"name": "read-bsconfig", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Library for reading the bsconfig.json for BuckleScript", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -8,3 +8,3 @@ # read-bsconfig | ||
```js | ||
const readBsConfig = require('read-bsconfig') | ||
const { readBsConfig, readBsConfigSync } = require('read-bsconfig') | ||
@@ -16,2 +16,10 @@ // Read from the CWD | ||
const otherConf = readBsConfig(__dirname) | ||
// A bsconfig for a given path will be cached. This can be turned off | ||
// by passing a second parameter as false | ||
const notCachedConf = readBsConfig(__dirname, false) | ||
// You can also read a config sync | ||
// It has a the same arguments | ||
const mySyncConf = readBsConfigSync() | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3282
26
24