Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

electrum-require-components

Package Overview
Dependencies
Maintainers
3
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

electrum-require-components - npm Package Compare versions

Comparing version 1.8.0 to 1.8.1

12

lib/index.js

@@ -15,7 +15,7 @@ 'use strict';

let dashdash = false;
let optionWrap = false;
let optionCrlf = process.platform === 'win32';
var dashdash = false;
var optionWrap = false;
var optionCrlf = process.platform === 'win32';
var args = process.argv.slice(2).filter(arg => {
var args = process.argv.slice(2).filter(function (arg) {
if (dashdash) {

@@ -36,3 +36,3 @@ return !!arg;

const rootDir = _path2.default.join(process.cwd(), args[0]);
var rootDir = _path2.default.join(process.cwd(), args[0]);

@@ -51,2 +51,2 @@ if (args.length < 3) {

(0, _main2.default)(rootDir, args, { optionWrap, optionCrlf });
(0, _main2.default)(rootDir, args, { optionWrap: optionWrap, optionCrlf: optionCrlf });

@@ -31,11 +31,13 @@ 'use strict';

function main(rootDir, args, options) {
const dir = args[1].split(/[\\/]/);
const suffix = args[2];
const outputPath = args.length > 3 ? _path2.default.join(rootDir, args[3]) : null;
var dir = args[1].split(/[\\/]/);
var suffix = args[2];
var outputPath = args.length > 3 ? _path2.default.join(rootDir, args[3]) : null;
function emitWrap(name, filePath, more) {
if (more.length === 0) {
return `Electrum.wrap ('${name}', _${name})`;
return 'Electrum.wrap (\'' + name + '\', _' + name + ')';
} else {
return `Electrum.wrap ('${name}', _${name}, {${more.map(x => `${x}: _${name}$${x}`).join(', ')}})`;
return 'Electrum.wrap (\'' + name + '\', _' + name + ', {' + more.map(function (x) {
return x + ': _' + name + '$' + x;
}).join(', ') + '})';
}

@@ -46,3 +48,3 @@ }

if (options.optionWrap) {
return (0, _sourceEmitter2.default)(result, `import Electrum from 'electrum';`, emitWrap);
return (0, _sourceEmitter2.default)(result, 'import Electrum from \'electrum\';', emitWrap);
} else {

@@ -53,3 +55,3 @@ return (0, _sourceEmitter2.default)(result);

(0, _processDirectory2.default)(rootDir, dir, suffix, (err, result) => {
(0, _processDirectory2.default)(rootDir, dir, suffix, function (err, result) {
if (err) {

@@ -60,3 +62,3 @@ console.error(err);

if (result) {
let source = emitSource(result);
var source = emitSource(result);
if (!outputPath) {

@@ -68,3 +70,3 @@ console.log(source);

}
_fs2.default.writeFile(outputPath, source, err => {
_fs2.default.writeFile(outputPath, source, function (err) {
if (err) {

@@ -71,0 +73,0 @@ console.error(err);

@@ -18,15 +18,39 @@ 'use strict';

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
/******************************************************************************/
function findSuffixes(name, files) {
let result = [];
for (let file of files) {
const regex = new RegExp(`${name}\\.([a-zA-Z]+)\\.js`);
const match = file.match(regex);
if (match) {
if (file.startsWith(name)) {
result.push(match[1]);
var result = [];
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = files[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var file = _step.value;
var regex = new RegExp(name + '\\.([a-zA-Z]+)\\.js');
var match = file.match(regex);
if (match) {
if (file.startsWith(name)) {
result.push(match[1]);
}
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return result;

@@ -45,12 +69,14 @@ }

const filter = new RegExp(suffix.replace('.', '\\.') + '$');
const pattern = new RegExp('([^\\/\\\\]+)' + filter.source);
let result = [];
var filter = new RegExp(suffix.replace('.', '\\.') + '$');
var pattern = new RegExp('([^\\/\\\\]+)' + filter.source);
var result = [];
function extract(dirs, file, files) {
const matches = file.match(pattern);
var matches = file.match(pattern);
if (matches) {
const name = matches[1];
const filePath = [...dirs, file].join('/');
const suffixes = findSuffixes(name, files.filter(x => x !== file));
var name = matches[1];
var filePath = [].concat(_toConsumableArray(dirs), [file]).join('/');
var suffixes = findSuffixes(name, files.filter(function (x) {
return x !== file;
}));
result.push([name, filePath, suffixes]);

@@ -60,7 +86,9 @@ }

traverse(root, dir, extract, err => {
traverse(root, dir, extract, function (err) {
if (err) {
next(err);
} else {
result.sort((a, b) => a[1].localeCompare(b[1]));
result.sort(function (a, b) {
return a[1].localeCompare(b[1]);
});
next(err, result);

@@ -74,20 +102,35 @@ }

function traverse(root, dirs, collect, next) {
const rootPath = _path2.default.join(root, ...dirs);
_fs2.default.lstat(rootPath, (err, stats) => {
var rootPath = _path2.default.join.apply(_path2.default, [root].concat(_toConsumableArray(dirs)));
_fs2.default.lstat(rootPath, function (err, stats) {
if (err) {
next(err);
} else {
_fs2.default.readdir(rootPath, (err, files) => {
let pending = files.length;
for (let file of files) {
const filePath = _path2.default.join(root, ...dirs, file);
_fs2.default.lstat(filePath, (err, stats) => {
if (err) {
next(err);
} else {
if (stats.isDirectory()) {
traverse(root, [...dirs, file], collect, err => {
if (err) {
next(err);
} else {
_fs2.default.readdir(rootPath, function (err, files) {
var pending = files.length;
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
var _loop = function _loop() {
var file = _step2.value;
var filePath = _path2.default.join.apply(_path2.default, [root].concat(_toConsumableArray(dirs), [file]));
_fs2.default.lstat(filePath, function (err, stats) {
if (err) {
next(err);
} else {
if (stats.isDirectory()) {
traverse(root, [].concat(_toConsumableArray(dirs), [file]), collect, function (err) {
if (err) {
next(err);
} else {
if (--pending === 0) {
next();
}
}
});
} else {
if (stats.isFile()) {
collect(dirs, file, files);
if (--pending === 0) {

@@ -97,13 +140,23 @@ next();

}
});
} else {
if (stats.isFile()) {
collect(dirs, file, files);
if (--pending === 0) {
next();
}
}
}
});
};
for (var _iterator2 = files[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
_loop();
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
});
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}

@@ -110,0 +163,0 @@ });

@@ -14,2 +14,4 @@ 'use strict';

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
/******************************************************************************/

@@ -22,15 +24,39 @@

function upper(name) {
return name.split('-').map(x => upperWord(x)).join('');
return name.split('-').map(function (x) {
return upperWord(x);
}).join('');
}
function getImport(name, filePath) {
return `import _${upper(name)} from './${filePath}';`;
return 'import _' + upper(name) + ' from \'./' + filePath + '\';';
}
function getImports(name, filePath, suffixes) {
const dirPath = _path2.default.dirname(filePath);
const list = [getImport(name, filePath)];
for (let suffix of suffixes) {
list.push(getImport(`${upper(name)}$${suffix}`, `${dirPath}/${name}.${suffix}.js`));
var dirPath = _path2.default.dirname(filePath);
var list = [getImport(name, filePath)];
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = suffixes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var suffix = _step.value;
list.push(getImport(upper(name) + '$' + suffix, dirPath + '/' + name + '.' + suffix + '.js'));
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return list;

@@ -40,8 +66,8 @@ }

function getExport(inject, name, filePath, suffixes) {
const Name = upper(name);
var Name = upper(name);
if (inject) {
const more = suffixes;
return `export const ${Name} = ${inject(Name, filePath, more)};`;
var more = suffixes;
return 'export const ' + Name + ' = ' + inject(Name, filePath, more) + ';';
} else {
return `export const ${Name} = _${Name};`;
return 'export const ' + Name + ' = _' + Name + ';';
}

@@ -52,9 +78,31 @@ }

var ret = [];
for (let value of ary) {
if (Array.isArray(value)) {
ret = ret.concat(flatten(value));
} else {
ret.push(value);
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = ary[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var value = _step2.value;
if (Array.isArray(value)) {
ret = ret.concat(flatten(value));
} else {
ret.push(value);
}
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
return ret;

@@ -66,5 +114,9 @@ }

function emit(components, require, inject) {
const imports = flatten(components.map(x => getImports(...x)));
const exports = components.map(x => getExport(inject, ...x));
const head = `'use strict';` + '\n' + (require || '') + '\n';
var imports = flatten(components.map(function (x) {
return getImports.apply(undefined, _toConsumableArray(x));
}));
var exports = components.map(function (x) {
return getExport.apply(undefined, [inject].concat(_toConsumableArray(x)));
});
var head = '\'use strict\';' + '\n' + (require || '') + '\n';
return head + imports.join('\n') + '\n' + exports.join('\n') + '\n';

@@ -71,0 +123,0 @@ }

{
"name": "electrum-require-components",
"version": "1.8.0",
"version": "1.8.1",
"description": "This Electrum build tool generates a source file with a list of requires.",

@@ -34,4 +34,4 @@ "main": "lib/index.js",

"devDependencies": {
"babel-env": "^1.3.1",
"mai-chai": "^3.1.0",
"babel-env": "^1.6.0",
"mai-chai": "^3.3.2",
"react": "^15.4.2",

@@ -38,0 +38,0 @@ "require-self": "^0.1.0",

@@ -1,2 +0,3 @@

'use strict';
/* global global console */
/* eslint no-console: 0 */

@@ -16,3 +17,2 @@ // Provide document and window as globals, so that React can be

/* global global */
global.document = doc;

@@ -19,0 +19,0 @@ global.window = win;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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