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

one

Package Overview
Dependencies
Maintainers
1
Versions
196
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 2.5.2 to 3.0.0

Devfile

2

lib/help.js

@@ -5,6 +5,6 @@ var fs = require("fs"),

module.exports = function(){
process.stdout.write('\u001B[2J\u001B[0;0f');
var man = fs.readFileSync(__dirname + '/../docs/man');
process.stdout.write('\u001B[2J\u001B[0;0f');
puts(man);
process.exit(0);
};

@@ -1,90 +0,42 @@

var debug = require('./debug')('manifest'),
path = require('path'),
fs = require("fs");
var debug = require("./debug")('manifest'),
parents = require('parents'),
path = require("path"),
fs = require('fs'),
exists = fs.existsSync,
readFile = fs.readFileSync;
function paths(pkg, dir){
var result = [path.join(dir, 'node_modules')],
up;
module.exports = readManifest;
up = path.join(dir, '../');
function findManifest(filename){
if(/package\.json$/.test(filename)) return filename;
while(fs.existsSync(up)){
result.push(path.join(up, 'node_modules'));
debug('Looking for the package manifest of %s', filename);
if( path.join(process.cwd(), up) == '/'){
break;
}
var dirs = parents(/^\//.test(filename) ? filename : path.join(process.cwd(), path.dirname(filename))),
maybe, found;
up = path.join(up, '../');
}
found = dirs.some(function(dir){
maybe = path.join(dir, 'package.json');
debug('Checking if %s exists', maybe);
return exists(maybe);
});
return result;
return found ? maybe : undefined;
}
function find(packageName, workingdir, callback){
function readManifest(filename){
debug('Reading manifest at %s', filename);
var found, filename;
var manifest = findManifest(filename),
parsed;
debug('Searching for the manifest file of package "%s" under "%s"', packageName, workingdir);
found = paths(packageName, workingdir).some(function(dir){
filename = path.join(dir, packageName, '/package.json');
if(fs.existsSync(filename)){
callback(undefined, filename);
return true;
}
});
if(!found){
debug('Failed to find package "%s"', packageName);
return callback(new Error('Failed to find package "' + packageName + '"'));
if( !manifest ){
debug('Unable to find the package manifest of %s', filename);
return undefined;
}
};
function fix(manifest){
parsed = JSON.parse( readFile(manifest) );
parsed.at = manifest;
var lib = manifest.directories && manifest.directories.lib,
main = manifest.main;
if( lib && main && ( main.substring(0, lib.length) != lib && ( './' + main ).substring(0, lib.length) != lib ) ){
delete manifest.directories.lib;
}
return manifest;
return parsed;
}
function read(filename, callback){
debug('Reading the manifest @ "%s"', filename);
var manifest;
fs.readFile(filename, function(error, bf){
if(error){
debug('Failed to read the file "%s"', filename);
callback(error);
return;
}
debug('Parsing the manifest @ "%s"', filename);
try {
manifest = JSON.parse(bf.toString());
debug('Manifest file "%s" loaded and parsed successfully.', filename);
} catch(exc) {
debug('Failed to parse the manifest @ "%s"', filename);
error = exc;
}
callback(error, fix(manifest));
});
}
module.exports = read;
module.exports.find = find;

@@ -1,184 +0,41 @@

var path = require('path'),
assert = require('assert'),
fs = require('fs'),
compose = require('functools').compose,
var debug = require("./debug")('package'),
fs = require("fs"),
path = require("path"),
memoize = require('memoize-sync'),
newModule = require('./module'),
debug = require('./debug')('package'),
id = require('./id'),
manifest = require('./manifest'),
modules = require('./modules'),
dependencies = require('./dependencies');
locked = {};
function construct(context, callback){
module.exports = memoize(newPackage);
assert.ok(context.manifest);
assert.ok(context.wd);
function newPackage(name, entry){
debug('New package: %s (%s)', name, entry);
var parents = !context.parents || !context.parents.length ? [] : context.parents;
if(locked[name]){
debug('%s is locked.', name);
return locked[name];
}
!context.parents && context.parent && parents.push( context.parent );
var pack = {
id : newModule.id(),
name : name
};
var struct = {
'id' : context.manifest.name,
'dependencies' : undefined,
'dirs' : context.manifest.directories || {},
'ignore' : context.ignore,
'main' : undefined,
'manifest' : context.manifest,
'modules' : undefined,
'modulesDict' : {},
'name' : context.manifest.name,
'parents' : parents,
'pkgdict' : parents.length ? parents[0].pkgdict : {},
'wd' : context.wd
pack.toString = function(){
return '(Package ' + name + ')';
};
struct.pkgdict[struct.name] = struct;
locked[name] = pack;
pack.main = newModule(entry, undefined, pack.id);
delete locked[name];
callback(undefined, struct);
}
function loadDependencies(params, callback){
var pkg = params.pkg, options = params.options;
debug('Loading dependencies of %s', pkg.name);
dependencies(pkg, options, function(error, deps){
if(error){
debug('An unexpected error occurred during collecting dependencies of the package "%s".', pkg.name);
debug(error);
callback(error);
return;
}
debug('%d dependencies has been loaded for the package "%s"', deps.length, pkg.name);
pkg.dependencies = deps;
callback(undefined, params);
});
}
function loadModules(params, callback){
var pkg = params.pkg, options = params.options;
modules(pkg, options, function(error, modules){
if(error){
debug('An unexpected error occurred during collecting modules of the package "%s".', pkg.name);
debug(error);
callback(error);
return;
}
debug('Collected %d modules for the package "%s"', modules.length, pkg.name);
pkg.modules = modules;
var i = modules.length, m;
while(i-->0){
m = modules[i];
pkg.modulesDict[m.path] = m;
}
callback(undefined, params);
});
}
function setMainModule(params, callback){
var pkg = params.pkg, options = params.options, errormsg;
if( ! pkg.manifest.main ){
return callback(undefined, pkg, options);
if (!pack.main) {
debug('Nothing found for %s at %s', name, entry);
return undefined;
}
debug('Setting main module of the package "%s" as %s', pkg.name, pkg.manifest.main);
pack.dependencies = pack.main.dependencies;
pack.render = pack.main.render;
var absolutePath = path.join(pkg.wd, pkg.manifest.main );
fs.stat(absolutePath, function(error, stat){
var isDirectory = stat && stat.isDirectory(),
hasJSExt = /\.js$/.test(pkg.manifest.main),
resolvedPath = isDirectory ? path.join( absolutePath, 'index.js') : hasJSExt ? absolutePath : absolutePath + '.js';
pkg.main = pkg.modulesDict[resolvedPath];
if( pkg.main ){
pkg.mainModuleId = pkg.main.name;
callback(undefined, params);
} else {
errormsg = 'Failed to find main module of "' + pkg.name + '". Resolved Path: "' + resolvedPath + '" Manifest Definition: "' + pkg.manifest.main + '"';
debug(errormsg);
callback(new Error(errormsg));
}
});
return pack;
}
function content(pkg, options, callback){
debug('Loading the package "%s"', pkg.manifest.name);
compose.async(loadDependencies, loadModules, setMainModule)({ 'pkg': pkg, 'options': options }, function(error){
if(error){
callback(error);
return;
}
debug('%s loaded.', pkg.name);
callback(undefined, pkg);
});
}
function main(options, buildOptions, callback){
var manifestPath;
typeof options == 'string'
&& ( manifestPath = options, options = { 'manifestPath': manifestPath } )
|| ( manifestPath = options.manifestPath );
debug('Building the package at "%s"', manifestPath);
manifest(manifestPath, function(error, manifestObj){
if(error){
callback(error);
return;
}
var constructOptions = {
'manifest': manifestObj,
'ignore':options.ignore,
'wd': path.normalize(path.dirname(manifestPath)),
'parents': options.parents,
'parent': options.parent
};
construct(constructOptions, function(error, pkgobj){
if(error){
callback(error);
return;
}
if(pkgobj.parents.length == 0){
buildOptions.rootPackage = pkgobj;
}
content(pkgobj, buildOptions, callback);
});
});
}
module.exports = main;
module.exports.id = id();
module.exports.content = content;
module.exports.construct = construct;

@@ -1,2 +0,3 @@

var puts = require('util').puts;
var puts = require('util').puts,
pkg = require('../package.json');

@@ -6,4 +7,4 @@ module.exports = version;

function version(){
puts('fox v' + require('../package.json').version);
puts(pkg.name + ' v' + pkg.version);
process.exit(0);
}
{
"name": "one",
"version": "2.5.2",
"description": "Transform NodeJS packages into single stand-alone script files.",
"author": "Azer Koculu <azer@kodfabrik.com>",
"keywords": [
"commonjs",
"browser"
],
"directories": {
"lib": "./lib"
"version": "3.0.0",
"description": "Bundles NodeJS modules/libraries for web browsers",
"main": "index.js",
"scripts": {
"test": "fox test/index.js test/options.js"
},
"main": "./lib",
"bin": {

@@ -18,16 +13,22 @@ "onejs": "./bin/onejs"

"dependencies": {
"functools": "1.x",
"optimist": "0.x",
"hogan.js": "2.x",
"debug": "*",
"optimist": "*",
"glob": "*",
"debug": "*",
"flatten-array": "*",
"boxcars": "*"
"memoize-sync": "*",
"uniques": "0.0.0",
"parents": "0.0.1",
"new-format": "0.0.1",
"core-modules": "0.0.0",
"new-chain": "0.0.0",
"attrs": "0.0.0"
},
"devDependencies": {
"highkick": "1.x"
"fox": "*"
},
"scripts": {
"test": "highkick test/index"
}
"repository": {
"url": "git@github.com:azer/onejs.git",
"type": "git"
},
"author": "Azer Koçulu <azer@kodfabrik.com>",
"license": "BSD"
}

@@ -1,406 +0,11 @@

OneJS is a command-line utility for converting CommonJS packages to single, stand-alone JavaScript
files that can be run on web browsers.
## onejs
```bash
$ one > browser.js
```
Bundles NodeJS modules/libraries for web browsers
![](https://dl.dropbox.com/s/r29fc29iip3mj8u/onejs.jpg)
### Install
# DOCUMENTATION
* [Install](#install)
* [First Steps](#first-steps)
* [Advanced Usage](#advanced-usage)
* [Saving Multiple Files & Async Loading](#multiple)
* [Watching File Changes](#watching)
* [Package Aliases](#alias)
* [Accessing Global Browser Variables](#global-vars)
* [Excluding Packages](#exclude)
* [Filtering Modules](#filter)
* [Customizing Global Name](#customize-name)
* [API Reference](#api)
* [Command-Line API](#cli)
* [NodeJS API](#nodejs)
* [package.json](#packagejson)
* [Examples](#examples)
* [Troubleshooting](#troubleshooting)
* [Testing](#testing)
<a name="install"></a>
## Install
```bash
$ npm install -g one
$ npm install onejs
```
<a name="first-steps"></a>
# First Steps
The quickest way of giving OneJS a try is to run "onejs build package.json" command in a project folder. It'll walk through all the directories, find
JavaScript files in the "lib" folder (if exists, and by considering .npmignore), and produce an output that can be run by any web browser and NodeJS, as well.
Bundle files produced by OneJS consist of a CommonJS implementation and the throughout package tree wrapped by [OneJS' templates](https://github.com/azer/onejs/tree/master/templates/dynamic).
And the produced output will be unobtrusive. Which means, your project will not conflict with any other JavaScript on the page that is embedded.
Once you produce the output, as you expect, it needs to be included by an HTML page, like the below example;
```bash
$ one build hello-world/package.json output.js
$ cat > index.html
<html>
<script src="output.js"></script>
<script>helloWorld();</script>
</html>
```
You may notice a function named `helloWorld` was called. That's what starts running your program by requiring the `main` module of the project.
Besides of that `helloWorld` refers to the main module, it also exports some utilities that can be useful. See following for an example;
```js
> helloWorld.require('./module');
[object ./module.js]
> helloWorld.require('dependency');
[object node_modules/dependency]
```
In addition to command-line API, there are two more ways to configure build options. You can have the configuration in a package.json manfest;
```json
{
"name": "hello-world",
"version": "1.0.0",
"directories": {
"lib": "lib"
},
"web": {
"save": "bundle.js",
"alias": {
"crypto": "crypto-browserify"
},
"tie": {
"jquery": "window.jQuery"
}
}
}
```
Or, you can write your own build script using OneJS' [chaining API](https://github.com/azer/onejs/blob/master/lib/chaining.js):
```js
// build.js
var one = require('../../../lib');
one('./package.json')
.alias('crypto', 'crypto-browserify')
.tie('pi', 'Math.PI')
.tie('json', 'JSON')
.exclude('underscore')
.filter(/^build\.js$/)
.filter(/^bundle\.js$/)
.save('bundle.js');
```
<a name="advanced-usage"></a>
## Advanced Usage
<a name="multiple"></a>
### Saving Multiple Files & Async Loading
Specified dependencies (including their subdependencies) can be splitted to different files via `package.json` manifest.
```json
{
"name": "hello-world",
"version": "1.0.0",
"dependencies": {
"foo": "*",
"bar": "*"
},
"web": {
"save": {
"hello-world": "hello-world.js",
"bar": {
"to": "bar.js",
"url: "/js/bar.js"
}
}
}
}
```
OneJS will be outputting an async require implementation to let you load splitted packages;
```js
// hello-world/index.js
var foo = require('foo');
require.async('bar', function(bar)){ // loads "/js/bar.js"
console.log('dependencies are loaded!');
console.log(bar);
// => [object bar]
});
```
<a name="watching"></a>
### Watching File Changes
OneJS doesn't have a watching utility since a built-in one becomes useless when you have other build steps.
Recommended way is to create a Makefile, and use the good tools such as [visionmedia/watch](https://github.com/visionmedia/watch) to
, [isaacs/node-supervisor](https://github.com/isaacs/node-supervisor) build your project when there is a change. Following Makefile example watches files under /lib directory.
```make
SRC = $(wildcard lib/*/*.js)
build: $(SRC)
@one build package.json bundle.js
```
Below command will be updating `bundle.js` when `lib/` has a change.
```bash
$ watch make
```
<a name="alias"></a>
### Package Aliases
Registers a new name for specified package. It can be configured via command-line, package.json and NodeJS APIs.
```bash
$ one build package.json output.js --alias request:superagent,crypto:crypto-browserify
```
package.json
```json
{
"name": "hello-world",
"web": {
"alias": {
"crypto": "crypto-browserify"
}
}
}
```
NodeJS
```js
one('./package.json')
.alias('crypto', 'crypto-browserify')
.save('foo.js');
```
<a name="global-vars"></a>
### Accessing Global Browser Variables
OneJS doesn't stop you from accessing globals. However, you may want to use `require` for accessing some global variables,
such as jQuery, for some purposes like keeping your source-code self documented.
OneJS may tie some package names to global variables if demanded. And it can be configured via command-line, package.json and NodeJS APIs.
```bash
$ one build package.json output.js --tie jquery:jQuery,google:goog
```
package.json
```json
{
"name": "hello-world",
"web": {
"tie": {
"jquery": "jQuery",
"google": "goog"
}
}
}
```
NodeJS
```js
one('./package.json')
.tie('jquery', 'jQuery')
.tie('google', 'goog')
.save('foo.js');
```
<a name="exclude"></a>
### Excluding Packages
Excludes specified packages from your bundle.
```bash
$ one build package.json output.js --excude underscore
```
package.json
```json
{
"name": "hello-world",
"web": {
"exclude": ["underscore"]
}
}
```
NodeJS
```js
one('./package.json')
.exclude('underscore')
.save('foo.js');
```
<a name="filter"></a>
### Filtering Modules/Files
OneJS reads .npmignore to ignore anything not wanted to have in the bundle. In addition to .npmignore, you may also
define your own Regex filters to ignore files. This config is only provided for only NodeJS scripts.
```js
one('./package.json')
.filter(/^build\.js$/)
.filter(/^bundle\.js$/)
.save('bundle.js');
```
<a name="add-deps"></a>
### Additional Dependencies
You may add some dependencies not defined in your package.json;
```js
one('./package.json')
.dependency('request', '2.x')
.dependency('async', '2.x')
.save(function(error, bundle){
bundle
// => the source code
})
```
<a name="dev-deps"></a>
### Enabling Development Dependencies
```js
one('./package.json')
.devDependencies()
.save('bundle.js')
```
<a name="customize-name"></a>
### Customizing Global Variable
OneJS defines the global variable that wraps the bundle by default. For example, a project named "hello-world" lies
under "helloWorld" object on the browsers.
To customize it, define "name" field on your package.json;
```json
{
"name": "hello-world",
"web": {
"name": "HelloWorld"
}
}
```
<a name="api"></a>
## API Reference
OneJS lets you pick any of the following ways to configure your build.
<a name="packagejson"></a>
### package.json
```json
{
"name": "hello-world",
"version": "1.0.0",
"directories": {
"lib": "lib"
},
"web": {
"name":"HelloWorld",
"save": "bundle.js",
"alias": {
"crypto": "crypto-browserify"
},
"tie": {
"jquery": "window.jQuery"
}
}
}
```
<a name="cli"></a>
### Command-Line
```bash
usage: onejs [action] [manifest] [options]
Transforms NodeJS packages into single, stand-alone JavaScript files that can be run at other platforms. See the documentation at http://github.com/azer/onejs for more information.
actions:
build <manifest> <target> Generate a stand-alone JavaScript file from specified package. Write output to <target> if given any.
server <manifest> <port> <host> Publish generated JavaScript file on web. Uses 127.0.0.1:1338 by default.
options:
--debug Enable SourceURLs.
--alias <alias>:<package name> Register an alias name for given package. e.g: request:superagent,crypto:crypto-browserify
--tie <package name>:<global object> Create package links to specified global variables. e.g; --tie dom:window.document,jquery:jQuery
--exclude <package name> Do not contain specified dependencies. e.g: --exclude underscore,request
--plain Builds the package within a minimalistic template for the packages with single module and no dependencies.
--quiet Make console output less verbose.
--verbose Tell what's going on by being verbose.
--version Show version and exit.
--help Show help.
```
<a name="nodejs"></a>
### NodeJS
```js
// build.js
var one = require('../../../lib');
one('./package.json')
.alias('crypto', 'crypto-browserify')
.tie('pi', 'Math.PI')
.tie('json', 'JSON')
.include('optional-module.js')
.dependency('optional-dependency', '2.x')
.exclude('underscore')
.filter(/^build\.js$/)
.filter(/^bundle\.js$/)
.devDependencies()
.name('helloKitty')
.save('bundle.js'); // or .save(function(error, bundle){ })
```
## Examples
// Following examples are out of date. Will be updated soon.
* [Fox](https://github.com/azer/fox/blob/master/lib/browser.js#L19)
* See the example project included in this repository
* MultiplayerChess.com ([Source Code](https://github.com/azer/multiplayerchess.com/tree/master/frontend) - [Output](http://multiplayerchess.com/mpc.js) )
* [ExpressJS built by OneJS](https://gist.github.com/2415048)
* [OneJS built by OneJS](https://gist.github.com/2998719)
# Troubleshooting
* The most common issue is to lack some dependencies. In that case, make sure that the missing dependency is located under `node_modules/` properly.
* Enabling verbose mode might be helpful: `onejs build package.json --verbose`
* See the content of `projectName.map` object if it contains the missing dependency
# TESTING
Run `npm test` for running all test modules. And run `make test module=?` for specific test modules;
```bash
> make test module=build
```
![](https://dl.dropbox.com/s/9q2p5mrqnajys22/npmel.jpg)

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