Skip to content
Browse files

Switching from actual URLs to foo.org/bar for http and !foo.org/bar f…

…or https.
  • Loading branch information...
1 parent 7797ee8 commit 76c81fe3de65f31df6d9ffcdd0d315d406a80612 @Gozala committed
Showing with 27 additions and 18 deletions.
  1. +21 −13 graphquire.js
  2. +6 −5 utils/deployment.js
View
34 graphquire.js
@@ -32,16 +32,25 @@ function extractDependencies(source) {
return dependencies
}
-function isPackageLocation(uri) { return path.basename(uri) === "package.json" }
-function isURI(uri) {
- return 0 === uri.indexOf('http:') || 0 === uri.indexOf('https:')
+function isHttps(id) {
+ return id.charAt(0) === '!'
+}
+function toURL(id) {
+ return isHttps(id) ? 'https://' + id.substr(1) : 'http://' + id
}
+function isPackageLocation(uri) { return path.basename(uri) === "package.json" }
function normalizePackageLocation(uri) {
return isPackageLocation(uri) ? uri :
uri + (uri[uri.length - 1] === "/" ? "" : "/") + "package.json"
}
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 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) {
var path, paths, last
if (!isRelative(id)) return id
@@ -61,7 +70,7 @@ function resolveID(id, base) {
return base.join('/')
}
function resolve(id, base) {
- return normalizeURI(isURI(id) ? id : resolveID(id, base))
+ return isSupported(id) ? id : resolveID(id, base)
}
function readURL(uri, callback) {
@@ -90,7 +99,7 @@ function getSource(graph, module, onComplete, onProgress) {
if (!error || error.code !== 'ENOENT' || !uri)
return onComplete(error, buffer)
if (onProgress) onProgress(FETCH_URL, uri)
- readURL(uri, onComplete)
+ readURL(toURL(uri), onComplete)
})
} else {
module.isNative = true
@@ -164,15 +173,14 @@ function getGraph(options, onComplete, onProgress) {
cachePath: options.cachePath || './',
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
}
}
if (onProgress) onProgress(GET_METADATA, location)
View
11 utils/deployment.js
@@ -15,22 +15,23 @@ var START_WRITE = exports.START_WRITE = 8
var WRITE_MODULE = exports.WRITE_MODULE = 9
var WROTE_MODULE = exports.WROTE_MODULE = 10
+
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))
.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
if (isReduced && onProgress) onProgress(DELETE_PATH, entry)
return isReduced

0 comments on commit 76c81fe

Please sign in to comment.
Something went wrong with that request. Please try again.