From 94f9724bcf7d964eef9ccd2456cd8f204a01d05c Mon Sep 17 00:00:00 2001 From: Emanuel Kluge Date: Thu, 8 Mar 2018 15:53:49 +0100 Subject: [PATCH 1/2] fix: use correct options object & set fallback context --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 95eab24..df08ef4 100644 --- a/index.js +++ b/index.js @@ -14,7 +14,7 @@ module.exports = function(source, map) { var options; var emitFile = true; if (queryOptions) { - options = Object.assign({}, queryOptions); + options = Object.assign({ context: process.cwd() }, queryOptions); emitFile = !options.noEmit; delete options.noEmit; } @@ -26,7 +26,7 @@ module.exports = function(source, map) { creator.create(this.resourcePath, source).then(content => { if (emitFile) { // Emit the created content as well - this.emitFile(path.relative(this.options.context, content.outputFilePath), content.contents || [''], map); + this.emitFile(path.relative(options.context, content.outputFilePath), content.contents || [''], map); } content.writeFile().then(_ => { callback(null, source, map); From 36042756ec80c68612d991e286cd41f19fa85023 Mon Sep 17 00:00:00 2001 From: Emanuel Kluge Date: Wed, 11 Apr 2018 12:02:43 +0200 Subject: [PATCH 2/2] fix: retrieve options & context the correct way --- index.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index df08ef4..fbf701b 100644 --- a/index.js +++ b/index.js @@ -10,14 +10,10 @@ module.exports = function(source, map) { // Pass on query parameters as an options object to the DtsCreator. This lets // you change the default options of the DtsCreator and e.g. use a different // output folder. - var queryOptions = loaderUtils.getOptions(this); - var options; - var emitFile = true; - if (queryOptions) { - options = Object.assign({ context: process.cwd() }, queryOptions); - emitFile = !options.noEmit; - delete options.noEmit; - } + var options = loaderUtils.getOptions(this) || {}; + var context = options.context || this.context || this.rootContext; + var emitFile = !options.noEmit; + delete options.noEmit; var creator = new DtsCreator(options); @@ -26,7 +22,7 @@ module.exports = function(source, map) { creator.create(this.resourcePath, source).then(content => { if (emitFile) { // Emit the created content as well - this.emitFile(path.relative(options.context, content.outputFilePath), content.contents || [''], map); + this.emitFile(path.relative(context, content.outputFilePath), content.contents || [''], map); } content.writeFile().then(_ => { callback(null, source, map);