Comparing version 0.0.5 to 0.0.6
@@ -20,5 +20,8 @@ { | ||
"path", | ||
"assert" | ||
"assert", | ||
"url", | ||
"punycode", | ||
"querystring" | ||
] | ||
} | ||
} |
@@ -34,3 +34,4 @@ // (The MIT License) | ||
path = require('path'), | ||
parse = require('url').parse; | ||
parse = require('url').parse, | ||
minify = require("uglify-js"); | ||
@@ -44,2 +45,8 @@ /* | ||
/* | ||
* Cache | ||
*/ | ||
var cache = {}; | ||
/** | ||
@@ -71,2 +78,4 @@ * decodeURIComponent. | ||
* @api private | ||
* | ||
* options.minify = true | false | ||
*/ | ||
@@ -81,3 +90,8 @@ | ||
path, | ||
file; | ||
file, | ||
start, // Var for wrapping the raw file | ||
middle, // Var to hold the raw file | ||
end, // Var for wrapping the raw file | ||
rawjs, // Var for the minify process | ||
ast; // Var for the minify process | ||
@@ -114,12 +128,47 @@ options = options || {}; | ||
if (file.name !== 'process') { | ||
res.write("process('" + file.name + "', function(exports, require, module, __filename, __dirname) {\n"); | ||
if (options.cache && cache[file.path]) { | ||
res.end(cache[file.path]); | ||
// console.log('cache hit: ' + file.path); | ||
return; | ||
} | ||
res.write(fs.readFileSync(file.path)); | ||
/* | ||
* Generate the start and end JS for the module | ||
*/ | ||
start = "process('" + file.name + "', function(exports, require, module, __filename, __dirname) {\n"; | ||
middle = fs.readFileSync(file.path, 'utf8'); | ||
end = "\n}, {uri: '" + file.uri + "'});"; | ||
/* | ||
* If the request is for the the "process" do not wrap it. | ||
*/ | ||
if (file.name !== 'process') { | ||
res.write("\n}, {uri: '" + file.uri + "'});"); | ||
rawjs = start + middle + end; | ||
} else { | ||
rawjs = middle; | ||
} | ||
/* | ||
* If the minify option is set to true apply it here. | ||
*/ | ||
if (options.minify) { | ||
ast = minify.parser.parse(rawjs); // parse code and get the initial AST | ||
ast = minify.uglify.ast_mangle(ast); // get a new AST with mangled names | ||
ast = minify.uglify.ast_squeeze(ast); // get an AST with compression optimizations | ||
rawjs = minify.uglify.gen_code(ast); // compressed code here | ||
} | ||
/* | ||
* If the cache option is set store the rawjs here. | ||
*/ | ||
if (options.cache) { | ||
cache[file.path] = rawjs; | ||
} | ||
res.write(rawjs); | ||
res.end(); | ||
@@ -126,0 +175,0 @@ } |
{ | ||
"name": "knot", | ||
"description": "A client side Node experiment.", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"author": { | ||
@@ -14,3 +14,4 @@ "name": "Richard S Allinson", | ||
"dependencies": { | ||
"connect": "1.x" | ||
"connect": "1.x", | ||
"uglify-js": "1.3.x" | ||
}, | ||
@@ -17,0 +18,0 @@ "repository": { |
@@ -98,8 +98,17 @@ # Knot Node | ||
Note: Requires "Query Strings". | ||
Note: Not fully tested yet. Requires "Query Strings". | ||
* url.parse(urlStr, [parseQueryString], [slashesDenoteHost]) | ||
* url.format(urlObj) | ||
* url.resolve(from, to) | ||
### Query Strings | ||
Notes: process.binding('http_parser').urlDecode. Requires "Buffer". | ||
Note: Not fully tested yet. Commented out "process.binding('http_parser').urlDecode" to make it work. | ||
* querystring.stringify(obj, [sep], [eq]) | ||
* querystring.parse(str, [sep], [eq]) | ||
* querystring.escape | ||
* querystring.unescape | ||
### Assertion Testing | ||
@@ -106,0 +115,0 @@ |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
139156
43
3627
146
2
8
+ Addeduglify-js@1.3.x
+ Addeduglify-js@1.3.5(transitive)