From 59ba626f234b1f4cb75cf2ab934f19d4afd363d2 Mon Sep 17 00:00:00 2001 From: yofreke Date: Sat, 18 Jul 2015 18:15:48 -0700 Subject: [PATCH 01/10] added noCompile option --- compilers/jsio_compile/compiler.js | 42 +++++++++++++++++------------- packages/preprocessors/compiler.js | 17 +++++++----- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/compilers/jsio_compile/compiler.js b/compilers/jsio_compile/compiler.js index 5ecbdab..8cbdb49 100755 --- a/compilers/jsio_compile/compiler.js +++ b/compilers/jsio_compile/compiler.js @@ -222,23 +222,7 @@ exports.run = function(args, opts) { rawOpts: opts }); - compiler.compile('import jsio.base'); - - if (opts.additionalDeps) { - var deps = opts.additionalDeps; - var n = deps.length; - - for (var i = 0; i < n; ++i) { - logger.info('compiling dependencies...', deps[i]); - compiler.compile(deps[i]); - } - } - - logger.info('compiling main program', initial); - - compiler.compile(initial); - - compiler.generateSrc(opts, function(src) { + var onFinish = function(src) { if (opts.appendImport) { src = src + ';' + JSIO + '("' + initial + '")'; } @@ -248,6 +232,28 @@ exports.run = function(args, opts) { } _interface.onFinish(opts, src); - }); + }; + + if (!opts.noCompile) { + compiler.compile('import jsio.base'); + + if (opts.additionalDeps) { + var deps = opts.additionalDeps; + var n = deps.length; + + for (var i = 0; i < n; ++i) { + logger.info('compiling dependencies...', deps[i]); + compiler.compile(deps[i]); + } + } + + logger.info('compiling main program', initial); + + compiler.compile(initial); + + compiler.generateSrc(opts, onFinish); + } else { + onFinish(compiler.getJsioSrc(opts.includeJsio)); + } } diff --git a/packages/preprocessors/compiler.js b/packages/preprocessors/compiler.js index 2f5e719..1b94b4a 100644 --- a/packages/preprocessors/compiler.js +++ b/packages/preprocessors/compiler.js @@ -178,18 +178,23 @@ exports.getPathJS = function() { } -function buildJsio(opts, callback) { - function getJsioSrc() { - var src = jsio.__jsio.__init__.toString(-1); +exports.getJsioSrc = function(includeJsio) { + var src = ''; + if (includeJsio) { + src = jsio.__jsio.__init__.toString(-1); if (src.substring(0, 8) == 'function') { src = 'jsio=(' + src + ')();'; } - return src; } + src += exports.getPathJS(); + + return src; +} + +function buildJsio(opts, callback) { var src; - var jsioSrc = (opts.includeJsio ? getJsioSrc() : '') - + exports.getPathJS(); + var jsioSrc = exports.getJsioSrc(opts.includeJsio); var cwd = jsio.__env.getCwd(); var table = {}; From 3aa8ff0ff731e08f074615c830bd81044075ae11 Mon Sep 17 00:00:00 2001 From: yofreke Date: Sun, 19 Jul 2015 23:04:01 -0700 Subject: [PATCH 02/10] moved failed into env --- packages/jsio.js | 52 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/packages/jsio.js b/packages/jsio.js index 4c048f6..44a3d0a 100644 --- a/packages/jsio.js +++ b/packages/jsio.js @@ -500,6 +500,17 @@ } } }; + + var _failedFetches = {}; + + this.hasFetchFailed = function(path) { + return (path in _failedFetches); + }; + + this.setFetchFailed = function(path) { + _failedFetches[path] = true; + }; + } function ENV_browser() { @@ -614,9 +625,42 @@ return xhr.responseText; }; - }; - var failedFetch = {}; + var _namespace = null; + + this._getNamespace = function() { + if (!_namespace) { + var cwd = this.getCwd(); + var _namespace = cwd.substring(cwd.indexOf('apps/'), cwd.length); + if (_namespace.charAt(_namespace.length - 1) === '/') { _namespace = _namespace.substring(0, _namespace.length - 1); } + _namespace += ':'; + } + return _namespace; + } + + var oldFailedKey = this._getNamespace() + 'failedFetches'; + var _failedFetches = null; + + this.hasFetchFailed = function(path) { + if (!_failedFetches) { + var oldFailed = localStorage.getItem(oldFailedKey); + if (oldFailed) { + _failedFetches = JSON.parse(oldFailed); + } else { + _failedFetches = {}; + } + } + + return (path in _failedFetches); + }; + + this.setFetchFailed = function(path) { + _failedFetches[path] = true; + // Save it + localStorage.setItem(oldFailedKey, JSON.stringify(_failedFetches)); + }; + + }; function findModule(possibilities) { var src; @@ -648,7 +692,7 @@ possible.src = src; return possible; } else { - failedFetch[path] = true; + ENV.setFetchFailed(path); } } @@ -677,7 +721,7 @@ return possibilities[i]; } - if (path in failedFetch) { possibilities.splice(i--, 1); } + if (ENV.hasFetchFailed(path)) { possibilities.splice(i--, 1); } } if (!possibilities.length) { From 346738b9204d48f234ec9eee142b9ab4189828f3 Mon Sep 17 00:00:00 2001 From: yofreke Date: Mon, 20 Jul 2015 08:27:38 -0700 Subject: [PATCH 03/10] initial preload --- compilers/jsio_compile/compiler.js | 7 +- packages/jsio.js | 136 ++++++++++++++++++++++++++--- 2 files changed, 128 insertions(+), 15 deletions(-) diff --git a/compilers/jsio_compile/compiler.js b/compilers/jsio_compile/compiler.js index 8cbdb49..b9481ef 100755 --- a/compilers/jsio_compile/compiler.js +++ b/compilers/jsio_compile/compiler.js @@ -10,6 +10,7 @@ var supportedEnvs = { }; var _interface = null; +var compiler = null; exports.start = function(/*optional*/ args, opts) { if (opts && opts['interface']) { @@ -38,6 +39,10 @@ exports.start = function(/*optional*/ args, opts) { } } +exports.getCompiler = function() { + return compiler; +} + function getPackage(fileName) { try { var pkg = eval('(' + J.__env.fetch(fileName) + ')'); @@ -209,7 +214,7 @@ exports.run = function(args, opts) { } // run the actual compiler - var compiler = J('import jsio.preprocessors.compiler'); + compiler = J('import jsio.preprocessors.compiler'); compiler.setCompilerOpts({ debugLevel: debugLevel, compressor: opts.compressor || ('compress' in _interface ? bind(_interface, 'compress') : null), diff --git a/packages/jsio.js b/packages/jsio.js index 44a3d0a..7aefb36 100644 --- a/packages/jsio.js +++ b/packages/jsio.js @@ -511,6 +511,14 @@ _failedFetches[path] = true; }; + this.registerFoundModule = function(path) { + // Pass + }; + + this.preloadModules = function(cb) { + cb(); + }; + } function ENV_browser() { @@ -603,29 +611,58 @@ } catch(e) {} }; - this.fetch = function(path) { + // Optional callback for async use + this.fetch = function(path, callback) { var xhr = new XHR(); try { - xhr.open('GET', path, false); - xhr.send(null); + xhr.open('GET', path, callback !== undefined); } catch(e) { ENV.log('e:', e); - return false; // firefox file:// + if (callback) { + callback(e); + } else { + return false; // firefox file:// + } } - if (xhr.status == 404 || // all browsers, http:// - xhr.status == -1100 || // safari file:// - // XXX: We have no way to tell in opera if a file exists and is empty, or is 404 - // XXX: Use flash? - //(!failed && xhr.status == 0 && !xhr.responseText && EXISTS)) // opera - false) - { - return false; + var isDone = false; + + var done = function() { + isDone = true; + if (xhr.status == 404 || // all browsers, http:// + xhr.status == -1100 || // safari file:// + // XXX: We have no way to tell in opera if a file exists and is empty, or is 404 + // XXX: Use flash? + //(!failed && xhr.status == 0 && !xhr.responseText && EXISTS)) // opera + false) + { + if (callback) { + callback(xhr.status); + } else { + return false; + } + } + + if (callback) { + callback(null, xhr.responseText); + } else { + return xhr.responseText; + } } - return xhr.responseText; + // If ansync, we wait otherwise done immediately + if (callback) { + xhr.onreadystatechange = function() { + if (xhr.readyState === 4) { + done(); + } + } + xhr.send(null); + } else { + xhr.send(null); + return done(); + } }; - var _namespace = null; this._getNamespace = function() { @@ -660,6 +697,76 @@ localStorage.setItem(oldFailedKey, JSON.stringify(_failedFetches)); }; + var _suggestions = null; + this._getSuggestions = function() { + if (!_suggestions) { + var oldSuggestionsKey = this._getNamespace() + 'suggestions'; + var oldSuggestions = localStorage.getItem(oldSuggestionsKey); + _suggestions = JSON.parse(oldSuggestions) || []; + } + return _suggestions; + } + + // Register modules that were found. These should be loaded first next run, if possible. + // They serve as a best guess for required files based on prior runs + this.registerFoundModule = function(path) { + var suggestions = this._getSuggestions(); + if (suggestions.indexOf(path) === -1 && path.indexOf('http') === 0) { + suggestions.push(path); + // // Save + var oldSuggestionsKey = this._getNamespace() + 'suggestions'; + localStorage.setItem(oldSuggestionsKey, JSON.stringify(suggestions)); + } + }; + + this.preloadModules = function(cb) { + // Get the old list from storage + var suggestions = this._getSuggestions(); + if (suggestions.length === 0) { + cb(); + } + + console.log('PRELOADING MODULES', suggestions.length); + + // Request all + var suggestionCount = suggestions.length; + var finished = 0; + var errors = []; + var importPreprocessor = getPreprocessor('import'); + var inlinePreprocessor = getPreprocessor('inlineSlice'); + + var onComplete = function() { + finished++; + if (finished === suggestionCount) { + // debugger + cb(errors.length > 0 ? errors : undefined); + } + }; + + var request = function(path) { + if (jsio.getCachedSrc(path)) { + onComplete(); + return; + } + + this.fetch(path, function(err, src) { + if (err) { + errors.push(path); + } else { + // Preprocessors use a moduleDef + // TODO: why is the src cache not actually the src? + var fakeModule = { src: src }; + importPreprocessor(null, fakeModule, null); + inlinePreprocessor(null, fakeModule, null); + jsio.setCachedSrc(path, fakeModule.src); + } + + onComplete(); + }); + }.bind(this); + + suggestions.forEach(request); + }; }; function findModule(possibilities) { @@ -690,6 +797,7 @@ if (src !== false) { possible.src = src; + ENV.registerFoundModule(path); return possible; } else { ENV.setFetchFailed(path); From 1b2a8166b5dd064b88b0003ede1d171b3b0d9e5c Mon Sep 17 00:00:00 2001 From: yofreke Date: Mon, 20 Jul 2015 17:00:23 +0000 Subject: [PATCH 04/10] add functionality to preserve caches --- packages/jsio.js | 23 +++++++++++++++++++---- packages/preprocessors/compiler.js | 4 ++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/packages/jsio.js b/packages/jsio.js index 7aefb36..8f465d8 100644 --- a/packages/jsio.js +++ b/packages/jsio.js @@ -697,12 +697,17 @@ localStorage.setItem(oldFailedKey, JSON.stringify(_failedFetches)); }; + var oldSuggestionsKey = this._getNamespace() + 'suggestions'; var _suggestions = null; + this._getSuggestions = function() { if (!_suggestions) { - var oldSuggestionsKey = this._getNamespace() + 'suggestions'; var oldSuggestions = localStorage.getItem(oldSuggestionsKey); - _suggestions = JSON.parse(oldSuggestions) || []; + if (oldSuggestions) { + _suggestions = JSON.parse(oldSuggestions); + } else { + _suggestions = []; + } } return _suggestions; } @@ -713,13 +718,23 @@ var suggestions = this._getSuggestions(); if (suggestions.indexOf(path) === -1 && path.indexOf('http') === 0) { suggestions.push(path); - // // Save - var oldSuggestionsKey = this._getNamespace() + 'suggestions'; + // Save localStorage.setItem(oldSuggestionsKey, JSON.stringify(suggestions)); } }; this.preloadModules = function(cb) { + // Check for the preserveCache key + // This is how the simulator tells us it is a soft reload + if (!localStorage.getItem('preserveCache')) { + // Clear the old things + localStorage.setItem(oldSuggestionsKey, ''); + localStorage.setItem(oldFailedKey, ''); + + cb(); + return; + } + // Get the old list from storage var suggestions = this._getSuggestions(); if (suggestions.length === 0) { diff --git a/packages/preprocessors/compiler.js b/packages/preprocessors/compiler.js index 1b94b4a..cb83610 100644 --- a/packages/preprocessors/compiler.js +++ b/packages/preprocessors/compiler.js @@ -185,9 +185,9 @@ exports.getJsioSrc = function(includeJsio) { if (src.substring(0, 8) == 'function') { src = 'jsio=(' + src + ')();'; } - } - src += exports.getPathJS(); + src += exports.getPathJS(); + } return src; } From c3a69a08908ba53055a5bea157644257f128d8c9 Mon Sep 17 00:00:00 2001 From: yofreke Date: Mon, 20 Jul 2015 18:59:58 -0700 Subject: [PATCH 05/10] cleanup preload --- packages/jsio.js | 50 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/packages/jsio.js b/packages/jsio.js index 8f465d8..640d575 100644 --- a/packages/jsio.js +++ b/packages/jsio.js @@ -501,6 +501,10 @@ } }; + this.getNamespace = function(str) { + return this.getCwd() + ':' + str; + }; + var _failedFetches = {}; this.hasFetchFailed = function(path) { @@ -663,19 +667,19 @@ return done(); } }; - var _namespace = null; - this._getNamespace = function() { + var _namespace = null; + this.getNamespace = function(str) { if (!_namespace) { var cwd = this.getCwd(); var _namespace = cwd.substring(cwd.indexOf('apps/'), cwd.length); if (_namespace.charAt(_namespace.length - 1) === '/') { _namespace = _namespace.substring(0, _namespace.length - 1); } _namespace += ':'; } - return _namespace; + return _namespace + str; } - var oldFailedKey = this._getNamespace() + 'failedFetches'; + var oldFailedKey = this.getNamespace('failedFetches'); var _failedFetches = null; this.hasFetchFailed = function(path) { @@ -697,7 +701,7 @@ localStorage.setItem(oldFailedKey, JSON.stringify(_failedFetches)); }; - var oldSuggestionsKey = this._getNamespace() + 'suggestions'; + var oldSuggestionsKey = this.getNamespace('suggestions'); var _suggestions = null; this._getSuggestions = function() { @@ -726,15 +730,18 @@ this.preloadModules = function(cb) { // Check for the preserveCache key // This is how the simulator tells us it is a soft reload - if (!localStorage.getItem('preserveCache')) { + if (!localStorage.getItem(this.getNamespace('preserveCache'))) { // Clear the old things - localStorage.setItem(oldSuggestionsKey, ''); - localStorage.setItem(oldFailedKey, ''); + localStorage.removeItem(oldSuggestionsKey); + localStorage.removeItem(oldFailedKey); cb(); return; } + // Clear from last time + localStorage.removeItem(this.getNamespace('preserveCache')); + // Get the old list from storage var suggestions = this._getSuggestions(); if (suggestions.length === 0) { @@ -747,10 +754,21 @@ var suggestionCount = suggestions.length; var finished = 0; var errors = []; + + // Load the preprocessors + // TODO: These synchronously block, should probably load them async var importPreprocessor = getPreprocessor('import'); var inlinePreprocessor = getPreprocessor('inlineSlice'); - var onComplete = function() { + var processSrc = function(path, src) { + var fakeModule = { src: src }; + importPreprocessor(null, fakeModule, null); + inlinePreprocessor(null, fakeModule, null); + jsio.setCachedSrc(path, fakeModule.src); + onComplete(); + }; + + var onComplete = function(err) { finished++; if (finished === suggestionCount) { // debugger @@ -764,19 +782,21 @@ return; } + // TODO: validate these before the request step + if (path === 'undefined') { + onComplete(); + return; + } + this.fetch(path, function(err, src) { if (err) { errors.push(path); + onComplete(err); } else { // Preprocessors use a moduleDef // TODO: why is the src cache not actually the src? - var fakeModule = { src: src }; - importPreprocessor(null, fakeModule, null); - inlinePreprocessor(null, fakeModule, null); - jsio.setCachedSrc(path, fakeModule.src); + processSrc(path, src); } - - onComplete(); }); }.bind(this); From ce91cf9106930a67d2a7c0f9466cd12219319133 Mon Sep 17 00:00:00 2001 From: yofreke Date: Thu, 23 Jul 2015 03:04:05 -0700 Subject: [PATCH 06/10] moved srcCache in to ENV This fixes the problem where multiple requests would be made for a dynamically loaded file. It also allows for squashing of equivalent sources with different http paths (eg. "http://mysite.com/modules/x.js" and "modules/x.js") --- packages/jsio.js | 122 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 86 insertions(+), 36 deletions(-) diff --git a/packages/jsio.js b/packages/jsio.js index 640d575..32aa9dc 100644 --- a/packages/jsio.js +++ b/packages/jsio.js @@ -260,19 +260,6 @@ jsio.__util = util; jsio.__init__ = init; - var srcCache; - jsio.setCache = function(cache) { srcCache = jsio.__srcCache = cache; }; - jsio.setCache(cloneFrom && cloneFrom.__srcCache || {}); - - jsio.setCachedSrc = function(path, src, locked) { - if (srcCache[path] && srcCache[path].locked) { - console.warn('Cache is ignoring (already present and locked) src ' + path); - return; - } - srcCache[path] = { path: path, src: src, locked: locked }; - }; - jsio.getCachedSrc = function(path) { return srcCache[path]; }; - jsio.__filename = 'jsio.js'; jsio.__cmds = []; jsio.__jsio = jsio; @@ -339,6 +326,12 @@ if (envCtor == ENV_browser) { jsio.path.set(ENV.getPath()); } + + jsio.setCache = ENV.setCache.bind(ENV); + jsio.setCache(cloneFrom && cloneFrom.__srcCache || {}); + + jsio.setCachedSrc = ENV.setCachedSrc.bind(ENV); + jsio.getCachedSrc = ENV.getCachedSrc.bind(ENV); }; if (cloneFrom) { @@ -394,13 +387,6 @@ this.pathSep = path.sep; - // var parentPath = util.splitPath(module.parent.filename); - // module.parent.require = function(request, opts) { - // if (!opts) { opts = {}; } - // opts.dontExport = true; - // return _require({}, parentPath.directory, parentPath.filename, request, opts); - // }; - this.log = function() { var msg; try { @@ -502,7 +488,7 @@ }; this.getNamespace = function(str) { - return this.getCwd() + ':' + str; + return this.getCwd() + ':' + (str || ''); }; var _failedFetches = {}; @@ -523,6 +509,20 @@ cb(); }; + var srcCache; + this.setCache = function(cache) { srcCache = jsio.__srcCache = cache; }; + + this.setCachedSrc = function(path, src, locked) { + if (srcCache[path] && srcCache[path].locked) { + console.warn('Cache is ignoring (already present and locked) src ' + path); + return; + } + srcCache[path] = { path: path, src: src, locked: locked }; + }; + this.getCachedSrc = function(path) { + return srcCache[path]; + }; + } function ENV_browser() { @@ -716,11 +716,12 @@ return _suggestions; } - // Register modules that were found. These should be loaded first next run, if possible. - // They serve as a best guess for required files based on prior runs + /** Register modules that were found. These should be loaded first next run, if possible. + They serve as a best guess for required files based on prior runs */ this.registerFoundModule = function(path) { var suggestions = this._getSuggestions(); - if (suggestions.indexOf(path) === -1 && path.indexOf('http') === 0) { + // If it doesnt have an http, add it! + if (path && suggestions.indexOf(path) === -1) { suggestions.push(path); // Save localStorage.setItem(oldSuggestionsKey, JSON.stringify(suggestions)); @@ -733,7 +734,9 @@ if (!localStorage.getItem(this.getNamespace('preserveCache'))) { // Clear the old things localStorage.removeItem(oldSuggestionsKey); + _suggestions = null; localStorage.removeItem(oldFailedKey); + _failedFetches = null; cb(); return; @@ -771,12 +774,15 @@ var onComplete = function(err) { finished++; if (finished === suggestionCount) { - // debugger cb(errors.length > 0 ? errors : undefined); } }; + var requestedPaths = []; var request = function(path) { + var originalPath = path; + + // TODO: This should never happen if (jsio.getCachedSrc(path)) { onComplete(); return; @@ -788,6 +794,17 @@ return; } + // Check for duplicates (potentially occuring from http://host/abc and /abc) + if (path.indexOf('http') !== 0) { + // First convert to a full path (assumes href ends in a '/' and path does not start with a '/') + path = locationString + path; + if (requestedPaths.indexOf(path) >= 0) { + onComplete(); + return; + } + } + + requestedPaths.push(path); this.fetch(path, function(err, src) { if (err) { errors.push(path); @@ -795,20 +812,51 @@ } else { // Preprocessors use a moduleDef // TODO: why is the src cache not actually the src? - processSrc(path, src); + processSrc(originalPath, src); } }); }.bind(this); suggestions.forEach(request); }; + + var srcCache; + var locationString = util.addEndSlash(location.href); + + var _cachePath = function(path) { + if (path.indexOf(locationString) === 0) { + return path.substring(locationString.length, path.length); + } + return path; + }; + + this.setCache = function(cache) { srcCache = jsio.__srcCache = cache; }; + + /** A http path will be stored relative to location.href, if possible */ + this.setCachedSrc = function(path, src, locked) { + path = _cachePath(path); + + if (srcCache[path] && srcCache[path].locked) { + console.warn('Cache is ignoring (already present and locked) src ' + path); + return; + } + + srcCache[path] = { path: path, src: src, locked: locked }; + }; + + this.getCachedSrc = function(path) { + return srcCache[_cachePath(path)]; + }; + }; function findModule(possibilities) { - var src; - for (var i = 0, possible; possible = possibilities[i]; ++i) { - var path = possible.path, - cachedVersion = srcCache[path]; + var i, possible, path; + + // Check for possibilities in the cache + for (i = 0, possible; possible = possibilities[i]; ++i) { + path = possible.path; + var cachedVersion = jsio.getCachedSrc(path); if (cachedVersion) { // extract a non-absolute dirname from the cache key: absolute paths @@ -822,13 +870,12 @@ possible.pre = true; return possible; } + } - /*if (/^\.\//.test(path)) { - // remove one path segment for each dot from the cwd - path = addEndSlash(ENV.getCwd()) + path; - }*/ - - src = ENV.fetch(path); + // Try to fetch + for (i = 0, possible; possible = possibilities[i]; ++i) { + path = possible.path; + var src = ENV.fetch(path); if (src !== false) { possible.src = src; @@ -908,6 +955,9 @@ moduleDef.pre = true; applyPreprocessors(fromDir, moduleDef, ["import", "inlineSlice"], opts); + + // Save it in the cache + jsio.setCachedSrc(moduleDef.path, moduleDef.src); } // any additional preprocessors? From 712424058268a6b914394a9f0d99a149eb864bf5 Mon Sep 17 00:00:00 2001 From: yofreke Date: Mon, 27 Jul 2015 17:27:55 -0700 Subject: [PATCH 07/10] fix broken browser builds --- packages/jsio.js | 11 +++++++++++ packages/preprocessors/compiler.js | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/jsio.js b/packages/jsio.js index 32aa9dc..bd1520b 100644 --- a/packages/jsio.js +++ b/packages/jsio.js @@ -363,6 +363,17 @@ this.eval = function(code, path) {}; this.fetch = function(path) { return contentsOfPath; }; this.log = function(args...) {}; + + this.getNamespace = function(key) { return CONFIG.shortName + ':' + key }; + this.hasFetchFailed = function() { return false; }; + this.setFetchFailed = function() {}; + this.registerFoundModule = function() {}; + this.preloadModules = function(cb) {}; + + this.setCache = function(cache) {}; + + this.setCachedSrc = function(path, src, locked) {}; + this.getCachedSrc = function(path) {}; } */ diff --git a/packages/preprocessors/compiler.js b/packages/preprocessors/compiler.js index cb83610..1b94b4a 100644 --- a/packages/preprocessors/compiler.js +++ b/packages/preprocessors/compiler.js @@ -185,10 +185,10 @@ exports.getJsioSrc = function(includeJsio) { if (src.substring(0, 8) == 'function') { src = 'jsio=(' + src + ')();'; } - - src += exports.getPathJS(); } + src += exports.getPathJS(); + return src; } From 37f5dbdba50ec29cb18cf00a4f645766b2f4f834 Mon Sep 17 00:00:00 2001 From: yofreke Date: Mon, 3 Aug 2015 23:23:51 -0700 Subject: [PATCH 08/10] remove devkit dependency for namespacing --- packages/jsio.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/packages/jsio.js b/packages/jsio.js index bd1520b..8007409 100644 --- a/packages/jsio.js +++ b/packages/jsio.js @@ -364,7 +364,7 @@ this.fetch = function(path) { return contentsOfPath; }; this.log = function(args...) {}; - this.getNamespace = function(key) { return CONFIG.shortName + ':' + key }; + this.getNamespace = function(key) { return 'jsio:' + key }; this.hasFetchFailed = function() { return false; }; this.setFetchFailed = function() {}; this.registerFoundModule = function() {}; @@ -679,15 +679,8 @@ } }; - var _namespace = null; this.getNamespace = function(str) { - if (!_namespace) { - var cwd = this.getCwd(); - var _namespace = cwd.substring(cwd.indexOf('apps/'), cwd.length); - if (_namespace.charAt(_namespace.length - 1) === '/') { _namespace = _namespace.substring(0, _namespace.length - 1); } - _namespace += ':'; - } - return _namespace + str; + return 'jsio:' + str; } var oldFailedKey = this.getNamespace('failedFetches'); From 4e37227a4f2a84e3f4bed8c3aad83cc48f178f52 Mon Sep 17 00:00:00 2001 From: yofreke Date: Wed, 5 Aug 2015 01:57:17 +0000 Subject: [PATCH 09/10] fix old suggestions leaking in to fresh loads --- packages/jsio.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/packages/jsio.js b/packages/jsio.js index 8007409..47bc01c 100644 --- a/packages/jsio.js +++ b/packages/jsio.js @@ -681,13 +681,26 @@ this.getNamespace = function(str) { return 'jsio:' + str; - } + }; + + this._tryClearSuggestions = function() { + if (!localStorage.getItem(this.getNamespace('preserveCache'))) { + // Clear the old things + localStorage.removeItem(oldSuggestionsKey); + _suggestions = null; + localStorage.removeItem(oldFailedKey); + _failedFetches = null; + return true; + } + return false; + }; var oldFailedKey = this.getNamespace('failedFetches'); var _failedFetches = null; this.hasFetchFailed = function(path) { if (!_failedFetches) { + this._tryClearSuggestions(); var oldFailed = localStorage.getItem(oldFailedKey); if (oldFailed) { _failedFetches = JSON.parse(oldFailed); @@ -710,6 +723,7 @@ this._getSuggestions = function() { if (!_suggestions) { + this._tryClearSuggestions(); var oldSuggestions = localStorage.getItem(oldSuggestionsKey); if (oldSuggestions) { _suggestions = JSON.parse(oldSuggestions); @@ -735,13 +749,7 @@ this.preloadModules = function(cb) { // Check for the preserveCache key // This is how the simulator tells us it is a soft reload - if (!localStorage.getItem(this.getNamespace('preserveCache'))) { - // Clear the old things - localStorage.removeItem(oldSuggestionsKey); - _suggestions = null; - localStorage.removeItem(oldFailedKey); - _failedFetches = null; - + if (this._tryClearSuggestions()) { cb(); return; } From f98b0603a80c21bea16f85312f5390f86f21933c Mon Sep 17 00:00:00 2001 From: yofreke Date: Thu, 6 Aug 2015 00:41:16 +0000 Subject: [PATCH 10/10] fix fetch problem, fix clear suggestions problem --- packages/jsio.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/jsio.js b/packages/jsio.js index 47bc01c..32fabda 100644 --- a/packages/jsio.js +++ b/packages/jsio.js @@ -653,14 +653,14 @@ { if (callback) { callback(xhr.status); - } else { - return false; } - } - if (callback) { - callback(null, xhr.responseText); + return false; } else { + if (callback) { + callback(null, xhr.responseText); + } + return xhr.responseText; } } @@ -687,9 +687,9 @@ if (!localStorage.getItem(this.getNamespace('preserveCache'))) { // Clear the old things localStorage.removeItem(oldSuggestionsKey); - _suggestions = null; + _suggestions = []; localStorage.removeItem(oldFailedKey); - _failedFetches = null; + _failedFetches = {}; return true; } return false;