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

bugpack

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bugpack - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

375

lib/BugPackContext.js

@@ -31,3 +31,3 @@ //-------------------------------------------------------------------------------

*/
this.autoloaded = false;
this.autoloaded = false;

@@ -38,3 +38,3 @@ /**

*/
this.bugPackApi = bugPackApi;
this.bugPackApi = bugPackApi;

@@ -45,3 +45,3 @@ /**

*/
this.generated = false;
this.generated = false;

@@ -52,3 +52,3 @@ /**

*/
this.loaded = false;
this.loaded = false;

@@ -59,21 +59,21 @@ /**

*/
this.library = new BugPackLibrary();
this.library = new BugPackLibrary();
/**
* @private
* @type {Array.<string>}
* @type {string}
*/
this.loadStack = [];
this.moduleTopDir = moduleTopDir;
/**
* @private
* @type {string}
* @type {Object}
*/
this.moduleTopDir = moduleTopDir;
this.processedSources = {};
/**
* @private
* @type {Object}
* @type {Array.<string>}
*/
this.processedSources = {};
this.processingExportStack = [];

@@ -84,3 +84,3 @@ /**

*/
this.registry = new BugPackRegistry();
this.registry = new BugPackRegistry();

@@ -91,3 +91,3 @@ /**

*/
this.requireStack = [];
this.requireStack = [];
};

@@ -113,58 +113,2 @@

/**
* @param {function(Error=)} callback
*/
BugPackContext.prototype.autoload = function(callback) {
var _this = this;
if (!this.autoloaded) {
this.autoloaded = true;
var registry = this.getRegistry();
var registryEntries = registry.getRegistryEntries();
var autoloadCount = 0;
var autoloadCompletedCount = 0;
var allEntriesProcessed = false;
var autoloadComplete = false;
registryEntries.forEach(function(registryEntry) {
if (registryEntry.getAutoload()) {
autoloadCount++;
var bugPackSource = registryEntry.getBugPackSource();
_this.loadSource(bugPackSource, function(error) {
if (!error) {
autoloadCompletedCount++;
if (autoloadCompletedCount === autoloadCount && allEntriesProcessed && !autoloadComplete) {
autoloadComplete = true;
callback();
}
} else {
callback(error);
}
});
}
});
allEntriesProcessed = true;
if (autoloadCompletedCount === autoloadCount && allEntriesProcessed && !autoloadComplete) {
autoloadComplete = true;
callback();
}
}
};
/**
*
*/
BugPackContext.prototype.autoloadSync = function() {
var _this = this;
if (!this.autoloaded) {
this.autoloaded = true;
var registry = this.getRegistry();
var registryEntries = registry.getRegistryEntries();
registryEntries.forEach(function(registryEntry) {
if (registryEntry.getAutoload()) {
var bugPackSource = registryEntry.getBugPackSource();
_this.loadSourceSync(bugPackSource);
}
});
}
};
/**
* @param {string} bugPackKeyString

@@ -233,14 +177,7 @@ * @param {*} bugPackExport

BugPackContext.prototype.loadExport = function(bugPackKeyString, callback) {
var bugPackKey = this.generateBugPackKey(bugPackKeyString);
var registryEntry = this.registry.getEntryByPackageAndExport(bugPackKey.getPackageName(), bugPackKey.getExportName());
var bugPackKey = this.generateBugPackKey(bugPackKeyString);
var registryEntry = this.registry.getEntryByPackageAndExport(bugPackKey.getPackageName(), bugPackKey.getExportName());
if (registryEntry) {
var bugPackSource = registryEntry.getBugPackSource();
if (this.loadStack.indexOf(bugPackKeyString) !== -1) {
callback(new Error("Circular dependency in load calls. Requiring '" + bugPackKeyString + "' which is already in the " +
"load stack. " + JSON.stringify(this.loadStack)));
} else {
this.loadStack.push(bugPackKeyString);
this.loadSource(bugPackSource, callback);
this.loadStack.pop();
}
this.processBugPackSource(bugPackSource, callback);
} else {

@@ -259,10 +196,3 @@ callback(new Error("Cannot find registry entry '" + bugPackKeyString + "'"));

var bugPackSource = registryEntry.getBugPackSource();
if (this.loadStack.indexOf(bugPackKeyString) !== -1) {
throw new Error("Circular dependency in load calls. Requiring '" + bugPackKeyString + "' which is already in the " +
"load stack. " + JSON.stringify(this.loadStack));
} else {
this.loadStack.push(bugPackKeyString);
this.loadSourceSync(bugPackSource);
this.loadStack.pop();
}
this.processBugPackSourceSync(bugPackSource);
} else {

@@ -320,2 +250,75 @@ throw new Error("Cannot find registry entry '" + bugPackKeyString + "'");

/**
* @param {string} sourceFilePath
* @param {function(Error=)} callback
*/
BugPackContext.prototype.loadSource = function(sourceFilePath, callback) {
var registryEntry = this.registry.getEntryBySourceFilePath(sourceFilePath);
if (registryEntry) {
var bugPackSource = registryEntry.getBugPackSource();
this.processBugPackSource(bugPackSource, callback);
} else {
callback(new Error("Cannot find registry entry for source file '" + sourceFilePath + "'"));
}
};
/**
* @param {string} sourceFilePath
*/
BugPackContext.prototype.loadSourceSync = function(sourceFilePath) {
var registryEntry = this.registry.getEntryBySourceFilePath(sourceFilePath);
if (registryEntry) {
var bugPackSource = registryEntry.getBugPackSource();
this.processBugPackSourceSync(bugPackSource);
} else {
throw new Error("Cannot find registry entry for source file '" + sourceFilePath + "'");
}
};
/**
* @param {Array.<string>} sourceFilePaths
* @param {function(Error=)} callback
*/
BugPackContext.prototype.loadSources = function(sourceFilePaths, callback) {
var _this = this;
var loadCount = 0;
var error = null;
if (sourceFilePaths instanceof Array) {
var expectedCount = sourceFilePaths.length;
if (expectedCount > 0) {
sourceFilePaths.forEach(function(sourceFilePath) {
_this.loadSource(sourceFilePath, function(returnedError) {
loadCount++;
if (returnedError) {
error = returnedError;
}
if (loadCount === expectedCount) {
callback(error);
}
});
});
} else {
callback();
}
} else {
callback(new Error("sourceFilePaths must be an Array"));
}
};
/**
* @param {Array.<string>} sourceFilePaths
* @param {function(Error=)} callback
*/
BugPackContext.prototype.loadSourcesSync = function(sourceFilePaths, callback) {
var _this = this;
if (sourceFilePaths instanceof Array) {
sourceFilePaths.forEach(function(sourceFilePath) {
_this.loadSourceSync(sourceFilePath);
});
} else {
throw new Error("sourceFilePaths must be an Array");
}
};
/**
* @param {string} bugPackKeyString

@@ -333,4 +336,62 @@ * @return {*}

/**
* @private
* @param {function(Error=)} callback
*/
BugPackContext.prototype.autoload = function(callback) {
var _this = this;
if (!this.autoloaded) {
this.autoloaded = true;
var registry = this.getRegistry();
var registryEntries = registry.getRegistryEntries();
var autoloadCount = 0;
var autoloadCompletedCount = 0;
var allEntriesProcessed = false;
var autoloadComplete = false;
registryEntries.forEach(function(registryEntry) {
if (registryEntry.getAutoload()) {
autoloadCount++;
var bugPackSource = registryEntry.getBugPackSource();
_this.processBugPackSource(bugPackSource, function(error) {
if (!error) {
autoloadCompletedCount++;
if (autoloadCompletedCount === autoloadCount && allEntriesProcessed && !autoloadComplete) {
autoloadComplete = true;
callback();
}
} else {
callback(error);
}
});
}
});
allEntriesProcessed = true;
if (autoloadCompletedCount === autoloadCount && allEntriesProcessed && !autoloadComplete) {
autoloadComplete = true;
callback();
}
}
};
/**
* @private
*/
BugPackContext.prototype.autoloadSync = function() {
var _this = this;
if (!this.autoloaded) {
this.autoloaded = true;
var registry = this.getRegistry();
var registryEntries = registry.getRegistryEntries();
registryEntries.forEach(function(registryEntry) {
if (registryEntry.getAutoload()) {
var bugPackSource = registryEntry.getBugPackSource();
_this.processBugPackSourceSync(bugPackSource);
}
});
}
};
/**
* @private
* @param {string} bugPackKeyString

@@ -354,4 +415,34 @@ * @return {BugPackKey}

* @private
* @param {BugPackSource} bugPackSource
* @param {function(Error=)} callback
*/
BugPackContext.prototype.loadBugPackSource = function(bugPackSource, callback) {
if (!bugPackSource.hasLoaded()) {
bugPackSource.addLoadCallback(callback);
if (!bugPackSource.hasLoadStarted()) {
this.bugPackApi.setCurrentContext(this);
bugPackSource.load();
}
} else {
callback();
}
};
/**
* @private
* @param {BugPackSource} bugPackSource
*/
BugPackContext.prototype.loadBugPackSourceSync = function(bugPackSource) {
if (!bugPackSource.hasLoaded()) {
if (!bugPackSource.hasLoadStarted()) {
this.bugPackApi.setCurrentContext(this);
bugPackSource.loadSync();
}
}
};
/**
* @private
* @param {function(Error=)} callback
*/
BugPackContext.prototype.loadRegistry = function(callback) {

@@ -389,2 +480,3 @@ var _this = this;

/**

@@ -395,8 +487,24 @@ * @private

*/
BugPackContext.prototype.loadSource = function(bugPackSource, callback) {
if (!bugPackSource.hasLoaded()) {
if (!bugPackSource.hasLoadStarted() && !this.hasProcessedSource(bugPackSource)) {
this.processSource(bugPackSource, callback);
BugPackContext.prototype.processBugPackSource = function(bugPackSource, callback) {
if (!this.hasProcessedSource(bugPackSource)) {
var _this = this;
var registryEntry = this.registry.getEntryBySourceFilePath(bugPackSource.getSourceFilePath());
var requiredExports = registryEntry.getRequires();
this.processedSources[bugPackSource.getSourceFilePath()] = true;
if (requiredExports.length > 0) {
var loadedExportsCount = 0;
requiredExports.forEach(function(requiredExport) {
_this.processExport(requiredExport, function(error) {
if (!error) {
loadedExportsCount++;
if (loadedExportsCount === requiredExports.length) {
_this.loadBugPackSource(bugPackSource, callback);
}
} else {
callback(error);
}
});
});
} else {
bugPackSource.addLoadCallback(callback);
this.loadBugPackSource(bugPackSource, callback);
}

@@ -412,7 +520,12 @@ } else {

*/
BugPackContext.prototype.loadSourceSync = function(bugPackSource) {
if (!bugPackSource.hasLoaded()) {
if (!bugPackSource.hasLoadStarted() && !this.hasProcessedSource(bugPackSource)) {
this.processSourceSync(bugPackSource);
}
BugPackContext.prototype.processBugPackSourceSync = function(bugPackSource) {
if (!this.hasProcessedSource(bugPackSource)) {
var _this = this;
var registryEntry = this.registry.getEntryBySourceFilePath(bugPackSource.getSourceFilePath());
var requiredExports = registryEntry.getRequires();
this.processedSources[bugPackSource.getSourceFilePath()] = true;
requiredExports.forEach(function(requiredExport) {
_this.processExportSync(requiredExport);
});
this.loadBugPackSourceSync(bugPackSource);
}

@@ -423,30 +536,20 @@ };

* @private
* @param {BugPackSource} bugPackSource
* @param {string} bugPackKeyString
* @param {function(Error=)} callback
*/
BugPackContext.prototype.processSource = function(bugPackSource, callback) {
var _this = this;
this.processedSources[bugPackSource.getSourceFilePath()] = true;
var registryEntry = this.registry.getEntryBySourceFilePath(bugPackSource.getSourceFilePath());
var requiredExports = registryEntry.getRequires();
if (requiredExports.length > 0) {
var loadedExportsCount = 0;
requiredExports.forEach(function(requiredExport) {
_this.loadExport(requiredExport, function(error) {
if (!error) {
loadedExportsCount++;
if (loadedExportsCount === requiredExports.length) {
_this.bugPackApi.setCurrentContext(_this);
bugPackSource.addLoadCallback(callback);
bugPackSource.load();
}
} else {
callback(error);
}
});
});
BugPackContext.prototype.processExport = function(bugPackKeyString, callback) {
if (this.processingExportStack.indexOf(bugPackKeyString) !== -1) {
callback(new Error("Circular dependency in load calls. Requiring '" + bugPackKeyString + "' which is already in the " +
"load stack. " + JSON.stringify(this.loadStack)));
} else {
this.bugPackApi.setCurrentContext(this);
bugPackSource.addLoadCallback(callback);
bugPackSource.load();
var bugPackKey = this.generateBugPackKey(bugPackKeyString);
var registryEntry = this.registry.getEntryByPackageAndExport(bugPackKey.getPackageName(), bugPackKey.getExportName());
if (registryEntry) {
var bugPackSource = registryEntry.getBugPackSource();
this.processingExportStack.push(bugPackKeyString);
this.processBugPackSource(bugPackSource, callback);
this.processingExportStack.pop();
} else {
callback(new Error("Cannot find registry entry '" + bugPackKeyString + "'"));
}
}

@@ -457,14 +560,20 @@ };

* @private
* @param {BugPackSource} bugPackSource
* @param {string} bugPackKeyString
*/
BugPackContext.prototype.processSourceSync = function(bugPackSource) {
var _this = this;
this.processedSources[bugPackSource.getSourceFilePath()] = true;
var registryEntry = this.registry.getEntryBySourceFilePath(bugPackSource.getSourceFilePath());
var requiredExports = registryEntry.getRequires();
requiredExports.forEach(function(requiredExport) {
_this.loadExportSync(requiredExport);
});
this.bugPackApi.setCurrentContext(this);
bugPackSource.loadSync();
BugPackContext.prototype.processExportSync = function(bugPackKeyString) {
if (this.processingExportStack.indexOf(bugPackKeyString) !== -1) {
throw new Error("Circular dependency in load calls. Requiring '" + bugPackKeyString + "' which is already in the " +
"load stack. " + JSON.stringify(this.loadStack));
} else {
var bugPackKey = this.generateBugPackKey(bugPackKeyString);
var registryEntry = this.registry.getEntryByPackageAndExport(bugPackKey.getPackageName(), bugPackKey.getExportName());
if (registryEntry) {
var bugPackSource = registryEntry.getBugPackSource();
this.processingExportStack.push(bugPackKeyString);
this.processBugPackSourceSync(bugPackSource);
this.processingExportStack.pop();
} else {
throw new Error("Cannot find registry entry '" + bugPackKeyString + "'");
}
}
};

@@ -471,0 +580,0 @@

//-------------------------------------------------------------------------------
// Annotations
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
// Declare Class
//-------------------------------------------------------------------------------
/**
* @constructor
* @param {string} name
*/
var BugPackPackage = function(name) {

@@ -11,0 +10,0 @@

{
"name": "bugpack",
"version": "0.1.2",
"version": "0.1.3",
"description": "Package loader to help make browser and node js package loading consistent",

@@ -5,0 +5,0 @@ "main": "./lib/BugPackApi.js",

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