New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

knot

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

knot - npm Package Compare versions

Comparing version 0.0.6 to 0.0.7

.npmignore

2

examples/simple_module/lib/math.js

@@ -34,4 +34,4 @@ // (The MIT License)

while (i < l) {
sum += args[i];
i = i + 1;
sum += args[i];
}

@@ -38,0 +38,0 @@

@@ -18,3 +18,2 @@ {

"events",
"stream",
"path",

@@ -24,5 +23,6 @@ "assert",

"punycode",
"querystring"
"querystring",
"dummy"
]
}
}

@@ -24,2 +24,6 @@ // (The MIT License)

/*global XMLHttpRequest: true, ActiveXObject: true, document: true, window: true, navigator: true*/
//'use strict';
/*

@@ -29,4 +33,4 @@ * The main "process" namespace variable.

var process = (function(){
var process = (function () {
/*

@@ -38,3 +42,3 @@ * This function eval's module code in the process scope.

*/
function evalModuleInScope(js) {

@@ -50,5 +54,5 @@ eval(js);

*/
return function(){
return (function () {
/*

@@ -64,15 +68,12 @@ * Provide the XMLHttpRequest constructor for Internet Explorer 5.x-6.x:

if (typeof XMLHttpRequest === "undefined") {
XMLHttpRequest = function() {
XMLHttpRequest = function () {
try {
return new ActiveXObject("Msxml2.XMLHTTP.6.0");
}
catch (e) {}
} catch (e) {}
try {
return new ActiveXObject("Msxml2.XMLHTTP.3.0");
}
catch (e) {}
} catch (er) {}
try {
return new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {}
} catch (err) {}
//Microsoft.XMLHTTP points to Msxml2.XMLHTTP and is redundant

@@ -84,2 +85,29 @@ throw new Error("This browser does not support XMLHttpRequest.");

/*
*
*/
function getModuleParentPath(id) {
return ClientModule.modules[id].filename.split('/').slice(0, -1).join('/');
}
/*
*
*/
function resolveFilename(id, parentPath) {
if (id.charAt(0) === '.') {
if (!parentPath) {
// This value must match "ROOT_PKG" in node.js
parentPath = '_root_';
}
id = ClientModule.require('path').join(parentPath, id);
}
return id;
}
/*
* ClientModule

@@ -90,3 +118,3 @@ *

*/
function ClientModule(id) {

@@ -118,5 +146,5 @@ this.id = id;

*/
ClientModule.require = function(id, parentPath) {
ClientModule.require = function (id, parentPath) {
var cached,

@@ -128,5 +156,4 @@ clientModule;

*/
if (id.charAt(0) === '.') {
id = ClientModule.require('path').join(parentPath, id);
}
id = resolveFilename(id, parentPath);

@@ -139,3 +166,7 @@ cached = ClientModule.getCached(id);

if (id) {
/*
* If the module was not cached we load it here for the first time.
*/
if (id && ClientModule.exists(id) === false) {
ClientModule.load(id);

@@ -162,6 +193,6 @@ }

*/
ClientModule.getCached = function(id) {
ClientModule.getCached = function (id) {
return ClientModule.cache[id];
}
};

@@ -177,3 +208,3 @@ /*

*
* @param {string} id
* @param {string|array} id
* @param {function} callback

@@ -183,6 +214,6 @@ * @api private

ClientModule.load = function(id, callback) {
ClientModule.load = function (id, callback) {
var uri = process.installPrefix + id + '.js',
script;
var ids = id,
uris = [];

@@ -194,37 +225,36 @@ if (!id) {

/*
* If no callback is given load the script synchronously.
* If we were given a string "id" convert it to an array.
*/
if (!callback) {
script = new XMLHttpRequest();
script.open("GET", uri, false);
script.send(null);
evalModuleInScope(script.responseText);
return;
if (typeof ids === 'string') {
ids = [id];
}
/*
* Otherwise load it asynchronously.
* Now loop over all the "ids" and load them.
*/
script = document.createElement("script");
script.type = "text/javascript";
if (script.readyState) { //IE
script.onreadystatechange = function() {
if (script.readyState == "loaded" || script.readyState == "complete"){
script.onreadystatechange = null;
callback();
}
};
} else { //Others
script.onload = function() {
callback();
};
}
ids.forEach(function (id) {
var uri = process.installPrefix + id + '.js',
script;
if (!callback) {
// If no callback is given load the script synchronously.
script = new XMLHttpRequest();
script.open("GET", uri, false);
script.send(null);
evalModuleInScope(script.responseText);
} else {
// Otherwise add the uri to the loading list
uris.push(uri);
}
});
script.src = uri;
/*
* If we have any "uris" load them asynchronously using LAB.js.
*/
document.body.appendChild(script);
}
if (uris.length > 0) {
$LAB.script(uris).wait(callback);
}
};

@@ -238,5 +268,5 @@ /*

ClientModule.exists = function(id) {
ClientModule.exists = function (id) {
return ClientModule.modules.hasOwnProperty(id);
}
};

@@ -248,5 +278,5 @@ /*

*/
ClientModule.prototype.compile = function() {
ClientModule.prototype.compile = function () {
var module = this,

@@ -256,6 +286,9 @@ dirname;

module.uri = ClientModule.modules[module.id].uri;
dirname = module.uri.split('/').slice(0, -1).join('/');
// If the the filename is empty then use the uri
module.filename = ClientModule.modules[module.id].filename || module.uri;
// Get the directory of the module to use as the root for any other relative require calls.
dirname = getModuleParentPath(module.id);
// Doing this so I can pass the parent dirname to require.
module.require = function(id) {
module.require = function (id) {
return ClientModule.require(id, dirname);

@@ -272,4 +305,4 @@ };

*/
ClientModule.prototype.cache = function() {
ClientModule.prototype.cache = function () {
ClientModule.cache[this.id] = this;

@@ -287,7 +320,8 @@ };

*/
ClientModule.prototype.deprecate = function(method, message) {
var original = this.exports[method];
var self = this;
var warned = false;
ClientModule.prototype.deprecate = function (method, message) {
var original = this.exports[method],
self = this,
warned = false;
message = message || '';

@@ -297,3 +331,3 @@

enumerable: false,
value: function() {
value: function () {
if (!warned) {

@@ -304,6 +338,7 @@ warned = true;

var moduleIdCheck = new RegExp('\\b' + self.id + '\\b');
if (moduleIdCheck.test(process.env.NODE_DEBUG))
if (moduleIdCheck.test(process.env.NODE_DEBUG)) {
console.trace(message);
else
} else {
console.error(message);
}

@@ -328,4 +363,6 @@ self.exports[method] = original;

var parentPath;
if (typeof id === 'function') {
meta = func
meta = func;
func = id;

@@ -335,3 +372,3 @@ id = '';

if (typeof name !== 'string') {
if (typeof id !== 'string') {
throw new Error('First argument must be a string representing the name of the module.');

@@ -341,3 +378,4 @@ }

if (ClientModule.exists(id)) {
throw new Error('Module "' + id + '" has already been loaded.');
// throw new Error('Module "' + id + '" has already been loaded.');
return;
}

@@ -356,3 +394,3 @@

*/
if (!meta) {

@@ -366,8 +404,11 @@ meta = {

* Add the module to the "modules" map.
*
* This data is read in ClientModule.compile()
*/
ClientModule.modules[id] = {
uri: meta.uri,
filename: meta.filename || meta.uri,
func: func
}
};

@@ -378,10 +419,34 @@ /*

if (id === '') {
ClientModule.require(id);
function callback() {
if (id === '') {
ClientModule.require(id);
}
}
}
}();
})();
/*
* Load any modules found in meta.requires
*/
if (meta.requires && meta.requires.length > 0) {
// Get the directory of the module to use as the root for any other relative require calls.
parentPath = getModuleParentPath(id);
// Now loop over any modules we have and expand their module ids.
meta.requires.forEach(function (moduleId, pos) {
// Make the paths relative to the current module
if (moduleId.charAt(0) === '.') {
meta.requires[pos] = resolveFilename(moduleId, parentPath);
}
});
// ClientModule.load(meta.requires, callback);
} else {
callback();
}
};
}());
}());
/*

@@ -391,8 +456,8 @@ * Prime the "process" variable as best we can.

(function(){
(function () {
/*
* The standard node functions attached to "process".
*/
var start = new Date().getSeconds(),

@@ -418,6 +483,6 @@ stream = {},

*/
for (name in functions) {
if (functions.hasOwnProperty(name)) {
process[functions[name]] = function() {
process[functions[name]] = function () {
throw new Error('Function is not available in Knot.');

@@ -431,7 +496,7 @@ };

*/
stream.writable = true;
stream.destroy = function() {};
stream.destroySoon = function() {};
stream.write = function(string) {
stream.destroy = function () {};
stream.destroySoon = function () {};
stream.write = function (string) {
if (typeof string === 'Buffer') {

@@ -442,3 +507,3 @@ string = string.toString();

};
stream.end = function(string) {
stream.end = function (string) {
stream.write(string);

@@ -450,3 +515,3 @@ };

*/
process.stdout = stream;

@@ -457,3 +522,3 @@ process.stderr = stream;

process.execPath = window.location.pathname;
process.cwd = function() {
process.cwd = function () {
return process.execPath;

@@ -472,3 +537,3 @@ };

process.platform = navigator.platform;
process.uptime = function() {
process.uptime = function () {
var cur = new Date().getSeconds();

@@ -475,0 +540,0 @@ return cur - start;

@@ -42,3 +42,4 @@ // (The MIT License)

var PACKAGE = 'package.json',
KNOT_PREFIX = '/knot/';
KNOT_PREFIX = '/knot/',
ROOT_PKG = '_root_';

@@ -87,3 +88,3 @@ /*

url,
path,
//path,
file,

@@ -115,6 +116,17 @@ start, // Var for wrapping the raw file

url = parse(options.path);
path = decode(url.pathname);
file = options.modules[path];
//path = decode(url.pathname);
file = options.modules[decode(url.pathname)];
/*
* If no file is found but the URL starts with "/knot" serve a dummy.js file.
* This is so the client side code keeps running as this file could
* have be auto detected by mistake.
*/
if (!file && decode(url.pathname).indexOf('/knot') === 0) {
console.log('Warning: Node module not found for url "'+decode(url.pathname) + '"');
file = options.modules['/knot/dummy.js'];
}
/*
* If the value of file is empty, return.

@@ -139,12 +151,16 @@ */

middle = fs.readFileSync(file.path, 'utf8');
end = "\n}, {uri: '" + file.uri + "'});";
end = "\n}, " + JSON.stringify({
uri: file.uri,
filename: file.filename,
requires: file.requires
}) + ");";
rawjs = start + middle + end;
/*
* If the request is for the the "process" do not wrap it.
* If the request is for the the "process" we do something special.
*/
if (file.name !== 'process') {
rawjs = start + middle + end;
} else {
rawjs = middle;
if (file.name === 'process') {
// Here we take the raw file and then append LAB.js to it.
rawjs = middle + '\n' + fs.readFileSync(path.join(__dirname, '../labjs/LAB.js'), 'utf8');
}

@@ -177,2 +193,70 @@

/*
* Given some meta data this function will add an entry to the module object.
* It will also attempt to find any required modules in the file using regex.
*
* @private
* @method makeModuleMapEntry
* @param {string} dir
* @param {string} uri
* @param {string} filename
* @param {string} name
* @param {string} file
* @param {object} modules
* @return {object}
*
* {
* name: name,
* path: {string},
* uri: uri,
* filename: filename,
* requires: array
* }
*/
function makeModuleMapEntry(dir, uri, filename, name, file, modules) {
var filepath = path.join(dir, file + '.js'),
rawjs,
requires;
/*
* Here we try and find any required modules using "regex"
*/
try {
rawjs = fs.readFileSync(filepath, 'utf8');
} catch (err) {
console.log('Module "' + name + '" not found at: ' + filepath);
return {};
}
requires = rawjs.match(/require\(('|")(.*?)('|")\)/g);
if (requires) {
requires.forEach(function (require, pos) {
requires[pos] = require.match(/['|"](.*)['|"]/)[1];
// console.log(requires[pos]);
});
} else {
// If there is nothing found reset the "requires" var to "undefined"
// so it does not get processed if JSON.stringify() is used later.
requires = undefined;
}
// console.log(JSON.stringify(requires, null,4));
/*
* With all the information now collected we build the final object.
*/
modules[KNOT_PREFIX + uri] = {
name: name,
path: filepath,
uri: uri,
filename: filename,
requires: requires
};
return modules[KNOT_PREFIX + uri];
}
/*
* This function looks for a <dir>/package.json file. If one is found it then

@@ -205,9 +289,10 @@ * sees if there is a knot entry and each file it finds it adds to the

function parsePackage(dir, modules) {
function parsePackage(dir, modules, HACK) {
var pack,
name,
name = HACK, // this may not be set so do it here
files,
file,
uri;
uri,
filename;

@@ -221,4 +306,11 @@ try {

name = pack.name;
/*
* Get the package name from package.json.
* However, if we were given a package name don't do anything.
*/
if (!name) {
name = pack.name;
}
if (pack.knot) {

@@ -229,21 +321,23 @@ if (pack.knot.modules) {

if (files.hasOwnProperty(file)) {
// Add the file to the modules map.
uri = (name ? name + '/' : '') + files[file] + '.js';
modules[KNOT_PREFIX + uri] = {
name: (name ? name + '/' : '') + files[file],
path: path.join(dir, files[file] + '.js'),
uri: uri
};
// Generate the knot filename for this module.
filename = (name ? name + '/' : '') + files[file] + '.js';
// Add the file to the modules map. We use the filename as the URL here because they are the same.
makeModuleMapEntry(dir, filename, undefined, ((name ? name + '/' : '') + files[file]), files[file], modules);
// If the file name is "index.js" then we have to add an
// entry for the diretory that points to the "index.js" frile.
if (files[file].slice(-5) === 'index') {
// Generate the knot url for this module.
if (files[file].slice(0, -5)) {
uri = (name ? name + '/' : '') + files[file].slice(0, -6);
} else {
uri = name;
}
// Add the file to the modules map.
makeModuleMapEntry(dir, uri + '.js', filename, uri, files[file], modules);
}
}
}
}
if (pack.knot.main) {
uri = name + '.js';
modules[KNOT_PREFIX + uri] = {
name: name,
path: path.join(dir, pack.knot.main + '.js'),
uri: (name ? name + '/' : '') + files[file] + '.js'
};
}
}

@@ -261,3 +355,3 @@ }

function findModules(dir, modules) {
function findModules(dir, modules, HACK) {

@@ -278,3 +372,3 @@ var files,

if (files[name] === PACKAGE) {
parsePackage(dir, modules);
parsePackage(dir, modules, HACK);
} else if (fs.statSync(absPath).isDirectory()) {

@@ -307,6 +401,10 @@ findModules(absPath, modules);

}
// Set the root
// Set the root and other options
options.root = root;
// Find all public modules
findModules(options.root, modules);
options.getOnly = true;
options.modules = modules;
// Find all public modules. As this is the first package it is treated special.
findModules(options.root, modules, ROOT_PKG);
// Find all system modules

@@ -317,6 +415,4 @@ findModules(path.join(__dirname, 'modules'), modules);

options.path = req.url;
options.getOnly = true;
options.modules = modules;
serve(req, res, next, options);
};
};
{
"name": "knot",
"description": "A client side Node experiment.",
"version": "0.0.6",
"version": "0.0.7",
"author": {

@@ -11,3 +11,3 @@ "name": "Richard S Allinson",

"engines": {
"node": ">= 0.6.0 < 0.7.0"
"node": ">= 0.6.0 <= 0.7.x"
},

@@ -14,0 +14,0 @@ "dependencies": {

@@ -13,4 +13,4 @@ {

"knot": {
"main": "all_tests",
"modules": [
"index",
"process",

@@ -20,3 +20,2 @@ "console",

"events",
"stream",
"path",

@@ -23,0 +22,0 @@ "assert"

Sorry, the diff of this file is not supported yet

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