diff --git a/lib/get.js b/lib/get.js index 9816fdd..e29a762 100644 --- a/lib/get.js +++ b/lib/get.js @@ -35,6 +35,17 @@ module.exports = function get(url, options) { 'content-type': mime.lookup(url), }, }; + }).catch(function (error) { + if (error.code === 'ENOENT') { + inliner.emit('warning', 'no such file: ' + url); + } + + return { + body: '', + headers: { + 'content-type': mime.lookup(url), + }, + }; }); return cache[url]; diff --git a/lib/index.js b/lib/index.js index 90a9d5d..3f48db9 100644 --- a/lib/index.js +++ b/lib/index.js @@ -113,7 +113,7 @@ function Inliner(source, options, callback) { this.jobs.done[key] = this.completeJob.bind(this, key); }.bind(this)); - this.isFile = false; + this.isFile = options.useStdin || false; this.on('error', function localErrorHandler(event) { inliner.callback(event); @@ -192,6 +192,7 @@ function main() { // otherwise we're dealing with an inline string debug('inlining by string: ', inliner.source); + inliner.isFile = true; inliner.url = '.'; var res = { body: new Buffer(inliner.source), diff --git a/package.json b/package.json index 30cb94f..220d2ce 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "scripts": { "cover": "tap test/*.test.js --cov --coverage-report=lcov", "lint": "jscs -v cli/*.js lib/*.js", - "test": "npm run lint && tap test/*.test.js --cov -R spec", + "tap": "tap test/*.test.js --cov -R spec", + "test": "npm run lint && npm run tap", "semantic-release": "semantic-release pre && npm publish && semantic-release post" }, "keywords": [ diff --git a/test/index.test.js b/test/index.test.js index a668bf2..f6fe7f6 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -36,6 +36,17 @@ test('inliner core functions', function coreTests(t) { }); }); +test('inliner handles given source as local', function sourcedTests(t) { + var Inliner = require('../'); + + t.plan(1); + + var content = fs.readFileSync(__dirname + '/fixtures/css-ext-import.src.html', 'utf8'); + new Inliner(content, function (error, content) { + t.equal(error, null, 'treats local content as file'); + }); +}); + test('failures', function failureTests(t) { var Inliner = require('../'); var throwBack = function (e) { return e; };