From 4d15003993bcb40d5735b69060ceb202a885f797 Mon Sep 17 00:00:00 2001 From: David Shepherd Date: Thu, 17 May 2018 10:45:19 +0100 Subject: [PATCH 1/2] Improve error reporting for bad relative paths --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 77a4e6c..f7da0b1 100644 --- a/index.js +++ b/index.js @@ -35,7 +35,7 @@ module.exports = function (content) { var relativeToIndex = resource.indexOf(relativeTo); if (relativeToIndex === -1 || (absolute && relativeToIndex !== 0)) { - throw new Error('The path for file doesn\'t contain relativeTo param'); + throw new Error('The path for file "' + resource + '" doesn\'t contain relativeTo param "' + relativeTo + '".'); } // a custom join of prefix using the custom path sep From 836ee17472d00508a6e324378d33af5b3167b43d Mon Sep 17 00:00:00 2001 From: David Shepherd Date: Thu, 17 May 2018 11:01:23 +0100 Subject: [PATCH 2/2] Allow relativeTo parent directories --- index.js | 2 +- test/src/entry.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index f7da0b1..efc71b8 100644 --- a/index.js +++ b/index.js @@ -7,7 +7,7 @@ module.exports = function (content) { var options = loaderUtils.getOptions(this) || {}; var ngModule = getAndInterpolateOption.call(this, 'module', 'ng'); // ng is the global angular module that does not need to explicitly required - var relativeTo = getAndInterpolateOption.call(this, 'relativeTo', ''); + var relativeTo = path.normalize(getAndInterpolateOption.call(this, 'relativeTo', '')); var prefix = getAndInterpolateOption.call(this, 'prefix', ''); var requireAngular = !!options.requireAngular || false; var absolute = false; diff --git a/test/src/entry.js b/test/src/entry.js index ee06d99..4798c7b 100644 --- a/test/src/entry.js +++ b/test/src/entry.js @@ -15,6 +15,7 @@ console.log(require('../../index.js?relativeTo=/test/src/!html-loader!./test.htm console.log(require('../../index.js?relativeTo=src/!html-loader!./test.html')); console.log(require('../../index.js?relativeTo=' + __dirname + '/!html-loader!./test.html')); console.log(require('../../index.js?relativeTo=/' + __dirname + '/!html-loader!./test.html')); +console.log(require('../../index.js?relativeTo=' + __dirname + '/../!html-loader!./test.html')); console.log(require('../../index.js?prefix=/prefix!html-loader!./test.html')); console.log(require('../../index.js?prefix=/prefix/&relativeTo=/' + __dirname + '/!html-loader!./test.html')); console.log(require('../../index.js?module=[name]&prefix=[folder]&relativeTo=[path]!html-loader!./test.html'));