New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.7 to 0.1.9

lib/BugPackSourceProcessor.js

234

lib/BugPackContext.js

@@ -10,2 +10,3 @@ //-------------------------------------------------------------------------------

var BugPackLibrary = require('./BugPackLibrary');
var BugPackSourceProcessor = require('./BugPackSourceProcessor');
var BugPackPackage = require('./BugPackPackage');

@@ -48,11 +49,11 @@ var BugPackRegistry = require('./BugPackRegistry');

* @private
* @type {boolean}
* @type {BugPackLibrary}
*/
this.loaded = false;
this.library = new BugPackLibrary();
/**
* @private
* @type {BugPackLibrary}
* @type {boolean}
*/
this.library = new BugPackLibrary();
this.loaded = false;

@@ -67,8 +68,2 @@ /**

* @private
* @type {Object}
*/
this.processedSources = {};
/**
* @private
* @type {Array.<string>}

@@ -89,2 +84,8 @@ */

this.requireStack = [];
/**
* @private
* @type {Object}
*/
this.sourceProcessors = {};
};

@@ -98,2 +99,16 @@

/**
* @return {BugPackApi}
*/
BugPackContext.prototype.getBugPackApi = function() {
return this.bugPackApi;
};
/**
* @return {Array.<string>}
*/
BugPackContext.prototype.getProcessingExportStack = function() {
return this.processingExportStack;
};
/**
* @return {BugPackRegistry}

@@ -121,3 +136,3 @@ */

}
var bugPackKey = this.generateBugPackKey(bugPackKeyString);
var bugPackKey = this.factoryBugPackKey(bugPackKeyString);
this.registerExport(bugPackKey.getPackageName(), bugPackKey.getExportName(), bugPackExport);

@@ -127,2 +142,10 @@ };

/**
* @param {string} bugPackKeyString
* @return {BugPackKey}
*/
BugPackContext.prototype.factoryBugPackKey = function(bugPackKeyString) {
return new BugPackKey(bugPackKeyString);
};
/**
* @param {string} packageName

@@ -176,3 +199,3 @@ * @return {BugPackPackage}

BugPackContext.prototype.loadExport = function(bugPackKeyString, callback) {
var bugPackKey = this.generateBugPackKey(bugPackKeyString);
var bugPackKey = this.factoryBugPackKey(bugPackKeyString);
var registryEntry = this.registry.getEntryByPackageAndExport(bugPackKey.getPackageName(), bugPackKey.getExportName());

@@ -191,3 +214,3 @@ if (registryEntry) {

BugPackContext.prototype.loadExportSync = function(bugPackKeyString) {
var bugPackKey = this.generateBugPackKey(bugPackKeyString);
var bugPackKey = this.factoryBugPackKey(bugPackKeyString);
var registryEntry = this.registry.getEntryByPackageAndExport(bugPackKey.getPackageName(), bugPackKey.getExportName());

@@ -331,2 +354,52 @@ if (registryEntry) {

//-------------------------------------------------------------------------------
// Protected Methods
//-------------------------------------------------------------------------------
/**
* @protected
* @param {string} bugPackKeyString
* @param {function(Error=)} callback
*/
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.processingExportStack)));
} else {
var bugPackKey = this.factoryBugPackKey(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 + "'"));
}
}
};
/**
* @protected
* @param {string} bugPackKeyString
*/
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.processingExportStack));
} else {
var bugPackKey = this.factoryBugPackKey(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 + "'");
}
}
};
//-------------------------------------------------------------------------------
// Private Methods

@@ -395,33 +468,12 @@ //-------------------------------------------------------------------------------

* @private
* @param {string} bugPackKeyString
* @return {BugPackKey}
*/
BugPackContext.prototype.generateBugPackKey = function(bugPackKeyString) {
return new BugPackKey(bugPackKeyString);
};
/**
* @private
* @param {BugPackSource} bugPackSource
* @return {boolean}
* @return {BugPackSourceProcessor}
*/
BugPackContext.prototype.hasProcessedSource = function(bugPackSource) {
return !!this.processedSources[bugPackSource.getSourceFilePath()];
};
/**
* @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();
BugPackContext.prototype.generateBugPackSourceProcessor = function(bugPackSource) {
var sourceProcessor = this.sourceProcessors[bugPackSource.getSourceFilePath()];
if (!sourceProcessor) {
sourceProcessor = new BugPackSourceProcessor(bugPackSource, this);
this.sourceProcessors[bugPackSource.getSourceFilePath()] = sourceProcessor;
}
return sourceProcessor;
};

@@ -431,15 +483,2 @@

* @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

@@ -485,23 +524,7 @@ */

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 {
this.loadBugPackSource(bugPackSource, callback);
var sourceProcessor = this.generateBugPackSourceProcessor(bugPackSource);
if (!sourceProcessor.hasProcessed()) {
sourceProcessor.addProcessedCallback(callback);
if (!sourceProcessor.hasProcessingStarted()) {
sourceProcessor.process();
}

@@ -518,56 +541,13 @@ } else {

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);
}
};
var sourceProcessor = this.generateBugPackSourceProcessor(bugPackSource);
if (!sourceProcessor.hasProcessed()) {
/**
* @private
* @param {string} bugPackKeyString
* @param {function(Error=)} callback
*/
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.processingExportStack)));
//TODO BRN: What do we do if this is the case?
//if (!sourceProcessor.hasProcessingStarted()) {
sourceProcessor.processSync();
//}
} 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.processBugPackSource(bugPackSource, callback);
this.processingExportStack.pop();
} else {
callback(new Error("Cannot find registry entry '" + bugPackKeyString + "'"));
}
}
};
/**
* @private
* @param {string} bugPackKeyString
*/
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.processingExportStack));
} 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 + "'");
}
}

@@ -593,3 +573,3 @@ };

var requiredObject = undefined;
var bugPackKey = this.generateBugPackKey(bugPackKeyString);
var bugPackKey = this.factoryBugPackKey(bugPackKeyString);
if (bugPackKey.isWildCard()) {

@@ -596,0 +576,0 @@ requiredObject = this.requirePackage(bugPackKey);

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

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

{
"name": "bugpack",
"version": "0.1.7",
"version": "0.1.9",
"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