graphquire
Advanced tools
Comparing version 0.7.0 to 0.8.0
@@ -35,6 +35,6 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */ | ||
function isHttps(id) { | ||
return id.charAt(0) === '!' | ||
} | ||
function isPackageLocation(uri) { return path.basename(uri) === "package.json" } | ||
function isURI(uri) { | ||
return 0 === uri.indexOf('http:') || 0 === uri.indexOf('https:') | ||
} | ||
function normalizePackageLocation(uri) { | ||
@@ -45,3 +45,12 @@ return isPackageLocation(uri) ? uri : | ||
function isRelative(id) { return id && id.charAt(0) === '.' } | ||
function normalizeURI(uri) { return path.extname(uri) ? uri : uri + '.js' } | ||
function isURI(uri) { return ~uri.indexOf('://') } | ||
function toURL(id) { | ||
return isURI(id) ? id : isHttps(id) ? 'https://' + id.substr(1) : 'http://' + id | ||
} | ||
function isSupported(uri) { | ||
return !isRelative(uri) && ~uri.indexOf('/') && | ||
~uri.slice(0, uri.indexOf('/')).indexOf('.') | ||
} | ||
exports.isSupported = isSupported | ||
function normalize(id) { return path.extname(id) ? id : id + '.js' } | ||
function resolveID(id, base) { | ||
@@ -66,3 +75,3 @@ var path, paths, last | ||
function resolve(id, base) { | ||
return normalizeURI(isURI(id) ? id : resolveID(id, base)) | ||
return isSupported(id) ? id : resolveID(id, base) | ||
} | ||
@@ -96,3 +105,3 @@ | ||
if (onProgress) onProgress(FETCH_URL, uri) | ||
readURL(uri, onComplete) | ||
readURL(toURL(uri), onComplete) | ||
}) | ||
@@ -170,12 +179,10 @@ } else { | ||
includesSource: options.includeSource || false, | ||
escape: options.escape || false, | ||
resolvePath: function resolvePath(id) { | ||
resolvePath: options.resolvePath || function resolvePath(id) { | ||
var root = path.dirname(graph.path) | ||
return isURI(id) ? | ||
path.join(root, graph.cachePath, | ||
graph.escape ? id.replace(/:/, encodeURIComponent) : id) | ||
: isRelative(id) ? path.join(root, id) : null | ||
return isSupported(id) ? normalize(path.join(root, graph.cachePath, id)) | ||
: isRelative(id) ? normalize(path.join(root, id)) : null | ||
}, | ||
resolveURI: function resolveURI(id) { | ||
return isURI(id) ? id : isRelative(id) ? resolve(id, graph.uri) : null | ||
resolveURI: options.resolveURI || function resolveURI(id) { | ||
return isSupported(id) ? normalize(id) | ||
: isRelative(id) ? normalize(resolve(id, graph.uri)) : null | ||
} | ||
@@ -182,0 +189,0 @@ } |
# History # | ||
## 0.8.0 / 2011-07-08 ## | ||
- Change API to use simplified URL pattern: | ||
foo.org/module -> http://foo.org/module.js | ||
!bar.org/index -> https://bar.org/index.js | ||
## 0.7.0 / 2011-07-01 ## | ||
@@ -4,0 +10,0 @@ |
{ | ||
"name": "graphquire", | ||
"id": "graphquire", | ||
"version": "0.7.0", | ||
"version": "0.8.0", | ||
"description": "module graph builder and installer.", | ||
@@ -22,3 +22,3 @@ "keywords": [ "dependencies", "graph", "modules", "require", "linker" ], | ||
"engines": { | ||
"node": "0.4.x" | ||
"node": ">=0.4.x" | ||
}, | ||
@@ -25,0 +25,0 @@ "bin": { "graphquire" : "./bin/graphquire.js" }, |
@@ -23,6 +23,7 @@ # graphquire # | ||
2. URL: | ||
`require('http://foo.org/bar')` | ||
`require('https://bla.org/baz.js)` | ||
`require('foo.org/bar') // http://foo.org/bar.js` | ||
`require('!bla.org/baz') // https://bla.org/baz.js` | ||
All other type of require's are assumed to be engine specific and are ignored. | ||
All other type of require's are assumed to be engine specific and are left up | ||
to engine. | ||
@@ -59,3 +60,3 @@ ## Install ## | ||
graphquire --clean --write --encode --cache-path ./ | ||
graphquire --clean --write --cache-path ./ | ||
@@ -66,3 +67,3 @@ 2. Or via npm, in this case you need to do a same thing as in instructions for | ||
"scripts": { | ||
"install": "graphquire --clean --write --encode --cache-path ./" | ||
"install": "graphquire --clean --write --cache-path ./" | ||
} | ||
@@ -82,6 +83,6 @@ | ||
graphquire test/fixtures/pckg1/package.json | ||
graphquire test/fixtures/pckg-cached/package.json | ||
{ | ||
"path": "/Users/gozala/Projects/graphquire/test/fixtures/pckg-cached/package.json", | ||
"path": "test/fixtures/pckg-cached/package.json", | ||
"uri": "./", | ||
@@ -97,19 +98,19 @@ "cachePath": "./node_modules", | ||
"requirements": { | ||
"http://foo.org/a": "http://foo.org/a.js" | ||
"foo.org/a": "foo.org/a" | ||
} | ||
}, | ||
"http://foo.org/a.js": { | ||
"id": "http://foo.org/a.js", | ||
"foo.org/a": { | ||
"id": "foo.org/a", | ||
"requirements": { | ||
"./nested/b": "http://foo.org/nested/b.js" | ||
"./nested/b": "foo.org/nested/b" | ||
} | ||
}, | ||
"http://foo.org/nested/b.js": { | ||
"id": "http://foo.org/nested/b.js", | ||
"foo.org/nested/b": { | ||
"id": "foo.org/nested/b", | ||
"requirements": { | ||
"http://bar.org/c": "http://bar.org/c.js" | ||
"!bar.org/c": "!bar.org/c" | ||
} | ||
}, | ||
"http://bar.org/c.js": { | ||
"id": "http://bar.org/c.js" | ||
"!bar.org/c": { | ||
"id": "!bar.org/c" | ||
} | ||
@@ -119,3 +120,2 @@ } | ||
2. You can also analyze dependency graphs on the remote packages (Output will | ||
@@ -140,19 +140,19 @@ contain module source if `--no-source` option is not used). | ||
"requirements": { | ||
"https://raw.github.com/Gozala/models/master/models.js": "https://raw.github.com/Gozala/models/master/models.js" | ||
"!raw.github.com/Gozala/models/master/models": "!raw.github.com/Gozala/models/master/models" | ||
} | ||
}, | ||
"https://raw.github.com/Gozala/models/master/models.js": { | ||
"id": "https://raw.github.com/Gozala/models/master/models.js", | ||
"!raw.github.com/Gozala/models/master/models": { | ||
"id": "!raw.github.com/Gozala/models/master/models", | ||
"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" | ||
"!raw.github.com/Gozala/events/v0.4.0/events": "!raw.github.com/Gozala/events/v0.4.0/events" | ||
} | ||
}, | ||
"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 | ||
"!raw.github.com/Gozala/events/v0.4.0/events": { | ||
"id": "!raw.github.com/Gozala/events/v0.4.0/events", | ||
"requirements": { | ||
"!raw.github.com/Gozala/extendables/v0.2.0/extendables": "!raw.github.com/Gozala/extendables/v0.2.0/extendables" | ||
} | ||
}, | ||
"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 | ||
"!raw.github.com/Gozala/extendables/v0.2.0/extendables": { | ||
"id": "!raw.github.com/Gozala/extendables/v0.2.0/extendables" | ||
} | ||
@@ -171,6 +171,7 @@ } | ||
5. Module cache by default is `node_modules` folder but can be set to different | ||
value via `--cache-path` argument. | ||
5. You can specify package relative cache path (defaults to `node_modules`): | ||
graphquire --write --clean --cache-path ./support path/to/package.json | ||
[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("foo.org/a"); |
exports.name = "main"; | ||
exports.absolute = require("http://foo.org/a.js"); | ||
exports.absolute = require("foo.org/a"); | ||
exports.dependency = require("dependency"); |
exports.name = "main"; | ||
exports.dependency = require("https://raw.github.com/Gozala/models/master/models.js"); | ||
exports.dependency = require("!raw.github.com/Gozala/models/v0.2.0/models"); |
@@ -26,19 +26,19 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */ | ||
"requirements": { | ||
"http://foo.org/a": "http://foo.org/a.js" | ||
"foo.org/a": "foo.org/a" | ||
} | ||
}, | ||
"http://foo.org/a.js": { | ||
"id": "http://foo.org/a.js", | ||
"foo.org/a": { | ||
"id": "foo.org/a", | ||
"requirements": { | ||
"./nested/b": "http://foo.org/nested/b.js" | ||
"./nested/b": "foo.org/nested/b" | ||
} | ||
}, | ||
"http://foo.org/nested/b.js": { | ||
"id": "http://foo.org/nested/b.js", | ||
"foo.org/nested/b": { | ||
"id": "foo.org/nested/b", | ||
"requirements": { | ||
"http://bar.org/c": "http://bar.org/c.js" | ||
"!bar.org/c": "!bar.org/c" | ||
} | ||
}, | ||
"http://bar.org/c.js": { | ||
"id": "http://bar.org/c.js", | ||
"!bar.org/c": { | ||
"id": "!bar.org/c", | ||
} | ||
@@ -58,24 +58,24 @@ }, 'modules linked correctly') | ||
"requirements": { | ||
"http://foo.org/a.js": "http://foo.org/a.js", | ||
"dependency": "dependency.js" | ||
"foo.org/a": "foo.org/a", | ||
"dependency": "dependency" | ||
} | ||
}, | ||
"http://foo.org/a.js": { | ||
"id": "http://foo.org/a.js", | ||
"foo.org/a": { | ||
"id": "foo.org/a", | ||
"requirements": { | ||
"./nested/b": "http://foo.org/nested/b.js" | ||
"./nested/b": "foo.org/nested/b" | ||
} | ||
}, | ||
"dependency.js": { | ||
"id": "dependency.js", | ||
"dependency": { | ||
"id": "dependency", | ||
"isNative": true | ||
}, | ||
"http://foo.org/nested/b.js": { | ||
"id": "http://foo.org/nested/b.js", | ||
"foo.org/nested/b": { | ||
"id": "foo.org/nested/b", | ||
"requirements": { | ||
"http://bar.org/c": "http://bar.org/c.js" | ||
"bar.org/c": "bar.org/c" | ||
} | ||
}, | ||
"http://bar.org/c.js": { | ||
"id": "http://bar.org/c.js" | ||
"bar.org/c": { | ||
"id": "bar.org/c" | ||
} | ||
@@ -95,25 +95,25 @@ }, 'modules linked correctly') | ||
}, "metadata is correct") | ||
assert.deepEqual(graph.modules, { | ||
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" | ||
"!raw.github.com/Gozala/models/v0.2.0/models": "!raw.github.com/Gozala/models/v0.2.0/models" | ||
} | ||
}, | ||
"https://raw.github.com/Gozala/models/master/models.js": { | ||
"id": "https://raw.github.com/Gozala/models/master/models.js", | ||
"!raw.github.com/Gozala/models/v0.2.0/models": { | ||
"id": "!raw.github.com/Gozala/models/v0.2.0/models", | ||
"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" | ||
"!raw.github.com/Gozala/events/v0.4.0/events": "!raw.github.com/Gozala/events/v0.4.0/events" | ||
} | ||
}, | ||
"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 | ||
"!raw.github.com/Gozala/events/v0.4.0/events": { | ||
"id": "!raw.github.com/Gozala/events/v0.4.0/events", | ||
"requirements": { | ||
"!raw.github.com/Gozala/extendables/v0.2.0/extendables": "!raw.github.com/Gozala/extendables/v0.2.0/extendables" | ||
} | ||
}, | ||
"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 | ||
"!raw.github.com/Gozala/extendables/v0.2.0/extendables": { | ||
"id": "!raw.github.com/Gozala/extendables/v0.2.0/extendables" | ||
} | ||
}, 'modules linked correctly') | ||
}), 'modules linked correctly') | ||
done() | ||
@@ -120,0 +120,0 @@ }) |
@@ -18,9 +18,6 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */ | ||
function clean(graph, onComplete, onProgress) { | ||
var modules = graph.modules | ||
var root = path.dirname(graph.path) | ||
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)) | ||
@@ -30,7 +27,11 @@ .map(path.join.bind(path, root)) | ||
var location = path.join(root, graph.cachePath) | ||
if (location.charAt(location.length - 1) !== '/') | ||
location = '/' + location | ||
utils.reduceTree(location, onComplete, function onReduce(entry) { | ||
var isNative = !(~entry.indexOf(http) || ~entry.indexOf(https)) | ||
var id = entry.substr(location.length) | ||
var isNative = !graphquire.isSupported(id) | ||
var isRequired = !paths.every(function(path) { | ||
return !~path.indexOf(entry) | ||
}) | ||
var isReduced = !isNative && !isRequired | ||
@@ -37,0 +38,0 @@ if (isReduced && onProgress) onProgress(DELETE_PATH, entry) |
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
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
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
Network access
Supply chain riskThis module accesses the network.
Found 3 instances in 1 package
61
735
170
7
2515074