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

js-loader

Package Overview
Dependencies
Maintainers
0
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-loader - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

test/.jsloader.js.swp

49

jsloader.js

@@ -5,3 +5,3 @@ var fs = require('fs'),

var JSLoader = function(srcDirs) {
var JSLoader = function(srcDirs, opt) {
if (srcDirs.length == 0) {

@@ -11,4 +11,19 @@ throw new Error('no source directories provided');

this.srcDirs = srcDirs;
this.initOptions();
this.setOptions(opt);
};
JSLoader.prototype.initOptions = function() {
this.opt = {
debug: false
};
};
JSLoader.prototype.setOptions = function(opt) {
opt = opt || {};
for (var key in opt) {
this.opt[key] = opt[key];
}
};
JSLoader.prototype.getContent = function(files, callback) {

@@ -21,2 +36,11 @@ var self = this;

this.readFilesWithDependencies(files, function(err, fileDataList, fileDataMap) {
var i, fileNames;
if (self.opt.debug) {
fileNames = [];
for (i = 0; i < fileDataList.length; i++) {
fileNames.push(fileDataList[i].file);
}
util.print('File Names: ' + fileNames.join(', ') + "\n");
util.print('srcDirs' + self.srcDirs.join(', ') + "\n");
}
var content = self.getFileContentInOrderByDependencies(fileDataList, fileDataMap);

@@ -35,8 +59,17 @@ callback(null, content);

if (self.opt.debug) {
util.print("Reading files with dependencies. fileIdx: " + fileIdx + "\n");
}
//don't repeat files we've already processed
if (fileDataMap[file]) {
if (++fileIdx < files.length) {
readFileWithDependencies(fileIdx);
if (fileIdx < files.length - 1) {
readFileWithDependencies(fileIdx + 1);
return;
} else {
if (self.opt.debug) {
util.print("Calling callback after reading files with dependencies (upper call)\n");
}
callback(null, fileDataList, fileDataMap);
return;
}

@@ -58,6 +91,11 @@ }

if (++fileIdx < files.length) {
readFileWithDependencies(fileIdx);
if (fileIdx < files.length - 1) {
readFileWithDependencies(fileIdx + 1);
return;
} else {
if (self.opt.debug) {
util.print("Calling callback after reading files with dependencies (lower call)\n");
}
callback(null, fileDataList, fileDataMap);
return;
}

@@ -106,2 +144,3 @@ });

fileData = this.removeNextFileData(fileDataList);
//content += '// File: ' + fileData.file + "\n";
content += fileData.content;

@@ -108,0 +147,0 @@ }

4

package.json
{
"name": "js-loader",
"description": "On-the-fly javascript contacatenator/minifier with dependency resolution. Happens to be written in node.js, but is by no means limited to node.js projects.",
"version": "0.0.1",
"description": "On-the-fly javascript contacatenator, minifier and dependency resolver for client-side JS",
"version": "0.0.2",
"homepage": "https://github.com/dmcquay/node-js-loader",

@@ -6,0 +6,0 @@ "repository": "git://github.com/dmcquay/node-js-loader.git",

var vows = require('vows'),
assert = require('assert'),
JSLoader = require('.././jsloader.js').JSLoader,
testSrcDirs = ['./test/test-src-1', './test/test-src-2'];
testSrc = './test/test-src',
testSrcDirs = [testSrc + '/test-src-1', testSrc + '/test-src-2'];

@@ -77,3 +78,36 @@ vows.describe('JSLoader').addBatch({

}
},
'the result of getContent with a duplicate dependency': {
topic: function() {
var loader = new JSLoader([testSrc + '/duplicate-dependency']);
loader.getContent(['a.js', 'c.js'], this.callback);
},
'contains the content of the dependency only once': function(topic) {
assert.equal(topic, "c\nb\na\n");
}
},
'the result of getContent with multiple dependencies in one file': {
topic: function() {
var loader = new JSLoader([testSrc + '/multi-dependencies']);
loader.getContent(['a.js'], this.callback);
},
'contains both dependencies': function(topic) {
assert.equal(topic, "b\nc\na\n");
}
},
'the result of getContent in complex example (chat)': {
topic: function() {
var loader = new JSLoader([testSrc + '/chat']);
loader.getContent(['chat.js'], this.callback);
},
'contains correct output': function(topic) {
assert.equal(topic, "vend/jquery-1.4.2.min.js\nvend/jquery.cookie.js\nPCHAT/controller/Chat.js\nchat.js\n");
}
}
}).export(module);
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