From f62b8d2e5706a19b34828952097730d3bbc97809 Mon Sep 17 00:00:00 2001 From: mrodal Date: Sat, 2 Feb 2019 08:18:25 -0300 Subject: [PATCH] Path passed up in the hierarchy is now the one of the current module instead of being always the one from the leaf component --- src/index.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/index.js b/src/index.js index b0e556d..3a02b06 100644 --- a/src/index.js +++ b/src/index.js @@ -27,7 +27,7 @@ const loader = function (source, map) { // To make HMR aware of the base file and reload it when it changes result.ancestorsPaths.forEach(ancestor => { this.addDependency(ancestor); - }) + }); callback(null, result.source, @@ -37,9 +37,9 @@ const loader = function (source, map) { }); }; -const getMergedCode = function (source, initialPath) { +const getMergedCode = function (source, currPath) { return new Promise((resolve, reject) => { - resolveComponent(source, initialPath).then(({source, ancestorsPaths}) => { + resolveComponent(source, currPath).then(({source, ancestorsPaths}) => { // Remove comment lines at beginning of script block that were generated by the SFC parser let finalDescriptor = toDescriptor(source); @@ -65,9 +65,9 @@ const getMergedCode = function (source, initialPath) { reject(error) }); }) -} +}; -function resolveComponent(currentSource, initialPath) { +function resolveComponent(currentSource, currPath) { return new Promise((resolve, reject) => { try { let currentDesc = toDescriptor(currentSource); @@ -76,14 +76,15 @@ function resolveComponent(currentSource, initialPath) { // else return code as is if (currentDesc.template && currentDesc.template.attrs[options.EXTENDS_ATTR]) { let baseRelPath = currentDesc.template.attrs[options.EXTENDS_ATTR]; - let baseAbsPath = path.join(initialPath, baseRelPath); + let baseAbsPath = path.join(currPath, baseRelPath); fs.readFile(baseAbsPath, 'utf8', (err, contents) => { // File read error, reject if (err) reject(err); // Resolve the base component recursively to support inheritance in N levels - resolveComponent(contents, initialPath).then(({source, ancestorsPaths}) => { + let basePath = path.dirname(baseAbsPath); + resolveComponent(contents, basePath).then(({source, ancestorsPaths}) => { try { // Add this ancestor to the ancestors return array ancestorsPaths.push(baseAbsPath);