summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--js/.jshintrc1
-rw-r--r--js/bin/HttpServer.js20
-rw-r--r--js/gulp/gulp-bundle/index.js90
-rw-r--r--js/gulpfile.js21
-rw-r--r--js/package.json3
-rw-r--r--js/src/Ice/Exception.js2
-rw-r--r--js/src/Ice/browser/ModuleRegistry.js19
7 files changed, 123 insertions, 33 deletions
diff --git a/js/.jshintrc b/js/.jshintrc
index a2c6f25b486..d7efda94bcf 100644
--- a/js/.jshintrc
+++ b/js/.jshintrc
@@ -2,6 +2,7 @@
"node": true,
"undef": true,
"evil": true,
+ "elision": true,
"globals":
{
"WebSocket" : false,
diff --git a/js/bin/HttpServer.js b/js/bin/HttpServer.js
index cde3cdec8cb..9e070937522 100644
--- a/js/bin/HttpServer.js
+++ b/js/bin/HttpServer.js
@@ -47,6 +47,12 @@ function Init()
"/lib/Glacier2.js", "/lib/Glacier2.min.js",
"/lib/IceStorm.js", "/lib/IceStorm.min.js",
"/lib/IceGrid.js", "/lib/IceGrid.min.js",];
+
+ var libraryMaps = libraries.map(
+ function(f)
+ {
+ return f + ".map";
+ });
var HttpServer = function(host, ports)
{
@@ -60,6 +66,7 @@ function Init()
var filePath;
var iceLib = libraries.indexOf(req.url.pathname) !== -1;
+ var iceLibMap = libraryMaps.indexOf(req.url.pathname) !== -1;
//
// If ICE_HOME has been set resolve Ice libraries paths into ICE_HOME.
//
@@ -69,9 +76,16 @@ function Init()
// If OPTIMIZE is set resolve Ice libraries to the corresponding minified
// versions.
//
- if(process.env.OPTIMIZE == "yes" && iceLib && filePath.substr(-7) !== ".min.js")
+ if(process.env.OPTIMIZE == "yes")
{
- filePath = filePath.replace(".js", ".min.js");
+ if(iceLib && filePath.substr(-7) !== ".min.js")
+ {
+ filePath = filePath.replace(".js", ".min.js");
+ }
+ else if(iceLibMap && filePath.substr(-11) !== ".min.js.map")
+ {
+ filePath = filePath.replace(".js.map", ".min.js.map");
+ }
}
var ext = path.extname(filePath).slice(1);
@@ -80,7 +94,7 @@ function Init()
// When the browser ask for a .js or .css file and it has support for gzip content
// check if a gzip version (.js.gz or .css.gz) of the file exists and use that instead.
//
- if((ext == "js" || ext == "css") && req.headers["accept-encoding"].indexOf("gzip") !== -1)
+ if((ext == "js" || ext == "css" || ext == "map") && req.headers["accept-encoding"].indexOf("gzip") !== -1)
{
fs.stat(filePath + ".gz",
function(err, stats)
diff --git a/js/gulp/gulp-bundle/index.js b/js/gulp/gulp-bundle/index.js
index c4b93a00ff8..34820c11295 100644
--- a/js/gulp/gulp-bundle/index.js
+++ b/js/gulp/gulp-bundle/index.js
@@ -13,6 +13,7 @@ var PLUGIN_NAME = "gulp-slice2js-bundle";
var through = require("through2");
var fs = require("fs");
var path = require("path");
+var sourcemap = require('source-map');
function rmfile(path)
{
@@ -228,10 +229,28 @@ StringBuffer.prototype.write = function(data)
this.buffer = Buffer.concat([this.buffer, new Buffer(data, "utf8")]);
};
+function sourceMapRelativePath(file)
+{
+ var modules = ["Ice", "Glacier2", "IceStorm", "IceGrid"],
+ rel = "",
+ filepath = file,
+ basename;
+ while(true)
+ {
+ basename = path.basename(filepath);
+ rel = path.join(basename, rel);
+ filepath = path.dirname(filepath);
+ if(modules.indexOf(basename) != -1)
+ {
+ break;
+ }
+ }
+ return rel;
+}
+
function bundle(args)
{
var files = [];
- var outputFile = null;
return through.obj(
function(file, enc, cb)
@@ -246,16 +265,11 @@ function bundle(args)
return this.emit('error', new PluginError(PLUGIN_NAME, 'Streaming not supported'));
}
- if(!outputFile)
- {
- outputFile = file;
- }
-
files.push(file);
cb();
},
function(cb)
- {
+ {
if(!isfile(args.target) ||
files.some(function(f){ return isnewer(f.path, args.target); }))
{
@@ -269,6 +283,12 @@ function bundle(args)
});
d.depends = d.expand().sort();
+
+ var sourceMap = new sourcemap.SourceMapGenerator(
+ {
+ file: path.basename(args.target)
+ });
+ var lineOffset = 0;
//
// Wrap the library in a closure to hold the private __Slice module.
@@ -295,31 +315,42 @@ function bundle(args)
var sb = new StringBuffer();
sb.write(preamble);
-
+ lineOffset += 2;
+
args.modules.forEach(
function(m){
sb.write(" window." + m + " = window." + m + " || {};\n");
+ lineOffset++;
+
if(m == "Ice")
{
sb.write(" Ice.Slice = Ice.Slice || {};\n");
+ lineOffset++;
}
});
- sb.write(" var Slice = Ice.Slice;");
-
+ sb.write(" var Slice = Ice.Slice;\n");
+ lineOffset++;
+
for(var i = 0; i < d.depends.length; ++i)
{
sb.write(modulePreamble);
+ lineOffset += 3;
+
var data = d.depends[i].file.contents.toString();
+ var file = d.depends[i].file;
var lines = data.toString().split("\n");
var skip = false;
var skipUntil;
var skipAuto = false;
var line;
+ var out;
- for(var j in lines)
+ var j = 0;
+ for(j = 0; j < lines.length; j++)
{
- line = lines[j].trim();
+ out = lines[j];
+ line = out.trim();
if(line == "/* slice2js browser-bundle-skip */")
{
@@ -380,7 +411,6 @@ function bundle(args)
continue;
}
- var out = lines[j];
if(line.indexOf("module.exports.") === 0)
{
continue;
@@ -393,34 +423,52 @@ function bundle(args)
{
continue;
}
-
- if(line.indexOf("__M.type") !== -1)
- {
- out = out.replace(/__M\.type/g, "eval");
- }
-
+
sb.write(" " + out + "\n");
+
+ sourceMap.addMapping(
+ {
+ generated:
+ {
+ line: lineOffset + 1,
+ column: 8
+ },
+ original:
+ {
+ line: j + 1,
+ column:0
+ },
+ source: sourceMapRelativePath(file.path)
+ });
+ lineOffset++;
}
sb.write(moduleEpilogue);
+ lineOffset++;
}
sb.write("\n");
+ lineOffset++;
+
//
// Now exports the modules to the global Window object.
//
args.modules.forEach(
function(m){
sb.write(" window." + m + " = " + m + ";\n");
+ lineOffset++;
});
sb.write(epilogue);
+ lineOffset++;
- this.push(new gutil.File(
+ var target = new gutil.File(
{
cwd: "",
base:"",
path:path.basename(args.target),
contents:sb.buffer
- }));
+ });
+ target.sourceMap = JSON.parse(sourceMap.toString());
+ this.push(target);
}
cb();
});
diff --git a/js/gulpfile.js b/js/gulpfile.js
index 1e06d135585..d64441934ed 100644
--- a/js/gulpfile.js
+++ b/js/gulpfile.js
@@ -22,6 +22,7 @@ var open = require("gulp-open");
var path = require("path");
var paths = require('vinyl-paths');
var spawn = require("child_process").spawn;
+var sourcemaps = require('gulp-sourcemaps');
var uglify = require("gulp-uglify");
var HttpServer = require("./bin/HttpServer");
@@ -139,12 +140,14 @@ libs.forEach(
function()
{
return gulp.src(libSources(lib, sources))
- .pipe(bundle(
- {
- srcDir: srcDir(lib),
- modules: sources.modules,
- target: libFile(lib)
- }))
+ .pipe(sourcemaps.init())
+ .pipe(bundle(
+ {
+ srcDir: srcDir(lib),
+ modules: sources.modules,
+ target: libFile(lib)
+ }))
+ .pipe(sourcemaps.write("../lib", {sourceRoot:"/src"}))
.pipe(gulp.dest("lib"))
.pipe(gzip())
.pipe(gulp.dest("lib"));
@@ -155,8 +158,10 @@ libs.forEach(
{
return gulp.src(libFile(lib))
.pipe(newer(libFileMin(lib)))
- .pipe(extreplace(".min.js"))
- .pipe(uglify())
+ .pipe(sourcemaps.init({loadMaps:true, sourceRoot:"./"}))
+ .pipe(uglify({compress:false}))
+ .pipe(extreplace(".min.js"))
+ .pipe(sourcemaps.write("../lib", {includeContent: false}))
.pipe(gulp.dest("lib"))
.pipe(gzip())
.pipe(gulp.dest("lib"));
diff --git a/js/package.json b/js/package.json
index db5af40381c..96f7edfb922 100644
--- a/js/package.json
+++ b/js/package.json
@@ -21,10 +21,12 @@
"gulp-minify-css": "^0.3.11",
"gulp-newer": "^0.5.0",
"gulp-open": "^0.3.1",
+ "gulp-sourcemaps": "^1.3.0",
"gulp-uglify": "^1.0.2",
"gulp-util": "^3.0.1",
"gulp-watch": "^3.0.0",
"http-proxy": "^1.8.1",
+ "source-map": "^0.2.0",
"through2": "^0.6.3",
"vinyl-paths": "^1.0.0"
},
@@ -35,6 +37,7 @@
"gulp:clean": "gulp clean",
"gulp:test": "gulp test",
"gulp:lint": "gulp lint",
+ "gulp:demo:run": "gulp demo:run",
"gulp:test:run-with-browser": "gulp test:run-with-browser",
"gulp:test:run-with-node": "gulp test:run-with-node"
}
diff --git a/js/src/Ice/Exception.js b/js/src/Ice/Exception.js
index bdd98b8c35a..1957ad7bdb2 100644
--- a/js/src/Ice/Exception.js
+++ b/js/src/Ice/Exception.js
@@ -40,7 +40,7 @@ var toString = function(key, object, objectTable, ident)
//
if(typeof object.toString == "function")
{
- return s = "\n" + ident + key + ":" + object.toString();
+ return "\n" + ident + key + ":" + object.toString();
}
var s = "\n" + ident + key + ":";
diff --git a/js/src/Ice/browser/ModuleRegistry.js b/js/src/Ice/browser/ModuleRegistry.js
index df0e644ed57..2f64dd42c4d 100644
--- a/js/src/Ice/browser/ModuleRegistry.js
+++ b/js/src/Ice/browser/ModuleRegistry.js
@@ -22,6 +22,25 @@ var __M =
require: function(name)
{
return window;
+ },
+ type: function(scoped)
+ {
+ if(scoped === undefined)
+ {
+ return undefined;
+ }
+ var components = scoped.split(".");
+ var T = window;
+
+ for(var i = 0, length = components.length; i < length; ++i)
+ {
+ T = T[components[i]];
+ if(T === undefined)
+ {
+ return undefined;
+ }
+ }
+ return T;
}
};