Socket
Socket
Sign inDemoInstall

joycon

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

joycon - npm Package Compare versions

Comparing version 2.2.5 to 3.0.0

339

lib/index.js

@@ -14,13 +14,2 @@ "use strict";

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
const readFile = fp => new Promise((resolve, reject) => {
_fs.default.readFile(fp, 'utf8', (err, data) => {
if (err) return reject(err);
resolve(data);
});
});
const readFileSync = fp => {

@@ -56,2 +45,3 @@ return _fs.default.readFileSync(fp, 'utf8');

this.packageJsonCache = new Map();
this.loadCache = new Map();
}

@@ -65,27 +55,6 @@

removeLoader(name) {
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = this.loaders[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
const loader = _step.value;
if (name && loader.name === name) {
this.loaders.delete(loader);
}
for (const loader of this.loaders) {
if (name && loader.name === name) {
this.loaders.delete(loader);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}

@@ -96,62 +65,35 @@

recusivelyResolve(options) {
var _this = this;
async recusivelyResolve(options) {
if (options.cwd === options.stopDir || _path.default.basename(options.cwd) === 'node_modules') {
return null;
}
return _asyncToGenerator(function* () {
if (options.cwd === options.stopDir || _path.default.basename(options.cwd) === 'node_modules') {
return null;
}
for (const filename of options.files) {
const file = _path.default.resolve(options.cwd, filename);
var _iteratorNormalCompletion4 = true;
var _didIteratorError4 = false;
var _iteratorError4 = undefined;
const exists = process.env.NODE_ENV !== 'test' && this.existsCache.has(file) ? this.existsCache.get(file) : await pathExists(file);
this.existsCache.set(file, exists);
try {
for (var _iterator4 = options.files[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
const filename = _step4.value;
if (exists) {
if (!options.packageKey || _path.default.basename(file) !== 'package.json') {
return file;
}
const file = _path.default.resolve(options.cwd, filename);
const data = require(file);
const exists = process.env.NODE_ENV !== 'test' && _this.existsCache.has(file) ? _this.existsCache.get(file) : yield pathExists(file);
delete require.cache[file];
const hasPackageKey = Object.prototype.hasOwnProperty.call(data, options.packageKey);
_this.existsCache.set(file, exists);
if (exists) {
if (!options.packageKey || _path.default.basename(file) !== 'package.json') {
return file;
}
const data = require(file);
delete require.cache[file];
const hasPackageKey = Object.prototype.hasOwnProperty.call(data, options.packageKey);
if (hasPackageKey) {
_this.packageJsonCache.set(file, data);
return file;
}
}
continue;
if (hasPackageKey) {
this.packageJsonCache.set(file, data);
return file;
}
} catch (err) {
_didIteratorError4 = true;
_iteratorError4 = err;
} finally {
try {
if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
_iterator4.return();
}
} finally {
if (_didIteratorError4) {
throw _iteratorError4;
}
}
}
return _this.recusivelyResolve(Object.assign({}, options, {
cwd: _path.default.dirname(options.cwd)
}));
})();
continue;
}
return this.recusivelyResolve(Object.assign({}, options, {
cwd: _path.default.dirname(options.cwd)
}));
}

@@ -164,46 +106,25 @@

var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
for (const filename of options.files) {
const file = _path.default.resolve(options.cwd, filename);
try {
for (var _iterator2 = options.files[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
const filename = _step2.value;
const exists = process.env.NODE_ENV !== 'test' && this.existsCache.has(file) ? this.existsCache.get(file) : pathExistsSync(file);
this.existsCache.set(file, exists);
const file = _path.default.resolve(options.cwd, filename);
if (exists) {
if (!options.packageKey || _path.default.basename(file) !== 'package.json') {
return file;
}
const exists = process.env.NODE_ENV !== 'test' && this.existsCache.has(file) ? this.existsCache.get(file) : pathExistsSync(file);
this.existsCache.set(file, exists);
const data = require(file);
if (exists) {
if (!options.packageKey || _path.default.basename(file) !== 'package.json') {
return file;
}
delete require.cache[file];
const hasPackageKey = Object.prototype.hasOwnProperty.call(data, options.packageKey);
const data = require(file);
delete require.cache[file];
const hasPackageKey = Object.prototype.hasOwnProperty.call(data, options.packageKey);
if (hasPackageKey) {
this.packageJsonCache.set(file, data);
return file;
}
if (hasPackageKey) {
this.packageJsonCache.set(file, data);
return file;
}
}
continue;
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
continue;
}

@@ -216,10 +137,5 @@

resolve(...args) {
var _this2 = this;
return _asyncToGenerator(function* () {
const options = _this2.normalizeOptions(args);
return _this2.recusivelyResolve(options);
})();
async resolve(...args) {
const options = this.normalizeOptions(args);
return this.recusivelyResolve(options);
}

@@ -232,54 +148,55 @@

load(...args) {
var _this3 = this;
runLoaderSync(loader, filepath) {
return loader.loadSync(filepath);
}
return _asyncToGenerator(function* () {
const options = _this3.normalizeOptions(args);
runLoader(loader, filepath) {
if (!loader.load) return loader.loadSync(filepath);
return loader.load(filepath);
}
const filepath = yield _this3.recusivelyResolve(options);
async load(...args) {
const options = this.normalizeOptions(args);
const filepath = await this.recusivelyResolve(options);
if (filepath) {
const loader = _this3.findLoader(filepath);
if (filepath) {
const defaultLoader = {
test: /\.+/,
loadSync: filepath => {
const extname = _path.default.extname(filepath).slice(1);
if (loader) {
return {
path: filepath,
data: yield loader.load(filepath)
};
}
if (extname === 'js') {
delete require.cache[filepath];
return require(filepath);
}
const extname = _path.default.extname(filepath).slice(1);
if (extname === 'json') {
if (this.packageJsonCache.has(filepath)) {
return this.packageJsonCache.get(filepath)[options.packageKey];
}
if (extname === 'js') {
delete require.cache[filepath];
return {
path: filepath,
data: require(filepath)
};
}
if (extname === 'json') {
if (_this3.packageJsonCache.has(filepath)) {
return {
path: filepath,
data: _this3.packageJsonCache.get(filepath)[options.packageKey]
};
const data = this.options.parseJSON(readFileSync(filepath));
return data;
}
const data = _this3.options.parseJSON((yield readFile(filepath)));
return {
path: filepath,
data
};
return readFileSync(filepath);
}
};
const loader = this.findLoader(filepath) || defaultLoader;
let data;
return {
path: filepath,
data: yield readFile(filepath)
};
if (this.loadCache.has(filepath)) {
data = this.loadCache.get(filepath);
} else {
data = await this.runLoader(loader, filepath);
this.loadCache.set(filepath, data);
}
return {};
})();
return {
path: filepath,
data
};
}
return {};
}

@@ -292,34 +209,32 @@

if (filepath) {
const loader = this.findLoader(filepath);
const defaultLoader = {
test: /\.+/,
loadSync: filepath => {
const extname = _path.default.extname(filepath).slice(1);
if (loader) {
return {
path: filepath,
data: loader.loadSync(filepath)
};
}
if (extname === 'js') {
delete require.cache[filepath];
return require(filepath);
}
const extname = _path.default.extname(filepath).slice(1);
if (extname === 'json') {
if (this.packageJsonCache.has(filepath)) {
return this.packageJsonCache.get(filepath)[options.packageKey];
}
if (extname === 'js') {
delete require.cache[filepath];
return {
path: filepath,
data: require(filepath)
};
}
const data = this.options.parseJSON(readFileSync(filepath));
return data;
}
if (extname === 'json') {
if (this.packageJsonCache.has(filepath)) {
return {
path: filepath,
data: this.packageJsonCache.get(filepath)[options.packageKey]
};
return readFileSync(filepath);
}
};
const loader = this.findLoader(filepath) || defaultLoader;
let data;
const data = this.options.parseJSON(readFileSync(filepath));
return {
path: filepath,
data
};
if (this.loadCache.has(filepath)) {
data = this.loadCache.get(filepath);
} else {
data = this.runLoaderSync(loader, filepath);
this.loadCache.set(filepath, data);
}

@@ -329,3 +244,3 @@

path: filepath,
data: readFileSync(filepath)
data
};

@@ -338,27 +253,6 @@ }

findLoader(filepath) {
var _iteratorNormalCompletion3 = true;
var _didIteratorError3 = false;
var _iteratorError3 = undefined;
try {
for (var _iterator3 = this.loaders[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
const loader = _step3.value;
if (loader.test && loader.test.test(filepath)) {
return loader;
}
for (const loader of this.loaders) {
if (loader.test && loader.test.test(filepath)) {
return loader;
}
} catch (err) {
_didIteratorError3 = true;
_iteratorError3 = err;
} finally {
try {
if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
_iterator3.return();
}
} finally {
if (_didIteratorError3) {
throw _iteratorError3;
}
}
}

@@ -372,2 +266,3 @@

this.packageJsonCache.clear();
this.loadCache.clear();
return this;

@@ -374,0 +269,0 @@ }

{
"name": "joycon",
"version": "2.2.5",
"version": "3.0.0",
"description": "Load config with ease.",

@@ -16,4 +16,3 @@ "repository": {

"scripts": {
"test": "npm run lint && jest",
"lint": "xo",
"test": "jest --testPathPattern tests",
"build": "babel src -d lib --no-comments",

@@ -28,26 +27,15 @@ "prepublishOnly": "npm run build"

"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@types/json5": "^0.0.29",
"@types/node": "^9.6.5",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^22.4.3",
"@babel/cli": "^7.13.10",
"@babel/core": "^7.13.10",
"@babel/preset-env": "^7.13.10",
"@egoist/prettier-config": "^0.1.0",
"@types/node": "^14.14.33",
"babel-jest": "^26.6.3",
"babel-plugin-sync": "^0.1.0",
"eslint-config-rem": "^3.0.0",
"jest-cli": "^22.4.3",
"xo": "^0.18.0"
"jest-cli": "^26.6.3",
"prettier": "^2.2.1"
},
"xo": {
"extends": "rem",
"envs": [
"jest"
],
"ignores": [
"lib/**"
]
},
"engines": {
"node": ">=6"
"node": ">=12"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc