Skip to content

Commit

Permalink
Release version 3.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
milankinen committed Jan 3, 2017
2 parents fb71b9c + ca9d199 commit 1efc4db
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 22 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
language: node_js
node_js:
- "4.2.0"
- "4"
- "5"
- "6"
before_script:
- npm install -g npm
script:
Expand Down
2 changes: 1 addition & 1 deletion examples/01-basic-usage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"devDependencies": {
"babel-plugin-react-transform": "^2.0.2",
"livereactload": "file:../..",
"livereactload": "latest",
"nodemon": "^1.9.2",
"react-proxy": "^1.1.8",
"watchify": "^3.7.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/02-redux/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"devDependencies": {
"babel-plugin-react-transform": "^2.0.2",
"livereactload": "file:../..",
"livereactload": "latest",
"nodemon": "^1.9.2",
"react-proxy": "^1.1.8",
"watchify": "^3.7.0"
Expand Down
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "livereactload",
"version": "3.1.1",
"version": "3.1.2",
"description": "Live code editing with Browserify and React",
"author": "Matti Lankinen <[email protected]> (https://github.com/milankinen)",
"license": "MIT",
Expand Down Expand Up @@ -29,21 +29,21 @@
"dependencies": {
"cli-color": "1.1.0",
"convert-source-map": "1.3.0",
"lodash": "4.13.1",
"md5": "2.1.0",
"lodash": "4.17.4",
"md5": "2.2.1",
"offset-sourcemap-lines": "1.0.0",
"through2": "2.0.1",
"through2": "2.0.3",
"umd": "3.0.1",
"ws": "1.1.1"
},
"devDependencies": {
"babel-cli": "^6.10.1",
"babel-preset-es2015": "^6.9.0",
"babel-cli": "^6.18.0",
"babel-preset-es2015": "^6.18.0",
"babel-tape-runner": "2.0.1",
"bluebird": "3.4.1",
"chokidar": "1.6.0",
"shelljs": "0.7.0",
"tape": "4.6.0",
"bluebird": "3.4.7",
"chokidar": "1.6.1",
"shelljs": "0.7.5",
"tape": "4.6.3",
"zombie": "4.2.1"
}
}
1 change: 0 additions & 1 deletion src/browserify-plugin/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ function LiveReactloadPlugin(b, opts = {}) {
if (converter) {
sourceWithoutMaps = convertSourceMaps.removeComments(source)
hash = md5(sourceWithoutMaps)
converter.setProperty('sources', [file.replace(basedir, hash)])
adjustedSourcemap = convertSourceMaps.fromObject(offsetSourceMaps(converter.toObject(), 1)).toComment()
} else {
hash = md5(source)
Expand Down
38 changes: 30 additions & 8 deletions src/reloading.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function loader(mappings, entryPoints, options) {

var scope = {
mappings: mappings,
revNums: {},
cache: {},
reloading: false,
reloadHooks: {},
Expand Down Expand Up @@ -80,23 +81,22 @@ function loader(mappings, entryPoints, options) {
}
}

function compile(mapping) {
function compile(mapping, revision) {
var body = mapping[0];
if (typeof body !== "function") {
debug("Compiling module", mapping[2])
debug("Compiling module", mapping[2], "[revision " + revision + " ]")
var compiled = compileModule(body, mapping[2].sourcemap);
mapping[0] = compiled;
mapping[2].source = body;
}
}

function compileModule(source, sourcemap) {
return eval(
"function __livereactload_module(require, module, exports){\n" +
source +
"\n}; __livereactload_module;" +
(sourcemap || "")
var toModule = new Function(
"__livereactload_source", "__livereactload_sourcemap",
"return eval('function __livereactload_module(require, module, exports){\\n' + __livereactload_source + '\\n}; __livereactload_module;' + (__livereactload_sourcemap || ''));"
);
return toModule(source, sourcemap)
}

function unknownUseCase() {
Expand Down Expand Up @@ -163,12 +163,34 @@ function loader(mappings, entryPoints, options) {
var mapping = mappings[id];
var meta = mapping[2];
if (!old || old[2].hash !== meta.hash) {
compile(mapping);
var rev = scope.revNums[id] ? ++scope.revNums[id] : (scope.revNums[id] = 1);
if (old && meta.sourcemap) {
addVersionToSourceMap(meta, rev);
}
compile(mapping, rev);
scope.mappings[id] = mapping;
changes.push([id, old]);
}
});
return changes;

// Updates the source map by adding a revision parameter to the filename.
// Without this new filename, browsers will ignore the updated source map.
function addVersionToSourceMap(meta, revision) {
var comment = meta.sourcemap
.replace(/^\/\*/g, '//')
.replace(/\*\/$/g, '');
// decode sourcemap comment and add hash param
comment = comment.split(',').pop();
var sourcemap = JSON.parse(atob(comment));
for (var i = 0; i < sourcemap.sources.length; i++) {
sourcemap.sources[i] += "?rev=" + revision;
}
// re-encode to sourcemap comment
comment = btoa(JSON.stringify(sourcemap));
comment = '//# sourceMappingURL=data:application/json;base64,' + comment;
meta.sourcemap = comment;
}
}

/**
Expand Down

0 comments on commit 1efc4db

Please sign in to comment.