From 8ddda9e5958cdf9753eb97192dea7bac95ac8200 Mon Sep 17 00:00:00 2001 From: muji Date: Fri, 27 Jan 2017 14:44:29 +0800 Subject: [PATCH 1/2] Always prefer context filename for root. --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index b3fee4e..6426e7b 100644 --- a/lib/index.js +++ b/lib/index.js @@ -4,7 +4,7 @@ const path = require('path') module.exports = function reshapeLayouts (options = {}) { return function layoutsPlugin (tree, ctx) { options.encoding = options.encoding || 'utf8' - if (!options.root && ctx.filename) { + if (ctx.filename) { options.root = path.dirname(ctx.filename) } options.root = options.root || './' From 87c99ed7c45a8e72e57b1d0cabba787312faa102 Mon Sep 17 00:00:00 2001 From: muji Date: Fri, 27 Jan 2017 14:51:36 +0800 Subject: [PATCH 2/2] Allow options.root override. --- .gitignore | 1 + lib/index.js | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3c3629e..c9106a7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +.nyc_output diff --git a/lib/index.js b/lib/index.js index 6426e7b..b56b111 100644 --- a/lib/index.js +++ b/lib/index.js @@ -2,9 +2,10 @@ const fs = require('fs') const path = require('path') module.exports = function reshapeLayouts (options = {}) { + const root = options.root return function layoutsPlugin (tree, ctx) { options.encoding = options.encoding || 'utf8' - if (ctx.filename) { + if (!root && ctx.filename) { options.root = path.dirname(ctx.filename) } options.root = options.root || './'