Skip to content

Commit

Permalink
fix($core): cannot read property 'globalLayout' of null (close: #1304)
Browse files Browse the repository at this point in the history
  • Loading branch information
ulivz committed Feb 17, 2019
1 parent b045642 commit 94dab12
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
36 changes: 29 additions & 7 deletions packages/@vuepress/core/lib/prepare/AppContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,18 +296,18 @@ module.exports = class AppContext {
themeAgreement
}) {
const siteConfigValue = this.siteConfig[configKey]
siteAgreement = path.resolve(this.vuepressDir, siteAgreement)
siteAgreement = this.resolveSiteAgreementFile(siteAgreement)

const themeConfigValue = this.getThemeConfigValue(configKey)
themeAgreement = this.getThemeAgreementFile(themeAgreement)
themeAgreement = this.resolveThemeAgreementFile(themeAgreement)

return fsExistsFallback([
siteConfigValue,
siteAgreement,
themeConfigValue,
themeAgreement,
defaultValue
])
].map(v => v))
}

/**
Expand Down Expand Up @@ -377,17 +377,39 @@ module.exports = class AppContext {
return this.themeEntryFile[key] || this.parentThemeEntryFile[key]
}

getThemeAgreementFile (filepath) {
/**
* Resolve the absolute path of a theme-level agreement file,
* return `undefined` when it doesn't exists.
*
* @param {string} filepath
* @returns {string|undefined}
*/

resolveThemeAgreementFile (filepath) {
const current = path.resolve(this.themePath, filepath)
if (fs.existsSync(current)) {
return current
}
const parent = path.resolve(this.parentThemePath, filepath)
if (fs.existsSync(parent)) {
return parent
if (this.parentThemePath) {
const parent = path.resolve(this.parentThemePath, filepath)
if (fs.existsSync(parent)) {
return parent
}
}
}

/**
* Resolve the absolute path of a site-level agreement file,
* return `undefined` when it doesn't exists.
*
* @param {string} filepath
* @returns {string|undefined}
*/

resolveSiteAgreementFile (filepath) {
return path.resolve(this.vuepressDir, filepath)
}

/**
* Get the data to be delivered to the client.
*
Expand Down
4 changes: 2 additions & 2 deletions packages/@vuepress/core/lib/prepare/loadTheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ module.exports = async function loadTheme (ctx) {
&& (fs.readdirSync(localThemePath)).length > 0

let themePath = null // Mandatory
let themeEntryFile = null // Optional
let themeEntryFile = {} // Optional
let themeName
let themeShortcut
let parentThemePath = null // Optional
let parentThemeEntryFile = null // Optional
let parentThemeEntryFile = {} // Optional

if (useLocalTheme) {
themePath = localThemePath
Expand Down

0 comments on commit 94dab12

Please sign in to comment.