Skip to content

Commit 94dab12

Browse files
committed
fix($core): cannot read property 'globalLayout' of null (close: #1304)
1 parent b045642 commit 94dab12

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

packages/@vuepress/core/lib/prepare/AppContext.js

+29-7
Original file line numberDiff line numberDiff line change
@@ -296,18 +296,18 @@ module.exports = class AppContext {
296296
themeAgreement
297297
}) {
298298
const siteConfigValue = this.siteConfig[configKey]
299-
siteAgreement = path.resolve(this.vuepressDir, siteAgreement)
299+
siteAgreement = this.resolveSiteAgreementFile(siteAgreement)
300300

301301
const themeConfigValue = this.getThemeConfigValue(configKey)
302-
themeAgreement = this.getThemeAgreementFile(themeAgreement)
302+
themeAgreement = this.resolveThemeAgreementFile(themeAgreement)
303303

304304
return fsExistsFallback([
305305
siteConfigValue,
306306
siteAgreement,
307307
themeConfigValue,
308308
themeAgreement,
309309
defaultValue
310-
])
310+
].map(v => v))
311311
}
312312

313313
/**
@@ -377,17 +377,39 @@ module.exports = class AppContext {
377377
return this.themeEntryFile[key] || this.parentThemeEntryFile[key]
378378
}
379379

380-
getThemeAgreementFile (filepath) {
380+
/**
381+
* Resolve the absolute path of a theme-level agreement file,
382+
* return `undefined` when it doesn't exists.
383+
*
384+
* @param {string} filepath
385+
* @returns {string|undefined}
386+
*/
387+
388+
resolveThemeAgreementFile (filepath) {
381389
const current = path.resolve(this.themePath, filepath)
382390
if (fs.existsSync(current)) {
383391
return current
384392
}
385-
const parent = path.resolve(this.parentThemePath, filepath)
386-
if (fs.existsSync(parent)) {
387-
return parent
393+
if (this.parentThemePath) {
394+
const parent = path.resolve(this.parentThemePath, filepath)
395+
if (fs.existsSync(parent)) {
396+
return parent
397+
}
388398
}
389399
}
390400

401+
/**
402+
* Resolve the absolute path of a site-level agreement file,
403+
* return `undefined` when it doesn't exists.
404+
*
405+
* @param {string} filepath
406+
* @returns {string|undefined}
407+
*/
408+
409+
resolveSiteAgreementFile (filepath) {
410+
return path.resolve(this.vuepressDir, filepath)
411+
}
412+
391413
/**
392414
* Get the data to be delivered to the client.
393415
*

packages/@vuepress/core/lib/prepare/loadTheme.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ module.exports = async function loadTheme (ctx) {
4040
&& (fs.readdirSync(localThemePath)).length > 0
4141

4242
let themePath = null // Mandatory
43-
let themeEntryFile = null // Optional
43+
let themeEntryFile = {} // Optional
4444
let themeName
4545
let themeShortcut
4646
let parentThemePath = null // Optional
47-
let parentThemeEntryFile = null // Optional
47+
let parentThemeEntryFile = {} // Optional
4848

4949
if (useLocalTheme) {
5050
themePath = localThemePath

0 commit comments

Comments
 (0)