Skip to content

Commit

Permalink
fix: always resolve pkg root for loadTheme
Browse files Browse the repository at this point in the history
  • Loading branch information
yarastqt committed Apr 15, 2021
1 parent a14e7c3 commit 38846d1
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/core/loadTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ export async function loadTheme(
platforms: ['common'],
}
const theme: InputTheme = await readJSON(source)

// In case with node_modules in cwd need resolve all sources from package root.
root = root.match(/node_modules/) === null ? root : findPackageRoot(root)
const packageRootPath = findPackageRoot(root)

if (theme.extends !== undefined) {
const parentThemePath = resolveFrom(root, theme.extends)
const parentThemePath = resolveFrom(packageRootPath, theme.extends)
if (parentThemePath && existsSync(parentThemePath)) {
const parentThemeCwd = dirname(parentThemePath)
const parentTheme = await loadTheme(parentThemePath, parentThemeCwd)
Expand All @@ -38,7 +36,7 @@ export async function loadTheme(
}

if (theme.mappers !== undefined) {
derivedTheme.mappers.push(...theme.mappers.map((filePath) => join(root, filePath)))
derivedTheme.mappers.push(...theme.mappers.map((filePath) => join(packageRootPath, filePath)))
}

if (theme.whitepaper !== undefined) {
Expand All @@ -47,7 +45,7 @@ export async function loadTheme(

for (const source of theme.sources) {
// Makes array of arrays with each source for save order after glob.
derivedTheme.sources.push([resolve(root, source)])
derivedTheme.sources.push([resolve(packageRootPath, source)])
}

return derivedTheme
Expand Down

0 comments on commit 38846d1

Please sign in to comment.