Skip to content

feat($core): Use mkdtemp for default tempdir #2419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/@vuepress/core/lib/node/createTemp.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const { fs, path, chalk, logger } = require('@vuepress/shared-utils')
const os = require('os')
const process = require('process')

/**
* Create a dynamic temp utility context that allow to lanuch
Expand All @@ -12,7 +14,10 @@ const { fs, path, chalk, logger } = require('@vuepress/shared-utils')

module.exports = function createTemp (tempPath) {
if (!tempPath) {
tempPath = path.resolve(__dirname, '../../.temp')
tempPath = fs.mkdtempSync(path.join(os.tmpdir(), 'vuepress-'))
process.on('exit', _code => {
fs.removeSync(tempPath)
})
} else {
tempPath = path.resolve(tempPath)
}
Expand Down
6 changes: 3 additions & 3 deletions packages/docs/docs/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ Specify the port to use for the dev server.
### temp

- Type: `string`
- Default: `/path/to/@vuepress/core/.temp`
- Default: `/tmp/vuepress-SUFFIX`


Specify the temporary directory for client.
Specify the temporary directory for client. `SUFFIX` is a random suffix generated by `fs.mkdtemp`.

### dest

Expand Down Expand Up @@ -321,7 +321,7 @@ This option is also included in [Plugin API](../plugin/option-api.md#extendmarkd
- Default: `['h2', 'h3']`

While preparing the page, headers are extracted from the Markdown file and stored in `this.$page.headers`. By default, VuePress will extract `h2` and `h3` elements for you. You can override the headers it pulls out in your `markdown` options.

``` js
module.exports = {
markdown: {
Expand Down
6 changes: 3 additions & 3 deletions packages/docs/docs/zh/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ module.exports = {
### temp

- Type: `string`
- Default: `/path/to/@vuepress/core/.temp`
- Default: `/tmp/vuepress-SUFFIX`

指定客户端文件的临时目录。
指定客户端文件的临时目录。`SUFFIX` 是 `fs.mkdtemp` 产生的随机后缀。

### dest

Expand Down Expand Up @@ -317,7 +317,7 @@ module.exports = {
- 默认值: `['h2', 'h3']`

Markdown 文件的 headers (标题 & 小标题) 会在准备阶段被提取出来,并存储在 `this.$page.headers` 中。默认情况下,VuePress 会提取 `h2` 和 `h3` 标题。你可以通过这个选项来修改提取出的标题级别。

``` js
module.exports = {
markdown: {
Expand Down