-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: cache option (boolean | absolute path | relative path)
It also close #993 via including siteConfig.extendMarkdown & siteConfig.markdown.extendMarkdown to cacheIdentifier.
- Loading branch information
Showing
5 changed files
with
96 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
'use strict' | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
const { | ||
path, toAbsolutePath, chalk, logger, | ||
datatypes: { isString, isBoolean } | ||
} = require('@vuepress/shared-utils') | ||
|
||
/** | ||
* Get cache directory and cache identifier via config. | ||
* @param {object} siteConfig | ||
* @param {object} cliOptions | ||
*/ | ||
|
||
exports.getCacheLoaderOptions = function (siteConfig, cliOptions, cwd, isProd) { | ||
const defaultCacheDirectory = path.resolve(__dirname, '../../node_modules/.cache/vuepress') | ||
let cache = cliOptions.cache || siteConfig.cache || defaultCacheDirectory | ||
|
||
if (isBoolean(cache)) { | ||
if (cache === true) { | ||
cache = defaultCacheDirectory | ||
} | ||
} else if (!isString(cache)) { | ||
throw new Error(`expected cache option to be string or boolean, but got ${typeof cache}`) | ||
} | ||
|
||
const cacheDirectory = toAbsolutePath(cache, cwd) | ||
const cacheIdentifier = JSON.stringify({ | ||
vuepress: require('../../package.json').version, | ||
'cache-loader': require('cache-loader/package.json').version, | ||
'vue-loader': require('cache-loader/package.json').version, | ||
isProd, | ||
config: ( | ||
( | ||
siteConfig.markdown | ||
? JSON.stringify(siteConfig.markdown) | ||
: '' | ||
) + | ||
( | ||
siteConfig.markdown && siteConfig.markdown.extendMarkdown | ||
? siteConfig.markdown.extendMarkdown.toString() | ||
: '' | ||
) + | ||
( | ||
siteConfig.extendMarkdown | ||
? siteConfig.extendMarkdown.toString() | ||
: '' | ||
) + | ||
(siteConfig.chainWebpack || '').toString() + | ||
(siteConfig.configureWebpack || '').toString() | ||
) | ||
}) | ||
|
||
logger.debug('\nCache directory: ' + chalk.gray(cacheDirectory)) | ||
logger.debug('\nCache identifier : ' + chalk.gray(cacheIdentifier)) | ||
|
||
return { cacheDirectory, cacheIdentifier } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict' | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
const path = require('upath') | ||
|
||
/** | ||
* Normalize path request to absolute path. | ||
*/ | ||
|
||
module.exports = function toAbsolutePath (raw, cwd = process.cwd()) { | ||
if (path.isAbsolute(raw)) { | ||
return raw | ||
} | ||
return path.resolve(cwd, raw) | ||
} |