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

one

Package Overview
Dependencies
Maintainers
1
Versions
180
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

one - npm Package Compare versions

Comparing version 1.1.1 to 1.1.2

lib/install_dict.js

22

lib/logging.js

@@ -1,20 +0,6 @@

var puts = require('sys').puts,
colors = require('colors');
var log4js = require('log4js'),
logger = log4js.getLogger('onejs');
function logger(lvl, prefix, color){
return function(){
var msg;
if(module.exports.level<lvl){
msg = Array.prototype.join.call(arguments, ' ');
puts((' '+(new Date)+' ').grey+prefix[color].bold+' '+msg);
}
}
}
logger.setLevel('TRACE');
module.exports = {
'level':0,
'debug':logger(1, 'DEBUG ', 'yellow'),
'info':logger(2,'INFO ', 'green'),
'warn':logger(3,'WARNING ', 'blue'),
'error':logger(4,'ERROR ', 'red')
};
module.exports = logger;
var templating = require('./templating'),
render = templating.render,
compose = require('functools').compose,
map = require('functools').map,
render = require('./render'),
functools = require('functools'),
compose = functools.compose,
combiner = require('combiner'),

@@ -9,22 +9,21 @@ path = require('path'),

logging = require('./logging'),
fs = require('fs');
fs = require('fs'),
server = require('./server'),
installDict = require('./install_dict'),
genpkg = require('genpkg');
function build(manifestPath, callback){
loadPkg(manifestPath, function(error, pkg){
var slice = Array.prototype.slice;
function build(options, callback){
logging.trace('Building package from "%s"', options.manifestPath);
logging.info('Given build options: %s', Object.keys(options).join(', '));
options.id = templating.idGenerator();
loadPkg(options.manifestPath, undefined, options, function(error, pkg){
if(error) return callback(error);
var pkgs = flattenPkgTree(pkg),
treeName = templating.makeVariableName(pkg.name);
pkgs = pkgs.map(function(el){
return { 'pkg':el, 'treeName':treeName };
render(pkg, options, function(error, sourceCode){
callback(error, sourceCode, pkg);
});
map.async(renderPackage, pkgs, function(error, renderedPkgs){
if(error) return callback(error);
renderWrapper({
'treeName':treeName,
'renderedPkgs':renderedPkgs
}, callback);
});

@@ -34,3 +33,3 @@ });

function collectDeps(pkg, callback){
function collectDeps(pkg, options, callback){

@@ -48,2 +47,3 @@ var deps = [],

if(i>=declaredDepList.length){
logging.debug('Loaded %d dependencies under the package "%s"',declaredDepList.length, pkg.manifest.name);
return callback(undefined,deps);

@@ -63,3 +63,3 @@ }

loadPkg(pkg, manifestPath, function(error, subpkg){
loadPkg(manifestPath, pkg, options, function(error, subpkg){
if(error){

@@ -95,2 +95,3 @@ return callback(error);

if(i>=filenames.length){
logging.debug('Loaded %d module(s) under the package "%s"',filenames.length,pkg.name);
return callback(undefined, modules);

@@ -109,2 +110,3 @@ }

module.id = module.filename.replace(/\.js$/,'');
if(!error) modules.push(module);

@@ -118,13 +120,4 @@ next();

function flattenPkgTree(tree){
var l = [tree];
var i = -1;
while(tree.dependencies && ++i<tree.dependencies.length){
Array.prototype.push.apply(l, flattenPkgTree(tree.dependencies[i]));
}
return l;
}
function filterFilename(filename,callback){

@@ -137,3 +130,4 @@ return /\.js$/.test(filename);

var manifest;
var manifest,
manifestSource;

@@ -151,4 +145,5 @@ readFile(path, function(error, bf){

manifest = JSON.parse(manifestSource);
logging.debug('Manifest file "%s" loaded and parsed successfully.', path);
} catch(exc) {
logging.error('Failed to parse the manifest @ "'+manifestPath+'"');
logging.error('Failed to parse the manifest @ "'+path+'"');
error = exc;

@@ -167,4 +162,4 @@ }

return function(filename, callback){
logging.debug('Load module "'+filename+'"');
return function loadModule(filename, callback){
logging.debug('Loading module "'+filename+'"');
readFile(filename, function(error, bf){

@@ -183,17 +178,12 @@ if(error) return callback(error);

});
}
};
})();
function loadPkg(/*parentPkg, manifestPath, callback*/){
function loadPkg(manifestPath, parentPkg, options, callback){
var argsLen = arguments.length,
parentPkg = argsLen == 3 && arguments[0] || undefined,
manifestPath = arguments[argsLen-2],
callback = arguments[argsLen-1];
var wd = path.normalize(path.dirname(manifestPath));
var wd = path.normalize(path.dirname(manifestPath));
logging.debug('Loading the package "%s"', manifestPath);
logging.info('Loading the package "'+manifestPath+'"');
loadManifest(manifestPath, function(error, manifest){

@@ -205,3 +195,3 @@ if(error){

var pkg = {
'id':templating.id(),
'id':options.id(),
'dependencies':undefined,

@@ -222,3 +212,3 @@ 'dirs':undefined,

collectDeps(pkg, function(error, deps){
collectDeps(pkg, options, function(error, deps){
if(error){

@@ -255,2 +245,4 @@ logging.error('An unexpected error occurred during collecting dependencies of the package "'+pkg.name+'".');

logging.info('%s loaded.', pkg.name);
callback(error, pkg);

@@ -270,85 +262,75 @@ });

function quiet(y){
logging.level = y ? 3 : 1;
logging.setLevel('ERROR');
}
function renderLibrary(callback){
logging.info('Rendering library...');
render({ 'template':'node/path.js' }, function(error, nodePathSC){
render({ 'template':'library.js', 'view':{}, 'partials':{ 'node_path':nodePathSC } }, callback);
});
function save(target, content, callback){
logging.debug('Saving output into '+target);
fs.writeFile(target, content, function(error) {
if(error) {
logging.error('Failed to write the target file "'+target+'"');
return callback(error);
}
logging.info('The target file "'+target+'" was saved!');
callback();
});
}
function renderModule(options, callback){
var view = {
'treeName':options.treeName,
'parentId':options.pkg.id,
'id':options.module.id
};
function setupNodeModules(/* modules ... */){
var modules = slice.call(arguments, 0);
logging.info('setup modules;', modules);
}
logging.debug('Rendering module "'+view.id+'"');
render({ 'template':'module.js', 'view':view, 'partials':{ 'content':options.module.content } }, callback);
function publish(options){
options.returnPackage = true;
build(options, function(error, built, pkg){
if(error) throw error;
options.content = built;
options.pkg = pkg;
server.start(options);
});
}
function renderPackage(options,callback){
function setupNodeModules(/* modules */){
var pkgs = slice.call(arguments, 0, arguments.length-1),
callback = arguments[arguments.length - 1],
len = pkgs.length;
var view = {
'treeName':options.treeName,
'parentId':!options.pkg.parent && 'undefined' || options.pkg.parent.id,
'id':options.pkg.id,
'main': options.pkg.main && options.pkg.main.id,
'name':options.pkg.name,
'wd':options.pkg.wd
};
var pkgName, pkgURI, next;
(function iter(i, error){
logging.info('Rendering package "'+view.name+'"');
var modules = options.pkg.modules.map(function(el){
return {
'treeName':options.treeName,
'pkg':options.pkg,
'module':el
if(i>=len || error){
return callback(error);
}
});
map.async(renderModule, modules, function(error, renderedModules){
if(error) return callback(error);
render({ 'template':'package.js', 'view':view, 'partials':{ 'modules':renderedModules.join('\n\n') } }, callback);
});
}
pkgName = pkgs[i];
pkgURI = installDict[pkgName];
function renderWrapper(options, callback){
logging.info('Rendering wrapper...');
renderLibrary(function(error, librarySC){
if(error){
return callback(error);
if(!pkgURI){
logging.error('Unknown package "%s" ', pkgName);
return callback(new Error('Unknown package "%s"', pkgName));
}
render({
'template':'wrapper.js',
'view':{ 'name':options.treeName },
'partials':{
'library':librarySC,
'packages':options.renderedPkgs.join('\n\n\n\n')
}
}, callback);
});
}
next = iter.bind(undefined, i+1);
function save(target, content, callback){
logging.info('Saving output into '+target);
fs.writeFile(target, content, function(error) {
if(error) {
logging.error('Failed to write the target file "'+target+'"');
return callback(error);
  }
genpkg.pkg({ 'uri':pkgURI }, function(error, pkg){
if(error) callback(error);
logging.info('The target file "'+target+'" was saved!');
callback();
});
pkg.target = path.join('node_modules', pkg.manifest.name);
genpkg.save(pkg, next);
});
})(0);
}
function verbose(y){
logging.level = y ? 0 : 1;
function verbose(){
logging.setLevel('TRACE');
}
function verbosity(level){
logging.setLevel(level);
}

@@ -360,3 +342,2 @@ module.exports = {

'filterFilename':filterFilename,
'flattenPkgTree':flattenPkgTree,
'loadManifest':loadManifest,

@@ -367,5 +348,7 @@ 'loadModule':loadModule,

'quiet':quiet,
'renderModule':renderModule,
'publish':publish,
'save':save,
'verbose':verbose
'setupNodeModules':setupNodeModules,
'verbose':verbose,
'verbosity':verbosity
}
var mustache = require('mustache'),
fs = require('fs'),
config = require('./config'),
errors = require('./errors');
config = require('./config');
var id = (function(){
var idGenerator = function(){
var serial = 0;
return function id(){
return ++serial;
}
})();
};
};

@@ -30,5 +29,6 @@ function makeVariableName(str){

module.exports = {
'id':id,
'id':idGenerator(),
'idGenerator':idGenerator,
'makeVariableName':makeVariableName,
'render':render
}
{
"name":"one",
"version":"1.1.1",
"version":"1.1.2",
"description":"Transform NodeJS packages into single stand-alone script files.",

@@ -12,5 +12,2 @@ "author":"Azer Koculu <azer@kodfabrik.com>",

},
"devDependencies":{
"highkick":"1.x"
},
"dependencies":{

@@ -21,4 +18,9 @@ "functools":"1.x",

"mustache":"0.x",
"colors":"0.x"
"highkick":"1.x",
"log4js":"0.x",
"genpkg":"0.x"
},
"scripts":{
"test": "node test/run.js"
}
}

@@ -1,9 +0,17 @@

var lib = (function(){
lib = (function(exports){
var exports = {};
exports.path = (function(exports){
{{>path}}
{{>node_path}}
return exports;
})({});
global.process = exports.process = (function(exports){
{{>process}}
return exports;
})({});
return exports;
})();
})({});

@@ -6,3 +6,3 @@ {{ treeName }}.module({{ parentId }}, function(parent){

'pkg':parent,
'wrapper':function(module, exports, require, global, undefined){
'wrapper':function(module, exports, global, Buffer, process, require, undefined){
{{>content}}

@@ -9,0 +9,0 @@ }

@@ -5,3 +5,4 @@ var {{ name }} = (function(global, undefined){

global = {},
_;
lib = undefined,
locals;

@@ -30,3 +31,3 @@ {{>library}}

var module = undefined,
moduleId = lib.join(lib.dirname(workingModule.id), uri),
moduleId = lib.path.join(lib.path.dirname(workingModule.id), uri),
pkg = workingModule.pkg;

@@ -63,19 +64,22 @@

var parent = pkgmap[parentId],
ctx = wrapper(parent),
exports = undefined;
mod = wrapper(parent),
cached = false;
ctx.require = genRequire(ctx);
ctx.call = function(){
if(exports) return exports;
exports = {};
ctx.wrapper(ctx, exports, ctx.require, global);
return exports;
}
mod.exports = {};
mod.require = genRequire(mod);
if(parent.mainModuleId == ctx.id){
parent.main = ctx;
!parent.parent && ( _.main = ctx.call );
mod.call = function call_module_wrapper(){
if(cached) return mod.exports;
cached = true;
global.require = mod.require;
mod.wrapper(mod, mod.exports, global, global.Buffer, global.process, global.require);
return mod.exports;
};
if(parent.mainModuleId == mod.id){
parent.main = mod;
!parent.parent && ( locals.main = mod.call );
}
parent.modules.push(ctx);
parent.modules.push(mod);
}

@@ -98,3 +102,3 @@

return (_ = {
return (locals = {
'lib':lib,

@@ -101,0 +105,0 @@ 'findPkg':findPkg,

require('dependency');
exports.a = true;
module.exports = {
'a':true,
'global':global,
'process':process,
'Buffer':Buffer
}
var kick = require('highkick'),
puts = require('sys').puts;
mkdir = require('fs').mkdir;
kick({ module:require('./tests'), name:' main' }, function(error, result){
if(error) throw error;
});
function clean(callback){
mkdir('tmp', 0755, function(){
callback();
});
}
function run(){
clean(function(){
kick({ module:require('./main'), name:' main' }, function(error, result){
if(error) throw error;
});
});
}
run();

@@ -1,52 +0,63 @@

var assert = require('assert');
var assert = require('assert'),
function init(){
return require('/tmp/__package.js');
common = require('./common'),
verifyListContent = common.verifyListContent;
function moduleIds(modules){
return modules.map(function(m){
return m.id;
});
}
function test_name(wrapper, callback){
assert.equal(wrapper.name, 'exampleProject');
function init(options, callback){
callback(null, require(options.target));
}
function test_name(mod, callback){
assert.equal(mod.name, 'exampleProject');
callback();
}
function test_findPkg(wrapper, callback){
assert.equal(wrapper.findPkg(wrapper.map.main,'dependency').name, 'dependency');
assert.equal(wrapper.findPkg(wrapper.map[6], 'subdependency').name, 'subdependency');
assert.equal(wrapper.findPkg(wrapper.map[9], 'sibling').name, 'sibling');
function test_findPkg(mod, callback){
assert.equal(mod.findPkg(mod.map.main,'dependency').name, 'dependency');
assert.equal(mod.findPkg(mod.map[2], 'subdependency').name, 'subdependency');
assert.equal(mod.findPkg(mod.map[4], 'sibling').name, 'sibling');
callback();
}
function test_findModule(wrapper, callback){
assert.equal(wrapper.findModule(wrapper.map[6].main, 'g'), wrapper.map[6].modules[1]);
function test_findModule(mod, callback){
var g = mod.map[2].modules[1];
g.id != 'g' && ( g = mod.map[2].modules[0] );
assert.equal(mod.findModule(mod.map[2].main, 'g'), g);
callback();
}
function test_packageTree(wrapper, callback){
assert.equal(wrapper.map.main.dependencies.length, 2);
assert.equal(wrapper.map.main.dependencies[0].name, 'dependency');
assert.equal(wrapper.map.main.dependencies[1].name, 'sibling');
assert.equal(wrapper.map.main.dependencies[0].dependencies[0].name, 'subdependency');
function test_packageTree(mod, callback){
assert.equal(mod.map.main.dependencies.length, 2);
assert.equal(mod.map.main.dependencies[0].name, 'dependency');
assert.equal(mod.map.main.dependencies[1].name, 'sibling');
assert.equal(mod.map.main.dependencies[0].dependencies[0].name, 'subdependency');
callback();
}
function test_moduleTree(wrapper, callback){
assert.equal(wrapper.map[3].modules.length, 2);
assert.equal(wrapper.map[3].modules[0].id, 'a');
assert.equal(wrapper.map[3].modules[1].id, 'b');
assert.equal(wrapper.map[9].modules.length, 2);
assert.equal(wrapper.map[9].modules[0].id, 'i');
assert.equal(wrapper.map[9].modules[1].id, 'j');
function test_moduleTree(mod, callback){
assert.ok( verifyListContent(moduleIds(mod.map[1].modules), ['a', 'b'] ) );
assert.ok( verifyListContent(moduleIds(mod.map[3].modules), ['i', 'j'] ) );
callback();
}
function test_packageCtx(wrapper, callback){
var p = wrapper.map[3];
function test_packageCtx(mod, callback){
var p = mod.map[1];
assert.equal(p.name, 'example-project');
assert.equal(p.id, 3);
assert.equal(p.id, 1);
assert.equal(p.parent);
assert.equal(p.mainModuleId, 'a');
assert.equal(p.main.id, 'a');
assert.equal(p.modules.length, 2);
assert.equal(p.modules[0].id, 'a');
assert.equal(p.modules[1].id, 'b');
assert.ok( verifyListContent(moduleIds(p.modules), ['a', 'b']) );
assert.equal(p.dependencies.length, 2);

@@ -57,31 +68,82 @@

function test_moduleCtx(wrapper, callback){
var m = wrapper.map[3].modules[0];
assert.equal(m.id, 'a');
assert.equal(m.pkg.name, 'example-project');
assert.equal(typeof m.wrapper, 'function');
assert.ok(m.require('dependency').f);
assert.ok(m.require('./b').b);
function test_moduleCtx(mod, callback){
var a, b;
m = wrapper.map.main.dependencies[ wrapper.map.main.dependencies[0].name == 'sibling' ? 0 :1 ].main;
assert.equal(m.id, 'n');
assert.equal(m.pkg.name, 'sibling');
assert.equal(typeof m.wrapper, 'function');
assert.ok(m.require('dependency').f);
assert.ok(m.require('./p/r').r);
a = mod.map[1].modules[0];
a.id == 'b' && ( a = mod.map[1].modules[1] );
assert.equal(a.id, 'a');
assert.equal(a.pkg.name, 'example-project');
assert.equal(typeof a.wrapper, 'function');
assert.ok(a.require('dependency').f);
assert.ok(a.require('./b').b);
b = mod.map.main.dependencies[ mod.map.main.dependencies[0].name == 'sibling' ? 0 :1 ].main;
assert.equal(b.id, 'n');
assert.equal(b.pkg.name, 'sibling');
assert.equal(typeof b.wrapper, 'function');
assert.ok(b.require('dependency').f);
assert.ok(b.require('./p/r').r);
callback();
}
function test_main(wrapper, callback){
assert.equal(wrapper.main, wrapper.map.main.main.call);
function test_main(mod, callback){
assert.equal(mod.main, mod.map.main.main.call);
callback();
}
function test_require(wrapper, callback){
assert.ok(wrapper.require('./b').b);
assert.ok(wrapper.require('dependency').f);
function test_process(mod, callback){
var proc = mod.lib.process;
assert.ok(proc);
assert.equal(typeof proc.Stream, 'function');
assert.equal(typeof proc.Buffer, 'function');
assert.equal(proc.binding('buffer').Buffer, proc.Buffer);
assert.equal(proc.binding('buffer').SlowBuffer, proc.Buffer);
assert.equal(proc.argv.length, 2);
assert.equal(proc.argv[0], 'node');
assert.equal(proc.argv[1], 'one.js');
assert.ok(proc.env);
assert.ok(proc.stderr instanceof proc.Stream);
assert.ok(proc.stdin instanceof proc.Stream);
assert.ok(proc.stdout instanceof proc.Stream);
assert.equal(proc.version, process.version);
assert.equal(proc.versions.node, process.versions.node);
assert.equal(proc.versions.v8, process.versions.v8);
assert.ok(proc.pid == proc.uptime);
assert.ok(proc.arch == proc.execPath == proc.installPrefix == proc.platform == proc.title == '');
var isNextTickAsync = false;
proc.nextTick(function(){
assert.ok(isNextTickAsync);
callback();
});
isNextTickAsync = true;
}
function test_require(mod, callback){
assert.ok(mod.require('./b').b);
assert.ok(mod.require('dependency').f);
callback();
}
function test_globals(mod, callback){
var globals = mod.require('./a');
assert.equal(typeof globals.Buffer, 'function');
assert.ok(globals.process);
assert.ok(globals.process.env);
callback();
}
module.exports = {

@@ -97,3 +159,5 @@ 'init':init,

'test_require':test_require,
'test_process':test_process,
'test_globals':test_globals,
'test_main':test_main
}
};

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