graphquire
Advanced tools
Comparing version 0.6.1 to 0.7.0
@@ -26,10 +26,12 @@ #!/usr/bin/env node | ||
} | ||
function isWriting() { | ||
function isEscape() { | ||
return params.some(function onEach(param) { | ||
return param === '-w' || param === '--write' | ||
return param === '-e' || param === '--escape' | ||
}) | ||
} | ||
function isUpdate() { | ||
function isWriting() { | ||
return params.some(function onEach(param) { | ||
return param === '-u' || param === '--update' | ||
return param === '-w' || param === '--write' | ||
}) | ||
@@ -90,2 +92,3 @@ } | ||
includeSource: !isNoSource(), | ||
escape: isEscape() | ||
} | ||
@@ -92,0 +95,0 @@ |
@@ -43,17 +43,8 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */ | ||
} | ||
function isPluginURI(uri) { return uri && ~uri.indexOf('!') } | ||
function isRelativeURI(id) { return id && id.charAt(0) === '.' } | ||
function isRelative(id) { return id && id.charAt(0) === '.' } | ||
function normalizeURI(uri) { return path.extname(uri) ? uri : uri + '.js' } | ||
function extractURI(uri) { | ||
var index = uri.indexOf('!') | ||
return ~index ? uri.substr(++index) : uri | ||
} | ||
function extractPluginName(id) { | ||
var index = id.indexOf('!') | ||
return index > 0 ? id.substr(0, index) : '' | ||
} | ||
function resolve(uri, base) { | ||
function resolveID(id, base) { | ||
var path, paths, last | ||
if (!isRelativeURI(uri)) return uri | ||
paths = uri.split('/') | ||
if (!isRelative(id)) return id | ||
paths = id.split('/') | ||
base = base ? base.split('/') : [ '.' ] | ||
@@ -73,12 +64,5 @@ if (base.length > 1) base.pop() | ||
} | ||
function resolveID(id, base) { | ||
if (isPluginURI(id)) | ||
id = extractPluginName(id) + '!' + resolve(extractURI(id), base) | ||
else | ||
id = resolve(id, base) | ||
return normalizeURI(id) | ||
function resolve(id, base) { | ||
return normalizeURI(isURI(id) ? id : resolveID(id, base)) | ||
} | ||
function resolvePluginURI(id) { | ||
return extractPluginName(id) + '://' + normalizeURI(extractURI(id)) | ||
} | ||
@@ -121,3 +105,3 @@ function readURL(uri, callback) { | ||
var id, module; | ||
id = resolveID(dependencyID, requirer.id) | ||
id = resolve(dependencyID, requirer.id) | ||
id = requirer.requirements[dependencyID] = id | ||
@@ -185,10 +169,12 @@ | ||
includesSource: options.includeSource || false, | ||
escape: options.escape || false, | ||
resolvePath: function resolvePath(id) { | ||
var root = path.dirname(graph.path) | ||
return isPluginURI(id) ? path.join(root, graph.cachePath, id) : | ||
isRelativeURI(id) ? path.join(root, id) : null | ||
return isURI(id) ? | ||
path.join(root, graph.cachePath, | ||
graph.escape ? id.replace(/:/, encodeURIComponent) : id) | ||
: isRelative(id) ? path.join(root, id) : null | ||
}, | ||
resolveURI: function resolveURI(id) { | ||
return isPluginURI(id) ? resolvePluginURI(id) : | ||
isRelativeURI(id) ? resolveID(id, graph.uri) : null | ||
return isURI(id) ? id : isRelative(id) ? resolve(id, graph.uri) : null | ||
} | ||
@@ -195,0 +181,0 @@ } |
# History # | ||
## 0.7.0 / 2011-07-01 ## | ||
- Switching to actual URL's instead of 'http!' hacks. | ||
## 0.6.1 / 2011-06-12 ## | ||
@@ -4,0 +8,0 @@ |
{ | ||
"name": "graphquire", | ||
"id": "graphquire", | ||
"version": "0.6.1", | ||
"version": "0.7.0", | ||
"description": "module graph builder and installer.", | ||
"keywords": [ "dependencies", "graph", "modules", "require", "linker" ], | ||
"author": "Irakli Gozalishvili <rfobic@gmail.com>", | ||
"author": "Irakli Gozalishvili <rfobic@gmail.com> (http://jeditoolkit.com/)", | ||
"repository": { | ||
@@ -17,3 +17,3 @@ "type": "git", | ||
"devDependencies": { | ||
"test": ">=0.0.10" | ||
"test": ">=0.2.1" | ||
}, | ||
@@ -23,4 +23,3 @@ "main": "./graphquire.js", | ||
"engines": { | ||
"node": "0.4.x", | ||
"teleport": ">=0.2.0" | ||
"node": "0.4.x" | ||
}, | ||
@@ -27,0 +26,0 @@ "bin": { "graphquire" : "./bin/graphquire.js" }, |
133
Readme.md
# graphquire # | ||
Module graph builder. This tool may be used to build module dependency graph | ||
starting form package's main module. This prototype recognizes two types of | ||
module ids: | ||
Web is awesome: cross platform, fully distributed and yet connected via [URL]s. | ||
1. Relative: | ||
This project is an attempt, to apply same principles for building a web itself. | ||
Idea is to build a fully distributed ecosystem (without any type of central | ||
authority) of cross platform JavaScript modules connected via URLs. Each module | ||
doing one thing only, but doing it well! Something to start building [harmony | ||
of our dreams]! | ||
## Tool ## | ||
This is a module linker / graph builder, that may be used to build module | ||
dependency graph starting form a package's main module. Graphequire recognizes | ||
two types of module requirements: | ||
1. Relative id: | ||
`require('./foo/bar')` | ||
@@ -12,15 +22,8 @@ `require('./bla.js')` | ||
2. Absolute: | ||
`require('http!foo.org/bar')` | ||
`require('https!bla.org/baz.js)` | ||
2. URL: | ||
`require('http://foo.org/bar')` | ||
`require('https://bla.org/baz.js)` | ||
Notice `http!` prefix in absolute id ? That's a way to define remote | ||
dependencies. This makes packages obsolete, defining dependencies in the package | ||
saves few keystrokes but is pretty is unwebby as it brings a lot of complexity | ||
by introducing nested dependencies, encouraging code duplication instead of | ||
sharing. Of course we can employ some tools to handle this complexity, but | ||
maybe absolute URIs are not bad ?! Also public module registry would make this | ||
a non problem: `require('http!jsm.org/underscore')`. | ||
All other type of require's are assumed to be engine specific and are ignored. | ||
## Install ## | ||
@@ -34,12 +37,13 @@ | ||
You can use `graphquire` as npm's install script. This way you can start using | ||
absolute module id's in nodejs today. All you need to do is: | ||
You can use `graphquire` to install all URL type modules that your project | ||
depends on as part of npm's install step. To do so you just need to do | ||
following: | ||
1. Add `graphquire` to your dev-dependencies in `package.json`: | ||
1. Add `graphquire` to your `dependencies` in `package.json` file: | ||
"dependencies": { | ||
"graphquire": ">=0.6.0" | ||
"graphquire": ">=0.7.0" | ||
} | ||
2. Add install script to your `package.json`: | ||
2. Add `install` `script` in `package.json` file: | ||
@@ -52,12 +56,13 @@ "scripts": { | ||
You can use `graphquire` with jetpack, either via command line or npm's install | ||
script. In both cases command to execute is following: | ||
You can use `graphquire` with jetpack: | ||
graphquire --clean --write --cache-path ./ | ||
1. Via command line: | ||
If you'd like to use with jetpack via npm just follow nodejs instructions but | ||
modify install script: | ||
graphquire --clean --write --encode --cache-path ./ | ||
2. Or via npm, in this case you need to do a same thing as in instructions for | ||
node with a difference that `install` script will look slightly different: | ||
"scripts": { | ||
"install": "graphquire --clean --write --cache-path ./" | ||
"install": "graphquire --clean --write --encode --cache-path ./" | ||
} | ||
@@ -67,5 +72,4 @@ | ||
There is experimental module loader | ||
[teleport](https://github.com/Gozala/teleport/blob/experimental/npm-1.x.x/teleport.js) | ||
allowing you to load all this modules in the browser. | ||
You can use on of many CommonJS [module loaders](http://jsm.io/jsm.js) for | ||
browsers. | ||
@@ -82,4 +86,6 @@ ### CLI ### | ||
{ | ||
"path": "/Users/gozala/Projects/graphquire/test/fixtures/pckg-cached/package.json", | ||
"uri": "./", | ||
"cachePath": "./node_modules", | ||
"location": "/Users/gozala/Projects/graphquire/test/fixtures/pckg1/package.json", | ||
"includesSource": true, | ||
"metadata": { | ||
@@ -90,20 +96,21 @@ "name": "pckg1" | ||
"./index.js": { | ||
"id": "./index.js", | ||
"requirements": { | ||
"http!foo.org/a": "http!foo.org/a.js" | ||
"http://foo.org/a": "http://foo.org/a.js" | ||
} | ||
}, | ||
"http!foo.org/a.js": { | ||
"id": "http!foo.org/a.js", | ||
"http://foo.org/a.js": { | ||
"id": "http://foo.org/a.js", | ||
"requirements": { | ||
"./nested/b": "http!foo.org/nested/b.js" | ||
"./nested/b": "http://foo.org/nested/b.js" | ||
} | ||
}, | ||
"http!foo.org/nested/b.js": { | ||
"id": "http!foo.org/nested/b.js", | ||
"http://foo.org/nested/b.js": { | ||
"id": "http://foo.org/nested/b.js", | ||
"requirements": { | ||
"http!bar.org/c": "http!bar.org/c.js" | ||
"http://bar.org/c": "http://bar.org/c.js" | ||
} | ||
}, | ||
"http!bar.org/c.js": { | ||
"id": "http!bar.org/c.js", | ||
"http://bar.org/c.js": { | ||
"id": "http://bar.org/c.js" | ||
} | ||
@@ -114,11 +121,13 @@ } | ||
2. You can also analyze graphs on the remote packages (Please note that source | ||
attributes are replaced by ...): | ||
2. You can also analyze dependency graphs on the remote packages (Output will | ||
contain module source if `--no-source` option is not used). | ||
graphquire https://github.com/Gozala/graphquire/raw/master/test/fixtures/pckg2/package.json | ||
graphquire --no-source https://raw.github.com/Gozala/graphquire/master/test/fixtures/pckg-uncached/package.json | ||
{ | ||
"path": "./", | ||
"uri": "https://raw.github.com/Gozala/graphquire/master/test/fixtures/pckg-uncached/package.json", | ||
"cachePath": "./node_modules", | ||
"location": "https://github.com/Gozala/graphquire/raw/master/test/fixtures/pckg2/package.json", | ||
"metadata" { | ||
"includesSource": false, | ||
"metadata": { | ||
"name": "pckg2", | ||
@@ -131,24 +140,20 @@ "version": "0.0.1", | ||
"id": "./index.js", | ||
"source": ".....", | ||
"requirements": { | ||
"https!github.com/Gozala/models/raw/master/lib/models.js": "https!github.com/Gozala/models/raw/master/lib/models.js" | ||
"https://raw.github.com/Gozala/models/master/models.js": "https://raw.github.com/Gozala/models/master/models.js" | ||
} | ||
}, | ||
"https!github.com/Gozala/models/raw/master/lib/models.js": { | ||
"id": "https!github.com/Gozala/models/raw/master/lib/models.js", | ||
"source": "....", | ||
"https://raw.github.com/Gozala/models/master/models.js": { | ||
"id": "https://raw.github.com/Gozala/models/master/models.js", | ||
"requirements": { | ||
"./events": "https!github.com/Gozala/models/raw/master/lib/events.js" | ||
"https!raw.github.com/Gozala/extendables/v0.2.0/extendables.js": "https!raw.github.com/Gozala/extendables/v0.2.0/extendables.js", | ||
"https!raw.github.com/Gozala/events/v0.2.0/events.js": "https!raw.github.com/Gozala/events/v0.2.0/events.js" | ||
} | ||
}, | ||
"https!github.com/Gozala/models/raw/master/lib/events.js": { | ||
"id": "https!github.com/Gozala/models/raw/master/lib/events.js", | ||
"source": "....", | ||
"requirements": { | ||
"./extendables": "https!github.com/Gozala/models/raw/master/lib/extendables.js" | ||
} | ||
"https!raw.github.com/Gozala/extendables/v0.2.0/extendables.js": { | ||
"id": "https!raw.github.com/Gozala/extendables/v0.2.0/extendables.js", | ||
"isNative": true | ||
}, | ||
"https!github.com/Gozala/models/raw/master/lib/extendables.js": { | ||
"id": "https!github.com/Gozala/models/raw/master/lib/extendables.js", | ||
"source": "....." | ||
"https!raw.github.com/Gozala/events/v0.2.0/events.js": { | ||
"id": "https!raw.github.com/Gozala/events/v0.2.0/events.js", | ||
"isNative": true | ||
} | ||
@@ -159,8 +164,14 @@ } | ||
3. Install missing dependencies to the local filesystem: | ||
3. You can install / cache missing dependencies of your package into filesystem: | ||
graphquire --write path/to/package.json | ||
4. No longer used dependencies can be also cleaned up by additional argument: | ||
4. Obsolete dependencies can be also cleaned up using additional argument: | ||
graphquire --write --clean path/to/package.json | ||
5. Module cache by default is `node_modules` folder but can be set to different | ||
value via `--cache-path` argument. | ||
[URL]:http://en.wikipedia.org/wiki/Uniform_Resource_Locator | ||
[harmony of our dreams]:http://wiki.ecmascript.org/doku.php?id=harmony:modules |
exports.name = "main"; | ||
exports.dependency = require("http!foo.org/a"); | ||
exports.dependency = require("http://foo.org/a"); |
exports.name = "main"; | ||
exports.absolute = require("http!foo.org/a"); | ||
exports.absolute = require("http://foo.org/a.js"); | ||
exports.dependency = require("dependency"); |
exports.name = "main"; | ||
exports.dependency = require("http!foo.org/a"); | ||
exports.dependency = require("http://foo.org/a"); | ||
exports.local = require("./local"); |
exports.name = "depencdency/local"; | ||
exports.dependency = require("http!foo.org/a"); | ||
exports.dependency = require("http://foo.org/a"); | ||
exports.nested = require("nested-dependency"); |
exports.name = "dependency/nested-dependency/lib/main"; | ||
exports.requires = require("http!foo.org/nested/b.js"); | ||
exports.requires = require("http://foo.org/nested/b.js"); |
exports.name = "main"; | ||
exports.dependency = require("https!github.com/Gozala/models/raw/master/lib/models.js"); | ||
exports.dependency = require("https://raw.github.com/Gozala/models/master/models.js"); |
@@ -18,3 +18,3 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */ | ||
exports['test basic'] = function(assert, done) { | ||
exports['test cached no package dependencies'] = function(assert, done) { | ||
var options = optionsFor('pckg-cached') | ||
@@ -27,19 +27,19 @@ getGraph(options, function onGraph(error, graph) { | ||
"requirements": { | ||
"http!foo.org/a": "http!foo.org/a.js" | ||
"http://foo.org/a": "http://foo.org/a.js" | ||
} | ||
}, | ||
"http!foo.org/a.js": { | ||
"id": "http!foo.org/a.js", | ||
"http://foo.org/a.js": { | ||
"id": "http://foo.org/a.js", | ||
"requirements": { | ||
"./nested/b": "http!foo.org/nested/b.js" | ||
"./nested/b": "http://foo.org/nested/b.js" | ||
} | ||
}, | ||
"http!foo.org/nested/b.js": { | ||
"id": "http!foo.org/nested/b.js", | ||
"http://foo.org/nested/b.js": { | ||
"id": "http://foo.org/nested/b.js", | ||
"requirements": { | ||
"http!bar.org/c": "http!bar.org/c.js" | ||
"http://bar.org/c": "http://bar.org/c.js" | ||
} | ||
}, | ||
"http!bar.org/c.js": { | ||
"id": "http!bar.org/c.js", | ||
"http://bar.org/c.js": { | ||
"id": "http://bar.org/c.js", | ||
} | ||
@@ -51,3 +51,74 @@ }, 'modules linked correctly') | ||
exports['test cached with package dependencies'] = function(assert, done) { | ||
var options = optionsFor('pckg-npm') | ||
getGraph(options, function onGraph(error, graph) { | ||
assert.deepEqual(graph.metadata, { "name": "pckg1" }, "metadat is correct") | ||
assert.deepEqual(graph.modules, { | ||
"./index.js": { | ||
"id": "./index.js", | ||
"requirements": { | ||
"http://foo.org/a.js": "http://foo.org/a.js", | ||
"dependency": "dependency.js" | ||
} | ||
}, | ||
"http://foo.org/a.js": { | ||
"id": "http://foo.org/a.js", | ||
"requirements": { | ||
"./nested/b": "http://foo.org/nested/b.js" | ||
} | ||
}, | ||
"dependency.js": { | ||
"id": "dependency.js", | ||
"isNative": true | ||
}, | ||
"http://foo.org/nested/b.js": { | ||
"id": "http://foo.org/nested/b.js", | ||
"requirements": { | ||
"http://bar.org/c": "http://bar.org/c.js" | ||
} | ||
}, | ||
"http://bar.org/c.js": { | ||
"id": "http://bar.org/c.js" | ||
} | ||
}, 'modules linked correctly') | ||
done() | ||
}) | ||
} | ||
exports['test package with remote modules (SLOW, requires network)'] = function(assert, done) { | ||
var options = optionsFor('pckg-uncached') | ||
getGraph(options, function onGraph(error, graph) { | ||
assert.deepEqual(graph.metadata, { | ||
"name": "pckg2", | ||
"version": "0.0.1", | ||
"description": "test package with remote dependencies" | ||
}, "metadata is correct") | ||
assert.deepEqual(graph.modules, { | ||
"./index.js": { | ||
"id": "./index.js", | ||
"requirements": { | ||
"https://raw.github.com/Gozala/models/master/models.js": "https://raw.github.com/Gozala/models/master/models.js" | ||
} | ||
}, | ||
"https://raw.github.com/Gozala/models/master/models.js": { | ||
"id": "https://raw.github.com/Gozala/models/master/models.js", | ||
"requirements": { | ||
"https!raw.github.com/Gozala/extendables/v0.2.0/extendables.js": "https!raw.github.com/Gozala/extendables/v0.2.0/extendables.js", | ||
"https!raw.github.com/Gozala/events/v0.2.0/events.js": "https!raw.github.com/Gozala/events/v0.2.0/events.js" | ||
} | ||
}, | ||
"https!raw.github.com/Gozala/extendables/v0.2.0/extendables.js": { | ||
"id": "https!raw.github.com/Gozala/extendables/v0.2.0/extendables.js", | ||
"isNative": true | ||
}, | ||
"https!raw.github.com/Gozala/events/v0.2.0/events.js": { | ||
"id": "https!raw.github.com/Gozala/events/v0.2.0/events.js", | ||
"isNative": true | ||
} | ||
}, 'modules linked correctly') | ||
done() | ||
}) | ||
} | ||
if (module == require.main) | ||
require("test").run(exports) |
@@ -21,4 +21,6 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */ | ||
var root = path.dirname(graph.path) | ||
var http = path.join(root, graph.cachePath, 'http!') | ||
var https = path.join(root, graph.cachePath, 'https!') | ||
var http = path.join(root, graph.cachePath, | ||
graph.escape ? encodeURIComponent('http:') : 'http:') | ||
var https = path.join(root, graph.cachePath, | ||
graph.escape ? encodeURIComponent('https:') : 'https:') | ||
var paths = Object.keys(modules).map(graph.resolvePath.bind(graph)) | ||
@@ -25,0 +27,0 @@ .map(path.join.bind(path, root)) |
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 10 instances in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 5 instances 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
Network access
Supply chain riskThis module accesses the network.
Found 4 instances in 1 package
2900141
60
729
169
22