Skip to content

Commit

Permalink
Handle missing image "src" properties
Browse files Browse the repository at this point in the history
  • Loading branch information
markdalgleish committed Dec 24, 2015
1 parent 9c27efe commit 89131ee
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
6 changes: 5 additions & 1 deletion index.js
Expand Up @@ -3,6 +3,10 @@ var loaderUtils = require('loader-utils');
var steed = require('steed');

function resolveImageSrc(loaderContext, image, callback) {
if (typeof image.src !== 'string') {
return callback(new Error('Missing image "src" property in Web App Manifest'));
}

var dirname = path.dirname(loaderContext.resourcePath);

// Resolve the image filename relative to the manifest file
Expand Down Expand Up @@ -34,7 +38,7 @@ function resolveImages(loaderContext, manifest, key, callback) {
return callback(null);
}

steed.each(manifest[key], resolveImageSrc.bind(null, loaderContext), function(err) {
steed.map(manifest[key], resolveImageSrc.bind(null, loaderContext), function(err) {
if (err) {
return callback(err);
}
Expand Down
1 change: 1 addition & 0 deletions test/error-cases/missing-src/expected-error.js
@@ -0,0 +1 @@
module.exports = 'Error: Missing image "src" property in Web App Manifest';
1 change: 1 addition & 0 deletions test/error-cases/missing-src/index.js
@@ -0,0 +1 @@
require('./manifest.json');
9 changes: 9 additions & 0 deletions test/error-cases/missing-src/manifest.json
@@ -0,0 +1,9 @@
{
"name": "Missing Src",
"icons": [
{
"sizes": "192x192",
"type": "image/png"
}
]
}
19 changes: 19 additions & 0 deletions test/error-cases/missing-src/webpack.config.js
@@ -0,0 +1,19 @@
module.exports = {
entry: {
main: __dirname + '/index.js'
},

output: {
filename: 'index.js',
path: __dirname + '/actual-output'
},

module: {
loaders: [
{
test: /manifest.json$/,
loader: 'file?name=manifest.json!../../../index.js'
}
]
}
};

0 comments on commit 89131ee

Please sign in to comment.