Skip to content

Commit

Permalink
update shim files to use window instead of global (RobotWebTools#286)
Browse files Browse the repository at this point in the history
The files in /shim is only used in browsers (remapped in the browser
field of package.json) when using build tools. Browsers do not have the
global propery which is a node thing. Browsers instead have the global
namespace window.

This commit solve my problem of importing roslib in my application and
building with webpack 4 without having webpack shim global = window.

Note: updated Gruntfile.js to have jshint read the config file from the
closes directory/parent directory and added a new .jshintrc to /shim to
lint the files there with a browser environment in mind.
  • Loading branch information
jorgenfb authored and jihoonl committed Oct 29, 2018
1 parent 47336fa commit 35e7474
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = function(grunt) {
},
jshint: {
options: {
jshintrc: '.jshintrc'
jshintrc: true
},
files: [
'./Gruntfile.js',
Expand Down
24 changes: 24 additions & 0 deletions src/util/shim/.jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"globals": {
"Blob": true,
"FileReader": true
},
"browser": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"latedef": false,
"newcap": true,
"noarg": true,
"sub": true,
"undef": true,
"boss": false,
"eqnull": false,
"node": true,
"devel": true,
"strict": false,
"trailing": true,
"quotmark": "single",
"proto": true,
"laxbreak": true
}
2 changes: 1 addition & 1 deletion src/util/shim/WebSocket.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = global.WebSocket;
module.exports = window.WebSocket;
4 changes: 2 additions & 2 deletions src/util/shim/decompressPng.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'use strict';

var Canvas = require('canvas');
var Image = Canvas.Image || global.Image;
var Image = Canvas.Image || window.Image;

/**
* If a message was compressed as a PNG image (a compression hack since
Expand Down Expand Up @@ -53,4 +53,4 @@ function decompressPng(data, callback) {
image.src = 'data:image/png;base64,' + data;
}

module.exports = decompressPng;
module.exports = decompressPng;
6 changes: 3 additions & 3 deletions src/util/shim/xmldom.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
exports.DOMImplementation = global.DOMImplementation;
exports.XMLSerializer = global.XMLSerializer;
exports.DOMParser = global.DOMParser;
exports.DOMImplementation = window.DOMImplementation;
exports.XMLSerializer = window.XMLSerializer;
exports.DOMParser = window.DOMParser;

0 comments on commit 35e7474

Please sign in to comment.