Comparing version 1.5.1 to 1.7.0
var path = require('path'), | ||
readdir = require('fs').readdir, | ||
logging = require('./logging'), | ||
manifest = require('./manifest'), | ||
installDict = Object.keys(require('./install_dict')), | ||
pkg; | ||
packages = require('./packages'); | ||
const BLACK_LIST = [ | ||
@@ -14,3 +13,3 @@ 'one' | ||
function nodePackages(pkg, callback){ | ||
function nodeCorePackages(pkg, callback){ | ||
readdir( path.join(pkg.wd, 'node_modules'), function(error, files){ | ||
@@ -32,6 +31,6 @@ | ||
function dependencies(pkg, options, callback){ | ||
function dependencies(parent, options, callback){ | ||
var deps = [], | ||
declaredDepObj = pkg.manifest.dependencies, | ||
declaredDepObj = parent.manifest.dependencies, | ||
declaredDepList, | ||
@@ -46,7 +45,7 @@ next; | ||
nodePackages(pkg, function(installedNodePackages){ | ||
nodeCorePackages(parent, function(installedNodeCorePackages){ | ||
if(installedNodePackages.length){ | ||
if(installedNodeCorePackages.length){ | ||
!declaredDepList && ( declaredDepList = [] ); | ||
declaredDepList = declaredDepList.concat(installedNodePackages); | ||
declaredDepList = declaredDepList.concat(installedNodeCorePackages); | ||
} | ||
@@ -62,3 +61,3 @@ | ||
if(i>=declaredDepList.length){ | ||
logging.debug('Loaded %d dependencies under the package "%s"',declaredDepList.length, pkg.manifest.name); | ||
logging.debug('Loaded %d dependencies under the package "%s"',deps.length, parent.manifest.name); | ||
callback(undefined, deps); | ||
@@ -70,16 +69,16 @@ return; | ||
var dp = declaredDepList[i], | ||
manifestPath = path.join(pkg.wd, 'node_modules/', dp, '/package.json'); | ||
var name = declaredDepList[i]; | ||
logging.debug('Loading the dependency in "'+manifestPath+'" for the package "'+pkg.name+'"'); | ||
manifest.find(name, parent.wd, function(error, manifestPath){ | ||
if(pkg.pkgDict[dp]){ | ||
next(); | ||
return; | ||
} | ||
if(error){ | ||
callback(error); | ||
return; | ||
} | ||
packages.loadFromManifestPath(manifestPath, pkg, options, function(error, subpkg){ | ||
logging.debug('Loading the dependency "%s" for its parent package "%s"', name + ' ('+ manifestPath +')', parent.name); | ||
if(error){ | ||
logging.warn(error); | ||
if(parent.pkgdict[name]){ | ||
parent.pkgdict[name].parents.push(parent); | ||
deps.push(parent.pkgdict[name]); | ||
next(); | ||
@@ -89,4 +88,10 @@ return; | ||
deps.push(subpkg); | ||
next(); | ||
!pkg && ( pkg = require('./package') ); | ||
pkg({ 'manifestPath': manifestPath, 'parent': parent }, options, function(error, dependency){ | ||
deps.push(dependency); | ||
next(); | ||
}); | ||
}); | ||
@@ -93,0 +98,0 @@ |
@@ -10,35 +10,49 @@ var functools = require('functools'), | ||
function filterFilename(filename,callback){ | ||
function filterFilename(filename){ | ||
return /\.js$/.test(filename); | ||
} | ||
var load = (function(){ | ||
function filterFilenames(filenames, callback){ | ||
callback(undefined,filenames.filter(filterFilename)); | ||
} | ||
var template; | ||
function filterIgnoredModules(pkg){ | ||
return function(filenames, callback){ | ||
return function load(filename, callback){ | ||
logging.debug('Loading module "'+filename+'"'); | ||
readFile(filename, function(error, bf){ | ||
if(error) { | ||
callback(error); | ||
return; | ||
} | ||
if(!pkg.ignore){ | ||
callback(undefined, filenames); | ||
return; | ||
} | ||
var content = bf.toString(), | ||
name = fixname(filename); | ||
var f = filenames.length, | ||
i, ignore, filename, | ||
ignored, result = []; | ||
if(content.substring(0,2) == '#!'){ | ||
content = content.replace(/\#\!.+\n/, ''); | ||
while( f -- ){ | ||
ignored = false; | ||
i = pkg.ignore.length; | ||
filename = filenames[f].substring(pkg.wd.length + ( pkg.wd.substring(pkg.wd.length-1) != '/' ? 1 : 0 )); | ||
while( i -- ){ | ||
ignore = pkg.ignore[i]; | ||
if( filename.substring( 0, ignore.length ) == ignore ){ | ||
logging.debug('Module "%s" is ignored by the line "%s" at .npmignore', filename, ignore); | ||
ignored = true; | ||
break; | ||
} | ||
} | ||
callback(undefined, { | ||
'name':name, | ||
'filename':filename, | ||
'path':filename, | ||
'content':content | ||
}); | ||
}); | ||
!ignored && result.push( filenames[f] ); | ||
} | ||
callback(undefined, result); | ||
}; | ||
} | ||
})(); | ||
@@ -50,3 +64,67 @@ function fixname(filename){ | ||
function modules(pkg, callback){ | ||
function loadModule(filename, callback){ | ||
logging.debug('Loading module "'+filename+'"'); | ||
readFile(filename, function(error, bf){ | ||
if(error) { | ||
callback(error); | ||
return; | ||
} | ||
var content = bf.toString(), | ||
name = fixname(filename); | ||
if(content.substring(0,2) == '#!'){ | ||
content = content.replace(/\#\!.+\n/, ''); | ||
} | ||
callback(undefined, { | ||
'name':name, | ||
'filename':filename, | ||
'path':filename, | ||
'content':content | ||
}); | ||
}); | ||
}; | ||
function loadModules(pkg, base){ | ||
return function(filenames, callback){ | ||
logging.debug('Found '+filenames.length+' file(s) under the package "'+pkg.name+'"'); | ||
var modules = []; | ||
(function next(i){ | ||
if(i>=filenames.length){ | ||
logging.debug('Loaded %d module(s) under the package "%s"',filenames.length,pkg.name); | ||
callback(undefined, modules); | ||
return; | ||
} | ||
loadModule(filenames[i], function(error, module){ | ||
if(error){ | ||
logging.error('Failed to load the module "'+filenames[i]+'"'); | ||
callback(error); | ||
return; | ||
} | ||
module.filename = module.filename.replace(base+'/', ''); | ||
module.filename.indexOf('/') > 0 && base != '.' && ( module.filename = module.filename.replace(base, '') ); | ||
module.id = module.filename.replace(/\.js$/,''); | ||
if(!error) modules.push(module); | ||
next(i+1); | ||
}); | ||
})(0); | ||
}; | ||
} | ||
function modules(pkg, options, callback){ | ||
logging.debug('Collect modules for the package "'+pkg.name+'"'); | ||
@@ -74,3 +152,3 @@ | ||
logging.debug('The directories to search:',dirs); | ||
logging.debug('The directories to search:', dirs); | ||
@@ -80,36 +158,5 @@ compose.async(combiner.findFiles, | ||
combiner.flatten, | ||
function(filenames,callback){ | ||
callback(undefined,filenames.filter(filterFilename)); | ||
}, | ||
function(filenames, callback){ | ||
logging.debug('Found '+filenames.length+' file(s) under the package "'+pkg.name+'"'); | ||
var modules = []; | ||
(function next(i){ | ||
if(i>=filenames.length){ | ||
logging.debug('Loaded %d module(s) under the package "%s"',filenames.length,pkg.name); | ||
callback(undefined, modules); | ||
return; | ||
} | ||
load(filenames[i], function(error, module){ | ||
if(error){ | ||
logging.error('Failed to load the module "'+filenames[i]+'"'); | ||
callback(error); | ||
return; | ||
} | ||
module.filename = module.filename.replace(base+'/', ''); | ||
module.filename.indexOf('/') > 0 && base != '.' && ( module.filename = module.filename.replace(base, '') ); | ||
module.id = module.filename.replace(/\.js$/,''); | ||
if(!error) modules.push(module); | ||
next(i+1); | ||
}); | ||
})(0); | ||
})(dirs,callback); | ||
filterFilenames, | ||
filterIgnoredModules(pkg), | ||
loadModules(pkg, base))(dirs, callback); | ||
} | ||
@@ -119,3 +166,4 @@ | ||
module.exports.filterFilename = filterFilename; | ||
module.exports.load = load; | ||
module.exports.loadModule = loadModule; | ||
module.exports.loadModules = loadModules; | ||
module.exports.fixname = fixname; |
var readFile = require('fs').readFile, | ||
logging = require('./logging'), | ||
templating = require('./templating'), | ||
functools = require('functools'), | ||
functools = require('functools'), | ||
map = functools.map; | ||
map = functools.map.async, | ||
juxt = functools.juxt.async; | ||
var templates = templating.collection('wrapper.js', 'package.js', 'module.js', 'console.js', 'library.js', 'path.js', 'process.js'), | ||
render = templating.render(templates); | ||
function flattenPkgTree(tree){ | ||
var l = [tree]; | ||
var pkgs = [], | ||
key; | ||
var i = -1; | ||
while(tree.dependencies && ++i<tree.dependencies.length){ | ||
Array.prototype.push.apply(l, flattenPkgTree(tree.dependencies[i])); | ||
for(key in tree.pkgdict){ | ||
pkgs.push( tree.pkgdict[ key ] ); | ||
} | ||
return l; | ||
return pkgs; | ||
} | ||
function render(pkg, options, callback){ | ||
function sandboxConsole(options, callback){ | ||
logging.trace('Rendering console template'); | ||
render('console', callback); | ||
} | ||
var treeName = options.treeName = templating.makeVariableName(pkg.name); | ||
var pkgs = flattenPkgTree(pkg); | ||
function env(options){ | ||
var result, key; | ||
pkgs = pkgs.map(function(el){ | ||
return { 'pkg':el, 'treeName':treeName }; | ||
}); | ||
if(options.debug){ | ||
result = {}; | ||
for(key in process.env){ | ||
result[ key ] = process.env[ key ].replace(/"/g, '\''); | ||
} | ||
} | ||
map.async(renderPackage, pkgs, function(error, renderedPkgs){ | ||
if(error) { | ||
return JSON.stringify(result); | ||
} | ||
function library(options, callback){ | ||
logging.trace('Rendering library template...'); | ||
var view = {}, partials = {}; | ||
view.debug = options.debug; | ||
view.version = '1.6.0'; // FIXME | ||
view.versions = '{}'; | ||
view.env = env(options); | ||
view.sandboxConsole = options.sandboxConsole; | ||
view.include_process = !options.noprocess; | ||
juxt({ 'path':path, 'process':process, 'console': sandboxConsole })(options, function(error, partials){ | ||
if(error){ | ||
callback(error); | ||
@@ -34,15 +60,12 @@ return; | ||
options.renderedPkgs = renderedPkgs; | ||
render({ 'template': 'library', 'view': view, 'partials': partials }, callback); | ||
logging.info('All packages has been built successfully.'); | ||
renderWrapper(options, callback); | ||
}); | ||
}; | ||
} | ||
function renderLibrary(options, callback){ | ||
logging.trace('Rendering library...'); | ||
function main(pkg, options, callback){ | ||
logging.trace('Rendering...'); | ||
templating.render({ 'template':'path.js' }, function(error, path){ | ||
if(error) { | ||
templates(function(error, buffers){ | ||
if(error){ | ||
callback(error); | ||
@@ -52,73 +75,116 @@ return; | ||
var env, key; | ||
var treeName = templating.makeVariableName(pkg.name), | ||
pkgs = flattenPkgTree(pkg); | ||
if(options.debug){ | ||
env = {}; | ||
for(key in process.env){ | ||
env[ key ] = process.env[ key ].replace(/"/g, '\''); | ||
map( npmpackage.bind(undefined, treeName, options), pkgs, function(error, packages){ | ||
if(error){ | ||
callback(error); | ||
return; | ||
} | ||
} | ||
var view = { | ||
'debug': options.debug, | ||
'version':'1.3.5', | ||
'versions': '{}', | ||
'env': options.debug ? JSON.stringify(env, null, 4) : undefined | ||
}; | ||
logging.info('All packages has been built. Rendering the output now...'); | ||
templating.render({ 'template':'process.js', view:view }, function(error, processEmu){ | ||
if(error) return callback(error); | ||
wrapper(treeName, packages.join('\n\n\n\n'), options, callback); | ||
return templating.render({ 'template':'library.js', 'view':{ node:true, include_process:!options.noprocess }, 'partials':{ 'path':path, 'process':processEmu } }, callback); | ||
}); | ||
}); | ||
} | ||
function renderModule(options, callback){ | ||
function npmpackage(treeName, options, pkg, callback){ | ||
logging.debug('Building package "'+pkg.name+'"'); | ||
var view = { | ||
'treeName':options.treeName, | ||
'parentId':options.pkg.id, | ||
'id':options.module.id | ||
'treeName': treeName, | ||
'hasParent': pkg.parents.length > 0, | ||
'parentIds': pkg.parents.map(function(el){ return el.id; }).join(', '), | ||
'id': pkg.id, | ||
'main': pkg.main && pkg.main.id, | ||
'name': pkg.name, | ||
'wd': pkg.wd | ||
}; | ||
logging.debug('Rendering module "'+view.id+'"'); | ||
var partials = {}; | ||
templating.render({ 'template':'module.js', 'view':view, 'partials':{ 'content':options.module.content } }, callback); | ||
map( npmmodule.bind(undefined, pkg, treeName, options), pkg.modules, function(error, modules){ | ||
if(error) { | ||
callback(error); | ||
return; | ||
} | ||
partials.modules = modules.join('\n\n'); | ||
render({ 'template':'package', 'view': view, 'partials': partials }, callback); | ||
}); | ||
} | ||
function renderPackage(options,callback){ | ||
function npmmodule(pkg, treeName, options, module, callback){ | ||
logging.debug('Building module "'+module.id+'"'); | ||
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 | ||
'treeName': treeName, | ||
'parentId': pkg.id, | ||
'id': module.id, | ||
'sandbox_console': options.sandboxConsole | ||
}; | ||
logging.debug('Rendering package "'+view.name+'"'); | ||
var partials = { | ||
'content': module.content | ||
}; | ||
var modules = options.pkg.modules.map(function(el){ | ||
return { | ||
'treeName':options.treeName, | ||
'pkg':options.pkg, | ||
'module':el | ||
}; | ||
}); | ||
render({ template: 'module', 'view': view, 'partials': partials }, callback); | ||
} | ||
map.async(renderModule, modules, function(error, renderedModules){ | ||
if(error) { | ||
callback(error); | ||
return; | ||
} | ||
function path(options, callback){ | ||
logging.trace('Rendering path template.'); | ||
render('path', callback); | ||
} | ||
templating.render({ 'template':'package.js', 'view':view, 'partials':{ 'modules':renderedModules.join('\n\n') } }, callback); | ||
}); | ||
function process(options, callback){ | ||
logging.trace('Rendering process template'); | ||
var view = { | ||
'env': env(options), | ||
'debug': options.debug, | ||
'version': '1.6.0', | ||
'versions': '{}' | ||
}; | ||
render({ template: 'process', view: view }, callback); | ||
} | ||
function renderWrapper(options, callback){ | ||
logging.trace('Rendering wrapper...'); | ||
renderLibrary({ 'node':options.node, 'debug':options.debug, 'noprocess': options.noprocess }, function(error, librarySC){ | ||
function ties(options){ | ||
if(!options.tie){ | ||
return undefined; | ||
} | ||
var output = '{', key, | ||
i = options.tie.length, | ||
comma = ''; | ||
while( i -- ){ | ||
output += comma + '"'+ options.tie[i].pkg + '": ' + options.tie[i].obj; | ||
comma = ', '; | ||
} | ||
output += '}'; | ||
return output; | ||
}; | ||
function wrapper(treeName, packages, options, callback){ | ||
logging.trace('Rendering wrapper template...'); | ||
var view = {}, partials = {}; | ||
view.name = treeName; | ||
view.debug = options.debug; | ||
view.ties = ties(options); | ||
view.sandbox_console = options.sandboxConsole; | ||
library(options, function(error, renderedLibrary){ | ||
if(error){ | ||
@@ -129,35 +195,16 @@ callback(error); | ||
var view = { | ||
'name': options.treeName, | ||
'debug': options.debug, | ||
}; | ||
partials.library = renderedLibrary; | ||
partials.packages = packages; | ||
options.tie && ( view.ties = (function(){ | ||
var ties = '{', key; | ||
render({ | ||
'template': 'wrapper', | ||
'view': view, | ||
'partials': partials | ||
}, callback); | ||
var i = options.tie.length, | ||
comma = ''; | ||
while( i -- ){ | ||
ties += comma + '"'+ options.tie[i].pkg + '": ' + options.tie[i].obj; | ||
comma = ', '; | ||
} | ||
ties += '}'; | ||
return ties; | ||
}()) ); | ||
templating.render({ | ||
'template':'wrapper.js', | ||
'view':view, | ||
'partials':{ | ||
'node':'', | ||
'library':librarySC, | ||
'packages':options.renderedPkgs.join('\n\n\n\n') | ||
} | ||
}, callback); | ||
}); | ||
} | ||
render.flattenPkgTree = flattenPkgTree; | ||
module.exports = render; | ||
main.flattenPkgTree = flattenPkgTree; | ||
module.exports = main; |
var mustache = require('mustache'), | ||
fs = require('fs'), | ||
config = require('./config'); | ||
boxcars = require('boxcars'), | ||
fs = require('fs'), | ||
var idGenerator = function(){ | ||
var serial = 0; | ||
return function id(){ | ||
return ++serial; | ||
}; | ||
}; | ||
config = require('./config'), | ||
logging = require('./logging'), | ||
id = require('./id'); | ||
function collection(){ | ||
var coll = {}; | ||
var i = arguments.length, | ||
filename; | ||
while( i --> 0 ){ | ||
filename = arguments[i]; | ||
coll[ filename.replace(/\.js$/, '') ] = config.TEMPLATES_DIR + '/' + filename; | ||
} | ||
return boxcars(coll); | ||
} | ||
function makeVariableName(str){ | ||
@@ -18,7 +29,7 @@ return str.toLowerCase().replace(/[^a-zA-Z0-9]+/g,' ').replace(/^[\d\s]+/g,'').split(' ').reduce(function(a,b){ | ||
function render(options,callback){ | ||
function _render(options, callback){ | ||
fs.readFile(config.TEMPLATES_DIR+'/'+options.template, function(error, bf){ | ||
var result; | ||
if(!error){ | ||
result = mustache.to_html(bf.toString(), options.view, options.partials); | ||
result = mustache.to_html(bf.toString(), options.view, options.partials);w | ||
} | ||
@@ -29,7 +40,51 @@ callback(error, result); | ||
function render(coll){ | ||
return function(/* options, callback */){ | ||
var options, callback = arguments[1]; | ||
if( typeof arguments[0] == 'string' ){ | ||
options = { 'template': arguments[0] }; | ||
} else { | ||
options = arguments[0]; | ||
} | ||
coll(function(error, templates){ | ||
if(error){ | ||
callback(error); | ||
return; | ||
} | ||
if( !templates.hasOwnProperty( options.template ) ){ | ||
callback(new Error('Unknown template: "' + options.template + '"')); | ||
return; | ||
} | ||
logging.trace('Rendering template "%s"', options.template); | ||
var output; | ||
try { | ||
output = mustache.to_html(templates[ options.template ], options.view, options.partials); | ||
} catch (mustacheError) { | ||
logging.error('Failed to render template "%s"', options.template); | ||
logging.error(mustacheError); | ||
callback(mustacheError); | ||
return; | ||
} | ||
callback(undefined, output); | ||
}); | ||
}; | ||
} | ||
module.exports = { | ||
'id':idGenerator(), | ||
'idGenerator':idGenerator, | ||
'collection': collection, | ||
'id':id(), | ||
'makeVariableName':makeVariableName, | ||
'render':render | ||
} | ||
}; |
{ | ||
"name":"one", | ||
"version":"1.5.1", | ||
"version":"1.7.0", | ||
"description":"Transform NodeJS packages into single stand-alone script files.", | ||
@@ -13,2 +13,3 @@ "author":"Azer Koculu <azer@kodfabrik.com>", | ||
"dependencies":{ | ||
"boxcars":"0.x", | ||
"functools":"1.x", | ||
@@ -20,7 +21,8 @@ "optimist":"0.x", | ||
"log4js":"0.x", | ||
"genpkg":"0.x" | ||
"genpkg":"0.x", | ||
"boxcars":"0.x" | ||
}, | ||
"scripts":{ | ||
"test":"node test/run.js" | ||
"test":"./node_modules/highkick/bin/highkick test/main.js" | ||
} | ||
} |
@@ -117,2 +117,20 @@ OneJS is a command-line utility for converting CommonJS packages to single, stand-alone JavaScript | ||
## Sandboxing Console Object | ||
OneJS doesn't provide an embed, encapsulated console object by default. Pass `--sandbox-console` if needed, output is available by `projectName.stdout()` and `project.stderr()`. | ||
```bash | ||
$ onejs build package.json foobar.js --sandbox-console | ||
``` | ||
```javascript | ||
> var foobar = require('./foobar'); | ||
> foobar.stdout(); | ||
'Trying out the embed console' | ||
'Hello world!' | ||
> foobar.stderr() | ||
'warning! something may be going wrong!' | ||
'error! something went wrong!' | ||
``` | ||
# Troubleshooting | ||
@@ -119,0 +137,0 @@ |
lib = (function(exports){ | ||
exports.path = (function(exports){ | ||
@@ -20,4 +20,11 @@ {{>path}} | ||
{{#sandboxConsole}} | ||
global.console = exports.console = (function(exports){ | ||
{{>console}} | ||
return exports; | ||
}({})); | ||
{{/sandboxConsole}} | ||
return exports; | ||
})({}); |
@@ -1,7 +0,7 @@ | ||
{{ treeName }}.module({{ parentId }}, function(onejsModParent){ | ||
{{ treeName }}.module({{ parentId }}, function(/* parent */){ | ||
return { | ||
'id':'{{ id }}', | ||
'pkg':onejsModParent, | ||
'wrapper':function(module, exports, global, Buffer, process, require, undefined){ | ||
'id': '{{ id }}', | ||
'pkg': arguments[0], | ||
'wrapper': function(module, exports, global, Buffer,{{#sandbox_console}} console, {{/sandbox_console}} process, require, undefined){ | ||
{{>content}} | ||
@@ -8,0 +8,0 @@ } |
@@ -1,2 +0,2 @@ | ||
{{ treeName }}.pkg({{ parentId }}, function(parent){ | ||
{{ treeName }}.pkg({{#hasParent}}{{ parentIds }}, {{/hasParent}}function(parents){ | ||
@@ -8,5 +8,4 @@ return { | ||
'mainModuleId':'{{ main }}', | ||
'dependencies':[], | ||
'modules':[], | ||
'parent':parent | ||
'parents':parents | ||
}; | ||
@@ -13,0 +12,0 @@ |
@@ -74,3 +74,3 @@ /** | ||
exports.version = '{{ node_version }}'; | ||
exports.version = '{{ version }}'; | ||
@@ -77,0 +77,0 @@ exports.versions = {{{ versions }}}; |
var {{ name }} = (function(global, undefined){ | ||
var DEBUG = {{#debug}}true{{/debug}}{{^debug}}false{{/debug}}, | ||
pkgdefs = {}, | ||
pkgmap = {}, | ||
@@ -17,17 +18,4 @@ global = {}, | ||
function findPkg(workingPkg, uri){ | ||
var pkg = undefined, | ||
parent = workingPkg; | ||
var i, len; | ||
do { | ||
i = parent.dependencies.length; | ||
while(i-->0){ | ||
parent.dependencies[i].name == uri && ( pkg = parent.dependencies[i] ); | ||
} | ||
parent = parent.parent; | ||
} while(!pkg && parent); | ||
return pkg; | ||
function findPkg(uri){ | ||
return pkgmap[uri]; | ||
} | ||
@@ -65,3 +53,3 @@ | ||
} else { | ||
pkg = findPkg(callingModule.pkg, uri); | ||
pkg = findPkg(uri); | ||
@@ -80,3 +68,3 @@ if(!pkg && nativeRequire){ | ||
module = pkg.main; | ||
module = pkg.index; | ||
} | ||
@@ -94,3 +82,3 @@ | ||
function module(parentId, wrapper){ | ||
var parent = pkgmap[parentId], | ||
var parent = pkgdefs[parentId], | ||
mod = wrapper(parent), | ||
@@ -110,9 +98,9 @@ cached = false; | ||
global.require = mod.require; | ||
mod.wrapper(mod, mod.exports, global, global.Buffer, global.process, global.require); | ||
mod.wrapper(mod, mod.exports, global, global.Buffer,{{#sandbox_console}} global.console,{{/sandbox_console}} global.process, global.require); | ||
return mod.exports; | ||
}; | ||
if(parent.mainModuleId == mod.id){ | ||
parent.main = mod; | ||
!parent.parent && ( locals.main = mod.call ); | ||
if(parent.mainModuleId == mod.id){ | ||
parent.index = mod; | ||
parent.parents.length == 0 && ( locals.main = mod.call ); | ||
} | ||
@@ -123,21 +111,26 @@ | ||
function pkg(parentId, wrapper){ | ||
var parent = pkgmap[parentId], | ||
ctx = wrapper(parent); | ||
function pkg(/* [ parentId ...], wrapper */){ | ||
pkgmap[ctx.id] = ctx; | ||
!parent && ( pkgmap['main'] = ctx ); | ||
var wrapper = arguments[ arguments.length - 1 ], | ||
parents = Array.prototype.slice.call(arguments, 0, arguments.length - 1), | ||
ctx = wrapper(parents); | ||
parent && parent.dependencies.push(ctx); | ||
if(pkgdefs.hasOwnProperty(ctx.id)){ | ||
throw new Error('Package#'+ctx.id+' "' + ctx.name + '" has duplication of itself.'); | ||
} | ||
pkgdefs[ctx.id] = ctx; | ||
pkgmap[ctx.name] = ctx; | ||
arguments.length == 1 && ( pkgmap['main'] = ctx ); | ||
} | ||
function mainRequire(uri){ | ||
return pkgmap.main.main.require(uri); | ||
return pkgmap.main.index.require(uri); | ||
} | ||
function stderr(){ | ||
return lib.process.stderr.content; | ||
} | ||
function stdin(){ | ||
@@ -156,5 +149,5 @@ return lib.process.stdin.content; | ||
'name' : '{{ name }}', | ||
'map' : pkgmap, | ||
'module' : module, | ||
'pkg' : pkg, | ||
'packages' : pkgmap, | ||
'stderr' : stderr, | ||
@@ -161,0 +154,0 @@ 'stdin' : stdin, |
var exampleProject = (function(global, undefined){ | ||
var DEBUG = true, | ||
pkgdefs = {}, | ||
pkgmap = {}, | ||
@@ -9,3 +10,2 @@ global = {}, | ||
lib = (function(exports){ | ||
exports.path = (function(exports){ | ||
@@ -93,185 +93,3 @@ // Copyright Joyent, Inc. and other Node contributors. | ||
exports.argv = ['onejs']; | ||
exports.env = { | ||
"npm_config_viewer": "man", | ||
"npm_config_browser": "google-chrome", | ||
"npm_config_showlevel": "2", | ||
"npm_config_rollback": "true", | ||
"DIR_webkitcss": "/home/azer/dev/webkit-css", | ||
"npm_config_usage": "false", | ||
"XDG_DATA_HOME": "/home/azer/.local/share", | ||
"DIR_lite": "/home/azer/dev/firebug1.4/content/lite", | ||
"DIR_media": "/media", | ||
"DIR_express": "/home/azer/dev/express", | ||
"DIR_bk": "/home/azer/bookmarks", | ||
"npm_config_globalignorefile": "/usr/etc/npmignore", | ||
"TERM": "xterm-256color", | ||
"SHELL": "/bin/bash", | ||
"DIR_emacsfiles": "/home/azer/.config/emacsfiles", | ||
"DIR_algorithms": "/media/a/movie/mit/algorithms", | ||
"DIR_delopt": "/home/azer/.opt/delicious-surf", | ||
"npm_config_shell": "/bin/bash", | ||
"npm_config_init_author_url": "", | ||
"npm_config_parseable": "false", | ||
"npm_config_email": "azer@kodfabrik.com", | ||
"DIR_music": "/media/a/music", | ||
"DIR_mac": "/home/azer/dev/mac", | ||
"npm_config_userignorefile": "/home/azer/.npmignore", | ||
"DIR_firebug": "/home/azer/dev/firebug1.4/content/firebug", | ||
"DIR_wallpaper": "/home/azer/.config/wallpaper", | ||
"HUSHLOGIN": "FALSE", | ||
"WINDOWID": "37748742", | ||
"npm_config_init_author_email": "", | ||
"npm_config_long": "false", | ||
"npm_config_ignore": "", | ||
"npm_config_registry": "https://registry.npmjs.org/", | ||
"npm_config_npat": "false", | ||
"ANT_HOME": "/usr/share/java/apache-ant", | ||
"npm_config_message": "%s", | ||
"DIR_h": "/home/azer", | ||
"npm_package_description": "Transform NodeJS packages into single stand-alone script files.", | ||
"USER": "azer", | ||
"DIR_visually": "/home/azer/dev/visually", | ||
"DIR_dotfiles": "/home/azer/.config/dotfiles", | ||
"npm_config_logprefix": "true", | ||
"DIR_delicioussurf": "/home/azer/dev/delicious-surf", | ||
"npm_config_globalconfig": "/usr/etc/npmrc", | ||
"npm_config_always_auth": "false", | ||
"DIR_dev": "/home/azer/dev", | ||
"DIR_docs": "/media/a/docs", | ||
"DIR_stonetunnel": "/home/azer/dev/stonetunnel", | ||
"NEO4J_HOME": "/home/azer/opt/neo4j", | ||
"DIR_highkick": "/home/azer/dev/highkick", | ||
"DIR_vms": "/home/azer/VirtualBox VMs", | ||
"DIR_boxcars": "/home/azer/dev/boxcars", | ||
"DIR_emacsprofiles": "/home/azer/.config/emacsfiles/profiles", | ||
"DIR_zen": "/home/azer/dev/zen", | ||
"CLOJURE_EXT": "/home/azer/.clojure", | ||
"DIR_a": "/media/a", | ||
"DIR_surfdev": "/home/azer/dev/surf", | ||
"DIR_emacs": "/home/azer/.config/emacsfiles", | ||
"npm_package_author_name": "Azer Koculu", | ||
"MAVEN_OPTS": "-Xmx512m", | ||
"MOZ_PLUGIN_PATH": "/usr/lib/mozilla/plugins", | ||
"DIR_b": "/media/b", | ||
"npm_package_dependencies_highkick": "1.x", | ||
"XDG_CONFIG_DIRS": "/etc/xdg:/etc/xdg", | ||
"DIR_tmp": "/home/azer/tmp", | ||
"DIR_console": "/home/azer/dev/mac/zendesk_console", | ||
"DIR_c": "/media/c", | ||
"DIR_chatcore": "/home/azer/dev/zen/zendesk_chat_core", | ||
"npm_package_dependencies_functools": "1.x", | ||
"DIR_surf": "/home/azer/.surf", | ||
"npm_config_logfd": "2", | ||
"npm_config_argv": "'test'", | ||
"PATH": "/home/azer/dev/onejs/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/share/java/apache-ant/bin:/opt/maven/bin:/usr/bin/core_perl:/home/azer/opt/leiningen:/home/azer/opt/neo4j/bin:/var/lib/gems/1.8/bin/:/home/azer/opt/clojure-contrib/launchers/bash:/home/azer/opt/leiningen:/home/azer/opt/android/tools:/home/azer/opt/android/platform-tools:/home/azer/.local/bin", | ||
"MAIL": "/var/spool/mail/azer", | ||
"npm_config_pre": "false", | ||
"npm_package_dependencies_optimist": "0.x", | ||
"DIR_snippets": "/home/azer/.local/share/snippets", | ||
"npm_config_https_proxy": "null", | ||
"npm_config_description": "true", | ||
"_": "/usr/bin/node", | ||
"HG": "/usr/bin/hg", | ||
"npm_config_userconfig": "/home/azer/.npmrc", | ||
"npm_config_npaturl": "http://npat.npmjs.org/", | ||
"PWD": "/home/azer/dev/onejs", | ||
"npm_config_user": "0", | ||
"npm_config_node_version": "0.4.11", | ||
"npm_config_bindist": "0.4-ares1.7.4-ev4.4-openssl1.0.0d-v83.1.8.26-linux-3.0-ARCH", | ||
"npm_package_dependencies_log4js": "0.x", | ||
"JAVA_HOME": "/opt/java", | ||
"DIR_chessbench": "/home/azer/dev/chess-benchmark", | ||
"npm_lifecycle_event": "test", | ||
"npm_package_dependencies_mustache": "0.x", | ||
"npm_config_save": "false", | ||
"npm_config_editor": "vi", | ||
"npm_package_keywords_0": "build", | ||
"npm_package_name": "one", | ||
"LANG": "en_US.UTF-8", | ||
"DIR_one": "/home/azer/dev/onejs", | ||
"npm_config_tag": "latest", | ||
"npm_package_keywords_1": "commonjs", | ||
"DIR_luke": "/home/azer/.config/wallpaper/images/luke", | ||
"npm_config_global": "false", | ||
"npm_package_keywords_2": "browser", | ||
"TZ": "US/Pacific", | ||
"DIR_mit": "/media/a/movie/mit", | ||
"npm_config_username": "azer", | ||
"npm_config_force": "false", | ||
"npm_package_bin_onejs": "./bin/onejs", | ||
"DIR_resumes": "/home/azer/resumes", | ||
"npm_config_searchopts": "", | ||
"npm_package_engines_node": "*", | ||
"npm_package_dependencies_genpkg": "0.x", | ||
"DIR_www": "/home/azer/www", | ||
"npm_config_depth": "Infinity", | ||
"npm_package_main": "./lib/one.js", | ||
"PS3": "> ", | ||
"DIR_chat": "/home/azer/dev/zen/zendesk_chat", | ||
"npm_config_rebuild_bundle": "true", | ||
"npm_config_outfd": "1", | ||
"npm_package_version": "1.5.1", | ||
"DIR_bin": "/home/azer/.local/bin", | ||
"DIR_opt": "/home/azer/.opt", | ||
"npm_config_yes": "null", | ||
"npm_config_unicode": "true", | ||
"DIR_lowkick": "/home/azer/dev/lowkick", | ||
"HOME": "/home/azer", | ||
"PS4": "+ ", | ||
"SHLVL": "5", | ||
"M2_HOME": "/opt/maven", | ||
"COLORFGBG": "default;default", | ||
"DIR_core": "/home/azer/dev/zen/zendesk_chat_core", | ||
"npm_package_scripts_test": "node test/run.js", | ||
"XDG_CONFIG_HOME": "/home/azer/.config", | ||
"TERMINFO": "/usr/share/terminfo", | ||
"DIR_drone": "/home/azer/dev/mac/drone", | ||
"npm_config_strict_ssl": "true", | ||
"npm_config_loglevel": "warn", | ||
"npm_config_ca": "'-----BEGIN CERTIFICATE-----\\nMIIChzCCAfACCQDauvz/KHp8ejANBgkqhkiG9w0BAQUFADCBhzELMAkGA1UEBhMC\\nVVMxCzAJBgNVBAgTAkNBMRAwDgYDVQQHEwdPYWtsYW5kMQwwCgYDVQQKEwNucG0x\\nIjAgBgNVBAsTGW5wbSBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkxDjAMBgNVBAMTBW5w\\nbUNBMRcwFQYJKoZIhvcNAQkBFghpQGl6cy5tZTAeFw0xMTA5MDUwMTQ3MTdaFw0y\\nMTA5MDIwMTQ3MTdaMIGHMQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExEDAOBgNV\\nBAcTB09ha2xhbmQxDDAKBgNVBAoTA25wbTEiMCAGA1UECxMZbnBtIENlcnRpZmlj\\nYXRlIEF1dGhvcml0eTEOMAwGA1UEAxMFbnBtQ0ExFzAVBgkqhkiG9w0BCQEWCGlA\\naXpzLm1lMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDLI4tIqPpRW+ACw9GE\\nOgBlJZwK5f8nnKCLK629Pv5yJpQKs3DENExAyOgDcyaF0HD0zk8zTp+ZsLaNdKOz\\nGn2U181KGprGKAXP6DU6ByOJDWmTlY6+Ad1laYT0m64fERSpHw/hjD3D+iX4aMOl\\ny0HdbT5m1ZGh6SJz3ZqxavhHLQIDAQABMA0GCSqGSIb3DQEBBQUAA4GBAC4ySDbC\\nl7W1WpLmtLGEQ/yuMLUf6Jy/vr+CRp4h+UzL+IQpCv8FfxsYE7dhf/bmWTEupBkv\\nyNL18lipt2jSvR3v6oAHAReotvdjqhxddpe5Holns6EQd1/xEZ7sB1YhQKJtvUrl\\nZNufy1Jf1r0ldEGeA+0ISck7s+xSh9rQD2Op\\n-----END CERTIFICATE-----'", | ||
"npm_config_tar": "tar", | ||
"npm_config_group": "100", | ||
"npm_config_dev": "false", | ||
"DIR_delshare": "/home/azer/.local/share/delicious-surf", | ||
"npm_config_version": "false", | ||
"DIR_share": "/home/azer/.local/share", | ||
"XDG_CACHE_HOME": "/home/azer/.cache", | ||
"DIR_hive": "/home/azer/dev/mac/hive", | ||
"npm_config_searchexclude": "null", | ||
"npm_config_cache": "/home/azer/.npm", | ||
"LOGNAME": "azer", | ||
"DIR_combiner": "/home/azer/dev/combiner", | ||
"npm_lifecycle_script": "node test/run.js", | ||
"npm_config_color": "true", | ||
"DIR_neo4j": "/home/azer/opt/neo4j", | ||
"npm_config_proxy": "null", | ||
"npm_package_author_email": "azer@kodfabrik.com", | ||
"J2SDKDIR": "/usr/lib/jvm/java-6-openjdk", | ||
"XDG_DATA_DIRS": "/usr/share/:/usr/local/share/:/usr/share/:/usr/local/share/", | ||
"BROWSER": "delicious-surf", | ||
"WINDOWPATH": "7", | ||
"DIR_zenchat": "/home/azer/dev/zen/zenchat", | ||
"npm_config_production": "false", | ||
"npm_config_bin_publish": "false", | ||
"npm_package_dependencies_combiner": "1.2.x", | ||
"DISPLAY": ":0", | ||
"DIR_disko": "/media/disko", | ||
"DIR_bookmarks": "/home/azer/bookmarks", | ||
"npm_config_umask": "022", | ||
"npm_config_init_version": "0.0.0", | ||
"J2REDIR": "/usr/lib/jvm/java-6-openjdk/jre", | ||
"npm_config_init_author_name": "", | ||
"DIR_rap": "/media/a/music/rap", | ||
"npm_config_unsafe_perm": "true", | ||
"npm_config_tmp": "/tmp", | ||
"npm_config_onload_script": "null", | ||
"npm_config_gzipbin": "gzip", | ||
"npm_package_directories_lib": "./lib", | ||
"G_BROKEN_FILENAMES": "1", | ||
"DIR_jedi": "/media/a/music/rap/jedi", | ||
"npm_config_prefix": "/usr", | ||
"npm_config_link": "false", | ||
"XAUTHORITY": "/home/azer/.Xauthority", | ||
"COLORTERM": "rxvt-xpm" | ||
}; | ||
exports.env = {}; | ||
exports.nextTick = function nextTick(fn){ | ||
@@ -283,3 +101,3 @@ return setTimeout(fn, 0); | ||
exports.stdout = Stream(true, false); | ||
exports.version = ''; | ||
exports.version = '1.6.0'; | ||
exports.versions = {}; | ||
@@ -310,15 +128,4 @@ /** | ||
})({}); | ||
function findPkg(workingPkg, uri){ | ||
var pkg = undefined, | ||
parent = workingPkg; | ||
var i, len; | ||
do { | ||
i = parent.dependencies.length; | ||
while(i-->0){ | ||
parent.dependencies[i].name == uri && ( pkg = parent.dependencies[i] ); | ||
} | ||
parent = parent.parent; | ||
} while(!pkg && parent); | ||
return pkg; | ||
function findPkg(uri){ | ||
return pkgmap[uri]; | ||
} | ||
@@ -350,3 +157,3 @@ function findModule(workingModule, uri){ | ||
} else { | ||
pkg = findPkg(callingModule.pkg, uri); | ||
pkg = findPkg(uri); | ||
if(!pkg && nativeRequire){ | ||
@@ -361,3 +168,3 @@ try { | ||
} | ||
module = pkg.main; | ||
module = pkg.index; | ||
} | ||
@@ -372,3 +179,3 @@ if(!module){ | ||
function module(parentId, wrapper){ | ||
var parent = pkgmap[parentId], | ||
var parent = pkgdefs[parentId], | ||
mod = wrapper(parent), | ||
@@ -380,27 +187,28 @@ cached = false; | ||
global.require = mod.require; | ||
mod.wrapper(mod, mod.exports, global, global.Buffer, global.process, global.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 ); | ||
if(parent.mainModuleId == mod.id){ | ||
parent.index = mod; | ||
parent.parents.length == 0 && ( locals.main = mod.call ); | ||
} | ||
parent.modules.push(mod); | ||
} | ||
function pkg(parentId, wrapper){ | ||
var parent = pkgmap[parentId], | ||
ctx = wrapper(parent); | ||
pkgmap[ctx.id] = ctx; | ||
!parent && ( pkgmap['main'] = ctx ); | ||
parent && parent.dependencies.push(ctx); | ||
function pkg(/* [ parentId ...], wrapper */){ | ||
var wrapper = arguments[ arguments.length - 1 ], | ||
parents = Array.prototype.slice.call(arguments, 0, arguments.length - 1), | ||
ctx = wrapper(parents); | ||
if(pkgdefs.hasOwnProperty(ctx.id)){ | ||
throw new Error('Package#'+ctx.id+' "' + ctx.name + '" has duplication of itself.'); | ||
} | ||
pkgdefs[ctx.id] = ctx; | ||
pkgmap[ctx.name] = ctx; | ||
arguments.length == 1 && ( pkgmap['main'] = ctx ); | ||
} | ||
function mainRequire(uri){ | ||
return pkgmap.main.main.require(uri); | ||
return pkgmap.main.index.require(uri); | ||
} | ||
function stderr(){ | ||
return lib.process.stderr.content; | ||
} | ||
function stdin(){ | ||
@@ -417,5 +225,5 @@ return lib.process.stdin.content; | ||
'name' : 'exampleProject', | ||
'map' : pkgmap, | ||
'module' : module, | ||
'pkg' : pkg, | ||
'packages' : pkgmap, | ||
'stderr' : stderr, | ||
@@ -428,3 +236,3 @@ 'stdin' : stdin, | ||
})(this); | ||
exampleProject.pkg(undefined, function(parent){ | ||
exampleProject.pkg(function(parents){ | ||
return { | ||
@@ -435,21 +243,29 @@ 'id':1, | ||
'mainModuleId':'a', | ||
'dependencies':[], | ||
'modules':[], | ||
'parent':parent | ||
'parents':parents | ||
}; | ||
}); | ||
exampleProject.module(1, function(onejsModParent){ | ||
exampleProject.module(1, function(/* parent */){ | ||
return { | ||
'id':'b', | ||
'pkg':onejsModParent, | ||
'wrapper':function(module, exports, global, Buffer, process, require, undefined){ | ||
exports.b = true; | ||
'id': 'a', | ||
'pkg': arguments[0], | ||
'wrapper': function(module, exports, global, Buffer,process, require, undefined){ | ||
console.log('Elle creuse encore, cette vieville amie au regard fatigué.'); | ||
module.exports = { | ||
'a':true, | ||
'dependency': require('dependency'), | ||
'now': +(new Date), | ||
'global':global, | ||
'process':process, | ||
'Buffer':Buffer, | ||
'console': console | ||
}; | ||
} | ||
}; | ||
}); | ||
exampleProject.module(1, function(onejsModParent){ | ||
exampleProject.module(1, function(/* parent */){ | ||
return { | ||
'id':'web', | ||
'pkg':onejsModParent, | ||
'wrapper':function(module, exports, global, Buffer, process, require, undefined){ | ||
'id': 'web', | ||
'pkg': arguments[0], | ||
'wrapper': function(module, exports, global, Buffer,process, require, undefined){ | ||
console.log('this module will be working for only web browsers'); | ||
@@ -459,20 +275,12 @@ } | ||
}); | ||
exampleProject.module(1, function(onejsModParent){ | ||
exampleProject.module(1, function(/* parent */){ | ||
return { | ||
'id':'a', | ||
'pkg':onejsModParent, | ||
'wrapper':function(module, exports, global, Buffer, process, require, undefined){ | ||
console.log('Elle creuse encore, cette vieville amie au regard fatigué.'); | ||
module.exports = { | ||
'a':true, | ||
'dependency': require('dependency'), | ||
'now': +(new Date), | ||
'global':global, | ||
'process':process, | ||
'Buffer':Buffer | ||
} | ||
'id': 'b', | ||
'pkg': arguments[0], | ||
'wrapper': function(module, exports, global, Buffer,process, require, undefined){ | ||
exports.b = true; | ||
} | ||
}; | ||
}); | ||
exampleProject.pkg(1, function(parent){ | ||
exampleProject.pkg(1, 4, function(parents){ | ||
return { | ||
@@ -483,12 +291,11 @@ 'id':2, | ||
'mainModuleId':'index', | ||
'dependencies':[], | ||
'modules':[], | ||
'parent':parent | ||
'parents':parents | ||
}; | ||
}); | ||
exampleProject.module(2, function(onejsModParent){ | ||
exampleProject.module(2, function(/* parent */){ | ||
return { | ||
'id':'index', | ||
'pkg':onejsModParent, | ||
'wrapper':function(module, exports, global, Buffer, process, require, undefined){ | ||
'id': 'index', | ||
'pkg': arguments[0], | ||
'wrapper': function(module, exports, global, Buffer,process, require, undefined){ | ||
exports.exclude = true; | ||
@@ -498,3 +305,3 @@ } | ||
}); | ||
exampleProject.pkg(1, function(parent){ | ||
exampleProject.pkg(1, function(parents){ | ||
return { | ||
@@ -505,12 +312,11 @@ 'id':3, | ||
'mainModuleId':'f', | ||
'dependencies':[], | ||
'modules':[], | ||
'parent':parent | ||
'parents':parents | ||
}; | ||
}); | ||
exampleProject.module(3, function(onejsModParent){ | ||
exampleProject.module(3, function(/* parent */){ | ||
return { | ||
'id':'g', | ||
'pkg':onejsModParent, | ||
'wrapper':function(module, exports, global, Buffer, process, require, undefined){ | ||
'id': 'g', | ||
'pkg': arguments[0], | ||
'wrapper': function(module, exports, global, Buffer,process, require, undefined){ | ||
exports.g = true; | ||
@@ -520,7 +326,7 @@ } | ||
}); | ||
exampleProject.module(3, function(onejsModParent){ | ||
exampleProject.module(3, function(/* parent */){ | ||
return { | ||
'id':'f', | ||
'pkg':onejsModParent, | ||
'wrapper':function(module, exports, global, Buffer, process, require, undefined){ | ||
'id': 'f', | ||
'pkg': arguments[0], | ||
'wrapper': function(module, exports, global, Buffer,process, require, undefined){ | ||
require('subdependency'); | ||
@@ -532,3 +338,3 @@ exports.parent = module.parent; | ||
}); | ||
exampleProject.pkg(3, function(parent){ | ||
exampleProject.pkg(3, function(parents){ | ||
return { | ||
@@ -539,12 +345,11 @@ 'id':4, | ||
'mainModuleId':'i', | ||
'dependencies':[], | ||
'modules':[], | ||
'parent':parent | ||
'parents':parents | ||
}; | ||
}); | ||
exampleProject.module(4, function(onejsModParent){ | ||
exampleProject.module(4, function(/* parent */){ | ||
return { | ||
'id':'i', | ||
'pkg':onejsModParent, | ||
'wrapper':function(module, exports, global, Buffer, process, require, undefined){ | ||
'id': 'i', | ||
'pkg': arguments[0], | ||
'wrapper': function(module, exports, global, Buffer,process, require, undefined){ | ||
require('sibling'); | ||
@@ -555,18 +360,45 @@ exports.i = true; | ||
}); | ||
exampleProject.pkg(1, function(parent){ | ||
exampleProject.pkg(3, function(parents){ | ||
return { | ||
'id':5, | ||
'name':'fruits', | ||
'main':undefined, | ||
'mainModuleId':'index', | ||
'modules':[], | ||
'parents':parents | ||
}; | ||
}); | ||
exampleProject.module(5, function(/* parent */){ | ||
return { | ||
'id': 'lib/fruits', | ||
'pkg': arguments[0], | ||
'wrapper': function(module, exports, global, Buffer,process, require, undefined){ | ||
module.exports = ['apple', 'orange']; | ||
} | ||
}; | ||
}); | ||
exampleProject.module(5, function(/* parent */){ | ||
return { | ||
'id': 'index', | ||
'pkg': arguments[0], | ||
'wrapper': function(module, exports, global, Buffer,process, require, undefined){ | ||
module.exports = require('./lib/fruits'); | ||
} | ||
}; | ||
}); | ||
exampleProject.pkg(3, 1, function(parents){ | ||
return { | ||
'id':6, | ||
'name':'sibling', | ||
'main':undefined, | ||
'mainModuleId':'n', | ||
'dependencies':[], | ||
'modules':[], | ||
'parent':parent | ||
'parents':parents | ||
}; | ||
}); | ||
exampleProject.module(5, function(onejsModParent){ | ||
exampleProject.module(6, function(/* parent */){ | ||
return { | ||
'id':'n', | ||
'pkg':onejsModParent, | ||
'wrapper':function(module, exports, global, Buffer, process, require, undefined){ | ||
'id': 'n', | ||
'pkg': arguments[0], | ||
'wrapper': function(module, exports, global, Buffer,process, require, undefined){ | ||
@@ -579,7 +411,7 @@ exports.n = true; | ||
}); | ||
exampleProject.module(5, function(onejsModParent){ | ||
exampleProject.module(6, function(/* parent */){ | ||
return { | ||
'id':'p/index', | ||
'pkg':onejsModParent, | ||
'wrapper':function(module, exports, global, Buffer, process, require, undefined){ | ||
'id': 'p/index', | ||
'pkg': arguments[0], | ||
'wrapper': function(module, exports, global, Buffer,process, require, undefined){ | ||
exports.p = true; | ||
@@ -590,7 +422,7 @@ exports.index = true; | ||
}); | ||
exampleProject.module(5, function(onejsModParent){ | ||
exampleProject.module(6, function(/* parent */){ | ||
return { | ||
'id':'p/r', | ||
'pkg':onejsModParent, | ||
'wrapper':function(module, exports, global, Buffer, process, require, undefined){ | ||
'id': 'p/r', | ||
'pkg': arguments[0], | ||
'wrapper': function(module, exports, global, Buffer,process, require, undefined){ | ||
require('../s/t'); | ||
@@ -601,7 +433,7 @@ exports.r = true; | ||
}); | ||
exampleProject.module(5, function(onejsModParent){ | ||
exampleProject.module(6, function(/* parent */){ | ||
return { | ||
'id':'s/t', | ||
'pkg':onejsModParent, | ||
'wrapper':function(module, exports, global, Buffer, process, require, undefined){ | ||
'id': 's/t', | ||
'pkg': arguments[0], | ||
'wrapper': function(module, exports, global, Buffer,process, require, undefined){ | ||
exports.t = true; | ||
@@ -611,18 +443,17 @@ } | ||
}); | ||
exampleProject.pkg(1, function(parent){ | ||
exampleProject.pkg(1, function(parents){ | ||
return { | ||
'id':6, | ||
'id':7, | ||
'name':'assert', | ||
'main':undefined, | ||
'mainModuleId':'assert', | ||
'dependencies':[], | ||
'modules':[], | ||
'parent':parent | ||
'parents':parents | ||
}; | ||
}); | ||
exampleProject.module(6, function(onejsModParent){ | ||
exampleProject.module(7, function(/* parent */){ | ||
return { | ||
'id':'assert', | ||
'pkg':onejsModParent, | ||
'wrapper':function(module, exports, global, Buffer, process, require, undefined){ | ||
'id': 'assert', | ||
'pkg': arguments[0], | ||
'wrapper': function(module, exports, global, Buffer,process, require, undefined){ | ||
exports.assert = true; | ||
@@ -629,0 +460,0 @@ } |
220
tmp/built.js
var exampleProject = (function(global, undefined){ | ||
var DEBUG = false, | ||
pkgdefs = {}, | ||
pkgmap = {}, | ||
@@ -10,3 +11,2 @@ global = {}, | ||
lib = (function(exports){ | ||
exports.path = (function(exports){ | ||
@@ -101,3 +101,3 @@ // Copyright Joyent, Inc. and other Node contributors. | ||
exports.stdout = Stream(true, false); | ||
exports.version = ''; | ||
exports.version = '1.6.0'; | ||
exports.versions = {}; | ||
@@ -128,15 +128,4 @@ /** | ||
})({}); | ||
function findPkg(workingPkg, uri){ | ||
var pkg = undefined, | ||
parent = workingPkg; | ||
var i, len; | ||
do { | ||
i = parent.dependencies.length; | ||
while(i-->0){ | ||
parent.dependencies[i].name == uri && ( pkg = parent.dependencies[i] ); | ||
} | ||
parent = parent.parent; | ||
} while(!pkg && parent); | ||
return pkg; | ||
function findPkg(uri){ | ||
return pkgmap[uri]; | ||
} | ||
@@ -168,3 +157,3 @@ function findModule(workingModule, uri){ | ||
} else { | ||
pkg = findPkg(callingModule.pkg, uri); | ||
pkg = findPkg(uri); | ||
if(!pkg && nativeRequire){ | ||
@@ -179,3 +168,3 @@ try { | ||
} | ||
module = pkg.main; | ||
module = pkg.index; | ||
} | ||
@@ -190,3 +179,3 @@ if(!module){ | ||
function module(parentId, wrapper){ | ||
var parent = pkgmap[parentId], | ||
var parent = pkgdefs[parentId], | ||
mod = wrapper(parent), | ||
@@ -202,27 +191,28 @@ cached = false; | ||
global.require = mod.require; | ||
mod.wrapper(mod, mod.exports, global, global.Buffer, global.process, global.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 ); | ||
if(parent.mainModuleId == mod.id){ | ||
parent.index = mod; | ||
parent.parents.length == 0 && ( locals.main = mod.call ); | ||
} | ||
parent.modules.push(mod); | ||
} | ||
function pkg(parentId, wrapper){ | ||
var parent = pkgmap[parentId], | ||
ctx = wrapper(parent); | ||
pkgmap[ctx.id] = ctx; | ||
!parent && ( pkgmap['main'] = ctx ); | ||
parent && parent.dependencies.push(ctx); | ||
function pkg(/* [ parentId ...], wrapper */){ | ||
var wrapper = arguments[ arguments.length - 1 ], | ||
parents = Array.prototype.slice.call(arguments, 0, arguments.length - 1), | ||
ctx = wrapper(parents); | ||
if(pkgdefs.hasOwnProperty(ctx.id)){ | ||
throw new Error('Package#'+ctx.id+' "' + ctx.name + '" has duplication of itself.'); | ||
} | ||
pkgdefs[ctx.id] = ctx; | ||
pkgmap[ctx.name] = ctx; | ||
arguments.length == 1 && ( pkgmap['main'] = ctx ); | ||
} | ||
function mainRequire(uri){ | ||
return pkgmap.main.main.require(uri); | ||
return pkgmap.main.index.require(uri); | ||
} | ||
function stderr(){ | ||
return lib.process.stderr.content; | ||
} | ||
function stdin(){ | ||
@@ -239,5 +229,5 @@ return lib.process.stdin.content; | ||
'name' : 'exampleProject', | ||
'map' : pkgmap, | ||
'module' : module, | ||
'pkg' : pkg, | ||
'packages' : pkgmap, | ||
'stderr' : stderr, | ||
@@ -249,3 +239,3 @@ 'stdin' : stdin, | ||
})(this); | ||
exampleProject.pkg(undefined, function(parent){ | ||
exampleProject.pkg(function(parents){ | ||
return { | ||
@@ -256,21 +246,29 @@ 'id':1, | ||
'mainModuleId':'a', | ||
'dependencies':[], | ||
'modules':[], | ||
'parent':parent | ||
'parents':parents | ||
}; | ||
}); | ||
exampleProject.module(1, function(onejsModParent){ | ||
exampleProject.module(1, function(/* parent */){ | ||
return { | ||
'id':'b', | ||
'pkg':onejsModParent, | ||
'wrapper':function(module, exports, global, Buffer, process, require, undefined){ | ||
exports.b = true; | ||
'id': 'a', | ||
'pkg': arguments[0], | ||
'wrapper': function(module, exports, global, Buffer,process, require, undefined){ | ||
console.log('Elle creuse encore, cette vieville amie au regard fatigué.'); | ||
module.exports = { | ||
'a':true, | ||
'dependency': require('dependency'), | ||
'now': +(new Date), | ||
'global':global, | ||
'process':process, | ||
'Buffer':Buffer, | ||
'console': console | ||
}; | ||
} | ||
}; | ||
}); | ||
exampleProject.module(1, function(onejsModParent){ | ||
exampleProject.module(1, function(/* parent */){ | ||
return { | ||
'id':'web', | ||
'pkg':onejsModParent, | ||
'wrapper':function(module, exports, global, Buffer, process, require, undefined){ | ||
'id': 'web', | ||
'pkg': arguments[0], | ||
'wrapper': function(module, exports, global, Buffer,process, require, undefined){ | ||
console.log('this module will be working for only web browsers'); | ||
@@ -280,20 +278,12 @@ } | ||
}); | ||
exampleProject.module(1, function(onejsModParent){ | ||
exampleProject.module(1, function(/* parent */){ | ||
return { | ||
'id':'a', | ||
'pkg':onejsModParent, | ||
'wrapper':function(module, exports, global, Buffer, process, require, undefined){ | ||
console.log('Elle creuse encore, cette vieville amie au regard fatigué.'); | ||
module.exports = { | ||
'a':true, | ||
'dependency': require('dependency'), | ||
'now': +(new Date), | ||
'global':global, | ||
'process':process, | ||
'Buffer':Buffer | ||
} | ||
'id': 'b', | ||
'pkg': arguments[0], | ||
'wrapper': function(module, exports, global, Buffer,process, require, undefined){ | ||
exports.b = true; | ||
} | ||
}; | ||
}); | ||
exampleProject.pkg(1, function(parent){ | ||
exampleProject.pkg(1, function(parents){ | ||
return { | ||
@@ -304,12 +294,11 @@ 'id':2, | ||
'mainModuleId':'f', | ||
'dependencies':[], | ||
'modules':[], | ||
'parent':parent | ||
'parents':parents | ||
}; | ||
}); | ||
exampleProject.module(2, function(onejsModParent){ | ||
exampleProject.module(2, function(/* parent */){ | ||
return { | ||
'id':'g', | ||
'pkg':onejsModParent, | ||
'wrapper':function(module, exports, global, Buffer, process, require, undefined){ | ||
'id': 'g', | ||
'pkg': arguments[0], | ||
'wrapper': function(module, exports, global, Buffer,process, require, undefined){ | ||
exports.g = true; | ||
@@ -319,7 +308,7 @@ } | ||
}); | ||
exampleProject.module(2, function(onejsModParent){ | ||
exampleProject.module(2, function(/* parent */){ | ||
return { | ||
'id':'f', | ||
'pkg':onejsModParent, | ||
'wrapper':function(module, exports, global, Buffer, process, require, undefined){ | ||
'id': 'f', | ||
'pkg': arguments[0], | ||
'wrapper': function(module, exports, global, Buffer,process, require, undefined){ | ||
require('subdependency'); | ||
@@ -331,3 +320,3 @@ exports.parent = module.parent; | ||
}); | ||
exampleProject.pkg(2, function(parent){ | ||
exampleProject.pkg(2, function(parents){ | ||
return { | ||
@@ -338,12 +327,11 @@ 'id':3, | ||
'mainModuleId':'i', | ||
'dependencies':[], | ||
'modules':[], | ||
'parent':parent | ||
'parents':parents | ||
}; | ||
}); | ||
exampleProject.module(3, function(onejsModParent){ | ||
exampleProject.module(3, function(/* parent */){ | ||
return { | ||
'id':'i', | ||
'pkg':onejsModParent, | ||
'wrapper':function(module, exports, global, Buffer, process, require, undefined){ | ||
'id': 'i', | ||
'pkg': arguments[0], | ||
'wrapper': function(module, exports, global, Buffer,process, require, undefined){ | ||
require('sibling'); | ||
@@ -354,18 +342,45 @@ exports.i = true; | ||
}); | ||
exampleProject.pkg(1, function(parent){ | ||
exampleProject.pkg(2, function(parents){ | ||
return { | ||
'id':4, | ||
'name':'fruits', | ||
'main':undefined, | ||
'mainModuleId':'index', | ||
'modules':[], | ||
'parents':parents | ||
}; | ||
}); | ||
exampleProject.module(4, function(/* parent */){ | ||
return { | ||
'id': 'lib/fruits', | ||
'pkg': arguments[0], | ||
'wrapper': function(module, exports, global, Buffer,process, require, undefined){ | ||
module.exports = ['apple', 'orange']; | ||
} | ||
}; | ||
}); | ||
exampleProject.module(4, function(/* parent */){ | ||
return { | ||
'id': 'index', | ||
'pkg': arguments[0], | ||
'wrapper': function(module, exports, global, Buffer,process, require, undefined){ | ||
module.exports = require('./lib/fruits'); | ||
} | ||
}; | ||
}); | ||
exampleProject.pkg(2, 1, function(parents){ | ||
return { | ||
'id':5, | ||
'name':'sibling', | ||
'main':undefined, | ||
'mainModuleId':'n', | ||
'dependencies':[], | ||
'modules':[], | ||
'parent':parent | ||
'parents':parents | ||
}; | ||
}); | ||
exampleProject.module(4, function(onejsModParent){ | ||
exampleProject.module(5, function(/* parent */){ | ||
return { | ||
'id':'n', | ||
'pkg':onejsModParent, | ||
'wrapper':function(module, exports, global, Buffer, process, require, undefined){ | ||
'id': 'n', | ||
'pkg': arguments[0], | ||
'wrapper': function(module, exports, global, Buffer,process, require, undefined){ | ||
@@ -378,7 +393,7 @@ exports.n = true; | ||
}); | ||
exampleProject.module(4, function(onejsModParent){ | ||
exampleProject.module(5, function(/* parent */){ | ||
return { | ||
'id':'p/index', | ||
'pkg':onejsModParent, | ||
'wrapper':function(module, exports, global, Buffer, process, require, undefined){ | ||
'id': 'p/index', | ||
'pkg': arguments[0], | ||
'wrapper': function(module, exports, global, Buffer,process, require, undefined){ | ||
exports.p = true; | ||
@@ -389,7 +404,7 @@ exports.index = true; | ||
}); | ||
exampleProject.module(4, function(onejsModParent){ | ||
exampleProject.module(5, function(/* parent */){ | ||
return { | ||
'id':'p/r', | ||
'pkg':onejsModParent, | ||
'wrapper':function(module, exports, global, Buffer, process, require, undefined){ | ||
'id': 'p/r', | ||
'pkg': arguments[0], | ||
'wrapper': function(module, exports, global, Buffer,process, require, undefined){ | ||
require('../s/t'); | ||
@@ -400,7 +415,7 @@ exports.r = true; | ||
}); | ||
exampleProject.module(4, function(onejsModParent){ | ||
exampleProject.module(5, function(/* parent */){ | ||
return { | ||
'id':'s/t', | ||
'pkg':onejsModParent, | ||
'wrapper':function(module, exports, global, Buffer, process, require, undefined){ | ||
'id': 's/t', | ||
'pkg': arguments[0], | ||
'wrapper': function(module, exports, global, Buffer,process, require, undefined){ | ||
exports.t = true; | ||
@@ -410,18 +425,17 @@ } | ||
}); | ||
exampleProject.pkg(1, function(parent){ | ||
exampleProject.pkg(1, function(parents){ | ||
return { | ||
'id':5, | ||
'id':6, | ||
'name':'assert', | ||
'main':undefined, | ||
'mainModuleId':'assert', | ||
'dependencies':[], | ||
'modules':[], | ||
'parent':parent | ||
'parents':parents | ||
}; | ||
}); | ||
exampleProject.module(5, function(onejsModParent){ | ||
exampleProject.module(6, function(/* parent */){ | ||
return { | ||
'id':'assert', | ||
'pkg':onejsModParent, | ||
'wrapper':function(module, exports, global, Buffer, process, require, undefined){ | ||
'id': 'assert', | ||
'pkg': arguments[0], | ||
'wrapper': function(module, exports, global, Buffer,process, require, undefined){ | ||
exports.assert = true; | ||
@@ -428,0 +442,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
2368
140
14
78918
8
31
2
+ Addedboxcars@0.x
+ Addedboxcars@0.0.6(transitive)