Skip to content

Commit

Permalink
Release version 3.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
milankinen committed Nov 25, 2016
2 parents c5d6935 + e3defcb commit a52c045
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "livereactload",
"version": "3.1.0",
"version": "3.1.1",
"description": "Live code editing with Browserify and React",
"author": "Matti Lankinen <m.lankinen@iki.fi> (https://github.com/milankinen)",
"license": "MIT",
Expand Down Expand Up @@ -28,8 +28,10 @@
},
"dependencies": {
"cli-color": "1.1.0",
"convert-source-map": "1.3.0",
"lodash": "4.13.1",
"md5": "2.1.0",
"offset-sourcemap-lines": "1.0.0",
"through2": "2.0.1",
"umd": "3.0.1",
"ws": "1.1.1"
Expand Down
19 changes: 18 additions & 1 deletion src/browserify-plugin/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import through from "through2"
import md5 from "md5"
import {readFileSync} from "fs"
import {resolve} from "path"
import convertSourceMaps from 'convert-source-map'
import offsetSourceMaps from 'offset-sourcemap-lines'
import {startServer} from "./server"
import {log} from "./console"
import loader from "../reloading"
Expand All @@ -16,6 +18,7 @@ function LiveReactloadPlugin(b, opts = {}) {
client = true,
dedupe = true,
debug = false,
basedir = process.cwd(),
'ssl-cert': sslCert = null,
'ssl-key': sslKey = null,
} = opts
Expand Down Expand Up @@ -96,10 +99,24 @@ function LiveReactloadPlugin(b, opts = {}) {
b.pipeline.get("label").push(through.obj(
function transform(row, enc, next) {
const {id, file, source, deps, entry} = row
const converter = convertSourceMaps.fromSource(source)
let sourceWithoutMaps = source
let adjustedSourcemap = ''
let hash;

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)
}

if (entry) {
entries.push(file)
}
mappings[file] = [source, deps, {id: file, hash: md5(source), browserifyId: id}]
mappings[file] = [sourceWithoutMaps, deps, {id: file, hash: hash, browserifyId: id, sourcemap: adjustedSourcemap}]
next(null, row)
},
function flush(next) {
Expand Down
12 changes: 10 additions & 2 deletions src/reloading.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,21 @@ function loader(mappings, entryPoints, options) {
var body = mapping[0];
if (typeof body !== "function") {
debug("Compiling module", mapping[2])
var compiled = new Function("require", "module", "exports", body);
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 || "")
);
}

function unknownUseCase() {
throw new Error(
"Unknown use-case encountered! Please raise an issue: " +
Expand Down Expand Up @@ -430,7 +439,6 @@ function loader(mappings, entryPoints, options) {
}
}


module.exports = loader;
module.exports["default"] = loader;

0 comments on commit a52c045

Please sign in to comment.