Comparing version 0.3.0 to 1.0.0
@@ -16,7 +16,2 @@ "use strict"; | ||
/** | ||
* Read and return file data | ||
* @param {string} fp file path | ||
* @return {Promise<string>} file data | ||
*/ | ||
const readFile = fp => new Promise((resolve, reject) => { | ||
@@ -27,15 +22,8 @@ _fs.default.readFile(fp, 'utf8', (err, data) => { | ||
}); | ||
}); // eslint-disable-next-line no-unused-vars | ||
}); | ||
const readFileSync = fp => { | ||
return _fs.default.readFileSync(fp, 'utf8'); | ||
}; | ||
/** | ||
* Check if a file exists | ||
* @param {string} fp file path | ||
* @return {Promise<boolean>} whether it exists | ||
*/ | ||
const pathExists = fp => new Promise(resolve => { | ||
@@ -45,15 +33,8 @@ _fs.default.access(fp, err => { | ||
}); | ||
}); // eslint-disable-next-line no-unused-vars | ||
}); | ||
const pathExistsSync = _fs.default.existsSync; | ||
/** | ||
* @typedef {(filepath: string) => any} Load | ||
* @typedef {{test: RegExp, load: Load}} Loader | ||
*/ | ||
class JoyCon { | ||
constructor( | ||
/** @type {{files?: string[], cwd?: string}} */ | ||
{ | ||
constructor({ | ||
files, | ||
@@ -65,17 +46,7 @@ cwd = process.cwd() | ||
cwd | ||
/** @type {Map<string, boolean>} */ | ||
}; | ||
this.existsCache = new Map(); | ||
/** @type {Set<Loader>} */ | ||
this.loaders = new Set(); | ||
} | ||
/** | ||
* Add a loader | ||
* @public | ||
* @param {Loader} loader | ||
*/ | ||
addLoader(loader) { | ||
@@ -85,13 +56,3 @@ this.loaders.add(loader); | ||
} | ||
/** | ||
* Resolve the files in working directory or parent directory | ||
* @private | ||
* @param {string[]} files Files to search | ||
* @param {string} cwd Working directory | ||
* @param {string} stopDir The directory to stop searching | ||
* @return {Promise<string|null>} | ||
*/ | ||
// __SYNCED__ | ||
recusivelyResolve(files, cwd, stopDir) { | ||
@@ -101,3 +62,2 @@ var _this = this; | ||
return _asyncToGenerator(function* () { | ||
// Don't traverse above the module root | ||
if (cwd === stopDir || _path.default.basename(cwd) === 'node_modules') { | ||
@@ -110,4 +70,3 @@ return null; | ||
const exists = // Disable cache in tests | ||
process.env.NODE_ENV !== 'test' && _this.existsCache.has(file) ? _this.existsCache.get(file) : yield pathExists(file); // eslint-disable-line no-await-in-loop | ||
const exists = process.env.NODE_ENV !== 'test' && _this.existsCache.has(file) ? _this.existsCache.get(file) : yield pathExists(file); | ||
@@ -119,6 +78,5 @@ if (exists) { | ||
} | ||
} // Continue in the parent directory | ||
} | ||
return _this.recusivelyResolve(files, _path.default.dirname(cwd), stopDir); // $MakeMeSync | ||
return _this.recusivelyResolve(files, _path.default.dirname(cwd), stopDir); | ||
})(); | ||
@@ -145,11 +103,3 @@ } | ||
} | ||
/** | ||
* Search files and resolve the path | ||
* @param {string[]=} files Files to search | ||
* @param {string=} cwd Working directory | ||
* @param {string=} stopDir The directory to stop searching | ||
*/ | ||
// __SYNCED__ | ||
resolve(files, cwd, stopDir) { | ||
@@ -167,3 +117,3 @@ var _this2 = this; | ||
return _this2.recusivelyResolve(files, cwd, stopDir); // $MakeMeSync | ||
return _this2.recusivelyResolve(files, cwd, stopDir); | ||
})(); | ||
@@ -183,11 +133,3 @@ } | ||
} | ||
/** | ||
* Search files and resolve the path and data | ||
* @param {string[]=} files Files to search | ||
* @param {string=} cwd Working directory | ||
* @param {string=} stopDir The directory to stop searching | ||
*/ | ||
// __SYNCED__ | ||
load(files, cwd, stopDir) { | ||
@@ -226,7 +168,4 @@ var _this3 = this; | ||
}; | ||
} // Don't parse data | ||
// If it's neither .js nor .json | ||
// Leave this to user-land | ||
} | ||
return { | ||
@@ -299,9 +238,3 @@ path: filepath, | ||
} | ||
/** | ||
* Find a loader for given path | ||
* @param {string} filepath file path | ||
* @return {Load|null} | ||
*/ | ||
findLoader(filepath) { | ||
@@ -316,5 +249,3 @@ for (const loader of this.loaders) { | ||
} | ||
/** Clear cache used by this instance */ | ||
clearCache() { | ||
@@ -321,0 +252,0 @@ this.existsCache.clear(); |
{ | ||
"name": "joycon", | ||
"version": "0.3.0", | ||
"version": "1.0.0", | ||
"description": "Load config with ease.", | ||
@@ -10,4 +10,6 @@ "repository": { | ||
"main": "lib/index.js", | ||
"types": "types/index.d.ts", | ||
"files": [ | ||
"lib" | ||
"lib", | ||
"types/index.d.ts" | ||
], | ||
@@ -17,3 +19,3 @@ "scripts": { | ||
"lint": "xo", | ||
"build": "babel src -d lib", | ||
"build": "babel src -d lib --no-comments", | ||
"prepublishOnly": "npm run build" | ||
@@ -20,0 +22,0 @@ }, |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
5
1
0
12165
224