Skip to content

Commit

Permalink
Path passed up in the hierarchy is now the one of the current module …
Browse files Browse the repository at this point in the history
…instead of being always the one from the leaf component
  • Loading branch information
mrodal committed Feb 2, 2019
1 parent e69fad2 commit f62b8d2
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit f62b8d2

Please sign in to comment.