make-dir

中文文档
5.1.0发布于 2025/09/11MITTypeScriptES Module零依赖近 30 天下载 5.5亿

Make a directory and its parents if needed - Think mkdir -p

原始使用文档
文档目录8 节
  1. Advantages over fsPromises.mkdir('…', {recursive: true})
  2. Advantages over mkdirp
  3. Install
  4. Usage
  5. API
  6. makeDirectory(path, options?)
  7. makeDirectorySync(path, options?)
  8. Related

make-dir

Make a directory and its parents if needed - Think mkdir -p

[!TIP] You probably want the built-in fsPromises.mkdir('…', {recursive: true}) instead.

Advantages over fsPromises.mkdir('…', {recursive: true})

  • Supports a custom fs implementation.

Advantages over mkdirp

  • Promise API (Async/await ready!)
  • Fixes many mkdirp issues
  • CI-tested on macOS, Linux, and Windows
  • Actively maintained
  • Doesn't bundle a CLI
  • Uses the native fs.mkdir/mkdirSync recursive option in Node.js unless overridden

Install

npm install make-dir

Usage

$ pwd
/Users/sindresorhus/fun
$ tree
.
import {makeDirectory} from 'make-dir';

const path = await makeDirectory('unicorn/rainbow/cake');

console.log(path);
//=> '/Users/sindresorhus/fun/unicorn/rainbow/cake'
$ tree
.
└── unicorn
    └── rainbow
        └── cake

Multiple directories:

import {makeDirectory} from 'make-dir';

const paths = await Promise.all([
    makeDirectory('unicorn/rainbow'),
    makeDirectory('foo/bar')
]);

console.log(paths);
/*
[
    '/Users/sindresorhus/fun/unicorn/rainbow',
    '/Users/sindresorhus/fun/foo/bar'
]
*/

API

makeDirectory(path, options?)

Returns a Promise for the path to the created directory.

makeDirectorySync(path, options?)

Returns the path to the created directory.

path

Type: string | URL

The directory to create.

options

Type: object

mode

Type: integer
Default: 0o777

The directory permissions.

fs

Type: object
Default: import fs from 'node:fs'

Use a custom fs implementation. For example graceful-fs.

Using a custom fs implementation will block the use of the native recursive option if fs.mkdir or fs.mkdirSync is not the native function.

版本与发布记录

make-dir 共发布 13 个版本,首次发布于 2017/05/10;过去 12 个月发布了 0 个版本。

版本发布日期距今
5.1.0latest2025/09/111.1 年前
5.0.02024/05/032 年前
4.0.02023/06/233 年前
3.1.02020/04/226 年前
3.0.22020/02/136 年前
3.0.12020/02/136 年前

关于 make-dir 的常见问题

make-dir 是什么?

Make a directory and its parents if needed - Think mkdir -p

如何安装 make-dir?

在项目目录运行 npm install make-dir,或使用 pnpm add / yarn add / bun add。

make-dir 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

make-dir 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

make-dir 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

make-dir 可以商用吗?

make-dir 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

make-dir 的下载量有多少?

根据 npm 官方下载统计,make-dir 在 2026/10/05 – 2026/11/03 这 30 天内被下载 545,697,697 次,日均约 18,189,923 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

make-dir 还在维护吗?

最新版本 5.1.0 发布于 2025/09/11(1.1 年前);至今共发布 13 个版本,其中过去 12 个月发布了 0 个;首次发布于 2017/05/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。