Skip to content

Commit

Permalink
remove unused bin, format with prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Jan 16, 2023
1 parent cb063fa commit f4ad8c1
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 91 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
!.gitattributes
!/tsconfig*.json
!/fixup.sh
!/.prettierignore
9 changes: 9 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/node_modules
/example
/.github
/dist
.env
/tap-snapshots
/.nyc_output
/coverage
/benchmark
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ Export hybrid module with TypeScript types.

## 1.0

Full rewrite. Essentially a brand new module.
Full rewrite. Essentially a brand new module.

- Return a promise instead of taking a callback.
- Use native `fs.mkdir(path, { recursive: true })` when available.
- Drop support for outdated Node.js versions. (Technically still works on
- Drop support for outdated Node.js versions. (Technically still works on
Node.js v8, but only 10 and above are officially supported.)

## 0.x
Expand Down
68 changes: 0 additions & 68 deletions bin/cmd.js

This file was deleted.

25 changes: 13 additions & 12 deletions readme.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const { mkdirp } = require('mkdirp')

// return value is a Promise resolving to the first directory created
mkdirp('/tmp/foo/bar/baz').then(made =>
console.log(`made directories, starting with ${made}`))
console.log(`made directories, starting with ${made}`)
)
```

Output (where `/tmp/foo` already exists)
Expand Down Expand Up @@ -54,8 +55,8 @@ or number, it will be treated as the `opts.mode`.
If `opts.mode` isn't specified, it defaults to `0o777`.

Promise resolves to first directory `made` that had to be
created, or `undefined` if everything already exists. Promise
rejects if any errors are encountered. Note that, in the case of
created, or `undefined` if everything already exists. Promise
rejects if any errors are encountered. Note that, in the case of
promise rejection, some directories _may_ have been created, as
recursive directory creation is not an atomic operation.

Expand Down Expand Up @@ -89,13 +90,13 @@ providing an `fs` option that only overrides one of these.

## `mkdirp.manual`, `mkdirp.manualSync`

Use the manual implementation (not the native one). This is the
Use the manual implementation (not the native one). This is the
default when the native implementation is not available or the
stat/mkdir implementation is overridden.

## `mkdirp.native`, `mkdirp.nativeSync`

Use the native implementation (not the manual one). This is the
Use the native implementation (not the manual one). This is the
default when the native implementation is available and
stat/mkdir are not overridden.

Expand All @@ -108,7 +109,7 @@ been overridden by an option.
## native implementation

- If the path is a root directory, then pass it to the underlying
implementation and return the result/error. (In this case,
implementation and return the result/error. (In this case,
it'll either succeed or fail, but we aren't actually creating
any dirs.)
- Walk up the path statting each directory, to find the first
Expand All @@ -120,7 +121,7 @@ been overridden by an option.
## manual implementation

- Call underlying `fs.mkdir` implementation, with `recursive:
false`
false`
- If error:
- If path is a root directory, raise to the caller and do not
handle it
Expand All @@ -135,13 +136,13 @@ been overridden by an option.
## windows vs unix caveat

On Windows file systems, attempts to create a root directory (ie,
a drive letter or root UNC path) will fail. If the root
directory exists, then it will fail with `EPERM`. If the root
a drive letter or root UNC path) will fail. If the root
directory exists, then it will fail with `EPERM`. If the root
directory does not exist, then it will fail with `ENOENT`.

On posix file systems, attempts to create a root directory (in
recursive mode) will succeed silently, as it is treated like just
another directory that already exists. (In non-recursive mode,
another directory that already exists. (In non-recursive mode,
of course, it fails with `EEXIST`.)

In order to preserve this system-specific behavior (and because
Expand All @@ -164,7 +165,7 @@ is encountered.

# choosing a recursive mkdir implementation

There are a few to choose from! Use the one that suits your
There are a few to choose from! Use the one that suits your
needs best :D

## use `fs.mkdir(path, {recursive: true}, cb)` if:
Expand Down Expand Up @@ -216,7 +217,7 @@ needs best :D
- You think vinyl just sounds warmer and richer for some weird
reason.
- You are supporting truly ancient Node.js versions, before even
the advent of a `Promise` language primitive. (Please don't.
the advent of a `Promise` language primitive. (Please don't.
You deserve better.)

# cli
Expand Down
4 changes: 2 additions & 2 deletions src/index-cjs.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import mkdirp from './index.js';
import mkdirp from './index.js'

export = mkdirp;
export = Object.assign(mkdirp, { default: mkdirp })
2 changes: 1 addition & 1 deletion src/mkdirp-native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const mkdirpNative = Object.assign(
return findMade(opts, path).then((made?: string | undefined) =>
opts
.mkdirAsync(path, opts)
.then((m) => made || m)
.then(m => made || m)
.catch(er => {
const fer = er as NodeJS.ErrnoException
if (fer?.code === 'ENOENT') {
Expand Down
6 changes: 1 addition & 5 deletions test/cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ fakeMkdirp.manual = (path: string, opts: MkdirpOptions) =>
fakeMkdirp.mkdirp = fakeMkdirp

if (process.argv[2] === 'RUN') {
process.argv = [
process.execPath,
cmd,
...process.argv.slice(3),
]
process.argv = [process.execPath, cmd, ...process.argv.slice(3)]
t.mock(cmd, {
'../dist/cjs/src/index.js': fakeMkdirp,
'../dist/cjs/package.json': {
Expand Down
5 changes: 4 additions & 1 deletion test/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { mkdir, mkdirSync, statSync } from 'fs'
import t from 'tap'
import mkdirp from '../dist/cjs/src/index.js'
import { MkdirpOptions, MkdirpOptionsResolved } from '../dist/cjs/src/opts-arg.js'
import {
MkdirpOptions,
MkdirpOptionsResolved,
} from '../dist/cjs/src/opts-arg.js'

// node before 10.13 didn't native recursive mkdir
const doNative = !/^v([0-8]\.|10.([0-9]\.|10\.|11\.([0-9]|1[01])$))/.test(
Expand Down

0 comments on commit f4ad8c1

Please sign in to comment.