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.2 to 1.1.3

example-project/lib/a.js

4

lib/config.js

@@ -0,3 +1,5 @@

var join = require('path').join;
module.exports = {
'TEMPLATES_DIR':'templates'
'TEMPLATES_DIR': join(__dirname, '../templates')
}

@@ -1,14 +0,15 @@

var templating = require('./templating'),
render = require('./render'),
functools = require('functools'),
compose = functools.compose,
combiner = require('combiner'),
path = require('path'),
readFile = require('fs').readFile,
logging = require('./logging'),
fs = require('fs'),
server = require('./server'),
installDict = require('./install_dict'),
genpkg = require('genpkg');
var templating = require('./templating'),
render = require('./render'),
functools = require('functools'),
compose = functools.compose,
combiner = require('combiner'),
genpkg = require('genpkg'),
path = require('path'),
fs = require('fs'),
readFile = fs.readFile,
logging = require('./logging'),
server = require('./server'),
installDict = require('./install_dict');
var slice = Array.prototype.slice;

@@ -22,3 +23,3 @@

loadPkg(options.manifestPath, undefined, options, function(error, pkg){
loadPkgFromManifestPath(options.manifestPath, undefined, options, function(error, pkg){
if(error) return callback(error);

@@ -47,3 +48,3 @@

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

@@ -62,3 +63,3 @@

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

@@ -175,67 +176,62 @@ return callback(error);

function loadPkg(manifestPath, parentPkg, options, callback){
function loadPkgFromManifestPath(manifestPath, parentPkg, options, callback){
logging.debug('Loading package from manifest path "%s"', manifestPath);
var wd = path.normalize(path.dirname(manifestPath));
logging.debug('Loading the package "%s"', manifestPath);
loadManifest(manifestPath, function(error, manifest){
if(error){
return callback(error);
callback(error);
return;
}
var pkg = {
'id':options.id(),
'dependencies':undefined,
'dirs':undefined,
'main':undefined,
'manifest':manifest,
'modules':undefined,
'modulesDict':{},
'name':manifest.name,
'parent':parentPkg,
'pkgDict':parentPkg ? parentPkg.pkgDict : {},
'wd':wd
};
pkg.pkgDict[pkg.name] = pkg;
pkg.dirs = manifest.directories || { 'lib':'.' };
var pkg = createPkg(path.normalize(path.dirname(manifestPath)), manifest, parentPkg, options);
collectDeps(pkg, options, function(error, deps){
if(error){
logging.error('An unexpected error occurred during collecting dependencies of the package "'+pkg.name+'".');
return callback(error);
}
loadPkg(pkg, options, callback);
logging.debug('Found '+deps.length+' dependencies for the package "'+pkg.name+'"');
});
}
pkg.dependencies = deps;
function loadPkg(pkg, options, callback){
collectModules(pkg, function(error, modules){
if(error){
logging.error('An unexpected error occurred during collecting modules of the package "'+pkg.name+'".');
return callback(error);
}
logging.debug('Collected '+modules.length+' modules for the package "'+pkg.name+'"');
logging.debug('Loading the package "%s"', pkg.manifest.name);
pkg.modules = modules;
collectDeps(pkg, options, function(error, deps){
if(error){
logging.error('An unexpected error occurred during collecting dependencies of the package "'+pkg.name+'".');
logging.error(error);
callback(error);
return;
}
var i = modules.length, m, mainModulePath;
logging.debug('Found '+deps.length+' dependencies for the package "'+pkg.name+'"');
while(i-->0){
m = modules[i];
pkg.modulesDict[m.path] = m;
}
pkg.dependencies = deps;
if(manifest.main){
mainModulePath = path.join(wd, manifest.main+'.js');
pkg.main = pkg.modulesDict[mainModulePath];
}
collectModules(pkg, function(error, modules){
if(error){
logging.error('An unexpected error occurred during collecting modules of the package "'+pkg.name+'".');
logging.error(error);
callback(error);
return;
}
logging.debug('Collected '+modules.length+' modules for the package "'+pkg.name+'"');
logging.info('%s loaded.', pkg.name);
pkg.modules = modules;
callback(error, pkg);
});
var i = modules.length, m, mainModulePath;
while(i-->0){
m = modules[i];
pkg.modulesDict[m.path] = m;
}
if(pkg.manifest.main){
mainModulePath = path.join(pkg.wd, pkg.manifest.main+'.js');
pkg.main = pkg.modulesDict[mainModulePath];
}
logging.info('%s loaded.', pkg.name);
callback(error, pkg);
});

@@ -251,2 +247,22 @@

function createPkg(wd, manifest, parentPkg, options){
var pkg = {
'id':options && options.id && options.id() || templating.idGenerator(),
'dependencies':undefined,
'dirs':manifest.directories || { 'lib':'.' },
'main':undefined,
'manifest':manifest,
'modules':undefined,
'modulesDict':{},
'name':manifest.name,
'parent': parentPkg,
'pkgDict': parentPkg ? parentPkg.pkgDict : {},
'wd': wd
};
pkg.pkgDict[pkg.name] = pkg;
return pkg;
}
function quiet(y){

@@ -328,16 +344,18 @@ logging.setLevel('ERROR');

module.exports = {
'build':build,
'collectDeps':collectDeps,
'collectModules':collectModules,
'filterFilename':filterFilename,
'loadManifest':loadManifest,
'loadModule':loadModule,
'loadPkg':loadPkg,
'moduleName':moduleName,
'quiet':quiet,
'publish':publish,
'save':save,
'setupNodeModules':setupNodeModules,
'verbose':verbose,
'verbosity':verbosity
'build': build,
'collectDeps': collectDeps,
'collectModules': collectModules,
'createPkg': createPkg,
'filterFilename': filterFilename,
'loadManifest': loadManifest,
'loadModule': loadModule,
'loadPkg': loadPkg,
'loadPkgFromManifestPath': loadPkgFromManifestPath,
'moduleName': moduleName,
'quiet': quiet,
'publish': publish,
'save': save,
'setupNodeModules': setupNodeModules,
'verbose': verbose,
'verbosity': verbosity
}
{
"name":"one",
"version":"1.1.2",
"version":"1.1.3",
"description":"Transform NodeJS packages into single stand-alone script files.",

@@ -22,4 +22,4 @@ "author":"Azer Koculu <azer@kodfabrik.com>",

"scripts":{
"test": "node test/run.js"
"test":"node test/run.js"
}
}
OneJS is a command-line utility for converting CommonJS packages to single, stand-alone JavaScript
files that can be run on the platforms with no CommonJS support, such as web browsers.
files that can be run on other JavaScript platforms such as web browsers, unity, silkjs etc.
Usage
=====
# Motivation
* **Reusability** OneJS aims to let developers run NodeJS modules and packages on all environments able to execute JavaScript.
* **Elegant Modularization** OneJS lets web projects benefit from CommonJS, an excellent proposal that gives us a very well designed way to structure JavaScript source codes.
* **NPM** It eventually makes it possible for web projects to use NPM. Which is a great tool that makes controlling dependencies even fun!
* **No Spaghetti Code** No awkward headers, no framework-specific definitions which become deprecated in a few years.
* **Reliable code generation** OneJS doesn't change your source code. It only generates a container environment that simply emulates NodeJS environment.
* **Unobtrusive Code** The source code OneJS generates wraps projects into a single, isolated JS object.
### Examples
* See the example project included in this repository
* See MultiplayerChess.com's source code.
# Install
```bash
$ onejs build package.json target.js
$ npm install one
```
* Tip: Pass -g parameter to install it globally. *
# First Steps
## Testing Example Project
It's an easy way to give OneJS a test-drive. Example project is located at this repository;
```bash
$ git clone git@github.com:azer/onejs.git
$ cd onejs
$ npm install
$ cd example-project
```
It's a non-functional NodeJS project with some dummy dependencies under node_modules directory. The built file will contain all the packages under node_modules directory;
```
$ ../bin/onejs build package.json bundle.js
```
Now we're willing to test the code OneJS generated for us. Quickest way might be requiring it from NodeJS;
```
> var exampleProject = require('./bundle');
> exampleProject.main() // calls main module of the package, returns its exports
> exampleProject.require('./b') // each package object has a require method available for external calls
```
To test it on web browsers, OneJS has a "server" command that builds the source code and start serving it at localhost:1338.
```bash
$ ../bin/onejs server example-project/package.json
```
You can simply go to that URL and inspect the content of "exampleProject" object, using Firebug Lite. The whole source code with
dependencies (if exists) is wrapped by it. It also provides an external API for the possible clients, containing some methods
such as require, main, stdin, stdout, stderror.
```javascript
> exampleProject.require('dependency'), exampleProject.require('./b');
> exampleProject.lib.process.stdout.write("Hello World");
> exampleProject.stdout();
"Hello World"
```
# Projects Using OneJS
* [MultiplayerChess.com](http://github.com/azer/multiplayerchess.com)
* [HighKick](http://github.com/azer/highkick)
# Beginner's Guide
FIXME
# API Reference
FIXME

@@ -24,2 +24,4 @@ /**

Buffer.call(this);
this.emulation = true;

@@ -31,3 +33,3 @@ this.readable = readable;

Stream.prototype = exports.Buffer(0,0);
Stream.prototype = Buffer(0,0);

@@ -37,3 +39,3 @@ exports.Stream = Stream;

function notImplemented(){
console.warn('Not Implemented.');
throw new Error('Not Implemented.');
}

@@ -57,3 +59,3 @@

exports.argv = ['node','one.js'];
exports.argv = ['node'];

@@ -72,3 +74,3 @@ exports.env = {};

exports.versions = {{ versions }};
exports.versions = {{{ versions }}};

@@ -75,0 +77,0 @@ /**

@@ -98,3 +98,15 @@ var {{ name }} = (function(global, undefined){

}
function stderr(){
return lib.process.stderr.content;
}
function stdin(){
return lib.process.stdin.content;
}
function stdout(){
return lib.process.stdout.content;
}
return (locals = {

@@ -108,2 +120,5 @@ 'lib':lib,

'pkg':pkg,
'stderr':stderr,
'stdin':stdin,
'stdout':stdout,
'require':require

@@ -110,0 +125,0 @@ });

@@ -29,7 +29,7 @@ var one = require('../lib/one'),

function test_build(callback){
one.build({ 'manifestPath':'test/example-project/package.json' }, function(error, sourceCode){
one.build({ 'manifestPath':'example-project/package.json' }, function(error, sourceCode){
if(error) return callback(error);
one.save('tmp/built.js', sourceCode, function(error){
if(error) return callback(error);
kick({ module:require('./templates'), 'silent':0, 'name':'built file', 'target':'../tmp/built.js' },function(error,result){
kick({ module:require('./templates'), 'silent': true, 'name':'built file', 'target':'../tmp/built.js' },function(error,result){
if(error) return callback(error);

@@ -51,3 +51,3 @@ callback(result.fail ? new Error('Build tests failed') : undefined);

},
'wd':'test/example-project/',
'wd':'example-project/',
'pkgDict':{}

@@ -77,3 +77,3 @@ };

function test_loadPkg(callback){
one.loadPkg('test/example-project/package.json', undefined, { id:templating.idGenerator(), 'azer':1 }, function(error, pkg){
one.loadPkgFromManifestPath('example-project/package.json', undefined, { id:templating.idGenerator(), 'azer':1 }, function(error, pkg){
if(error) return callback(error);

@@ -91,2 +91,3 @@

pkgDict = Object.keys(pkg.pkgDict);
assert.equal(pkgDict.length, 4);

@@ -98,6 +99,5 @@ assert.equal(pkgDict[0], 'example-project');

assert.ok(verifyListContent( moduleFilenames(pkg.modules), ['web.js', 'a.js', 'b.js']));
assert.ok(verifyListContent( moduleFilenames(pkg.modules), ['a.js', 'b.js']));
assert.ok(verifyListContent( moduleFilenames(pkg.pkgDict.dependency.modules), ['f.js','g.js']));

@@ -117,5 +117,5 @@

function test_collectModules(callback){
one.collectModules({ 'name':'example-project', 'dirs':{'lib':'lib'}, 'wd':'test/example-project/' }, function(error, modules){
one.collectModules({ 'name':'example-project', 'dirs':{'lib':'lib'}, 'wd':'example-project/' }, function(error, modules){
try {
assert.ok(verifyListContent(moduleFilenames(modules), ['a.js', 'b.js']));
assert.ok(verifyListContent(moduleFilenames(modules), ['a.js', 'b.js','web.js']));
callback();

@@ -146,6 +146,6 @@ } catch(exc) {

function test_loadModule(callback){
one.loadModule('test/example-project/lib/a.js', function(error, module){
one.loadModule('example-project/lib/a.js', function(error, module){
try {
assert.equal(module.name, 'a');
assert.equal(module.filename, 'test/example-project/lib/a.js');
assert.equal(module.filename, 'example-project/lib/a.js');
assert.equal(module.content.substring(0,22), 'require(\'dependency\');');

@@ -186,3 +186,3 @@ callback();

function test_loadManifest(callback){
one.loadManifest('test/example-project/package.json', function(error, manifest){
one.loadManifest('example-project/package.json', function(error, manifest){
assert.equal(manifest.name, "example-project");

@@ -189,0 +189,0 @@ assert.equal(manifest.main, "./lib/a");

var assert = require('assert'),
common = require('./common'),

@@ -13,11 +12,5 @@ verifyListContent = common.verifyListContent;

function init(options, callback){
callback(null, require(options.target));
}
function test_name(mod, callback){
assert.equal(mod.name, 'exampleProject');
callback();
}
function test_findPkg(mod, callback){

@@ -39,29 +32,23 @@ assert.equal(mod.findPkg(mod.map.main,'dependency').name, 'dependency');

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');
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();
}
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'] ) );
function test_name(mod, callback){
assert.equal(mod.name, 'exampleProject');
callback();
}
function test_packageCtx(mod, callback){
function test_main(mod, callback){
assert.equal(mod.main, mod.map.main.main.call);
callback();
}
var p = mod.map[1];
assert.equal(p.name, 'example-project');
assert.equal(p.id, 1);
assert.equal(p.parent);
assert.equal(p.mainModuleId, 'a');
assert.equal(p.main.id, 'a');
assert.ok( verifyListContent(moduleIds(p.modules), ['a', 'b']) );
assert.equal(p.dependencies.length, 2);
function test_moduleTree(mod, callback){
assert.ok( verifyListContent(moduleIds(mod.map[1].modules), ['a', 'b', 'web'] ) );
assert.ok( verifyListContent(moduleIds(mod.map[3].modules), ['i', 'j'] ) );
callback();

@@ -71,7 +58,21 @@ }

function test_moduleCtx(mod, callback){
var a, b;
var pkg = mod.map[1],
a, b, web;
a = mod.map[1].modules[0];
assert.equal(pkg.modules.length, 3);
a.id == 'b' && ( a = mod.map[1].modules[1] );
var i = pkg.modules.length;
while(i-->0){
switch(pkg.modules[i].id){
case 'a':
a = pkg.modules[i];
break;
case 'b':
b = pkg.modules[i];
break;
case 'web':
web = pkg.modules[i];
break;
}
}

@@ -84,9 +85,9 @@ assert.equal(a.id, 'a');

b = mod.map.main.dependencies[ mod.map.main.dependencies[0].name == 'sibling' ? 0 :1 ].main;
var n = 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);
assert.equal(n.id, 'n');
assert.equal(n.pkg.name, 'sibling');
assert.equal(typeof n.wrapper, 'function');
assert.ok(n.require('dependency').f);
assert.ok(n.require('./p/r').r);

@@ -96,7 +97,35 @@ callback();

function test_main(mod, callback){
assert.equal(mod.main, mod.map.main.main.call);
function test_packageCtx(mod, callback){
assert.ok(mod.require);
assert.equal(mod.name, 'exampleProject');
assert.equal(typeof mod.stderr(), 'string');
assert.equal(typeof mod.stdin(), 'string');
assert.equal(typeof mod.stdout(), 'string');
assert.equal(mod.stdout(), mod.lib.process.stdout.content);
assert.equal(mod.stdin(), mod.lib.process.stdin.content);
assert.equal(mod.stderr(), mod.lib.process.stderr.content);
var p = mod.map[1];
assert.equal(p.name, 'example-project');
assert.equal(p.id, 1);
assert.equal(p.parent);
assert.equal(p.mainModuleId, 'a');
assert.equal(p.main.id, 'a');
assert.ok( verifyListContent(moduleIds(p.modules), ['a', 'b', 'web']) );
assert.equal(p.dependencies.length, 2);
callback();
}
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_process(mod, callback){

@@ -112,5 +141,3 @@ var proc = mod.lib.process;

assert.equal(proc.argv.length, 2);
assert.equal(proc.argv[0], 'node');
assert.equal(proc.argv[1], 'one.js');

@@ -130,2 +157,6 @@ assert.ok(proc.env);

proc.stdout.write('hello');
proc.stdout.write(' world');
assert.equal(proc.stdout.content, 'hello world');
var isNextTickAsync = false;

@@ -147,9 +178,2 @@ proc.nextTick(function(){

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();
}

@@ -156,0 +180,0 @@ module.exports = {

@@ -76,2 +76,3 @@ var exampleProject = (function(global, undefined){

if (!(this instanceof Stream)) return new Stream(writable, readable);
Buffer.call(this);
this.emulation = true;

@@ -82,6 +83,6 @@ this.readable = readable;

};
Stream.prototype = exports.Buffer(0,0);
Stream.prototype = Buffer(0,0);
exports.Stream = Stream;
function notImplemented(){
console.warn('Not Implemented.');
throw new Error('Not Implemented.');
}

@@ -100,3 +101,3 @@ exports.binding = (function(){

})();
exports.argv = ['node','one.js'];
exports.argv = ['node'];
exports.env = {};

@@ -109,4 +110,4 @@ exports.nextTick = function nextTick(fn){

exports.stdout = Stream(true, false);
exports.version = 'v0.4.11';
exports.versions = {"node":"0.4.11","v8":"3.1.8.26","ares":"1.7.4","ev":"4.4","openssl":"1.0.0d"};
exports.version = 'v0.5.0-pre';
exports.versions = {"node":"0.5.0-pre","v8":"3.1.8.3","ares":"1.7.4","ev":"4.4","openssl":"1.0.0d"};
/**

@@ -206,2 +207,13 @@ * void definitions

}
function stderr(){
return lib.process.stderr.content;
}
function stdin(){
return lib.process.stdin.content;
}
function stdout(){
return lib.process.stdout.content;
}
return (locals = {

@@ -215,2 +227,5 @@ 'lib':lib,

'pkg':pkg,
'stderr':stderr,
'stdin':stdin,
'stdout':stdout,
'require':require

@@ -232,6 +247,6 @@ });

return {
'id':'b',
'id':'web',
'pkg':parent,
'wrapper':function(module, exports, global, Buffer, process, require, undefined){
exports.b = true;
console.log('this module will be working for only web browsers');

@@ -261,4 +276,16 @@

exampleProject.module(1, function(parent){
return {
'id':'b',
'pkg':parent,
'wrapper':function(module, exports, global, Buffer, process, require, undefined){
exports.b = true;
}
};
});
exampleProject.pkg(1, function(parent){

@@ -277,6 +304,7 @@ return {

return {
'id':'g',
'id':'f',
'pkg':parent,
'wrapper':function(module, exports, global, Buffer, process, require, undefined){
exports.g = true;
require('subdependency');
exports.f = true;

@@ -289,7 +317,6 @@ }

return {
'id':'f',
'id':'g',
'pkg':parent,
'wrapper':function(module, exports, global, Buffer, process, require, undefined){
require('subdependency');
exports.f = true;
exports.g = true;

@@ -315,6 +342,7 @@ }

return {
'id':'j',
'id':'i',
'pkg':parent,
'wrapper':function(module, exports, global, Buffer, process, require, undefined){
exports.j = true;
require('sibling');
exports.i = true;

@@ -327,7 +355,6 @@ }

return {
'id':'i',
'id':'j',
'pkg':parent,
'wrapper':function(module, exports, global, Buffer, process, require, undefined){
require('sibling');
exports.i = true;
exports.j = true;

@@ -353,7 +380,7 @@ }

return {
'id':'n',
'id':'p/r',
'pkg':parent,
'wrapper':function(module, exports, global, Buffer, process, require, undefined){
require('./p/r');
exports.n = true;
require('../s/t');
exports.r = true;

@@ -366,7 +393,7 @@ }

return {
'id':'p/r',
'id':'n',
'pkg':parent,
'wrapper':function(module, exports, global, Buffer, process, require, undefined){
require('../s/t');
exports.r = true;
require('./p/r');
exports.n = true;

@@ -373,0 +400,0 @@ }

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